weird "perl -e" behaviour

Discussion in 'Perl Misc' started by Francois Wisard, Jul 30, 2003.

  1. Hi folks,

    I encounter a strange "perl -e" behaviour since I'm running FreeBSD 5.1
    (Perl 5.6.1). My one-liners are refused with strange error messages.

    Some examples:

    bash-2.05b$ perl -e "@a=('a'..'z');print $a[5]"
    ARRAY(0x810115c)bash-2.05b$

    or

    bash-2.05b$ perl -e "$_="abc";s/b/c/g;print $_"
    Undefined subroutine &main::ls called at -e line 1.

    or even

    bash-2.05b$ perl -e "@a=('a'..'z');print $#a"
    Bareword found where operator expected at -e line 1, near "0a"
    (Missing operator before a?)
    syntax error at -e line 1, next token ???

    Anyone knows what happens there? I'm tired of writing files when a
    one-liner should have sufficed.

    TIA

    Francois


    --
    "The main reception foyer was almost empty but Ford
    nevertheless weaved his way through it."

    - Ford making his way out of Milliways whilst under the
    influence of enough alchol to make a rhino sing.
    Francois Wisard, Jul 30, 2003
    #1
    1. Advertising

  2. On 30 Jul 2003 13:58:54 +0200, Francois Wisard wrote:
    > bash-2.05b$ perl -e "$_="abc";s/b/c/g;print $_"
    > Undefined subroutine &main::ls called at -e line 1.


    Should be "$_='abc';s/b/c/g;print $_" of course. Same error message

    Francois


    --
    "Yes, it's the right planet, all right, " he said again.
    "Right planet, wrong universe. "
    Francois Wisard, Jul 30, 2003
    #2
    1. Advertising

  3. Francois Wisard

    pkent Guest

    In article <>,
    Francois Wisard <> wrote:

    > I encounter a strange "perl -e" behaviour since I'm running FreeBSD 5.1
    > (Perl 5.6.1). My one-liners are refused with strange error messages.


    Someone's already pointed out that this is just bash interpolating
    variables, e.g:

    > bash-2.05b$ perl -e "@a=('a'..'z');print $a[5]"
    > ARRAY(0x810115c)bash-2.05b$


    I get the same. If we do this, to see what the argument really is:

    $ echo "@a=('a'..'z');print $a[5]"
    @a=('a'..'z');print [5]

    And now it's obvious why we get the array ref.


    > bash-2.05b$ perl -e "$_="abc";s/b/c/g;print $_"
    > Undefined subroutine &main::ls called at -e line 1.


    I get:

    $ echo "$_="abc";s/b/c/g;print $_"
    @a=('a'..'z');print [5]=abc;s/b/c/g;print @a=('a'..'z');print [5]

    but then if I run ls -lab:

    $ echo "$_="abc";s/b/c/g;print $_"
    -lab=abc;s/b/c/g;print -lab

    And so on... this is why I generally use single quotes for perl -e :-/

    P

    --
    pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
    Remove the tea to reply
    pkent, Jul 31, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dorayme
    Replies:
    1
    Views:
    603
    richard
    Jan 21, 2011
  2. richard
    Replies:
    0
    Views:
    571
    richard
    Jan 21, 2011
  3. richard
    Replies:
    0
    Views:
    607
    richard
    Jan 21, 2011
  4. Beauregard T. Shagnasty

    Re: A Weird Appearance for a Weird Site

    Beauregard T. Shagnasty, Jan 21, 2011, in forum: HTML
    Replies:
    1
    Views:
    425
    Captain Paralytic
    Jan 21, 2011
  5. David Segall
    Replies:
    0
    Views:
    621
    David Segall
    Jan 22, 2011
Loading...

Share This Page