Pattern matching and for loops

2006-01-13 Thread Dave Whipp
Today I wrote some perl5 code for the umpteenth time. Basically: for( my $i=0; $i $#ARGV; $i++ ) { next unless $ARGV[$i] eq -f; $i++; $ARGV[$i] = absolute_filename $ARGV[$i]; } chdir foo; exec bar, @ARGV; I'm trying to work out if there's a clever perl6 way to write

Re: Pattern matching and for loops

2006-01-13 Thread Austin Hastings
Dave Whipp wrote: Today I wrote some perl5 code for the umpteenth time. Basically: for( my $i=0; $i $#ARGV; $i++ ) { next unless $ARGV[$i] eq -f; $i++; $ARGV[$i] = absolute_filename $ARGV[$i]; } chdir foo; exec bar, @ARGV; I'm trying to work out if there's a

Re: Pattern matching on arrays and for loops

2006-01-13 Thread Luke Palmer
On 1/13/06, Dave Whipp [EMAIL PROTECTED] wrote: I'm trying to work out if there's a clever perl6 way to write this using pattern matching: for @*ARGV - -f, $filename { $filename .= absolute_filename; } There is, but it's a different kind of pattern matching: if @*ARGV ~~ / ,

Array Holes

2006-01-13 Thread Luke Palmer
In perl 5: my @a = (1,2,3); delete $a[1]; print exists $a[1]; This is false, whereas $a[0] and $a[2] do exist. This is creepy. Not only is it creepy, it raises a whole bunch of questions with nontrivial answers: * does [EMAIL PROTECTED] include nonexistent elements? * does

Re: Pattern matching on arrays and for loops

2006-01-13 Thread Dave Whipp
Luke Palmer wrote: On 1/13/06, Dave Whipp [EMAIL PROTECTED] wrote: Would this actually work, or would it stop at the first elem that doesn't match (-f, ::Item)? If by stop you mean die, yes it would stop. not what I wanted :-( Is there some way to associate alternate codeblocks for

Re: Array Holes

2006-01-13 Thread Nicholas Clark
On Fri, Jan 13, 2006 at 10:33:23PM +, Luke Palmer wrote: In perl 5: my @a = (1,2,3); delete $a[1]; print exists $a[1]; This is false, whereas $a[0] and $a[2] do exist. This is creepy. Not only is it creepy, it raises a whole bunch of questions with nontrivial answers:

Re: Pattern matching on arrays and for loops

2006-01-13 Thread Luke Palmer
On 1/13/06, Dave Whipp [EMAIL PROTECTED] wrote: What happens if I simply abandon the attempt at anonymous MMD and use a named multi-sub, instead: { my multi sub process_arg(-f, Str $f is rw) { $f .= absolute_filename } my multi sub process_arg(--quux, Str arg1, Str arg2) {

Re: Pattern matching on arrays and for loops

2006-01-13 Thread Larry Wall
On Fri, Jan 13, 2006 at 11:42:13PM +, Luke Palmer wrote: : On 1/13/06, Dave Whipp [EMAIL PROTECTED] wrote: : What happens if I simply abandon the attempt at anonymous MMD and use a : named multi-sub, instead: : : { : my multi sub process_arg(-f, Str $f is rw) { :$f .=

Re: Pattern matching and for loops

2006-01-13 Thread Brad Bowman
On 13/01/06 20:36, Dave Whipp wrote: Is there some way to associate alternate codeblocks for different patterns (i.e. local anonymous MMD)? Is it possible to have an anonymous multi sub? This would seem to require new syntax for combining two anonymous definitions. Of course we want

Re: Array Holes

2006-01-13 Thread Larry Wall
On Fri, Jan 13, 2006 at 10:33:23PM +, Luke Palmer wrote: : In perl 5: : : my @a = (1,2,3); : delete $a[1]; : print exists $a[1]; : : This is false, whereas $a[0] and $a[2] do exist. This is creepy. Not : only is it creepy, it raises a whole bunch of questions with : nontrivial