Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-20 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found