Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Re: Returning Values from Subroutines

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


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

A little more golf on this one:

#!/usr/local/bin/perl print add(1,2); sub add{ return $result = ($_[0] + $_[1]); }

Unless, of course, you wanted to save the value returned.
mb


Comment on Re: Re: Returning Values from Subroutines
Download Code
Replies are listed 'Best First'.
Re: Re: Re: Returning Values from Subroutines
by mojobozo (Monk) on Sep 06, 2002 at 16:38 UTC
    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!
    _____________________________________________
    mojobozo
    word (wrd)
    interj. Slang. Used to express approval or an affirmative response to
    something. Sometimes used with up. Source
      Well, as long as we're golfing:
      #!/usr/local/bin/perl print add(1,2); sub add{ $_[0] + $_[1]; }

      -- Dan

      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.

      blokhead

Re(3): Returning Values from Subroutines
by Arien (Pilgrim) on Sep 06, 2002 at 22:22 UTC

    In 9 strokes:

    # 123456789 sub add{pop()+pop}

    — Arien

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2015-08-02 13:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...













    Results (2 votes), past polls