Hello all,
I have a string that is equal to:
my $str = Hello world a[0]! a wonderful experience.And I need to replace all occurrence of a[0] to a random number from a map. So what I do is the following:
my @arr = ("a", "a[0]", "b", "b[0]");I have a map that maps each of the above variables to a random number. My problem is when I try the following:
foreach (@arr) { $str =~ s/($_)/random{$1}/g; #where random is my map}
Non of the a[0] gets replaced with its value from the map, instead with the value of a. Any idea how to fix this in perl?
In reply to Replace strings with [] by jess195
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |