Skip to content

Instantly share code, notes, and snippets.

@JannikZed
Last active August 29, 2015 14:18
Show Gist options
  • Save JannikZed/75d5c97c0fdbf3fcada5 to your computer and use it in GitHub Desktop.
Save JannikZed/75d5c97c0fdbf3fcada5 to your computer and use it in GitHub Desktop.
The first draft of the perl script to open and analyse the csv data from IR.
#! /usr/bin/perl -w
#
use strict;
use warnings;
use Text::CSV;
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n"; # To get the .csv file from the command-line parameter
my $csv = Text::CSV->new ({
binary => 1,
auto_diag => 1, # Report irregularities immediately
sep_char => ';' # not really needed as this is the default
});
my @Werte = ();
open(my $fh, '<:encoding(utf8)', $file ) or die "Could not open '$file' $!\n";
$csv->getline ($fh); # read the csv-File line-by-line
while (my $row = $csv->getline ($fh)) {
if ($row->[0] eq 'D' && substr($row->[4],0 ,3) eq 'GTP') { # only use the lines with "D" in the first row and where the service-description starts with "GTP"
push(@Werte, ["$row->[1]", "$row->[4]", "$row->[8]", "$row->[14]"]); # Build an array in the array @Werte with ['Start_Time', 'Service_description', 'Time_ok_unscheduled', 'Time_warning_scheduled']
}
}
close $fh;
print "@{$Werte[3]}[0]\n"; # Print one value to test, if everything works correctly (This is the syntax to derefer an array in an array. https://perl-seiten.homepage.t-online.de/html/perl_array.html)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment