in reply to Help display when executing the script

if(@ARGV="h")

A single equals sign is an assignment operator. You're overwriting the value of @ARGV with "h". As "h" is true, that expression will always be true.

You need two equals signs to check equality. But that checks _numeric_ equality, so you actually need "eq"

if(@ARGV eq "h")

But that's still not right as that compares "h" to the number of elements in @ARGV. If the "h" will always be the first option on the command line, then you could do this:

if ($ARGV[0] eq 'h')

Or to cover more options, you could use this:

if (grep { $_ eq 'h' } @ARGV)

But really, you should look at one of the command line option processing modules like Getopt::Std or Getopt::Long.

--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Help display when executing the script
by Not_a_Number (Prior) on Aug 08, 2006 at 17:09 UTC
    As "h" is true that expression will always be true.

    To be pedantic, it is not because "h" is true that the expression is true, otherwise

    if ( @ARGV = 0 )

    would evaulate to false, which it doesn't.

    Rather, if my reading of perlop is correct, it is because the assignment operator returns true (or more strictly, the number of elements assigned to @ARGV):

    my $return = @ARGV = ( 1, 2, 3 ); print $return;

    prints 3.

    Update: fixed typos in text.