develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [PATCH op.c] \? prototype

Thread Previous | Thread Next
From:
Casey West
Date:
August 1, 2001 07:04
Subject:
Re: [PATCH op.c] \? prototype
Message ID:
20010801090726.C24273@stupid.geeknest.com
On Tue, Jul 31, 2001 at 11:41:30PM -0700, Richard Soderberg wrote:
: > From: Jeff 'japhy/Marillion' Pinyan [mailto:jeffp@crusoe.net]
: > Subject: [PATCH op.c] \? prototype
: > On Jul 29, Arthur Bergman said:
: 
: > >A \($|@|%) prototype or something like that taking a
: > reference to anything
: > >would be a very very very welcome addition.
: 
: > How about a \? prototype, which automatically takes a
: > reference?  Then the
: > user can decide, inside the function, what to accept?  Patch
: > below sig.
: 
: +1 to this idea - I like the idea of being able to force any generic
: argument into the subroutine as a reference.  That feels right, somehow.

My +1 as well.  Imagine, if you will:

use subs 'chomp';

sub chomp(\?) {
  my $ref = shift;
  if ( $ref ) {
    if ( ref($ref) eq 'SCALAR' ) {
      chomp( $$ref );
    } elsif ( ref($ref) eq 'ARRAY' ) {
      chomp foreach @$ref;
    } elseif ( ref($ref) eq 'HASH' ) {
      chomp foreach values %$ref;
    }
  } else {
    chomp $_;
  }
}

chomp( %foo );

__END__

  Casey West

-- 
Shooting yourself in the foot with Cray
You shoot yourself in the foot with an Uzi.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About