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. Perhaps sub printRec(->$rec) I'm just throwing that out, but some way to say that the argument defaults to getting the topic would seem to be called for.