#!/usr/bin/perl $type = "u"; if ( $ARGV[0] =~ /^-([udm])$/ ) { $type = $1; shift @ARGV; } &convert(@ARGV); sub convert { my(@files) [EMAIL PROTECTED]; foreach my $file (@files) { next if (not -T $file ); print "Converting file: $file\n"; unless (open(IN, "<$file") ) { print qq|Unable to open file "$file"\n|; next; } unless ( open(OUT, ">${file}.tmp") ) { print qq|Unable to open temporary output file\n|; next; } if ( $type eq 'u' ) { while (<IN>) { s/\r\n/\n/g; print OUT; } } elsif ( $type eq 'm' ) { while (<IN>) { s/\r\n|\n/g; print OUT; } } elsif ( $type eq 'd' ) { while (<IN>) { s/\r|\n/\r\n/g; print OUT; } } close OUT; close IN; unless ( rename("file", "${file}~") ) { print qq|Failed to rename old file\n|; next; } unless ( rename("${file}.tmp", "$file") ) { print qq|Failed to rename new file\n|; next; } } } I have few question regarding code above, 1. what the function for if ( $ARGV[0] =~ /^-([udm])$/ ) { $type = $1; shift @ARGV; } &convert(@ARGV); 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? thanks, any comment.
--------------------------------- Do You Yahoo!? Get your free @yahoo.com.hk address at Yahoo! Mail.