It looks like you pasted together a couple bits of code that do something similar to what you're trying to do, but together they don't actually work, and they're really not what you want anyway. You could do this task by slurping the entire file into a single string and then stepping through it by using a //g regex in a while test, but it'd look more like this:

while($huge_multi_line_string =~ /ccParty<(\S+)> Port<(\S+)> DTMF<(\S+ +)>/g){ # do something with $1, $2, and $3 }

But don't do that, because that's an ugly way to do it, especially with large files, since it means pulling the whole file into memory. You don't want to do that unless it's necessary, and it's not in your case. Start by thinking through your problem, and how you'd solve it logically, before getting into the code. Write pseudo-code if you have to. You've got a bunch of lines, and you want to pick out the lines that contain certain strings. So your logic will be:

open the file while there are more lines, get a line if the line matches certain strings do something with it close the file

Then it's just a matter of turning it into code. In perl, "while there are more lines, get a line" is normally done by using <angle brackets> around a filehandle in a while test. This returns one line from the filehandle to a scalar variable, or to $_ if you didn't specify a variable. Then within your while loop, you can use a regex (or regexes) to see if your line matches your requirements. A little time spent reading about using a while loop to read a file line-by-line, and some more time spent in perlretut, and you should be close, at least.

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.


In reply to Re^2: Perl = Greek to me by aaron_baugher
in thread Perl = Greek to me by smolikmd

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.