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

Contents of @_ using subroutine signatures with default values

by davido (Cardinal)
on Jul 13, 2020 at 22:22 UTC ( [id://11119273]=perlquestion: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub baz ($this, $that) {
        warn '@_ contains ', scalar(@_), " elements.\n";
    }
    
    baz('hello', 'world') # @_ contains 2 elements.
    
  2. or download this
    sub foo ($this, $that = 'world') {
        warn '@_ contains ', scalar(@_), " elements.\n";
    }
    
    foo('hello'); # @_ contains 1 elements.
    
  3. or download this
    #!/usr/bin/env perl
    
    ...
    
    note "\n\nTesting foo()";
    foo("a");
    
  4. or download this
    1..8
    # 
    ...
    # Looks like you failed 2 tests of 8.
    
    shell returned 2
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11119273]
Approved by marto
Front-paged by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2024-04-19 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found