in reply to Print 4 Lines below matching criteria

The following might get you started. Cheers.
use strict; use warnings; while (my $line = <DATA>) { if ($line =~ /^id:\d+/) { for (1 .. 4) { my $following = <DATA>; print $following; } } }
__END__ John, Doe Michael id:1234567890123 library:ACME City, state:PUEBLO, CO Phone:719-555-555 Street:1610 Sorrow AVE APT D Zip: 81004 Shakespeare, William id:4567890123999 library:Fisher Fine Arts Library City, state:Philadelphia, PA Phone:215-898-8325 Street:Locust Zip: 19104
prints:
City, state:PUEBLO, CO Phone:719-555-555 Street:1610 Sorrow AVE APT D Zip: 81004 City, state:Philadelphia, PA Phone:215-898-8325 Street:Locust Zip: 19104

Update: Sorry, jbert, your post was not on yet when I started.

Replies are listed 'Best First'.
Re^2: Print 4 Lines below matching criteria
by johngg (Canon) on Nov 16, 2006 at 11:30 UTC
    I tend to use scalar file reads when appropriate so as to avoid temporary variables so I would write your

    for (1 .. 4) { my $following = <DATA>; print $following; }

    like this

    print scalar <DATA> for 1 .. 4;

    It just looks a little cleaner to me.

    Cheers,

    JohnGG

Re^2: Print 4 Lines below matching criteria
by Anonymous Monk on Nov 16, 2006 at 10:41 UTC
    Small issue with your program: it will generate warnings if there's an 'id:' string in the last 4 lines of the file, as it will try to read past the end of the file.