Perl Monk, Perl Meditation | |
PerlMonks |
Re: C idioms in Perlby Anno (Deacon) |
on Sep 05, 2007 at 23:18 UTC ( [id://637289]=note: print w/replies, xml ) | Need Help?? |
I agree that the use of a scalar reference to keep track of a hash value looks like a something a C programmer would do. In general, scalar references are rarely used in Perl (they do have their place). In this case, knowing the hash(ref) and the key is good enough. Declaring all the variables near the beginning of a sub is another C-ism. Most of the time it is possible, and preferrable, to declare variables where they are first used.
The fact that the input format uses a fixed string "</TEMPLATE>" as a terminator allows for reading one record per input-operation. That way there is no need for line-assemblage to build up the hash value. Each round in the read loop processes one template. In the code I'm using the DATA filehandle instead of opening the given file. Note the slight modification in the name-extracting regex. I have made it match trailing whitespace, so that the index $+[0] (for @- and @+ see perlvar) points to the first valid character of the template text. Anno
In Section
Seekers of Perl Wisdom
|
|