Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

(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).


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?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2015-11-27 08:57 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (722 votes), past polls