guzz1 has asked for the wisdom of the Perl Monks concerning the following question:

All, I can't find the answer to this anywhere, and I would
appreciate some help. I'm reading lines out of an address
book file. I know what the last line of each entry is
(there is also a blank line between each entry). I want to
read certain information out of each listing, then perform
some other functions before going on to the next listing.

So I was thinking of using a while loop to do it, but I'm
not sure of the syntax. Trying the "not equal" like this
doesn't work:

while ((substr$_,0,19)<>~/objectclass: person/) {
    ....
}


I could also key off the blank line between listings instead
of the last line of the listing, but right now I'm too fried
to think how. Thanks for your help (and patience!).

Replies are listed 'Best First'.
Re: syntax for while substr
by tachyon (Chancellor) on Apr 16, 2002 at 18:18 UTC

    This sound like a job for $/ the INPUT RECORD SEPARATOR. By default this is "\n" so we read one line at a time. If we set it to "\n\n" then we read in chunks of data until we find two newlines (ie one blank line). Thus:

    { local $/ = "\n\n"; while( my $record = <DATA> ) { print "This is a record:\n", $record; # do stuff with record } } __DATA__ This is a record This is a multiline record This is just another address book record

    Remeber $/ is a global var so localise its effect of you may get some nasty suproses elsewhere in you code.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: syntax for while substr
by CukiMnstr (Deacon) on Apr 16, 2002 at 17:58 UTC
    i think you want
    while ((substr$_,0,19) !~ /objectclass: person/) { ... }

    the "does not match" operator is !~, and not <>~

    hope this helps,