Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: how to next line after the pattern in perl

by lidden (Curate)
on Jun 09, 2010 at 19:04 UTC ( #843896=note: print w/replies, xml ) Need Help??


in reply to how to next line after the pattern in perl

Change:
while (<FF>) { next unless /XXXX/; $. += 1; ### obviously this does not work ... print $_ ; }
To:
while (<FF>) { next unless /XXXX/; print <FF>; }
and it should work. (not tested)

Update: it does not work, prints way too much, see moritz and kennethk below.

Replies are listed 'Best First'.
Re^2: how to next line after the pattern in perl
by moritz (Cardinal) on Jun 09, 2010 at 19:14 UTC
    print <FF>; executes the <...> aka readline in list context, and thus prints all the remaining lines in the file.

    Adding a scalar after the print should solve that problem.

    Perl 6 - links to (nearly) everything that is Perl 6.
Re^2: how to next line after the pattern in perl
by ww (Archbishop) on Jun 09, 2010 at 19:19 UTC

    Not quite, lidden, as yours (modified solely to use __DATA__ rather than a file, prints the matching string (not sought by OP), as well as the line thereafter.

    perl 843893.pl XX XXXX 3333 ii XXXX asdfddd

    Testing pays off.

    Update: See moritz' diagnosis and Rx, above.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2023-12-11 12:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (41 votes). Check out past polls.

    Notices?