Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^4: Defining hash structure

by mtx (Initiate)
on Aug 25, 2014 at 11:03 UTC ( [id://1098518]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Defining hash structure
in thread Defining hash structure

Thank you all for your help, I got the desired result and didn't have to change the contents of the file, here is the code for reference

use Path::Class; use Data::Dumper; #Input was inserted into a file... my $dir = dir("C:\\temp\\"); my $file = $dir->file("hashinput.txt"); my $file_handle = $file->openr(); my %slotHash = (); while (my $line = $file_handle->getline()){ if (index($line, "Press", 0) == -1 && index($line, "Slot", 0) +== -1) { $value0 = substr($line, 0, 2); $value1 = substr($line, 3, 17); $value2 = substr($line, 20, 15); $value3 = substr($line, 36, 17); $value4 = substr($line, 55, 17); $uptime = $value4; my $find = " days "; my $replace = ":"; $find = quotemeta $find; # escape regex metachars if prese +nt $uptime =~ s/$find/$replace/g; $delimiter = quotemeta(":"); my @uptime = split(/$delimiter/, $uptime); $totalUptime = (((@uptime[0] * 24) * 60) * 60) + ((@uptime +[1] * 60) * 60) + (@uptime[2] * 60) + @uptime[3]; $slothash{$value0} = ( {type => substr($value1,0, 3) ,slotID => $value0, des +cription => $value1,hwVersion => $value2, swVersion => $value3 ,slotI +d => $value0, upTime => $totalUptime} ); } } print Dumper(\%slothash);
THANKS!

Log In?
Username:
Password:

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

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

    No recent polls found