Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Moving to next iteration of a while loop

by trippledubs (Chaplain)
on Sep 24, 2013 at 01:25 UTC ( #1055419=note: print w/replies, xml ) Need Help??

in reply to Moving to next iteration of a while loop

Okay I think I know what you meant. In your earlier Search file for certain lines post the monks told you to use a state machine so you were using $check%2 == 1.

When it doubt, spell it out! Be more explicit if it helps you think it through

#!/usr/bin/env perl use strict; use warnings; my $state = 0; sub change_state { my $state = shift; return 1 if $state == 0; return 0 if $state == 1; die "epic fail" } sub read_between_hs { my $line=shift; if ($line =~ /^(j|E|G)/) { print $line; } } while (<DATA>) { my $line = $_; $state = change_state($state) if ($line =~ /^h/); read_between_hs($line) if ($state); } __DATA__ h start printing x dontprintme a dontprintme G printme j printme E printme h stop printing j not between hs should not print E dont print me G dont print me h start printing definitely printable j ahh back to not being ignored G print E print e print -- just kidding h stop printing

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055419]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (13)
As of 2018-06-19 16:19 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (114 votes). Check out past polls.