Reputation: 503
I'm using the command line to pass a string to a Perl program. For instance, this passes "stackOveflow"
to the program hello
hello "stackOveflow"
I use chop
to remove the last character from the last element of @ARGV
chop($ARGV[$#ARGV]);
and then print it
say "$ARGV[$#ARGV]";
I'm expecting "stackOveflow
in the output, but instead I'm seeing stackOveflo
Can someone tell me why?
Upvotes: 0
Views: 229
Reputation: 386416
hello "stackOveflow"
tells the shell to execute the program hello
and pass the string stackOveflow
to it as an argument (similar to how my $s = "stackOveflow";
assigns the string stackOveflow
to $x
in Perl).
chop
removes the last character of the string, so the value changes from stackOveflow
to stackOveflo
.
$ perl -E'say $ARGV[-1]; chop($ARGV[-1]); say $ARGV[-1]' "stackOveflow"
stackOveflow
stackOveflo
Upvotes: 1