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.


In reply to Re: File Parsing by mpeg4codec
in thread File Parsing by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.