in reply to How to include a doublequoted string into a backticked expression?

backticks interpolate, so $lemma gets interpolated. See perlop Quote and Quote-like Operators The problem is linux shell does its own interpolation, just like windows
my $backtick = q~" print qq,$_, for @ARGV " 1 2 "3 4 5" 6 %cd% ~; print " # copy in between backticks and paste in shell `$^X -le $backtick` "; print `$^X -le $backtick `; __END__ # copy in between backticks and paste in shell `D:\Perl\bin\perl.exe -le " print qq,$_, for @ARGV " 1 2 "3 4 5" 6 %cd +% ` 1 2 3 4 5 6 D:\
  • Comment on Re: How to include a doublequoted string into a backticked expression?
  • Download Code

Replies are listed 'Best First'.
Re^2: How to include a doublequoted string into a backticked expression?
by pat_mc (Pilgrim) on Jan 23, 2009 at 14:03 UTC
    The problem is linux shell does its own interpolation
    Yes, Anonymous Monk - you were spot-on in your analysis.

    Here is why:
    $ a="Hello" $ echo $a Hello $ echo "$a" Hello $ echo '"$a"' "$a" $ echo "'"$a"'" 'Hello' $ echo ""'"$a"'"" "$a"
    For the actual solution to my problem, this means:
    my $command = qq/egrep "'"^$lemma:"'" \/home\/lexicon/; my $lexical_entry = `$command`;

    Thanks to all those who were willing to help. Your effort to respond is much appreciated.

    Thanks for leading me towards the actual solution!

    Cheers - Pat
Re^2: How to include a doublequoted string into a backticked expression?
by pat_mc (Pilgrim) on Jan 23, 2009 at 12:53 UTC
    Thanks, Anonymous Monk, for pointing this out. Essentially, if I understand your reply correctly, each shell will handle certain variables in its own, idiosyncratic way. I guess, this comes as no surprise as such.

    Any idea then as to why a string consisting of \w+ characters only would not interpolate properly into my backticked expression then?

    Cheers - Pat
      Any idea then as to why a string consisting of \w+ characters only would not interpolate properly into my backticked expression then?
      You're making the assumption that it does not interpolate properly. Prove each part. As you do, you'll find your error.