@browser = ("NS", "IE", "Opera");
my $add_str = "Browser:";
$count = 0;
foreach (@browser) {
my $br = $_;
$browser[$count] = "$add_str:$br";
$count++ ;
}
is there any other way to do this ? best way ?
@browser = ("NS", "IE", "Opera");
my $add_str = "Browser:";
$count = 0;
foreach (@browser) {
my $br = $_;
$browser[$count] = "$add_str:$br";
$count++ ;
}
is there any other way to do this ? best way ?
You could use map.
@browser = ("NS", "IE", "Opera");
my $add_str = "Browser";
@browser = map { "${add_str}:$_"; } @browser;
In Perl 5, the for
loop aliases each item, so you can simply say
#!/usr/bin/perl
use strict;
use warnings;
my @browsers = qw/NS IE Opera/;
my $add_str = "Browser:";
for my $browser (@browsers) {
$browser = "$add_str:$browser";
}
print join(", ", @browsers), "\n";