Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Summing repeated counts for items stored in separate file

by DigitalKitty (Parson)
on Jul 28, 2007 at 03:54 UTC ( [id://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

Replies are listed 'Best First'.
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

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 11:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found