Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi i am trying to run perl one liner from command prompt , i am able to get the output when i use single but not with double quotes, so please help me where i am doing wrong with double quotes

I have a file nosum_website.sh in the current diretory and when i execute below command

$ perl -e '($hi)=glob("nosum*"); print "$hi"'; nosum_website.sh$

but with double quotes i am not getting output

$ perl -e "($hi)=glob(\"nosum*\"); print \"$hi\""; $

Replies are listed 'Best First'.
Re: double quotes and single qoutes
by CountZero (Bishop) on Mar 14, 2013 at 06:58 UTC
    Two comments:
    1. What operating system are you on? Different types of OS have different rules on quoting.
    2. Do avoid (some of) the problems with quoting in one-liners, use q() or qq() to single or double quote.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

      i am on AIX

        try perl -e "($hi)=glob(qq(nosum*)); print qq($hi)"; and see if that works.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        My blog: Imperial Deltronics
Re: double quotes and single qoutes
by soonix (Chancellor) on Mar 14, 2013 at 08:16 UTC
    Although the others already pointed you to the right direction, here a tip:

    You could prepend echo to your command, thus:
    echo perl -e "($hi)=glob(\"nosum*\"); print \"$hi\"";
    to see what's going on before perl even get a chance to do anything. Most probably perl will see something like
    perl -e ()=glob("nosum*"); print "";

      My tip in this tips section: As soon as you have to fiddle with quotes more than 30 seconds, it's better to write a little perl script into a file even when this is not so qwel like a perl one liner. ;-)

      McA

Re: double quotes and single qoutes (shell interpolation)
by Anonymous Monk on Mar 14, 2013 at 07:52 UTC

      thanks for your explanation , it worked after escaping every $, and i have one question , can you use the modules at command line as we did in this case perl -MO=Deparse -e "(\$hi)=glob(\"nosum*\"); print \"$hi\"" , if suppose i want to use Dumper module how can i use it.

        perl -MData::Dumper -e'print Dumper [1..3]'
        package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

        Read perlrun search for "use module"

        Files are where it's at :) oneliners get unwieldy pretty quick  perl -le ' use Data::Dump; dd [6..9]; '

        OTOH, it could be as simple as perl -MToolkit -e ' dd \@INC '

        or even

        export PERL5OPT=-MData::Dump -CSD 
        perl  -e ' dd\%INC '