use strict;
use warnings;
use Getopt::Long;
# make a copy of the cmd line before GetOptions processes it
my $cmd_line = join( ' ', @ARGV );
my $saw_something = 0;
my @things;
GetOptions( 'something:s' => sub { shift @_; $saw_something = 1;
push( @things, grep { $_ ne '' } @_ ); } );
if( $cmd_line =~ m/-?-something\b/ )
{
print "I saw something on the cmd line\n";
}
if( $saw_something )
{
if( scalar @things )
{
print 'And it was ' . join( ' ', @things ) . "\n";
}
else
{
print "But I don't know what I saw\n";
}
}
####
C:\>test.pl --something NodeReaper
I saw something on the cmd line
And it was NodeReaper
####
C:\>test.pl --something
I saw something on the cmd line
But I don't know what I saw
####
C:\>test.pl --something a -something grue
I saw something on the cmd line
And it was a grue