Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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]
Discipulus is lazily looking his automated migration in backgound and has lot of free tiime..
Discipulus 'Thou art so fat-witted with drinking of old sack..' ++Shakespeare

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-11-23 11:33 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (334 votes). Check out past polls.