in reply to Perl store as variables regex matches for use outside of loop.
You just need to capture the output of the regexp match, which Perl makes available in $1.
See Extracting matches.
(Update: added link to docs)
#!/usr/bin/perl use strict; use warnings; my $book= "^\\s\*book ref \#"; my $book_res = $book =~ "/^\\s\*owner \#/"; my $title = "^\\s\*title "; my $title_res = $title =~ "/^\\s\*title /"; my %keepers; foreach (<DATA>) { #next unless /$book|$title/ip; chomp; if ( /($book|$title)/ip ) { $keepers{ $_ } = $1; } #print ; } # here i would like to access the regex matches as scalers for (keys %keepers ) { print "Here's your scalar: <<$_>> has value <<$keepers{ $_ }>>\n"; } __DATA__ Book ref #4346 Lent: Sun Jul 12 03:26:43 BST 2015 status Lent Description: classic title blah blah blah last used: 2 color red Pages 238 Publisher Bca Type Hardback Location: N/a Author R jones
|
|---|