Pant, Hridyesh <mailto:[EMAIL PROTECTED]> wrote:

: Why are u using this.
: local $/ = "\n\n";

    Because I'm cocky! :)


    $/ is a special perl variable which is used to define the
input record separator. It is set to "\n" as a default. By
resetting it to "\n\n", I was able to get two lines at a time.
This is because Jeff's data looked like this:

356.5
192.168.2.20

283.3
192.168.2.21

261.9
192.168.2.22

        Another way look at that is like this.

356.5\n192.168.2.20\n\n283.3\n192.168.2.21\n\n261.9\n192.168.2.22\n\n

        If we tell perl that the input record separator is "\n\n", we
end up with these values as we loop through the file.

356.5\n192.168.2.20\n\n
283.3\n192.168.2.21\n\n
261.9\n192.168.2.22\n\n

    "chomp" uses the input record separator also. So chomping
these values gives us this.

356.5\n192.168.2.20
283.3\n192.168.2.21
261.9\n192.168.2.22


    I didn't have to use m// to split these, but Jeff was set on
it. "split" would also work. (It works on "$_" by default.)

use strict;
use warnings;

local $/ = "\n\n";
while ( <DATA> ) {
    chomp;
    printf "%-5s% 15s\n", split "\n";
}

__END__

    For clarity, that is logically the same as this.
    
local $/ = "\n\n";
while ( defined $_ = <DATA> ) {
    chomp $_;
    printf "%-5s% 15s\n", split "\n", $_;
}

__END__


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to