in reply to Re: Re: Re: Re: Re: opening a file in a subroutine
in thread opening a file in a subroutine

WOOOOOOWWWW !!!!!

the call local $/; did the magic!!! as soon as I put that into my function my code is flying now.

Thank you so much for the slurp function .... Now its really really fast!!!

BTW, what did it do? I don't understand the meaining of local $/?

regards,
Abhishek.
  • Comment on Re: Re: Re: Re: Re: Re: opening a file in a subroutine

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: Re: opening a file in a subroutine
by demerphq (Chancellor) on Feb 09, 2003 at 17:20 UTC
    Er, hold on there... Dont be too hasty.

    $/ is the end of record seperator. It defaults to "\n".

    What my code, which is in essence

    my @list=split /\n/,do {local $/; <$fh>};
    does is to read the whole file into a buffer then split it up by newlines and then return them, which should be more or less the same as
    my @list=<$fh>;
    (at least under default conditions) but obviously isn't on AS 5.6.

    I hope you didnt do it naively as otherwise youll only have one entry in the array, which will contain the whole file.

    --- demerphq
    my friends call me, usually because I'm late....

      Thanks again,
      I modified my code to
      local $/; open my $fh, "xml.log"; my $line = <$fh>; close ($fh);

      Now I have the whole file in $line and I extract all the data which I want from regular expressions. My code is working as expected and is very very fast.

      regards,
      Abhishek.