Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
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 exploiting the Monastery: (9)
As of 2015-07-03 17:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (54 votes), past polls