perlmeditation
BigLug
I have a few things I'd like to see in perl 6 (or 7). (They may already be in development, I don't read as much apocolyptic literature as I probably should.)<p>
Consider this code:
<code>
my $highest = 0;
my $lowest = 1_000_000_000;
foreach (@list_of_int) {
$highest = $_ if $_ > $highest;
$lowest = $_ if $_ < $lowest; # was $highest - see update
}
</code>
Now I'd like to get rid of the '<code>= $_ if $_ ></code>' as it's annoyingly long winded. In the spirit of ||= ('or equals'), let me suggest =>> become 'equals the greater' and =<< become 'equals the lesser'. So now we have:
<code>
my $highest = 0;
my $lowest; # undef
foreach (@list_of_int) {
$highest =>> $_;
$lowest =<< $_;
}
</code>
(I'd use '=>' but that would be confusing to perl5ers.)<p>
There'd also be string equivelents:
<code>
my $highest = '';
my $lowest; # undef
foreach (@list_of_string) {
$highest eg $_;
$lowest el $_;
}
</code>
Note that my =<< and el operators would consider anything <code>defined</code> to be less than 'undef' which is why the <code>my</code> declarations for $lowest are undef. This means we don't have to guess a value that is higher than the lowest value when initialising.<p>
Thoughts? Comments? Ridicule?<p>
<font size=1><b>Update:</b> Fixed typo pointed out by [NetWallah]. Added a pile of semi-colons.</font>
<div class="pmsig">
<div class="pmsig-76853">
<font size=1 color=gray>"Get real! This is a discussion group, not a helpdesk. You post something, we discuss its implications. If the discussion happens to answer a question you've asked, that's incidental." <i>-- nobull@mail.com in clpm</i></font>
</div></div>