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

Re: File Parsing

by mpeg4codec (Pilgrim)
on Aug 22, 2004 at 20:51 UTC ( #384969=note: print w/replies, xml ) Need Help??

in reply to File Parsing

If you know what line the word is on and the file is in an array, you can work with that specific line. Let's say it's on line four and the file had been read into the array @file. To just work with line four, you'd have to work with the value $file[3]. Remember that Perl starts numbering line one as zero.

As for the location of the word on that line, if you know which word (in terms of the number of the word) it is, you can again make use of an array. Again, working with line four:

my @words = split(/\s/,$file[3]);

Perl numbers the first word as word zero, and so forth. So, if it were say, the ninth word, the value would be stored in $words[8].

If you don't know its position relative to other words, but do know that it's characters seven through ten on the line, for instance, you could make use of substr. Perl again starts the numbering at zero, so:

my $word = substr($file[3], 6, 3); # The third argument to substr is the length of the string

If this doesn't help, clarify it a bit, and I'll see what I can do. Good luck.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://384969]
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2017-05-26 16:09 GMT
Find Nodes?
    Voting Booth?