Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

(Ovid constants) Re: my $var; vs. use constant VAR = '';

by Ovid (Cardinal)
on Apr 27, 2001 at 01:08 UTC ( #75911=note: print w/ replies, xml ) Need Help??


in reply to my $var = ''; vs. use constant VAR => '';

The second method is better defensive programming. However, what it does is pretty much equivalent to the following:

BEGIN { sub FILENAME() { '/path/to/file/to/munge' } }
Because FILENAME is actually a subroutine, it cannot be interpolated in quotes. In other words, the following are not synonymous:
my $filename = "/path/to/file/to/munge"; print "$filename"; use constant FILENAME => '/path/to/file/to/munge'; print "FILENAME";
The first example prints the filename, the second just prints "FILENAME".

That's a minor issue, but it does crop up from time to time (particularly when I'm writing an open X, Y or die statement).

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


Comment on (Ovid constants) Re: my $var; vs. use constant VAR = '';
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://75911]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2014-09-18 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (115 votes), past polls