perl.org wrote:
> If my Perl contains ${DBI::errstr} I get warnings like this:
> 
> Ambiguous use of ${DBI::errstr} resolved to $DBI::errstr at (eval 20)
> line 284. 
> 
> If my Perl contains $DBI::errstr (without the braces) I don't get
> these warnings.  Is there an explanation for this?

When Perl sees the ${ blah } notation, it's usually expecting "blah" to be a
scalar reference that you're dereferencing. But you're not doing that;
you're just giving the name of a symbol. You should just write it as
$DBI::errstr and leave the braces off.

It's only a warning, because Perl lets you use this notation inside double
quotes where you need to delimit the symbol name. Consider:

   my $package = 'DBI';

   print "The error is $package::errstr\n";    # oops, doesn't work
   print "The error is ${package}::errstr\n";  # that does it

The latter can also be written as:

   print "The error is $package\::errstr\n";

Bottom line is: you only need the braces inside double quotes, and even then
you don't usually need them. They are only used to tell Perl where your
identifier ends. If the identifier name is followed by a character that
can't be part of an identifier name (e.g. the backslash above), it will stop
there and no braces are needed.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to