I'm not sure what you're really trying to achieve with this, but let's make sure you know how arrays get assigned to hashes.
my @array = (1, 2, 3, 4, 5, 6);
my %hash = @array;
Is the same as saying:
my %hash = ( 1 => 2, 3 => 4, 5 => 6 );
apart from not having an @array floating around in the second version of course. If you really want to get each non-empty line in your input file into a hash with a key that's generated by some iterative process, you want something like
open my $file, '<', $filename or die "Unable to open '$filename': $!";
my %edit;
for (<$file>) {
next if //;
chomp;
# Some code to get a $key with an appropriate value
$edit{$key} = $_;
}
close $file;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.