[ic] Mike H, one step at a time

Jon Jensen interchange-users@interchange.redhat.com
Wed Mar 20 15:24:00 2002


On Wed, 20 Mar 2002, Steffen Dettmer wrote:

> * Paul Jordan wrote on Tue, Mar 19, 2002 at 20:23 -0800:
> > >         my $docroot = $opt->{document_root} || $::Variable->{DOCROOT};
> > >         my $server  = $opt->{server}   || $::Variable->{SERVER_NAME};
> >
> > Well, When I restarted interchange, I got some barewords errors, See I
> > substituted www.imagemogul.com for SERVER_NAME.
>
> Try $::Variable->{'SERVER_NAME'}; SERVER_NAME is a string used as key
> in a hashmap and here it seems to be undefined, and Perl doesn't know
> if you mean a sub function or a string or what, since it's just a bare
> word. Quoting is the correct usage of strings always, but if
> SERVER_NAME if undefined, $server is undefined.

$::Variable->{SERVER_NAME} is fine, according to perlfaq7:

Do I always/never have to quote my strings or use semicolons and commas?

Normally, a bareword doesn't need to be quoted, but in most cases probably
should be (and must be under "use strict"). But a hash key consisting of a
simple word (that isn't the name of a defined subroutine) and the
left-hand operand to the "=>" operator both count as though they were
quoted:

           This                    is like this
           ------------            ---------------
           $foo{line}              $foo{"line"}
           bar => stuff            "bar" => stuff

Jon