On Fri, Apr 12, 2002 at 09:40:16AM -0400, Aaron Sherman wrote: > On Fri, 2002-04-12 at 04:26, 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 > > I think was he was saying is that your first printRec would not have a > $_ available to it (lexically scoped, as I understand it). > > You've got a problem here, which I don't think there's a mechanism for.
If $_ is lexical by default (did larry say this somewhere?), then I'm sure we can make it dynamic on request ala: for $_ is temp <> { printRec; } I may have the syntax slightly borked but you get the idea. I read the original posters message the same as Piers though. -Scott -- Jonathan Scott Duff [EMAIL PROTECTED]