Michele Dondi writes:
> On Tue, 22 Jun 2004, Juerd wrote:
>
> > > rename -v => 1, $orig, $new;
> [snip]
> > I think just using named arguments would be better and much easier.
> >
> > sub rename ($old, $new, +$verbose) {
> > say "Renaming '$old' to '$new'" if $verbose;
>
>
> On Tue, 22 Jun 2004, Brent 'Dax' Royal-Gordon wrote:
>
> > It's already being done:
> >
> > rename $orig, $new :verbose;
> >
> > sub rename($orig, $new, +$verbose) {
> > say "Renaming `$orig' to `$new'" if $verbose;
>
>
> On Tue, 22 Jun 2004, Luke Palmer wrote:
>
> > No, builtins can and will have named arguments. And you can even add
> > your own to builtin functions:
>
>
> Well, much of what has been said here seems to be quite a bit above my
> head as far as my Perl6 knowledge is concerned. However I'd like to
> provide some context for my proposal: one motivation is to give yet
> more WTDI, and another one is to give a quick'n'easy WTD certain things.
>
> AIUI the first point is already addressed as explained in your mails
> above. As for the second one, the key concept is that of "suitable
> defaults". For example, using Perl5 syntax, here's what I mean:
>
> perl -le 'unlink and print "removing $_" or warn "something: $!\n" for <*.txt>'
>
> Well, it would be nice if that may just be
>
> perl -e 'unlink <*.txt> :v'
Well it's certainly not going to be that, since the <glob> operator is
going far, far away.
At first I thought it would be a good idea to just make it a perl
command-line argument:
perl -ve 'unlink glob "*.txt"'
Since it would seem that one-liners would be their primary use. But now
I think about the many times I've written in longer scripts:
print "Moving $old to $new\n";
rename $old => $new or die "Move failed: $!\n";
# ...
And indeed I would love to have written:
rename $old => $new :verbose;
Instead.
> And here of course I do *not* want to roll my own version of unlink to
> manage the verbose info, otherwise it wouldn't be easier than in the
> first attempt above. Even if put in a package, it would imply more
> typing:
>
> perl -MVerbose -e 'unlink <*.txt> :v'
> ^^^^^^^ or even more letters!!
Oh dear. Not that.
I understand your logic, but I believe this case is tolerable if it need
exist.
> Of course you may ask why not using
>
> rm -v *.txt
>
> from start instead, but then there are indeed situations in which perl is
> actually useful. For example one I can think of (and done in practice) is
> this:
>
> perl -lne 'rename $_, do{($t=$_)=~s/.../.../; $t}' files.txt
> ^^^^^^^^^^ fake!
Just as a side note, that awful en passant substitution has been cleaned
up to a functional version something like:
perl -lne 'rename $_, do { .s/.../.../ }' files.txt
Or perhaps:
perl -lne 'rename $_, do { .subst(/.../, { ... }) } files.txt
Luke