Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Mr. Muskrat (4572)

Mr. Muskrat
  reversethis-{moc ... ta} {tarksum.rm}

I'm married with 2 girls. I work as a full time Perl programmer for a Land Mobile Radio company in the Dallas/Fort Worth area.

I am enrolled at the Art Institute of Pittsburgh - Online working towards a Bachelor of Science in photography.

My other blog [blogspot.com]

Journal of Mr. Muskrat (4572)

Friday April 15, 2005
03:30 PM

Hyper Operators

[ #24206 ]
I can't wait for the hyper operators to be implemented in pugs. Take the following example:

my $count;
my @apples = (32, 38, 37, 29, 41); # apples in each bushel
$count += $_ for @apples; # total number of apples
$count.say;

I'd like to do it like this (if it's valid to declare $count in this way):

my @apples = (32, 38, 37, 29, 41); # apples in each bushel
my $count +=<<@apples; # total number of apples
$count.say;

Another example where hyper operators would be nice:

my @credits = (5, 20, 125.50, 37.25);
my @debits = (3.66, 11.77, 23.99, 40.12, 9.95);
my @balances = @credits;
@balances[$_] -= @debits[$_] for (0 .. @debits.elems - 1);
my $total;
$total += $_ for @balances;
$total.say;

Could be written as:

my @credits = (5, 20, 125.50, 37.25);
my @debits = (3.66, 11.77, 23.99, 40.12, 9.95);
my @balances = @credits >>-<< @debits;
my $total +=<<@balances;
$total.say;

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • my $count +=<<@apples; # total number of apples

    That's not how you should use them, though, I think. With op= and then a list on the RHS, you're better off with good old for, or just sum:
    my $count = sum @apples;
    my $count = @apples.sum;