Hi again, Edward!
Just so you know, you should CC the list when you reply!
On Tue, 28 Sep 2004 22:26:55 +0800, Edward Wijaya
<[EMAIL PROTECTED]> wrote:
> Thanks Errin,
> It works just as you suggested.
> Thanks so much for your thorough
> explanation. Glad that I learnt much from it.
>
> >
> > Edward, I could write this script two ways. The first is the way I
> > prefer and it doesn't use 'Getopt::Std' at all:
> >
> I need to use Getopt, as I will increase
> the number of user given options.
>
> Regards
> Edward WIJAYA
>
I'm glad I could help!! Just wanted to mention one last thing. Just
because you have to use Getopt::Std doesn't mean you can't ALSO use
the diamond ('<>') operator. Let me demonstrate:
#!/usr/bin/perl
use warnings;
use strict;
use Getopt::Std;
our $opt_p;
getopts( 'p:' );
if( $opt_p ) {
print "You used the -p flag. The value passed was $opt_p\n";
}
while( <> ) {
print;
}
The above will print out all the lines of the file found at the END of
your command line (that's the diamond operator at work), but it will
also allow you to specify some other option with a '-p'. So, if you
have a text file called test.txt:
Test Data
More Test Data
Other Test Data
and you call the above program with this command line:
# test_options.pl test.txt
the output will be as follows:
Test Data
More Test Data
Other Test Data
if You instead use THIS command line:
# test_options.pl -p foobar test.txt
the output will be as follows:
You used the -p flag. The value passed was foobar.
Test Data
More Test Data
Other Test Data
I hope that makes sense. Don't forget that the diamond operator will
see more than one filename on that command line as well:
# test_options.pl -p foobar test.txt test.txt
You used the -p flag. The value passed was foobar.
Test Data
More Test Data
Other Test Data
Test Data
More Test Data
Other Test Data
HTH
--Errin
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>