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

Re: Re: Re: Returning Values from Subroutines

by mojobozo (Monk)
on Sep 06, 2002 at 16:38 UTC ( #195697=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Returning Values from Subroutines
in thread Returning Values from Subroutines

And, using the example in ignatz's reposnse, even more strokes shaved:
#!/usr/local/bin/perl print add(1,2); sub add{ return ($_[0] + $_[1]); }

Man, this is getting fun. I wish I could shave this many strokes of my discgolf game!
word (wrd)
interj. Slang. Used to express approval or an affirmative response to
something. Sometimes used with up. Source

Replies are listed 'Best First'.
Re:^4 Returning Values from Subroutines
by zigdon (Deacon) on Sep 06, 2002 at 17:48 UTC
    Well, as long as we're golfing:
    #!/usr/local/bin/perl print add(1,2); sub add{ $_[0] + $_[1]; }

    -- Dan

Re: Re: Re: Re: Returning Values from Subroutines
by blokhead (Monsignor) on Sep 06, 2002 at 17:33 UTC
    The return keyword can be omitted when it's the last line of a sub, so this will also work:
    #!/usr/local/bin/perl print add(1,2); sub add{ $_[0]+$_[1]; }
    or for that matter
    sub add{ shift+shift; }
    Update: OK, so I guess the shift() there is ambiguous. Anyway, you get the point.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2018-08-20 02:37 GMT
Find Nodes?
    Voting Booth?
    Asked to put a square peg in a round hole, I would:

    Results (190 votes). Check out past polls.