in reply to searching for multiple matches and then seek from last match
Hi james28909,
Let me try re-frame what you are trying to do and work within that premises as your intent in this post is not clear to me. More so, probably showing the content of both searchfile and key file, and the format of how your final output will look like would have also help.
That said, I think you want to read dataset from your searchfile into three scalar variables, then use those to search lines from another file called key file to search and get the corresponding values of the three variables. If that is right, one of the ways you can achieve your aim is like so:
OUTPUT:use warnings; use strict; use Inline::Files; use Data::Dumper; my %set = map { chomp; $_ => undef } <SEARCHFILE>; while (<DATA>) { if ( my ( $key, $value ) = /^(.+)=(.+)\s+</ ) { if ( exists $set{$key} ) { push @{ $set{$key} }, $value; } } } print Dumper \%set; __SEARCHFILE__ revision version type __DATA__ revision=0.0.1.1 <--newline at end of line version=0.0.1 <--newline at end of line type=A <--newline at end of line key1=64 characters <--newline at end of line key2=32 character <--search will stop before going to newline revision=0.0.2.1 <--newline at end of line version=0.0.2 <--newline at end of line type=B <--newline at end of line key1=64 characters <--newline at end of line key2=32 character <--search will stop before going to newline revision=0.0.3.1 <--newline at end of line version=0.0.3 <--newline at end of line type=C <--newline at end of line key1=64 characters <--newline at end of line key2=32 character <--search will stop before going to newline revision=0.0.4.1 <--newline at end of line
Note: This might not meet your need but should get you a look into what you are doing. The regex I used might also not work for you even if my premises is correct ( hope so ) You might also want to see How do I post a question effectively?.$VAR1 = { 'revision' => [ '0.0.1.1', '0.0.2.1', '0.0.3.1', '0.0.4.1' ], 'version' => [ '0.0.1', '0.0.2', '0.0.3' ], 'type' => [ 'A', 'B', 'C' ] };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: searching for multiple matches and then seek from last match
by james28909 (Deacon) on Jun 12, 2014 at 02:05 UTC |