Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: how do subroutines work

by Pancho (Pilgrim)
on Mar 22, 2008 at 13:32 UTC ( [id://675625]=note: print w/replies, xml ) Need Help??


in reply to how do subroutines work

The zivad sub gets one parameter 'mago' in the array @_, which is stores in my $animal as a result of the default use of shift. It is shifting the leftmost scalar in the array @_. The my $list variable does not store a list but a scalar, namely the value of the %list hash for the key $animal. then the scalar $list is returned and printed...

This should be clearer

my %hash = ( pas => 'vau-vau', macak => 'mijau', krava => 'muuuuu', pile => 'pi-pi', mago => 'ia-ia' ); sub zivad { my $animal = shift; my $hash_value = $hash{$animal} || die "no animal"; return $hash_value; } print zivad('mago');

Not that I would use those variable names but they give you an idea of what the variables contain.

Pancho

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2024-07-25 17:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.