I am trying to setup a hash from an array to sort out
related data. I am very much a newbie to perl. I have
a semicolon delimeted file that looks somewhat like this:
Mac PPC;43
Client for Windows NT 4.0;204
(goes on for about 30 lines)
I have that data placed into an array (@calarray) and would like to get the two fields into a hash. I have been unsuccessful so far. My code is:
my @calarray;
#puts data to @calarray like I want it to
while (<OUTFILE>) {
push (@calarray, $_);
}
my $key = "";
my $value = "";
#This is what I'm having trouble with.
%sorting = map {
my ($key, $value1) = split ";";
$key => $value } @calarray;
print "$key, $value";
I have tried multiple other solutions with no luck. I am a newbie, trying to learn perl on my own so I apologize if this is a dumb question. Any thoughts or info is greatly appreciated... Thanks,
Ben
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.