Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

One of these things is not like the others...

by writch (Novice)
on Oct 22, 2013 at 18:23 UTC ( #1059242=perlquestion: print w/ replies, xml ) Need Help??
writch has asked for the wisdom of the Perl Monks concerning the following question:

I have some code that's throwing an error on my development machine, but not on any of our production servers, and it started throwing the error this morning, outside of any changes to the machine that we can tell. I've resolved the error, but now I want to know *why* I'm not seeing it on the production boxes.

$target is an array reference. This is the line (fixed vs. broken)

push @$target, \%item
vs.
push $target, \%item

The error is:

Type of arg 1 to push must be array (not scalar dereference)
The "broken" code is running fine on half a dozen machines w/o so much as a burp. Any ideas what might have changed to make this dev box notice it? Yes, it's version 5.12 on the older dev box, and 5.14 on all the other dev boxes and production servers.

Comment on One of these things is not like the others...
Select or Download Code
Re: One of these things is not like the others...
by McA (Deacon) on Oct 22, 2013 at 18:34 UTC

    The question is: What Perl version do you have on the dev box and what version do you have on the production machines?

    Since Perl 5.14 the first expression to the function push can also be a array ref.

    McA

      From push:

      Starting with Perl 5.14, push can take a scalar EXPR, which must hold a reference to an unblessed array. The argument will be dereferenced automatically. This aspect of push is considered highly experimental. The exact behaviour may change in a future version of Perl.
      Update: (which McA pointed out in an update)

      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        While looking up the version which introduced the new behaviour you answered it. A ++ for that.

        UPDATE: I've decided to upvote all answers which came in more or less at the same time referencing the new behaviour. It came faster in than I could hit the reload button. :))

        McA

Re: One of these things is not like the others...
by Cristoforo (Deacon) on Oct 22, 2013 at 18:36 UTC
    From the documentation for push.
    Starting with Perl 5.14, "push" can take a scalar EXPR, which must hold a reference to an unblessed array. The argument will be dereferenced automatically. This aspect of "push" is considered highly experimental. The exact behaviour may change in a future version of Perl.
    This is probably the answer and note that the docs say it is experimental and may change in the future.
Re: One of these things is not like the others...
by hdb (Parson) on Oct 22, 2013 at 18:36 UTC

    From push:

    Starting with Perl 5.14, push can take a scalar EXPR, which must hold a reference to an unblessed array. The argument will be dereferenced automatically. This aspect of push is considered highly experimental. The exact behaviour may change in a future version of Perl.
Re: One of these things is not like the others...
by 2teez (Priest) on Oct 22, 2013 at 18:42 UTC

    Hi writch,
    The "broken" code is running fine on half a dozen machines w/o so much as a burp. Any ideas what might have changed to make this dev box notice it?
    Are all your machine running the same version of Perl?
    Check the push you probably get the reason for this as:

    Starting with Perl 5.14, push can take a scalar EXPR, which must hold a reference to an unblessed array. The argument will be dereferenced automatically. This aspect of push is considered highly experimental. The exact behaviour may change in a future version of Perl.
    Thus the following advise was given:
    To avoid confusing would-be users of your code who are running earlier versions of Perl with mysterious syntax errors, put this sort of thing at the top of your file to signal that your code will work only on Perls of a recent vintage: use 5.014; # so push/pop/etc work on scalars (experimental)
    #Update:
    Other monks were faster than I.....Ah!

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re: One of these things is not like the others...
by Anonymous Monk on Oct 23, 2013 at 01:45 UTC

    Hi,

    This illustrates something very important. The dev, test and prod environments should be identical.

    As you have found, even having a different version of Perl can cause problems.

    Sometimes these can cause real problems. You don't want to find a major problem in a mission critical production envorinment. That's what dev and test are for.

    J.C.

      I think you do want to find it (before it causes a major problem.)
      Bill
Re: One of these things is not like the others...
by boftx (Chaplain) on Oct 23, 2013 at 17:32 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2014-07-22 20:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (127 votes), past polls