Re: Why doesn't this work: perl -e "@s=([1,2],[3,4]); print $s[0][0];"
- From: jwkrahn@xxxxxxx (John W. Krahn)
- Date: Fri, 31 Oct 2008 10:50:52 -0700
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
.
- References:
- Why doesn't this work: perl -e "@s=([1,2],[3,4]); print $s[0][0];"
- From: Kevin Zembower
- Why doesn't this work: perl -e "@s=([1,2],[3,4]); print $s[0][0];"
- Prev by Date: RE: Why doesn't this work: perl -e "@s=([1,2],[3,4]); print $s[0][0];"
- Next by Date: Re: merge 2 or more files together without creating new file
- Previous by thread: RE: Why doesn't this work: perl -e "@s=([1,2],[3,4]); print $s[0][0];"
- Index(es):
Relevant Pages
|