You're using numeric comparison to check string equality, which converts the arguments to numbers first before comparing them.
In this case, 'start' is not a number, so it gets converted to 0
; the value in $ARGV[0]
(which is expected to be a word here) is also converted, resulting in another 0
and a final condition of if (0 == 0)
, which is always true.
You want to use the eq
string-wise comparison operator instead:
if ($ARGV[0] eq 'start') { start }
See the docs for more information on the different comparison operators.
Note that (as has been pointed out in the comments) including use warnings;
at the top of your script would have caused perl
to warn you about this from the start. Always including use warnings;
and use strict;
is generally best practice, as it helps catch these kinds of errors early.