In the name of TMTOWTDI, here's another way (though I actually like Kevin's solution better). If for some reason you want the other text, like the author or the publisher, it's in @text.
open FILE, "sample.txt";
my %list;
while (<FILE>) {
my @text;
do {
if ($_ =~ /[a-z]+/i) {...
If you're using regexes, then you'll probably want to use $&. $& is the captured text from the most recent regex. Maybe something like this ...
my $str = "class1:\n entry1: bumble.\"";
if ($str =~ /entry1:(\s+|\t+)[a-z0-9_\.,:;\"]*/i) {
$str = $&;
}
Try it this way ...
my %c;
for (keys(%b)) {
$c{$_} = $a{$b{$_}} unless !exists($a{$b{$_}});
}
Hopefully this will make more sense. We want to map the keys of %b to the values of %a, but as Miller pointed out, we need to check that a given key (from the values of %b) exists in %a...
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.