Re: Why doesn't this work: perl -e "@s=([1,2],[3,4]); print $s[0][0];"



Zembower, Kevin wrote:
(This should probably be an easy one for someone.}

Why doesn't this work:
kevinz@centernet:/usr/local/src/rrd$ perl -e "@s=(["a","b"],["c","d"]);print $s[0][0];"
syntax error at -e line 1, near "]["
Execution of -e aborted due to compilation errors.

The shell interpolates your string before perl sees it:

$ echo "@s=(["a","b"],["c","d"]);print $s[0][0];"
@s=([a,b],[c,d]);print [0][0];

So use single quotes instead:

$ echo '@s=(["a","b"],["c","d"]);print $s[0][0];'
@s=(["a","b"],["c","d"]);print $s[0][0];



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.



Relevant Pages

  • Re: problems to connect to a mysql-database
    ... CAMPBELL, BRIAN D wrote: ... Your Windows path delimiters act as escape chars in Perl. ...
    (perl.dbi.users)
  • Re: DBI Issue with MySQL query
    ... Red Hat Linux Workstation 4.0 on Intel Pentium 4 ... DBI 1.50 ... Don't put single quotes around the table name. ... but fails in perl with a malformed SQL syntax error: ...
    (perl.dbi.users)
  • Re: Odd behaviour with has key - wide character
    ... use strict; ... Execution of - aborted due to compilation errors. ... but this is because I do have Perl ... "Version Strings" in the perldata documentation. ...
    (comp.lang.perl.misc)
  • Re: Scientific Ruby (was Re: enterprise ruby)
    ... Ruby is the newest language in my toolbox, ... years behind R and ten years behind Perl. ... The other side of that coin, ...
    (comp.lang.ruby)
  • Re: FTP Errors?
    ... IMO it's best to use single quotes for strings unless you particularly need ... they will make Perl shell out to execute ... Presumably you don't have execute permission for ...
    (perl.beginners)