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; }

In reply to Error Correction by PyrexKidd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.