Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Variable being saved as a list?

by Bloodnok (Vicar)
on Aug 06, 2014 at 18:47 UTC ( #1096498=note: print w/replies, xml ) Need Help??


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 (Bishop) 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096498]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2020-05-31 22:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (177 votes). Check out past polls.

    Notices?