Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Yet another array problem

by 5mi11er (Deacon)
on Jul 29, 2005 at 16:30 UTC ( #479471=note: print w/replies, xml ) Need Help??


in reply to Yet another array problem

From the line immediately following your commented line "#this works", you attempt to overwrite your array @line1 by splitting the numbers out of @line1, except you've forgotten to specify that you want it to operate on @line1, so instead it's operating on $_.

So, not only is it operating on the wrong variable, it also destroys the array that had the correct information. Overwriting variables like this is not generally a good idea.

If you don't need the intermediate result learn how to chain the operations together, or how to dereference things correctly. I'd suggest placing the data read from the file into a two dimensional array as you're reading it in, rather than keeping the lines as they were read, and then later attempting to split everything out.

-Scott

Replies are listed 'Best First'.
Re^2: Yet another array problem
by Angharad (Pilgrim) on Jul 29, 2005 at 17:26 UTC
    Thanks for the tip.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2020-05-31 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (173 votes). Check out past polls.

    Notices?