Greeting fellow monks.

I should start by saying I'm still very new to Perl, and that this is only homework in the sense that I am trying to remedy my ignorance. I want to know whether or not something is possible, and where I should go to read and learn more.

Here's my situation: I have an input file with some junk at the top of it, and then some lines I want to do something with. I know the last line of junk contains a certain pattern. What I wanted to do was tell Perl to start doing stuff after it read the line with that pattern in it. But I'm not sure how to do that within the while loop, or even if that's possible.

What I ended up doing, because I knew how, was to identify and skip the junk lines (all of which begin with either "qcp" or "#", or are blank) and then process all the other lines the way I wanted to, thus:

#!/usr/bin/perl use warnings; use strict; my ($vars); while <DATA>{ if (/^qcp|^\#|^\s?\n/){} else {do stuff here} } __DATA__ #data... qcp_junk qcp_more junk #cardtype... NOT_JUNK NOT_JUNK etc....

If I know that #cardtype Always begins the last line of junk, what could I do instead?

Thanks for any insight or wisdom you care to offer.

Pax,

NovMonk


In reply to Processing lines after a pattern in a while loop by NovMonk

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.