Perl defining a pattern for a variable to follow
If you define my $top = (0 .. 100)
you g开发者_开发百科et each number 1,2,3,4...100 but how can I define $top to only produce 0, 2.5, 5, 7.5, ... 100? Thanks
@top = map { 2.5 * $_ } 0 .. 40;
#!/usr/bin/perl -w
use strict;
use warnings;
use Data::Dumper;
my @numbers = ( 0 .. 40 );
my @top = map { $_ * 5 / 2 } @numbers;
print Dumper \@top;
Output:
$ ./test.pl
$VAR1 = [
'0',
'2.5',
'5',
'7.5',
...
'95',
'97.5',
'100'
];
精彩评论