Hello there.
I have a CSV file that has some data including a timestamp (column 6). I am trying to parse out the last field of data from each row in the CSV file and then use each field separately to compare with one another. Basically I am trying to see if the last two fields are 300 seconds apart. If I could only parse the data out correctly, I could compare the two values. PLEASE HELP, I am a Perl Newbie!! The CSV file looks like:
I have tried Text::CSV, Text::CSV_XS etc but I just can't figure out how to work them. I seem to be getting Array Refs back rather than useful data. I think I came closest to figuring it out when I tried this code:
However this code only prints the following:
I believe these are array refs but I have no idea on how to extract the data I want through them. Thanks so much!
I have a CSV file that has some data including a timestamp (column 6). I am trying to parse out the last field of data from each row in the CSV file and then use each field separately to compare with one another. Basically I am trying to see if the last two fields are 300 seconds apart. If I could only parse the data out correctly, I could compare the two values. PLEASE HELP, I am a Perl Newbie!! The CSV file looks like:
Code:
TIME,SERVERNAME,COUNTERNAME,CURRENTVALUE,THRESHOLDBROKEN,TIMEINSECONDS
Mon Apr 9 11:31:11 2007,MULTI1,C:,22.7,20%,1176143471
Mon Apr 9 11:36:12 2007,MULTI1,C:,22.7,20%,1176143772
I have tried Text::CSV, Text::CSV_XS etc but I just can't figure out how to work them. I seem to be getting Array Refs back rather than useful data. I think I came closest to figuring it out when I tried this code:
Code:
#!/usr/local/bin/perl
#
# Log File Base Directory
$logdir = "C:\\Inetpub\\wwwroot\\MRTG\\Servers\\[servernamehere]\\thresh\\";
$logfile = "server.storage1.txt";
$filename = $logdir . $logfile;
use Text::CSV::Simple;
# Only want certain fields?
my $parser = Text::CSV::Simple->new;
$parser->want_fields(5);
my @data = $parser->read_file($filename);
#should be the header field (TIMEINSECONDS);
print $data[0];
#should be the first row, 5th column data field;
print $data[1];
#should be the fifth row, 5th column data field;
print $data[2];
However this code only prints the following:
Code:
ARRAY(0x1a0a414)ARRAY(0x1a0a408)ARRAY(0x1a0a3fc)
I believe these are array refs but I have no idea on how to extract the data I want through them. Thanks so much!