Hello all! Newbie here, I've been tasked with a fairly intensive project here and my perl skills are still at a minimum so this post may eventually turn into a long one, but I am only going to ask the immediate problems I am having first and try to figure the rest out myself.
Basically I need to compare the contents of a directory, with the contents of a series of 'csv' files, when those two match it will trigger some moving of the contents of said directory to another one. But first here is the issue I am having.
I can print the contents of the directory like this...
Although its adds a . and .. to the array, thats fine I just added them to my csv files. I can also print the contents of a csv with this
one problem here is that I can't get the array to sort tried this for lines 11 and 12
but that does work either... help here would also be much appreciated.
finally I piece the code together and try and do a cmp with my two arrays, but I am obviously taking everything out of contents am lost. here is what the whole mess looks like pieced together..
I get warnings of "Use of uninitialized value $MyDir in string comparison (cmp) at line 28" and "Use of uninitialized value $MyDir2 in string comparison (cmp) at line 28"
and "not the same" prints, not sure if its cause the second list in not sorted correctly or its just not reading them right.
Any assistance will greatly be appreciated!
Thanks,
Eric
Basically I need to compare the contents of a directory, with the contents of a series of 'csv' files, when those two match it will trigger some moving of the contents of said directory to another one. But first here is the issue I am having.
I can print the contents of the directory like this...
Code:
#!/usr/bin/perl
use strict;
use warnings;
opendir(DIR, "D:/data/eclipse/workspace/contents");
foreach my $MyDir (sort readdir(DIR))
{
print "$MyDir\n";
}
closedir (DIR);
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
my $MyDir2 = "D:/data/eclipse/workspace/contents/navteq/01.csv";
my $csv = Text::CSV->new();
open (CSV, "<", $MyDir2) or die $!;
while (<CSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
print "$columns[0]\n";
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV;
Code:
my @columns = $csv->fields(); my @columns2 = sort $columns[0]; print "$columns2[0];
finally I piece the code together and try and do a cmp with my two arrays, but I am obviously taking everything out of contents am lost. here is what the whole mess looks like pieced together..
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
opendir(DIR, "D:/data/eclipse/workspace/contents/RijTijd_in");
foreach my $MyDir (sort readdir(DIR))
{
print "$MyDir\n";
}
closedir (DIR);
my $MyDir2 = "D:/data/eclipse/workspace/contents/navteq/01.csv";
my $csv = Text::CSV->new();
open (CSV, "<", $MyDir2) or die $!;
while (<CSV>) {
if ($csv->parse($_)) {
my @columns = $csv->fields();
print "$columns[0]\n";
} else {
my $err = $csv->error_input;
print "Failed to parse line: $err";
}
}
close CSV;
if (my $MyDir cmp my $MyDir2)
{print "it is the same\n";
} else {
print "not the same\n"
}
and "not the same" prints, not sure if its cause the second list in not sorted correctly or its just not reading them right.
Any assistance will greatly be appreciated!
Thanks,
Eric
Comment