Looks to me like the first candidate is a !~~ operator (or maybe a change to the behaviour table of ~~). Due to all the magic in the ~~ operator, $a !~~ $b is (well would not be) not the same thing as !($a ~~ $b). Let's have a look at what does the ~~ mean in case $a is an array and $b is a regexp:

@ARGV ~~ /\.mdb$/i
What does that mean? Is it true if ANY of the elements in the array match the regexp or if ALL match? According to the docs @ARRAY ~~ $regexp is equivalent to grep /$regexp/, @ARRAY. Which means that statement above is true if ANY of the parameters matches the regexp (ends with .mdb).

Ok, but how do I make sure all are? How do we rewrite:

if (grep { not /\.mdb$/i } @ARGV) { print STDERR "All parameters must be MDB files\n"; exit; }
with the cool new ~~ if
@ARGV ~~ /\.mdb\z/ or die "All parameters must be MDB files"
doesn't cut it? And
@ARGV ~~ sub {$_[0] !~ /\.mdb$/i} and die "All parameters must be MDB files"
according to the docs doesn't work? (According to the docs @ARRAY ~~ $sub is $sub->(@ARRAY) not grep {$sub->($_)} @ARRAY)

With !~~ it would be easy:

@ARGV !~~ /\.mdb$/i and die "All parameters must be MDB files";

And

given($foo) { when (! /some regexp/) {...} ... }
or maybe
given($foo) { when ! (/some regexp/) {...} ... }
would also come in handy.

Replies are listed 'Best First'.
Re: What's missing in Perl 5.10
by grinder (Bishop) on Dec 20, 2007 at 11:38 UTC

    What is missing is the ability to use each on an array. It would work like this:

    my @array = qw( foo bar rat ); while (my ($val,$idx) = each @array) { say "$val at $idx"; } # produces foo at 0 bar at 1 rat at 2

    Sometimes it's really nice to have both the value and index at once. Nicholas Clark had this up and running in bleadperl a few months ago, but the pumpking judged that it was regretfully a far too major change in the syntax to hold up the release of 5.10

    There is discussion about how to retro-future-fit it into the 5.10 maintenance track, so as to avoid a full release cycle that would require waiting for the first 5.12 release.

    • another intruder with the mooring in the heart of the Perl

      That made me want to implement it. Ironically, I don't have 5.10 installed yet, and there are a few features that would be appropriate here. Note that I reversed the result list, so that the order is key/value, like hash-each is.
      use strict; use warnings; BEGIN { my %state; sub a_each(\@) { my $aref = shift; exists $state{$aref} or $state{$aref} = -1; if (++$state{$aref} > $#$aref) { delete $state{$aref}; return (); } else { return ($state{$aref}, $aref->[$state{$aref}]); } } } my @array = qw( foo bar rat ); while (my ($idx,$val) = a_each @array) { print "$val at $idx\n"; }

      Caution: Contents may have been coded under pressure.
      What is missing is the ability to use each on an array.

      I personally believe that it could be worth to remind of ysth's 5.12 feature quest to which I've just added a reply.

      There is discussion about how to retro-future-fit it into the 5.10 maintenance track, so as to avoid a full release cycle that would require waiting for the first 5.12 release.

      But wouldn't the new feature mechanism make it easier to implement new syntactic features without risking too much with backwards compatibility?

      --
      If you can't understand the incipit, then please check the IPB Campaign.
      each @array is now implemented in blead (and returns ($index, $value), not the other way round).

      See this thread for details, once nntp.perl.org works again.

      And there is Array::Each::Override, thanks to Nicholas for the hint.

Re: What's missing in Perl 5.10
by educated_foo (Vicar) on Dec 20, 2007 at 00:50 UTC
    Can I put in a vote for ~!? ;)

    More seriously, one thing that's seriously missing is structured captures. With the addition of named captures, (?(DEFINE)...), and (more convenient) recursive patterns, the regex engine has all the necessary ingredients to implement fast recursive-descent parsers.

    Well, all but one: there's no convenient way to get at the structure of the match to build up a parse tree. The raw materials to do so are there: you can take actions in code blocks and have them undone during backtracking via local; you can refer to capture groups by relative position and name so that embedded subpatterns work. But it's an enormous pain to put these ingredients together in any but the most trivial cases.

Re: What's missing in Perl 5.10
by mugwumpjism (Hermit) on Dec 21, 2007 at 05:41 UTC

    !~~ sounds a bit ambiguous to me. Sounds like you should be using junctions - see Perl6::Junction

    $h=$ENV{HOME};my@q=split/\n\n/,`cat $h/.quotes`;$s="$h/." ."signature";$t=`cat $s`;print$t,"\n",$q[rand($#q)],"\n";
A reply falls below the community's threshold of quality. You may see it by logging in.
A reply falls below the community's threshold of quality. You may see it by logging in.