in reply to map question
By modifiying your format string to have "%d" it becomes something that sprintf can handle.@numbers = (4, 5, 6); # not necessarly consecutive $str = 'test number X'; my $fmt=$str; $fmt=~s/X/\%d/; my @newArray=map {sprintf $fmt,$_} @numbers; print join "\n",@newArray;
Another alternative would be:
But that only works because your "X" is at the end of the string.@numbers = (4, 5, 6); # not necessarly consecutive $str = 'test number X'; my $fmt=$str; $fmt=~s/X//; my @newArray=map { "$fmt$_" } @numbers; print join "\n",@newArray;
|
|---|