Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

(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 surveying the Monastery: (6)
As of 2014-12-29 11:18 GMT
Find Nodes?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?

    Results (186 votes), past polls