Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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.

Comment on Re: File Parsing
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2016-05-30 16:27 GMT
Find Nodes?
    Voting Booth?