Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: ~~ and list literal

by 2teez (Priest)
on Oct 25, 2012 at 12:07 UTC ( #1000837=note: print w/replies, xml ) Need Help??


in reply to ~~ and list literal

  1. Please check perlop under the subheading
    Smartmatch Operator
    ..It is also unique in that all other Perl operators impose a context (usually string or numeric context) on their operands, autoconverting those operands to those imposed contexts. In contrast, smartmatch infers contexts from the actual types of its operands and uses that type information to select a suitable comparison mechanism...
  2. Moreover, using this
    print( "x" ~~ ("x", "y", "z") );
    with use warnings in your script turn on, it would shout"Useless use of a constant (x),(y) in void context". Which shows you are inferring a void context using smartmatch like so.

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

Replies are listed 'Best First'.
Re^2: ~~ and list literal
by Anonymous Monk on Oct 25, 2012 at 23:43 UTC

    TIL that parentheses don't imply a list context. Also these don't:

    "x" ~~ qw(x y z) "x" ~~ sort(x y z)

    I find that only this do: "x" ~~ @{["x", "y", "z"]}

    Any other which I missed?

      TIL that parentheses don't imply a list context

      Ofcourse, I never said parentheses imply a list context, it's the comma operator that does.
      But, what I did say/wrote is that the smartmatch ..infers contexts from the actual types of its operands and uses that type information to select a suitable comparison mechanism...

      Any other which I missed?
      Please, check perlop for detailed information

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000837]
help
Chatterbox?
[marioroy]: why do some posters not know to provide a good SSCCE? Nested loops?
[Corion]: marioroy: Producing good SSCCE is an acquired skill :) You have to produce bad SSCCEs for a long time until you get good. And when you get good, you don't need them that much anymore because you simply isolate the problem and then solve it ;)
[marioroy]: ... and kcott is able to provide something. Amazing.

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2017-08-18 08:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (297 votes). Check out past polls.

    Notices?