NovMonk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Processing lines after a pattern in a while loop
by broquaint (Abbot) on Apr 05, 2004 at 16:36 UTC | |
Re: Processing lines after a pattern in a while loop
by kvale (Monsignor) on Apr 05, 2004 at 16:38 UTC | |
by tilly (Archbishop) on Apr 05, 2004 at 17:42 UTC | |
by halley (Prior) on Apr 06, 2004 at 14:41 UTC | |
Re: Processing lines after a pattern in a while loop
by ysth (Canon) on Apr 05, 2004 at 16:37 UTC | |
Re: Processing lines after a pattern in a while loop
by Limbic~Region (Chancellor) on Apr 05, 2004 at 16:34 UTC | |
by tilly (Archbishop) on Apr 05, 2004 at 17:47 UTC | |
by talexb (Chancellor) on Apr 05, 2004 at 17:58 UTC | |
by Happy-the-monk (Canon) on Apr 05, 2004 at 16:49 UTC |