PyrexKidd has asked for the wisdom of the Perl Monks concerning the following question:
can I get some help adding some error checking. when my source file CONF_ID has blank lines it gives me an error of uninitialized value in $confID and $confPIN, which is true, how would I test for this before running the rest of the code?
also are there any other suggestions on cleaning up the code?
And lastly, is there a more secure way to copy files to a server w/o putting the password in the perl file?
#!/usr/bin/perl # # Written By Jon # This script takes CONF_IN and populates # 3 templates which are then put into a final file all # together # Usage: perl conf_add.pl # requires: # input: templates in templates folder # input: list of conference IDs and conference PINs # with ID and PIN on one line in order. # program outputs to file: conference_additions # # TODO: Error handling when there are no entries in CONF_ID # TODO: SCP files to server # TODO: Random Number Generator # TODO: Add insert.pl use strict; use warnings; use File::Copy ("cp"); my($confINPUT); my($i) =0; #my($confOutName) = $ARGV[0]; my($date) = &getDate; open(CONF_ID, "<", "$ARGV[0]") || die("$!\n"); open(CONFLIST1, ">>", "conf_list1.tmp") || die("$!\n"); open(CONFLIST2, ">>", "conf_list2.tmp") || die("$!\n"); open(CONFLIST3, ">>", "conf_list3.tmp") || die("$!\n");; open(CONFADD, ">>", "./additions/additions\_$ARGV[0]\_$date") || die( +"$!\n"); while(<CONF_ID>){ $i++; open(TEMPLATE1, "<", "./templates/conf_template1") || die("$!\n") +; open(TEMPLATE2, "<", "./templates/conf_template2") || die("$!\n") +; open(TEMPLATE3, "<", "./templates/conf_template3") || die("$!\n") +; my($confINPUT) = $_; (my($confID), my($confPIN)) = split(" ",$confINPUT); while(<TEMPLATE1>){ $_ =~ s/XXXXXX/$confID/g; print CONFLIST1 $_; } while(<TEMPLATE2>){ $_ =~ s/XXXXXX/$confID/g; $_ =~ s/AAAA/$confPIN/g; print CONFLIST2 $_; } while(<TEMPLATE3>){ $_ =~ s/XXXXXX/$confID/g; print CONFLIST3 $_; } close(TEMPLATE1) || die("$!\n"); close(TEMPLATE2) || die("$!\n"); close(TEMPLATE3) || die("$!\n"); } # close files for input close(CONFLIST1) || die("$!\n"); close(CONFLIST2) || die("$!\n"); close(CONFLIST3) || die("$!\n"); # open files for output open(CONFLIST1, "<", "conf_list1.tmp") || die("$!\n"); open(CONFLIST2, "<", "conf_list2.tmp") || die("$!\n"); open(CONFLIST3, "<", "conf_list3.tmp") || die("$!\n"); # adds 1st set of conf config to conf_additions print CONFADD ("; start conference config 1\n"); while(<CONFLIST1>){ print CONFADD $_; } # adds 2nd set of conf config to conf_additions print CONFADD ("\n\n; start conference config 2\n"); while(<CONFLIST2>){ print CONFADD $_; } # adds 3rd set of conf config to conf_additions print CONFADD ("\n\n; meetme_additional_custom.conf\n"); while(<CONFLIST3>){ print CONFADD $_; } close(CONFADD); # closes temporary files close (CONFLIST1) || die("$!\n"); close (CONFLIST2) || die("$!\n"); close (CONFLIST3) || die("$!\n"); # moves list to finished folder cp("$ARGV[0]", "./finished_list/$ARGV[0].finished"); unlink("$ARGV[0]"); # deletes temporary files unlink("conf_list1.tmp") || die("$!\n"); unlink("conf_list2.tmp") || die("$!\n"); unlink("conf_list3.tmp") || die("$!\n"); print("Number of Entries processed: $i\n"); exit(0); sub getDate(){ my(@months) = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my(@weekDays) = qw(Sun Mon Tue Wed Thu Fri Sat Sun); my($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $day +OfWeek, $dayOfYear, $daylightSavings) = localtime(); my($year) = 1900 + $yearOffset; my($theTime) = "$dayOfMonth\_$months[$month]"; return $theTime; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Error Correction
by almut (Canon) on Apr 22, 2010 at 21:56 UTC | |
|
Re: Error Correction
by chromatic (Archbishop) on Apr 22, 2010 at 21:48 UTC | |
|
Re: Error Correction
by amedico (Sexton) on Apr 23, 2010 at 07:00 UTC | |
|
Re: Error Correction
by toolic (Bishop) on Apr 23, 2010 at 00:36 UTC | |
|
Re: Error Correction
by Khen1950fx (Canon) on Apr 22, 2010 at 23:12 UTC | |
|
Re: Error Correction
by apl (Monsignor) on Apr 23, 2010 at 11:36 UTC |