in reply to Strange File read problem

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
•Re: Re: Strange File read problem
by merlyn (Sage) on Apr 09, 2003 at 15:10 UTC
    Not true. The filehandle read operation is in a list context. This slurps the entire file (delimited by $/) as a series of lines, returning one element per line.

    No need to change the delimiter here. That wasn't the problem.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

Re: Re: Strange File read problem
by nothingmuch (Priest) on Apr 09, 2003 at 15:10 UTC
    wrong. the readline operator will return all the lines in list context. Setting $/ to undef will only make the whole file be treated as one line, so the file will be in one array element instead of being smeared across the array.

    -nuffin
    zz zZ Z Z #!perl
Re: Re: Strange File read problem
by abhishes (Friar) on Apr 09, 2003 at 15:19 UTC

    I had tried the undef $/; approach before posting. It didn't work. I wrote the code like

    undef $/; open FILE, shift; my @lines = <FILE>; close FILE; foreach my $str (@lines){print $str};

    But the output was just the same.

    To make the matters more funny for me, I created a file Sample2.java with the content
    package my; import n.a.m.e; import i.s; import a.b.h.i.s.h.e.k; import s.r.i.v.a.s.t.a.v.a;
    It worked perfectly !! So what's wrong with the first file??
    regards,
    Abhishek.