in reply to my $var = ''; vs. use constant VAR => '';
You could always convert this to a hash-structure, such as:my ($filename) = "/path/to/file"; my ($filemode) = "immolate"; my ($opmode) = "seek"; my ($filetype) = "image/gif";
This has the advantage of allowing you to declare virtually unlimited constants, without having to explicitly declare them on their own my() line. Additionally, you can load these from a file quickly and easily (i.e. an INI-type file, an Apache-style file, or something else) such that you can vary the configuration without modifying the program itself.my (%config) = ( filename => "/path/to/file", filemode => "immolate", opmode => "seek", filetype => "image/gif", );
In this admittedly simple example, the hash is only used once, and the variable itself is repeatedly used.my ($thing) = $config{'thing_to_mash'}; for (my $x = 0; $x < 100_000_000; $x++) { DoCrazyStuff($thing, $x, Foo($x)); }
|
---|
Replies are listed 'Best First'. | |
---|---|
scalar my vs list my
by merlyn (Sage) on Apr 27, 2001 at 01:11 UTC | |
by tadman (Prior) on Apr 27, 2001 at 01:47 UTC | |
by merlyn (Sage) on Apr 27, 2001 at 01:50 UTC | |
by $code or die (Deacon) on Apr 27, 2001 at 01:56 UTC | |
by tadman (Prior) on Apr 27, 2001 at 02:12 UTC |