Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^4: Counting keys in a hash

by cspctec (Sexton)
on Nov 20, 2012 at 14:05 UTC ( [id://1004719]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Counting keys in a hash
in thread Counting keys in a hash

I'm sorry to keep bugging you NetWallah, but I'm still getting the uninitialized value error.

I can't figure out why its still giving me the error. I have my original text file with all of the data dumped into an array and my code looks like this:

while (@log) { <code here> }

The array @log contains my data. The loop will still work if the data is in an array, won't it? When the code is run, it continually throws the uninitialized value error until I Ctrl^C to stop it. It never leaves the loop.

I'm going to continue to work on it because your output looks exactly how I need it to look... If you have anymore suggestions let me know.

UPDATE: Its working now... I had to change the while to a foreach because it is an array and not a filehandle... I may be able to figure this out by myself, but is there a way to make it display the device on every output instead of just the first one?

Replies are listed 'Best First'.
Re^5: Counting keys in a hash
by Athanasius (Archbishop) on Nov 20, 2012 at 14:50 UTC
    The loop will still work if the data is in an array, won't it?

    No, the diamond operator <> is special. In the original loop:

    while (<DATA>) {

    one line is read on each iteration, and the loop continues until <DATA> returns undef to signal that the data accessed via the filehandle (DATA in this case) has all been read in.

    But if you have your data in an array (presumably one line per element), you need a for loop (also spelled foreach — they’re the same):

    for (@log) { <code here> }

    which iterates over the array until each element has been processed.

    (Note that in both loops, the line/element read in on a single iteration is stored in the special variable $_.)

    Hope that helps,

    Athanasius <°(((><contra mundum

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-19 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found