Changes between Version 16 and Version 17 of Perl


Ignore:
Timestamp:
10/26/06 00:51:26 (18 years ago)
Author:
atzm
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Perl

    v16 v17  
    446446$SIG{__WARN__} = \&Carp::cluck; 
    447447}}} 
     448 
     449== ステップつきスライス == 
     450 * つまるところ Python での {{{list[start:end:step]}}}. 
     451{{{ 
     452#!perl 
     453my @array = (100 .. 150); 
     454my $step  = 3; 
     455 
     456print join(", ", &slice(\@array, 0, $#array, $step)), "\n"; 
     457print join(", ", &slice(\@array, 1, $#array, $step)), "\n"; 
     458print join(", ", &slice(\@array, 2, $#array, $step)), "\n"; 
     459 
     460sub slice($$$$) { 
     461  my ($array, $start, $end, $step) = @_; 
     462 
     463  my @subs = grep { $_ % $step == $start } ($start .. $end); 
     464 
     465  return @{$array}[@subs]; 
     466} 
     467}}} 
     468 * 実行結果 
     469{{{ 
     470100, 103, 106, 109, 112, 115, 118, 121, 124, 127, 130, 133, 136, 139, 142, 145, 148 
     471101, 104, 107, 110, 113, 116, 119, 122, 125, 128, 131, 134, 137, 140, 143, 146, 149 
     472102, 105, 108, 111, 114, 117, 120, 123, 126, 129, 132, 135, 138, 141, 144, 147, 150 
     473}}}