On Mar 30, 6:54 am, [EMAIL PROTECTED] (John W. Krahn) wrote:
> That is usually written as:
>
> if ( @ARGV != 1 ) {
>
Good tip.  Thank you.


> Why not pass $EX_USAGE to ExitScript() instead of using global $ExitStatus?
>
>         ExitScript( $EX_USAGE );
Consistency is all.  I try to get into a habit of doing things the
same way all of the time.  Also, once I get the program debugged, I'll
end up with only one call to ExitScript somewhere at the bottom of the
script.  I've only placed multiple calls to ExitStatus for debugging
purposes, though I don't know why.
>
> die() exits the program.
>
Yes, I understand that die() exits the program.  My question was are
you able to process more than one line of code in a die() context?
Since I didn't know the answer to that, I set my $ExitStatus varialbe
to $EX_NOINPUT so that I would be able to process more than one line
of code before `die`ing.
>
> You are using the assignment operator so the test is always true.  You
> need to test for numerical equality instead:
>
>         if ( $ExitStatus == $EX_NOINPUT ) {
>
There's my problem.  Thank you for pointing it out to me.  I must have
looked at that line of code 100 times and never noticed that I
assigned instead of compared.  I corrected that in my script and it
works fine now.  Now, I am able to move on to actually processing the
file.
>
 You are using the $! variable six statements away from the open()
> statement which means that there is no guarantee that its value will be
> related to what open() may have set it to.
>
Yes, but I'm doing nothing between the open() and where I use it that
should cause it to be changed.  Plus, if you look at the output from
the run of my script, you can see that it is reporting the correct
error.  However, you bring up a good point regarding the distance, so
I am going to make the next line after the open() statement an
assignment to a variable to hold that exit error, just in case.
>
>
> Pass the exit code to your subroutine:
>
>         my $ExitStatus = shift;
>
What does `shift` do? And, how does the line `my $ExitStatus = shift;`
pass the exit code to my subroutine?
>
> >    if ( $ExitStatus == 64 ) {
>
> Shouldn't that be:
>
>         if ( $ExitStatus == $EX_USAGE ) {
>
Yes, yes it should...thanks for noticing that one.  *grin*
>
> >            system ( 'clear' );
> >            print "INVOICE GENERATOR v0.6\n";
> >            print "~~~~~~~~~~~~~~~~~~~~~~\n";
> >            print "PekinSOFT Systems\n";
> >            print "Copyright(c) 2008\n";
> >            print "\n";
> >            print "\n";
> >            print "USAGE:  invoice {TimeCard Filename}\n";
> >            print "\n";
> >            print "   TimeCard Filename\tName of the time card for which to 
> > have
> > an invoice generated.\n";
> >            print "\n";
>
> The subroutine is named 'ExitScript' but you are not exiting here?
>
Good catch!  My logic is flawed here.  The exit($ExitStatus) call
should not be in and `else` block, there shouldn't *be* and `else`
block.  I've got that fixed.
>
> John
>
Thank you for all of your input, John.  I've made the corrections
noted above and the script now seems to be easier to read and running
the way I intended.  All-in-all, though, that's not too bad for my
first Perl script, huh?  I mean, I normally develop in Java and Qt,
but just wanted a quick and dirty script to parse my TimeCard files
into invoices.  However, I didn't want to use Bash because that would
have involved a lot of `grep`ing, `awk`ing and `sed`ing, and I'm not
too good with awk and sed.

Cheers,

Sean Carrick
PekinSOFT Systems
PekinSOFT at gmail dot com


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to