http://www.perlmonks.org?node_id=1096498


in reply to Variable being saved as a list?

Hiya fiona , Welcome to the monastry.

my(@LINES)=<REFFILE>; doesn't look right, you tried my @LINES = <REFFILE>; ?

Also, open (REFFILE,">$reffile") || print "Content-type: text/html\n\n Can't Open $reffile(r): $!\n"; appears to be wrong since, even if open() fails, the next line still tries to write to it - try open (REFFILE,">$reffile") || die "Content-type: text/html\n\n Can't Open $reffile(r): $!\n";

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: Variable being saved as a list?
by Your Mother (Archbishop) on Aug 06, 2014 at 19:07 UTC

    die goes to STDERR unless set up specially otherwise. So that ostensibly HTML error goes nowhere but server error logs, if even there; again by setup.

      My point being, Your Mother, that the open failure could and indeed should, be better handled since if open() fails, the error log will get extended by the subsequent write failures.

      A user level that continues to overstate my experience :-))

        Heh. My point being, from a UI perspective, it’s not handled at all in your “correction.” Your code would give a generic server error and is not appropriate for production. :P

Re^2: Variable being saved as a list?
by Anonymous Monk on Aug 06, 2014 at 19:08 UTC
    my(@LINES)=<REFFILE>; doesn't look right, you tried my @LINES = <REFFILE>; ?

    In this case it's the same thing.

    $ perl -MO=Deparse -e 'my @LINES=<REFFILE>; my(@LINES)=<REFFILE>;' my(@LINES) = <REFFILE>; my(@LINES) = <REFFILE>;

    The parens would make a difference if the thing on the left wasn't an array, and the thing on the right behaved differently in scalar and list context. In that case the parens would cause the thing on the right to be in list context. For example my $x = @foo; assigns the length of @foo to $x (scalar context), while my ($x) = @foo; assigns the first item of @foo to $x (list context). It's what makes sub { my ($arg0,$arg1,$arg2,@rest) = @_; ... } work.