Hello.. I asked a question here earlier about making a logfile and reportfile command line argument type script. Here is what I have.

#!C:\Perl\Bin\Perl.exe # Enable Pragmatic Modules use warnings ; use strict; # Define Variables and Hashes my $numelements ; my $done = 3 ; my $count = 0 ; my $username = "" ; my %userhash ; my $inputfile = "" ; my $outputfile = "" ; my $userlist = "" ; my $record = "" ; my $bigcounter = 0 ; # Argument testing $numelements = @ARGV ; print "\n$numelements\n" ; # Check for 0 arguments and switches, apply error message if true if ( $numelements == 0 ) { print "\n *** Error : Command-line switches and arguments must be p +rovided. ***\n\n" ; print " $0 -l <log_file> -u <userlist_file> -r <report_file>\n\n" ; print " -l <log_file> The relative or absolute path to +the webserver logfile.\n" ; print " -u <userlist_file> The relative or absolute path to +the user list file.\n" ; print " -r <report_file> The relative or absolute path to +the generated report file.\n\n" ; exit 200 ; } # Check to osee that they gave more or less than 6 arguments, appply a +pproproiate error message. if (( $numelements > 0 ) and ( $numelements !~ 6 )) { print "\n *** Error : Too many (or too few) command-line switches a +nd arguments were provided. ***\n\n" ; print " $0 -l <log_file> -u <userlist_file> -r <report_file>\n\n" ; print " -l <log_file> The relative or absolute path to +the webserver logfile.\n" ; print " -u <userlist_file> The relative or absolute path to +the user list file.\n" ; print " -r <report_file> The relative or absolute path to +the generated report file.\n\n" ; exit 201 ; } # Check for double switches if (( $ARGV[0] =~ $ARGV[2] ) or ( $ARGV[2] =~ $ARGV[4] ) or ( $ARGV[0] =~ $ARGV[4] )) { print "\n *** Error : Incomplete (or incorrect) command-line sw +itches and arguments were provided. ***\n\n" ; print " $0 -l <log_file> -u <userlist_file> -r <report_file>\n\ +n" ; print " -l <log_file> The relative or absolute path + to the webserver logfile.\n" ; print " -u <userlist_file> The relative or absolute path + to the user list file.\n" ; print " -r <report_file> The relative or absolute path + to the generated report file.\n\n" ; exit 202 ; } # Start a loop to check for all correct switches, and apply input file +names to variables while ( $done != 0 ) { if ( $count == 6 ) { print "\n *** Error : Incomplete (or incorrect) command-line swit +ches and arguments were provided. ***\n\n" ; print " $0 -l <log_file> -u <userlist_file> -r <report_file>\n\n" + ; print " -l <log_file> The relative or absolute path t +o the webserver logfile.\n" ; print " -u <userlist_file> The relative or absolute path t +o the user list file.\n" ; print " -r <report_file> The relative or absolute path t +o the generated report file.\n\n" ; exit 202 ; } if ( $ARGV[$count] =~ /^-l$/i ) { $inputfile = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-u$/i ) { $userlist = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-r$/i ) { $outputfile = $ARGV[$count + 1] ; $done-- ; } $count = $count + 2 ; } # Check for input file existance and begin to parse file, otherwise di +splay appropriate error message if ( -e $inputfile ) { open( INPUTDATAFILE, "< $inputfile" ) or die " \n\nError: $!\n\n" ; while ( defined( $record = <INPUTDATAFILE> ) ) { if ( $bigcounter == 100000 ) { print "." ; $bigcounter = 0 ; } chomp( $record ) ; if($record =~ /\/\~(c(s|e)[0-9][0-9][0-9][0-9])/) { $username = $1 ; if(exists $userhash{$username}) { $userhash{$username}++; } else{ $userhash{$username}=1 ; } } $bigcounter++ ; } $numelements = %userhash ; print "$numelements\n" ; }else { print "\n *** Error : Webserver logfile '$inputfile' : NOT FOUND. * +**\n\n" ; exit 100 ; } # Check for userlist file, or display apropriate error message if ( -e $userlist ) { }else { print "\n *** User list file '$userlist' : NOT FOUND. ***\n\n" ; exit 101 ; } system "( Pause ) " ;

Now.. My problem is.. I want to find a different way to do the following:

# Start a loop to check for all correct switches, and apply input fil +enames to variables while ( $done != 0 ) { if ( $count == 6 ) { print "\n *** Error : Incomplete (or incorrect) command-line swit +ches and arguments were provided. ***\n\n" ; print " $0 -l <log_file> -u <userlist_file> -r <report_file>\n\n" + ; print " -l <log_file> The relative or absolute path t +o the webserver logfile.\n" ; print " -u <userlist_file> The relative or absolute path t +o the user list file.\n" ; print " -r <report_file> The relative or absolute path t +o the generated report file.\n\n" ; exit 202 ; } if ( $ARGV[$count] =~ /^-l$/i ) { $inputfile = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-u$/i ) { $userlist = $ARGV[$count + 1] ; $done-- ; } if ( $ARGV[$count] =~ /^-r$/i ) { $outputfile = $ARGV[$count + 1] ; $done-- ; } $count = $count + 2 ; }
How Would I accomplish this? I am being told this is an odd way to do this.

In reply to Script Help! by blackice69

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.