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.

while (<LOG>) { $alarm_details{ $1 } = $2 if /^(.*)=(.*)$/; }
The other error is that Dumper needs a reference to the array, not the array itself.
{ open my $fh, '>', 'hash.i' or die $!; print $fh Dumper(\@alarm_details); }
To read the Dumper file back:
my $alarm_details_ref = do '/path/to/hash.i';
or,
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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.