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:
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
OUTPUT:
$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'
]
};
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?.
All I did, was to get data from searchfile as keys of an hash, then using a regex, pick out what I need from the key file, if the hash keys exists. Then display it.
If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author
unknown to me