develooper Front page | perl.beginners | Postings from May 2008

Re: another help on input record separator clarity please

Thread Previous
From:
Richard Lee
Date:
May 2, 2008 15:21
Subject:
Re: another help on input record separator clarity please
Chas. Owens wrote:
> On Fri, May 2, 2008 at 5:55 PM, Richard Lee <rich.japh@gmail.com> wrote:
> snip
>   
>>  while (<FH>) {
>>    local $/ = "\n\n";
>>     
> snip
>   
>>  }
>>     
> snip
>
> You want $/ to have an effect on <FH>, but it is localized to inside
> of the loop.  You need to say
>
> {
>     local $/ = "\n\n";
>     while (<FH>) {
>     }
> }
>
>   
thanks..

works for me,


#!/usr/bin/perl

use strict;
use warnings;

open "FH", "<", "/tmp/fgg", or die "cannot $!\n";

my @yahoo;
my $count;

{
   local $/ = "\n\n";
   while (<FH>) {
    ++$count;

    #my $fgh =~ /fgh\s+(\S+)/;
    my ($f,$i,$l);
    if (/fgh\s+(\d+)/smx) {
           $f = $1;
    }
    if (/ijk\s+(\S+)/smx) {
           $i = $1;
    }
    if (/lmn\s+(\S+)/smx) {
           $l = $1;
    }
 
    push @yahoo, join('_', $f, $i, $l);
   }
}

for (@yahoo)  {
    print "$_\n";
}
[root@server tmp]# cat fgg
abc
def
fgh 111
ijk 333
lmn 2

abc
def
fgh 222
ijk 121
lmn 23
[root@wks-86-96 tmp]# ./f_this.pl
111_333_2
222_121_23

Thread Previous


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About