Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: reading array elements

by moritz (Cardinal)
on Nov 26, 2008 at 08:57 UTC ( [id://726041]=note: print w/replies, xml ) Need Help??


in reply to reading array elements

1. this script jumps to the 2nd line/record in the file instead of processing from the first line.
Sure it does, because you read one line before the loop, in line 5 of your script. So the loop never sees the first line of cdata.txt
2. Another issue is that accessing the elements using even numbers doesn't work, only odd numbers can be used to retrieve the elements, eg. when $i = 7

Care to explain what "doesn't work" mean? Does a ninja attack you from behind every time you try? Or does your computer blow up?

Please note that since you declared my $i inside the while loop, its value is reset in every iteration - probably not what you want. The special variable $. contains the line number of the input file handle, maybe that helps you.

And what do you think the next is doing in line 15?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-18 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found