[ale] Trust the Source - Re: Perl NewbieQ: backtick operator

John Mills johnmills at speakeasy.net
Wed May 19 10:44:17 EDT 2010


ALErs -

It looks like I was worried about a non-problem.

I wrote a simple test and Perl appears not to confuse back-ticks 
embedded in text with backtick operators in Perl commands when either 
reading from or writing to the shell.

I created the following one-line file:
  +++++++++++++++++++++++++ back_tick_test.txt ++++++++++++++++++++++
Hello -- step past ` or die "tripped on embedded back-tick"; without tripping
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
(It started as one line - edit to use it that way. #8-)

and the following Perl fragment:
  +++++++++++++++++++++++++ embedded_tick.pl +++++++++++++++++++++++
#!/usr/local/bin/perl
print "Embedded back-tick test in Perl\n";
$test_str = `cat ./back_tick_test.txt`;
print "OK - read text without tripping:\n";
print $test_str . "\n";
print "Test ended successfully\n";
  ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Output was:
jmills at jmmanchor:~/sandbox> ./embedded_tick.pl
  Embedded back-tick test in Perl
  OK - read text without tripping:
  Hello -- step past ` or die "tripped on embedded back-tick"; without tripping
  Test ended successfully
jmills at jmmanchor:~/sandbox>

On Tue, 18 May 2010, Mills John M-NPHW64 wrote:

> My problem in 'bash' was numerous functions whose return strings may 
> contain "`" characters that would burst 'bash's string capture and leave 
> the shell interpreting random text returned by the external function. 
> Fortunately the 'bash' operator "$( ... )" seem to have solved my 
> problem.

> Question: Are strings returned by the Perl construct "` ... `" protected 
> from detecting embedded '`'s within the returned text and terminating 
> the string capture?


More information about the Ale mailing list