develooper Front page | perl.beginners | Postings from July 2003

Re: Pipe Delimited File

Thread Previous | Thread Next
From:
Rob Dixon
Date:
July 30, 2003 08:50
Subject:
Re: Pipe Delimited File
Message ID:
20030730155049.17088.qmail@onion.perl.org
Pablo Fischer wrote:
> Thanks!!!
>
> That's what I was looking for!
>
> Yep, the file has a single record, It works, thanks!
>
> Now looking your code, the difference its the local $/. What does local $/ its
> doing?

The scalar $/ is a perdefined variable which is the 'input record
separator'. It is set to "\n" by default, so

  my $line = <FILEHANDLE>;

will read everything from the filehandle up to the next newline. Setting
it to 'undef' hash the effect of disabling records altogether, so the
next read will fetch the entire file. The line

  local $/;

is an idiomatic way of saying

  $/ = undef;

and, if you want to write it even more explicitly

  use IO::Handle;
  IO::Handle->input_record_separator(undef);

You can set the value to anytyhing you want, so you could write

  $/ = '|'

then every time you read from the filehandle you will get the next field
up to (and including) the pipe.

HTH,

Rob



Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About