On Fri, 12 Apr 2002, Trey Harris wrote: > 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"; > } > > Assuming the input file "1\n2\n3\n", I want to end up with: > > :1: > :2: > :3: > :Done!: > > I assume I'm missing something in the "sub printRec {" line. But what? > (I also assume, perhaps incorrectly, that I won't have to resort to > anything so crass as checking whether my first parameter is defined...)
Couldn't you do it with old-style Perl5 subs? sub printRec { my $p = chomp(shift // $_); print ":$_:\n" } Or am _I_ missing something? Luke