[Chicago-talk] Bareword found where operator expected

Alexander Danel danel at speakeasy.net
Mon Mar 8 05:44:08 PST 2010

Your quoting is not working as you expect.  Don't feel bad -- everybody goes
through this at some point.  You are going through several levels of
interpretation.  At the first level, the single quotes are within double
quotes, and therefore the single quotes have no special meaning.  Since the
single quotes are not giving you any protection, the next double quote DOES
have special meaning -- it is the end of the quoted string.  Therefore, the
word "Hello" is not within a quoted string; so the compiler is trying to
interpret it as something that could possibly stand alone, i.e. a

Shield the internal quotation marks with backslashes.  Furthermore, although
"\n" will work as it stands, it does so for the wrong reason; I recommend
you escape the backslash by using double backslash, like this: "\\n".

Alexander Danel

-----Original Message-----
From: chicago-talk-bounces+danel=speakeasy.net at pm.org
[mailto:chicago-talk-bounces+danel=speakeasy.net at pm.org] On Behalf Of
Richard Reina
Sent: Monday, March 08, 2010 7:28 AM
To: chicago-talk at pm.org
Subject: [Chicago-talk] Bareword found where operator expected

I was hoping someone might help me figure out why this simple three line
program won't work.

If I do:

#!/usr/bin/perl -w

use strict;
system("gnome-terminal -x perl -e 'print "Hello World\n"; sleep 4;'");

I get:

Bareword found where operator expected at test.pl line 5, near
""gnome-terminal -x perl -e 'print "Hello"
	(Missing operator before Hello?)
String found where operator expected at test.pl line 5, near "n"; sleep
syntax error at test.pl line 5, near ""gnome-terminal -x perl -e 'print
"Hello World"
Execution of test.pl aborted due to compilation errors.

What is especially confusing to me is that if I type in:

gnome-terminal -x perl -e 'print "Hello World\n"; sleep 4;

at the command line, it works.  I am running linux.

Any help would be greatly appreciated.

Chicago-talk mailing list
Chicago-talk at pm.org

More information about the Chicago-talk mailing list