in reply to Squeezing $a+1 to be magical like $a++
Not that I approve of this, but you would need to overload binary + to recognise when it is called in void context. Otherwise my $y = $x + 1; would modify $x with chaos resulting. I don't think there is a way to do that in the manner of wantarray.
As an aside, $a and $b are already magical, representing package scope variables sacred to sort. Also be careful of numbers with leading zeros. They can be taken as octal and refuse to recognise '8' and '9'
Update: Rereading your question, I think I misunderstood what you want. Here is code without any overloading:
This is rough and completely untested. The references to args are used so that the original string is modified with ++ magic.sub addsome { ++$_[0] for 1..$_[1]; }
Update2: The code works, but it's not very efficient. Now I understand that you want addition to act on alphanumeric strings according to the rules for ++ on non-numeric strings. I suspect you don't require modification in place. That makes my comment about void context useless, and suggests that overload of binary + is perfectly approporiate.
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Squeezing $a+1 to be magical like $a++
by pixel (Scribe) on Oct 10, 2001 at 13:16 UTC | |
by blakem (Monsignor) on Oct 10, 2001 at 13:45 UTC | |
by davorg (Chancellor) on Oct 10, 2001 at 14:23 UTC |