Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Declaring with my, assigning, and testing in same line (custom routine)

by LanX (Sage)
on Dec 12, 2015 at 03:17 UTC ( #1150090=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @v= keys %h;
    die "Got extra Z: @v\n" if @v >1
    
  2. or download this
       
      DB<100> sub check { die "Got extra Z: @_\n" if @_ >1 }
    
    ...
    
      DB<104> check my @v= keys %h
    Got extra Z: a b
    
  3. or download this
      DB<106> sub avoid (&;@) { 
               my $code=shift;
    ...
      DB<109> avoid { "Got extra Z: @_\n" if @_ >1 } my @v = keys %h;
    
      DB<110>
    
  4. or download this
    avoid { "Got extra Z: @_\n" if @_ >1 } 
        my @v = keys %h;
    
  5. or download this
           The declared variable is not introduced (is not visible) until 
    +after
           the current statement.  Thus,
    ...
               my $x = 123 and $x == 123
    
           is false unless the old $x happened to have the value 123.
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-05-25 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?