好的,所以我有一个看起来像这样的数组:
@foo = ("a","b","c","d");
Run Code Online (Sandbox Code Playgroud)
...以及存储在变量中的字符串:
my $foo = "e";
Run Code Online (Sandbox Code Playgroud)
我想把它变成一个看起来像这样的字符串:
"e/a;e/b;e/c;e/d"
Run Code Online (Sandbox Code Playgroud)
换句话说,我想在每个数组元素的开头添加"$ foo /"并将其转换为由分号分隔的字符串.我怎样才能做到这一点?
谢谢!
too*_*lic 10
use warnings;
use strict;
my @foo = ("a","b","c","d");
my $foo = "e";
my $s = join ';', map { "$foo/$_" } @foo;
print "$s\n";
__END__
e/a;e/b;e/c;e/d
Run Code Online (Sandbox Code Playgroud)