Hello Monks, I want to do something that I am not sure I am able to do, so any help would be appreciated. A brief summary of what I think I want to do: I have a file I want to load into a hash table, this is just a plain csv file, with either a BLANK or an X in its fields. Why? I have a script that needs to determine if the hash field is something I want to turn off. I could use a multi dimenisonal array, but it would be more clear to other developers if I could use a Hash to represent the name of what I want to turn off. I tried to create and initialize the hash table like this:
%HashTempRec = ( 'Name' => '', 'AlarmConsistencyMgr' => '', 'AlarmForwarder' => '', 'AlarmForwarderServer' => '', 'alert_publisher' => '', 'AnalogGatewayMain' => '', 'AssetTracking' => '', 'CallerPosition' => '', );
There are more fields, but for readability I've removed them. So now when I read the csv file, ace.dll,,,X,X,,X,X,X,X,X,X,X,,,,,,,X,X,X,,,,X,,,,,,,,X,,,,,X,,, -- there are more records, but I want to keep this post reasonable. I want to populate the Hash Table with the elements from this file. So I tried to do
for each $item (@Dependency) { @HashTempRec = $item; }
This obvisuouly fails and I don't know where to go from here. Is there a way to load a hash table is this fashion?
--Hash table definiion here-- $Test1 = "D:\\Profiles\\p57571\\Desktop\\Book3.csv"; if( -e $Test1) { print "Opening $Test1\n"; open(PACKAGEINPUT, "<$Test1"); my(@lines) = <PACKAGEINPUT>; foreach $temp(@lines) { chomp $temp; if( $temp =~ m/\S/ig) { #find the extension my $fileExt = substr( $temp, -3 ) ||''; #this searches for exe's then any coresponding dlls + if( $fileExt eq 'exe' ) { foreach my $element( split /,/, $temp) { if( $element =~ m/\.exe/) { #print "element = $element\n"; } } } else { print "temp = $temp\n"; %HastTempRec = $temp; } } } } else { print "$Test1 does not exist\n"; }
thanks in advance. I hope my question and reasons why are clear enough.

In reply to Loading a hash table by JFarr

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.