Changes between Version 19 and Version 20 of Perl


Ignore:
Timestamp:
10/30/06 09:14:36 (18 years ago)
Author:
atzm
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Perl

    v19 v20  
    451451{{{ 
    452452#!perl 
     453use Clone qw(clone); 
     454 
    453455my @array = (100 .. 150); 
    454456my $step  = 3; 
    455457 
    456 print join(", ", &slice(\@array, 0, $#array, $step)), "\n"; 
    457 print join(", ", &slice(\@array, 1, $#array, $step)), "\n"; 
    458 print join(", ", &slice(\@array, 2, $#array, $step)), "\n"; 
     458for (0 .. 10) { 
     459  print join(", ", &slice(\@array, $_, $#array, $step)), "\n"; 
     460} 
    459461 
    460462sub slice($$$$) { 
    461463  my ($array, $start, $end, $step) = @_; 
    462  
    463   my @subs = grep { $_ % $step == $start } ($start .. $end); 
    464  
    465   return @{$array}[@subs]; 
     464  my @subs = (); 
     465 
     466  for (my $i = $start; $i < $end; $i += $step) { 
     467    push(@subs, clone($array->[$i])); 
     468  } 
     469 
     470  return @subs; 
    466471} 
    467472}}} 
     
    470475100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148 
    471476101, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149 
    472 102, 105, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147, 150 
    473 }}} 
     477102, 105, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147 
     478103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148 
     479104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149 
     480105, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147 
     481106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148 
     482107, 110, 113, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149 
     483108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147 
     484109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148 
     485110, 113, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149 
     486}}}