in reply to Can I tell a sub to take $_ instead of @_ (like some builtins do)

A slight variation

#! perl -w sub test { my $parm = $_[0] || $_; print $parm, $/; } test( "fred"); test for qw(the quick brown fox); __END__ # Output C:\test>192129 fred the quick brown fox C:\test>

What's this about a "crooked mitre"? I'm good at woodwork!
  • Comment on Re: Can I tell a sub to take $_ instead of @_ (like some builtins do)
  • Download Code

Replies are listed 'Best First'.
Re x 2: Can I tell a sub to take $_ instead of @_ (like some builtins do)
by Sweeper (Pilgrim) on Aug 23, 2002 at 05:44 UTC
    About your line:
        my $parm = $_[0] || $_;
    
    What is you call this?
    test(0);
    test("");
    
    You should wait for Perl 6 and use the new operator //.

      <tongue-in-cheek>

      Printing a null byte to the screen isn't very useful anyway!

      It's a feature:)

      </tongue-in-cheek>

      my $parm = defined $_[0] ? $_[0] : $_;?


      What's this about a "crooked mitre"? I'm good at woodwork!