Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: seek and process from there on

by rminner (Chaplain)
on May 30, 2006 at 13:52 UTC ( [id://552493]=note: print w/replies, xml ) Need Help??


in reply to seek and process from there on

my $file = shift @ARGV; if (open my $FH , $file) { my $start_pattern_found = 0; while (my $line = <$FH>) { if ($start_pattern_found and $line =~ m{^need\s+this}) { print "found: $line"; } elsif ($line =~ m{^internal\s+name}) { $start_pattern_found++; } } close $FH; } else { die "failed to open '$file' ($!)\n"; }

Replies are listed 'Best First'.
Re^2: seek and process from there on
by blazar (Canon) on May 30, 2006 at 14:06 UTC
    my $file = shift @ARGV; if (open my $FH , $file) { my $start_pattern_found = 0; while (my $line = <$FH>) {

    It's a side note, but I can't understand why you do this. You just want to show the use of a flag, which is a good point. Since the example may very well stay minimal, why not using good old <> instead?

    In any case, using the range operator in scalar context may be much easier than maintaining a flag yourself:

    while (<>) { chomp; next if 1 .. /^internal name/; print "Found pattern at line $.\n" if /^need this/; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://552493]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-24 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found