Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: u+ fails to force scalar context to empty list assignment: +( () = ... )

by Marshall (Canon)
on Mar 12, 2019 at 00:30 UTC ( [id://1231142]=note: print w/replies, xml ) Need Help??


in reply to Re^2: u+ fails to force scalar context to empty list assignment: +( () = ... )
in thread u+ fails to force scalar context to empty list assignment: +( () = ... )

fair enough, both work.

As an update, string concatenation can be used in other situations to force scalar context so it is valid to mention that possibility. In this particular case, 0+ is perfect. However if the goal is only to count ";", tr is even better.

Replies are listed 'Best First'.
Re^4: u+ fails to force scalar context to empty list assignment: +( () = ... )
by LanX (Saint) on Mar 12, 2019 at 01:24 UTC
    > fair enough, both work.

    Still different, your result is a string.

    Perl works hard to treat all scalar sub-types equally by operators, but I seem to remember edge cases where the internal type mattered and resulted in errors.

    No need to stringify a number.

    And a reader - at least me - would be confused.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (8)
As of 2024-03-28 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found