Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Parsing/regex question

by superfrink (Curate)
on Jul 06, 2009 at 18:39 UTC ( #777632=note: print w/replies, xml ) Need Help??

in reply to Parsing/regex question

What do you want the script to do when it encounters a "has rolled into" line? eg: skip the line and the following line or two?

You could set a variable used to keep state when a line matches and at the top of the loop skip lines if the variable is set. Here is some sample completely un-tested code:
my $lines_to_skip = 0; LINE: while (<MSOUT>) { if (0 < $lines_to_skip) { $lines_to_skip --; next LINE; } ... if ($line =~ /^(Position|Spot|Mark) has rolled into$/)) { $lines_to_skip = 1; next LINE; } }

Replies are listed 'Best First'.
Re^2: Parsing/regex question
by vxp (Pilgrim) on Jul 06, 2009 at 18:43 UTC

    When the script encounters a "Position has rolled into" line it should skip everything up to the datestamp, and place that datestamp into a $position_rolled_into var

    Same goes for the "spot/mark has rolled into" :)

      should skip everything up to the datestamp

      oops, missed the "---" line. Adding one line of code addresses that:

      my $position_rolled = 0; while (<$fh>) { chomp; if ($position_rolled) { next if !/^... .\d 20\d\d/; $position_rolled = 0; $position_rolled_into = $_; } elsif ($_ eq 'Position has rolled into') { $position_rolled = 1; } ... }
      Then in the while loop you can do something like this:
      ... if (0 < $lines_to_skip) { if ($line =~ /datestamp-regex/) { next LINE; } # we are at the next date stamp line so fall through, etc. } ...
      Also rename $lines_to_skip to something suitable.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://777632]
[LanX]: Moma knows best! ;-)
[Your Mother]: I am quite aware that Module::Build is MUCH more in favor with many monks but I had trouble with it every time I tried to use it and trouble with CPAN stuff that used it too.
[Your Mother]: Take my advice with a grain of salt. I haven't done a new CPAN release in years at this point.
[LanX]: I want to author a new module for CPAN w/o complicated build structure
[LanX]: ther is also Dist::Zilla :-/
[LanX]: How to make a CPAN Module Distribution from 2002
[Your Mother]: Dist::Zilla is kind of the nuclear option. I set it up back in the day but it's really targeted at authors who are managing MANY modules and want to automate everything.
[erix]: perlancar should know ;)
[LanX]: see warning

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-08-18 17:45 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (306 votes). Check out past polls.