Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

(jeffa) Re: Finding the size of an array in a hash?

by jeffa (Bishop)
on Feb 10, 2003 at 15:36 UTC ( #234147=note: print w/replies, xml ) Need Help??


in reply to Finding the size of an array in a hash?

Hofmater set you straight, but i feel inclined to offer two more tips:
  1. push @{$FULLLINES{$account}}, “$lines”;
    Don't put quotes around $lines -- this is habit that will get you into trouble when you start dealing with references. Besides, the quotes are completely superficial since they will allow the contents to evaluate to the ... contents, namely, the variable $lines. Use this instead:
    push @{$FULLLINES{$account}}, $lines;
  2. Learn how to format. Get a copy of PerlTidy if you have to. Having to count braces to determine where scope starts and ends is no fun for an experienced programmer. If you want to play with the big dogs, dress the part!
Here is your above code, reformatted for clarity and corrected (you left out the closing brace for the very first foreach).
foreach $key ( sort keys %FULLLINES ) { $CCOUNT = 0; print "key = $key\n"; next if $key eq "N/A"; $CCOUNT++ for @{$FULLLINES{$key}}; $num = $CCOUNT; if ( $num <= 1 ) { print "account number for $key listed $num times\n"; } else { print "Account $key is listed:$num times\n"; } }
Oh yeah .... one more tip: USE STRICT! ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2018-11-17 00:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (200 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!