new_perl
new_perl

Reputation: 7735

What's wrong when running commandline perl here?

[root@dev-test test]$ perl -e "%hash=(key,1);print 1 if exists $hash{key};"
exists argument is not a HASH or ARRAY element at -e line 1.

The above works if I put it in a file,but why command line fails?

Upvotes: 0

Views: 90

Answers (2)

ldav1s
ldav1s

Reputation: 16305

$hash is being treated by the shell as a variable.

Upvotes: 6

TLP
TLP

Reputation: 67900

Works for me (windows). Perhaps in your OS you need to use single quotes? Looks like linux/unix, and double quotes expand variables prefixed with the $ dollar sign.

Upvotes: 1

Related Questions