Why does the second one-liner work despite the single quotes in it?
perl -wE 'say('Hello')'
# Name "main::Hello" used only once: possible typo at -e line 1.
# say() on unopened filehandle Hello at -e line 1.
perl -wE 'say length('Hello')'
# 5
Why does the second one-liner work despite the single quotes in it?
perl -wE 'say('Hello')'
# Name "main::Hello" used only once: possible typo at -e line 1.
# say() on unopened filehandle Hello at -e line 1.
perl -wE 'say length('Hello')'
# 5
Copyright © 2021 Jogjafile Inc.
In a shell command,
'abc'def,abc'def',abcdefand'abcdef'are all equivalent, so'...'Hello'...'is the same as'...Hello...'.For
perl -wE 'say('Hello')', your shell callsIf the first argument of
sayis a bareword and no sub has been declared with that name, the bareword is used as a file handle.For
perl -wE 'say length('Hello')', your shell callsIf a bareword is found, no sub has been declared by that name, a file handle is not expected, the next token isn't
=>, anduse strict 'subs';is not in effect, the bareword is a string literal that returns itself.Solutions:
Note that
perldoesn't require the code to be a separate argument.