command line argument - perl

how do i check if a command line argument is -g?

for example,

if command line argument equals "-g"
{
  print "Goodbye \n";
}
else
{
  print "Welcome to the program! \n";
}

Hi bshell_1214,

Try:

if ( grep { $_ eq qq[-g] } @ARGV ) {
        print "Goodbye \n";
}
else {
        print "Welcome to the program! \n";
}

Regards,
Birei

1 Like