Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: How do I load a hash table?

by rjsaulakh (Beadle)
on Jan 13, 2005 at 08:22 UTC ( [id://421912]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I load a hash table?
in thread How do I load a hash table?

the log files has several entries but the entry i have to keep track of is

SQL for inserting : INSERT INTO PRONTO_REQUEST_LOG (REQUEST_ID,REQUEST_DATE_TIME, NAS_ID, REQUEST_VERSION, REQUEST_MSG_CODE,RESPONSE_VERSION, RESPONSE_STATUS, RESPONSE_MSG_CODE) VALUES(request_log_seq.nextval, to_date('12/28/2004 12:48:08','mm/dd/yyyyHH24:MI:SS'), '00:d0:cf:61:95:e1', 3, 1, 1, 0, 1)

i am able to retrieve the NAS_ID,RESPONSE_STATUS,REQUEST_DATE_TIME ,/p>

what i want is to get all this values in a hash table

if($line =~ /SQL for inserting : INSERT INTO PRONTO_REQUEST_LOG/) { @data = split(/,/, $line); # get the +data $nas = $data[$#data -5]; # get the +nas id $nas =~ s/\s+//g; $response_status = $data[$#data -1]; +# get the response status $response_status =~ s/\s+//g; # here you get the time at which the i +nit request time ; $date = $data[$#data -7]; @request = split(/'/, $date); $request_date_time = $request[$#reques +t - 0]; print " $request_date_time \n "; $list{$nas}{$response_status} = $reque +st_date_time; #take input from the user chomp( $input = <STDIN> ); $output_mac = "'". $input ."'"; if($list{$output_mac} eq "") { print "Not found \n "; } else { here i want to compare the response_status to 0 if it is successful i +want to print the corresponind mac, reponse and date print " $date1 = $list{ $key0 } " or die " the response_status was fai +led $!";; }

please let me know is my approach fine

or shloud i take different approach

thx

Replies are listed 'Best First'.
Re^3: How do I load a hash table?
by castaway (Parson) on Jan 13, 2005 at 08:41 UTC
    Much better!
    Now that we know what you are talking about, here are some suggestions:
    • Add a use Data::Dumper; line to the top of your script
    • Add print Dumper(\%list); after you have finished filling the hash, then you will see what information is in it.
    • To check if a value exists in a hash, you can use the exists function, eg: if(exists($list{$output_mac})).
    • You are storing the response_status as a hash key, and not a value, try storing it like this: $list{$nas} = {response_status => $response_status, request_date_time => $request_date_time };
    Now you can read it like this:
    if($list{$output_mac}{response_status} == 0) { print "Mac found: $output_mac\n"; print "Response Status: $list{$output_mac}{response_status}\n"; print "Date/Time: $list{$output_mac}{request_date_time}\n"; }
    I hope this helps you some.

    C.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://421912]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-19 02:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found