You can print the Dumper output to an open file handle. Read back with do.
You have two errors there which needs to be corrected. You need make the hash value assignment conditional on a fresh match. As you have it, $1 will still be defined forever after the first match. That will do no great harm, but it could be a lot of lost motion. It's a good habit to get into when using regex backreferences.
The other error is that Dumper needs a reference to the array, not the array itself.while (<LOG>) { $alarm_details{ $1 } = $2 if /^(.*)=(.*)$/; }
To read the Dumper file back:{ open my $fh, '>', 'hash.i' or die $!; print $fh Dumper(\@alarm_details); }
or,my $alarm_details_ref = do '/path/to/hash.i';
my @old_alarm_details = @{do '/path/to/hash.i'};
(Added) Ha! I thought you wanted a file, 'hash.i'. To simply make the hash available without persistence, either return the reference as suggested above (preferred), or make @alarm_details a global package variable.
After Compline,
Zaxo
In reply to Re: reuse hashes in another method
by Zaxo
in thread reuse hashes in another method
by perumal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |