Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Summing repeated counts for items stored in separate file

by DigitalKitty (Parson)
on Jul 28, 2007 at 03:54 UTC ( #629250=note: print w/ replies, xml ) Need Help??


in reply to Summing repeated counts for items stored in separate file

Hi dmorgo.

Perhaps a minor point but I felt as though declaring lexical variables in a 'collective fashion':

my ( $key,$value ); # or... my ( %tips_by_name, %av_by_name, %max_by_name, %min_by_name );

might lead to a state of frustration at some point. If one wishes to initialize one of the variables listed, it would be inconvenient to do so. Instead, I would advocate structuring your code like this:

my $key = ''; my $value = ''; my %tips_by_name = ''; my %av_by_name = ''; my %max_by_name = ''; my %min_by_name = '';


Initializing one or more of the variables listed above to another value would now be trivial.

Hope this helps,
~Katie


Comment on Re: Summing repeated counts for items stored in separate file
Select or Download Code
Re^2: Summing repeated counts for items stored in separate file
by mrpeabody (Friar) on Jul 28, 2007 at 04:41 UTC
    Initializing a variable in dmorgo's code would also be trivial. Your suggestion forces the programmer to do a lot of extra typing up front in order to maybe save a small amount of typing later, which seems like a poor tradeoff.

    I would also argue that dmorgo's code has a clarity advantage in that it is immediately obvious which variables don't have default values and which do.

Re^2: Summing repeated counts for items stored in separate file
by Anno (Deacon) on Jul 28, 2007 at 16:58 UTC
    Why on earth would you do that?

    The scalars $keys and $value don't need initialization, but initializing to an empty string at least makes sense. Initializing a hash as in

    my %tips_by_name = '';
    is, pardon the bluntness, plain nonsense. Under warnings, Perl warns about it.

    Anno

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://629250]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2014-07-12 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls