Juerd writes: > Michele Dondi skribis 2004-06-22 18:24 (+0200): > > rename -v => 1, $orig, $new; > > Any specific reason for the minus there? Perl's not a shell (yet). > > > rename.SWITCHES{-v} = sub { > > my ($o, $n) = @_; > > print "renaming `$o' to `$n'\n"; > > } > > I think just using named arguments would be better and much easier. > > sub rename ($old, $new, +$verbose) { > say "Renaming '$old' to '$new'" if $verbose; > ...; > } > > rename verbose => 1, $oldthingy, $newthingy;
That one doesn't work. Named arguments have to come at the end of the parameter list (just before the "data list", if there is one). This is a decision I'm gradually beginning to disagree with, because of: sub repeat (&code, +$times = Inf) { code() for 1..$times; } This is a plausable routine. Now look how it's called: repeat { print "I'm "; print "doing "; print "stuff\n"; } :times(4); This is a horrid violation of the end weight principle. Much nicer is the illegal: repeat :times(4) { print "I'm "; print "doing "; print "stuff\n"; } Luke > rename $oldthingy, $newthingy, :verbose; # alternative, more > # switch-like pair constructor > > > Juerd