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...
Expand|Select|Wrap|Line Numbers
- #!/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);
Expand|Select|Wrap|Line Numbers
- #!/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;
Expand|Select|Wrap|Line Numbers
- 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..
Expand|Select|Wrap|Line Numbers
- #!/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