Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^5: Make $^V and "my" implicit

by boftx (Deacon)
on Feb 04, 2014 at 07:38 UTC ( #1073330=note: print w/ replies, xml ) Need Help??

in reply to Re^4: Make $^V and "my" implicit
in thread Make $^V and "my" implicit

I was looking specifically at this line:

my @sorted = sort { ($a->{order} // 0) <=> ($b->{order} // 0) } @aoh;

In that case, || would indeed give the same result. The same goes if one were dealing with char data and used $foo || ''. Granted, in those cases the assignment would be redundant, but the warning would be avoided when the value in question is not defined. (Which ignores the question of whether or not it should be avoided since it might be an indication of working with bad data to begin with.)

That said, you and I can both point to cases where what you are saying would be true, especially in the case of char data and having '' (empty string) replaced by a non-empty default would be an error. But in my experience that is the exception to the general use-case and is not a serious problem to deal with.

It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Comment on Re^5: Make $^V and "my" implicit
Select or Download Code
Replies are listed 'Best First'.
Re^6: Make $^V and "my" implicit
by Tux (Monsignor) on Feb 04, 2014 at 08:11 UTC

    In the sorted case example, you are right. But having the correct code as in the example makes a change from 0 to -1 or 999 as default a very easy edit, which is not to say when using ||.

       The same goes if one were dealing with char data and used $foo || ''

    Why do you want to change a perfectly valid string "0" to the empty string "". I seldom want such a change for defaults.

    Enjoy, Have FUN! H.Merijn
Re^6: Make $^V and "my" implicit
by ikegami (Pope) on Feb 05, 2014 at 18:29 UTC
    Or save 4 ops and use the following :)
    my @sorted = sort { no warnings 'uninitialized'; $a->{order} <=> $b->{order} } @aoh;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2015-11-29 08:56 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (749 votes), past polls