On Jun 25, 2004, at 2:49 AM, Jame Brooke wrote:

#!/usr/bin/perl

[snip code]

I have few question regarding code above,

1. what the function for

if ( $ARGV[0] =~ /^-([udm])$/ ) {
    $type = $1;
    shift @ARGV;
}
&convert(@ARGV);

It's grabbing the command line switches, crudely. Better would be to use the standard module Getopt::Std.


2. How i add line to the script that would print out a usage line, if wrong number of the argument are give in the script?

die "Usage: whatever you want to say here\n" unless @ARGV;

That line will check that you are passed arguments. If you want to check for a certain number of arguments, add a == # after the @ARGV.

thanks, any comment.

I have a few more comments.

1. I'm assuming this script converts line endings from DOS to other formats. If types u, m, and d represent Unix, Mac, and DOS, the Mac conversion is incorrect. That replacement should be:

s/\r\n|\r/g; # for Mac OS 9 and below; OS X+ is Unix and uses that conversion

2. As written, the script is not portable. It probably works on DOS/Windows and Unix. It will not work on old versions of the Mac OS and possibly other platforms. To fix this, you need to replace all \r and \n characters with their escapes \015 and \012.

3. This script doesn't use strict and warnings, and it should. See my previously posted rant today in the thread "Printing outside of foreach...".

4. Replace &convert(...) with convert(...). That's how we call subs now.

5. The script can definitely be simplified a lot, if desired. That is left as an exercise for the reader... ;)

James


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




Reply via email to