$fc = 'abcdfoofrobnicatebardefforspambazghi'; $re2 = qr/(fo.)(.*?)(ba.)/; push @excerpts, $1 while $fc =~ /($re2)/g; print "0: $excerpts[0]; print "0: $excerpts[0]; for my $i ( 0 .. 1 ) { $excerpts[i] =~ /$re2/; $%{$excerpts[$i]}{fpart} = $1; $%{$excerpts[$i]}{bpart} = $3; } print "0{fpart}: $%{$excerpts[0]}{fpart}\n; print "0{bpart}: $%{$excerpts[0]}{bpart}\n; print "1{fpart}: $%{$excerpts[1]}{fpart}\n; print "1{bpart}: $%{$excerpts[1]}{bpart}\n; __END__ 0:foofrobnicatebar 1:forspambaz 0{fpart}: foo 0{bpart}: bar 1{fpart}: for 1{bpart}: baz
Hope I typed all this correctly
Edit: changed $2 to $3 in for loop. Running it on PC with perl yields above results with exception of 1{bpart} for some reason
Addendum: I also realize that I could have started out with an array of hashes and put the original contents into $excerpts[$i]{contents} and then from it gotten $excerpts[$i]{bpart} $excerpts[$i]{fpart} with the normal AoH syntax, but this question is for an already existing array with stuff in $excerpts[$i].
In reply to Re^2: Adding hashes to already existing array
by ExReg
in thread Adding hashes to already existing array
by ExReg
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |