The print statement
print"$config[$t][0]\n";
in the print loop of example (1) of the OP suggests the possibility* you are dealing not with an array of strings, but with an array of array references each of which has at least one element, the first, that is a string.
If this is so, the following code addresses this case, both with more and less redundant, as NetWallah has pointed out, map approaches, and with a more 'standard' for-loop.
>perl -wMstrict -le "my @config = ([ 'fee fie' ], [ 'foe'], [ 'fum' ],); printf qq{'$_->[0]' } for @config; print ''; ;; @config = map { $_->[0] =~ s{(f[eio]e)}{\u$1}xmsg; $_; } @config; printf qq{'$_->[0]' } for @config; print ''; ;; map { $_->[0] =~ s{ (F [eio] e) }{\U$1}xmsg } @config; printf qq{'$_->[0]' } for @config; print ''; ;; for my $ar (@config) { $ar->[0] =~ s{ (F [EIO] E) }{\L$1}xmsg;; } printf qq{'$_->[0]' } for @config; print ''; " 'fee fie' 'foe' 'fum' 'Fee Fie' 'Foe' 'fum' 'FEE FIE' 'FOE' 'fum' 'fee fie' 'foe' 'fum'
* I know this is a possibility because if you had been dealing with an array of simple strings, you would have seen an error or a bunch of warnings because, of course, you're running with strictures and warnings enabled.
In reply to Re: String substitution inside an array
by AnomalousMonk
in thread String substitution inside an array
by Monkomatic
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |