[Pdx-pm] File-Fu overloading: '*' replaces '.'
Eric Wilhelm
scratchcomputing at gmail.com
Sat Feb 23 12:21:37 PST 2008
Hi all,
Perl's overloading of "$obj\n" calls the '.' method, so it looks like
the File::Fu inner append has to be changed.
Note: the operators are pronounced:
/ "slash" (not "divide")
+ "plus" (not "add")
* "glue" (not "multiply")
Before:
my $dir = File::Fu->dir("bar"); # "bar/"
my $alsodir = $dir . 'bat'; # "barbat/"
my $subdir = $alsodir / 'baz'; # "barbat/baz/"
my $subdir2 = ($dir . 'bat') / 'baz'; # "barbat/baz/"
my $file = $subdir + 'file.txt'; # "barbat/baz/file.txt"
After:
my $dir = File::Fu->dir("bar"); # "bar/"
my $alsodir = $dir * 'bat'; # "barbat/"
my $subdir = $alsodir / 'baz'; # "barbat/baz/"
my $subdir2 = $dir * 'bat' / 'baz'; # "barbat/baz/"
my $file = $subdir + 'file.txt'; # "barbat/baz/file.txt"
Notice the bump in precedence eliminates the need for parens on
the "inner append 'bat'" in the $subdir2 line.
Unfortunately, the '+' precedence is still low, so this won't work:
my $file = $dir * 'bat' / 'baz' + 'file' * '.txt'
Because of that, I'm considering involving "%" ("mod") and shuffling
things around a bit. But, perl6 fixes the ".=" and "=~" bits, right?
(If so, then I would like to keep the interface closer to that.)
Another alternative is to dualize "&", but that would mean breaking the
map() nature.
--Eric
--
The reasonable man adapts himself to the world; the unreasonable man
persists in trying to adapt the world to himself. Therefore all progress
depends on the unreasonable man.
--George Bernard Shaw
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------
More information about the Pdx-pm-list
mailing list