http://www.perlmonks.org?node_id=75911


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.