Pearl Script Error

I have a a pearl script given to me for parsing my ftp server and then outputting the info to an html file.  I was first getting an interpreter error and then I added -w to #!/usr/bin/perl. Here is the complete command I run:

find . -name '*.pdf' | /var/ftp/parse_directory_list.pl > /var/ftp/index.html

and the error:

find . -name '*.pdf' | /var/ftp/parse_directory_list.pl > /var/ftp/index.html Parentheses missing around "my" list at /var/ftp/parse_directory_list.pl line 11.
Useless use of a variable in void context at /var/ftp/parse_directory_list.pl line 11.
Useless use of a variable in void context at /var/ftp/parse_directory_list.pl line 11.
"my" variable $fileRef masks earlier declaration in same scope at /var/ftp/parse_directory_list.pl line 82.
find: ./Mail: Permission denied
find: ./.dbus: Permission denied

#!/usr/bin/perl -w



my $data;



while(<STDIN>) {



	next if ! m/(agenda|minutes)/;

	chomp;



	my ($dot, $division, $year, $meeting, $file) = split(/\//);

	my $prefix, $date, $suffix;

	if(defined $file) {

		($prefix, $date, $suffix) = $file =~ m/(\D*)(\d*)(\D*)\.pdf/;

		next if ! defined $date;

		# print "$file - Pre: $prefix, Date: $date, Suffix: $suffix\n";

		if( $date =~ m/^\d{5}$/ ) {

			$date = "0" . $date;

		}

	} else {

		next;

	}



	if( defined  $data{$division}{$year}{$date}{$meeting}{$file} ) {

		print "Ooops:  Multiple files for Div: $division Year: $year Date: $date Meeting: $meeting\n";

		print "        Current:  $_\n";

		print "        Previous: $data{$division}{$year}{$date}{$meeting}{$file}\n";

	}

	$data{$division}{$year}{$date}{$meeting}{$file} = $_;



}

print "<style>

<!--

h3 {font: bold 18px Arial;color:#ca0002;border-bottom:3px solid #003366;margin-bottom:12px; padding-top:1px; }

h4 {font: bold 15px Arial;color:#ca1012;border-bottom:3px solid #003366;margin-bottom:5px; padding-top:1px; }

..meeting-table {

	border: none;

	margin: none;

	padding:none;

	border-collapse: collapse;

}



..meeting-date {

	font: normal 12px Arial;

	color:#1010CA;

	background: #F0F0F0; 

	vertical-align: top;

	margin: none;

	padding-bottom: 2px;

}



-->

</style>\n";



print "<table class='meeting-table'>\n";

foreach $div  (sort keys %data) {

	print "<tr><td colspan='5'><h3>$div</h3></td><tr>\n";

	

	my $yearsRef = $data{$div};



	foreach $year ( reverse sort keys %$yearsRef ) {

		print "<tr><td width='30px'></td><td colspan='4'><h4>$year</h4></td></tr>\n";



		my $dateRef =$data{$div}{$year};

		foreach $date (reverse sort keys %$dateRef) {



			my ($mo, $dy, $yr) = $date =~ m/(\d\d)(\d\d)(\d\d\d*)/;

			if($yr =~ m/^\d\d(\d\d)/) {

				$yr = $1;

			}

			print "<tr><td></td><td></td><td class='meeting-date'>$mo/$dy/$yr</td>";



			my $meetingRef = $data{$div}{$year}{$date};



			print "<td class='meeting-date'>";

			my $fileRef = $data{$div}{$year}{$date}{agendas};

			foreach $file ( sort keys %$fileRef) {

				print "$file<br />";

			}

			print "</td>";



			print "<td class='meeting-date'>";

			my $fileRef = $data{$div}{$year}{$date}{minutes};

			foreach $file ( sort keys %$fileRef) {

				print "$file<br />";

			}

			print "</td>";







			print "<tr>\n";

		}

	}

}

print "</table>\n";

Open in new window

#!/usr/bin/perl -w



my $data;



while(<STDIN>) {



	next if ! m/(agenda|minutes)/;

	chomp;



	my ($dot, $division, $year, $meeting, $file) = split(/\//);

	my $prefix, $date, $suffix;

	if(defined $file) {

		($prefix, $date, $suffix) = $file =~ m/(\D*)(\d*)(\D*)\.pdf/;

		next if ! defined $date;

		# print "$file - Pre: $prefix, Date: $date, Suffix: $suffix\n";

		if( $date =~ m/^\d{5}$/ ) {

			$date = "0" . $date;

		}

	} else {

		next;

	}



	if( defined  $data{$division}{$year}{$date}{$meeting}{$file} ) {

		print "Ooops:  Multiple files for Div: $division Year: $year Date: $date Meeting: $meeting\n";

		print "        Current:  $_\n";

		print "        Previous: $data{$division}{$year}{$date}{$meeting}{$file}\n";

	}

	$data{$division}{$year}{$date}{$meeting}{$file} = $_;



}

print "<style>

<!--

h3 {font: bold 18px Arial;color:#ca0002;border-bottom:3px solid #003366;margin-bottom:12px; padding-top:1px; }

h4 {font: bold 15px Arial;color:#ca1012;border-bottom:3px solid #003366;margin-bottom:5px; padding-top:1px; }

..meeting-table {

	border: none;

	margin: none;

	padding:none;

	border-collapse: collapse;

}



..meeting-date {

	font: normal 12px Arial;

	color:#1010CA;

	background: #F0F0F0; 

	vertical-align: top;

	margin: none;

	padding-bottom: 2px;

}



-->

</style>\n";



print "<table class='meeting-table'>\n";

foreach $div  (sort keys %data) {

	print "<tr><td colspan='5'><h3>$div</h3></td><tr>\n";

	

	my $yearsRef = $data{$div};



	foreach $year ( reverse sort keys %$yearsRef ) {

		print "<tr><td width='30px'></td><td colspan='4'><h4>$year</h4></td></tr>\n";



		my $dateRef =$data{$div}{$year};

		foreach $date (reverse sort keys %$dateRef) {



			my ($mo, $dy, $yr) = $date =~ m/(\d\d)(\d\d)(\d\d\d*)/;

			if($yr =~ m/^\d\d(\d\d)/) {

				$yr = $1;

			}

			print "<tr><td></td><td></td><td class='meeting-date'>$mo/$dy/$yr</td>";



			my $meetingRef = $data{$div}{$year}{$date};



			print "<td class='meeting-date'>";

			my $fileRef = $data{$div}{$year}{$date}{agendas};

			foreach $file ( sort keys %$fileRef) {

				print "$file<br />";

			}

			print "</td>";



			print "<td class='meeting-date'>";

			my $fileRef = $data{$div}{$year}{$date}{minutes};

			foreach $file ( sort keys %$fileRef) {

				print "$file<br />";

			}

			print "</td>";







			print "<tr>\n";

		}

	}

}

print "</table>\n";

Open in new window

pwtadmAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Justin MathewsCommented:
Add parentheses on line 11:

my ($prefix, $date, $suffix);

Remove my on line 164:

$fileRef = $data{$div}{$year}{$date}{minutes};

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Justin MathewsCommented:
find: ./Mail: Permission denied
find: ./.dbus: Permission denied

are error messages from find because you don't have permission in those directories.
pwtadmAuthor Commented:
Thanks It's up and running, but it doe not appear to be creating tables and popluatiing the file like it should. The person that gave me the script also gave me his output file to show that he got it working, so i attached it. When I run the script, the output file goes from 75KB to 524 bytes. I attached what the output file should look like.
ftp.pewaukee.index.html
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Justin MathewsCommented:
What is the content of the file generated? Check if pdf files exist using:

find . -name '*.pdf'

OR

by adding a debug print:

while(<STDIN>) {



      next if ! m/(agenda|minutes)/;

      chomp;

                print "File found: $_\n";
pwtadmAuthor Commented:
oh yeah they exist. when i run find . -name '*.pdf from my ftp root, it list them all.
Justin MathewsCommented:

-Check if your directory structure from ftp root matches ./<division>/<year>/<meeting>

-Check if file names match the format <prefix><date><suffix>
pwtadmAuthor Commented:
they do structure is: Common Council > Year(s)> Agenda
file name is ccagenda101810.pdf
Justin MathewsCommented:
With the current code even case difference matters. eg agenda Vs Agenda

Change the line:

next if ! m/(agenda|minutes)/;

To:

next if ! m/(agenda|minutes)/i;

to make it case insensitive.
pwtadmAuthor Commented:
Ok, I'm getting output, but still getting some errors first is line 67 & 93:

syntax error at /var/ftp/parse_directory_list.pl line 67, near "m/^ (\d\d(\d\d)(\d\d\d*))/ {"
syntax error at /var/ftp/parse_directory_list.pl line 93, near "}"
pwtadmAuthor Commented:
tried to make them case insensitive and get this:

Use of uninitialized value in pattern match (m//) at /var/ftp/parse_directory_list.pl line 69, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in pattern match (m//) at /var/ftp/parse_directory_list.pl line 69, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in pattern match (m//) at /var/ftp/parse_directory_list.pl line 69, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in pattern match (m//) at /var/ftp/parse_directory_list.pl line 69, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in pattern match (m//) at /var/ftp/parse_directory_list.pl line 69, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Use of uninitialized value in concatenation (.) or string at /var/ftp/parse_directory_list.pl line 72, <STDIN> line 981.
Justin MathewsCommented:
Can you post your latest code?
pwtadmAuthor Commented:
here you go
#!/usr/bin/perl -w



my %data;



while(<STDIN>) {



	next if ! m/(agenda|minutes)/i;

	chomp;



	my ($dot, $division, $year, $meeting, $file) = split(/\//);

	my $prefix;
my $date;
my $suffix;

	if(defined $file) {

		($prefix, $date, $suffix) = $file =~ m/(\D*)(\d*)(\D*)\.pdf/;

		next if ! defined $date;

		# print "$file - Pre: $prefix, Date: $date, Suffix: $suffix\n";

		if( $date =~ m/^\d{5}$/ ) {

			$date = "0" . $date;

		}

	} else {

		next;

	}



	if( defined  $data{$division}{$year}{$date}{$meeting}{$file} ) {

		print "Ooops:  Multiple files for Div: $division Year: $year Date: $date Meeting: $meeting\n";

		print "        Current:  $_\n";

		print "        Previous: $data{$division}{$year}{$date}{$meeting}{$file}\n";

	}

	$data{$division}{$year}{$date}{$meeting}{$file} = $_;



}

print "<style>

<!--

h3 {font: bold 18px Arial;color:#ca0002;border-bottom:3px solid #003366;margin-bottom:12px; padding-top:1px; }

h4 {font: bold 15px Arial;color:#ca1012;border-bottom:3px solid #003366;margin-bottom:5px; padding-top:1px; }

..meeting-table {

	border: none;

	margin: none;

	padding:none;

	border-collapse: collapse;

}



..meeting-date {

	font: normal 12px Arial;

	color:#1010CA;

	background: #F0F0F0; 

	vertical-align: top;

	margin: none;

	padding-bottom: 2px;

}



-->

</style>\n";



print "<table class='meeting-table'>\n";

foreach $div  (sort keys %data) {

	print "<tr><td colspan='5'><h3>$div</h3></td><tr>\n";

	

	my $yearsRef = $data{$div};



	foreach $year ( reverse sort keys %$yearsRef ) {

		print "<tr><td width='30px'></td><td colspan='4'><h4>$year</h4></td></tr>\n";



		my $dateRef =$data{$div}{$year};

		foreach $date (reverse sort keys %$dateRef) {



			my ($mo, $dy, $yr) = $date =~ m/(\d\d)(\d\d)(\d\d\d*)/;

			if($yr =~ m/^\d\d(\d\d)/) {

				$yr = $1;

			}

			print "<tr><td></td><td></td><td class='meeting-date'>$mo/$dy/$yr</td>";



			my $meetingRef = $data{$div}{$year}{$date};



			print "<td class='meeting-date'>";

			my $fileRef = $data{$div}{$year}{$date}{agendas};

			foreach $file ( sort keys %$fileRef) {

				print "$file<br />";

			}

			print "</td>";



			print "<td class='meeting-date'>";

			$fileRef = $data{$div}{$year}{$date}{minutes};

			foreach $file ( sort keys %$fileRef) {

				print "$file<br />";

			}

			print "</td>";







			print "<tr>\n";

		}

	}

}

print "</table>\n";

Open in new window

Justin MathewsCommented:
Those are just warnings which you can get rid of by removing -w option at the top:

#!/usr/bin/perl

The scripts is working fine if you are getting the output file right and no errors.
AceTCommented:
one small thought, depending on the Linux-config you may need the '-w', to avoid those annoying warnings add:
$|  = 1; # show all result-data immediately (flush)
$^W = 0; # don't show those "Use of uninitialized value in " warnigs...

Open in new window

pwtadmAuthor Commented:
I also ran my script through dos2unix so I didn't have to have the -w option
pwtadmAuthor Commented:
I need some help with the output not generating html :
http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_26556946.html
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.