On Fri, Apr 12, 2002 at 09:26:45AM +0100, Piers Cawley wrote:
> Trey Harris <[EMAIL PROTECTED]> writes:
> 
> > I think I've missed something, even after poring over the archives for
> > some hours looking for the answer.  How does one write defaulting
> > subroutines a la builtins like print() and chomp()? Assume the code:
> >
> >   for <> {
> >      printRec;
> >   }
> >   printRec "Done!";
> >
> >   sub printRec {
> >      chomp;
> >      print ":$_:\n";
> >   }
> 
> You could take advantage of subroutine signatures and multi-dispatch
> 
>     sub printRec()     { printRec($_) } # No args, therefore no new topic.
>     sub printRec($rec) { .chomp; print ":$rec:\n" } # 1 arg

Hm, I wonder if

  sub printRec($rec=$_) { ... }

or someother way to specify that the current topic be used
as a default argument, might be possible

Graham.

Reply via email to