[ABE.pm] backticking problem

Walt Mankowski waltman at pobox.com
Wed Nov 30 09:59:16 PST 2005


On Wed, Nov 30, 2005 at 11:58:51AM -0500, Faber Fedor wrote:
> I'm trying to get Perl to read the output of some shell comands tht
> involve pipes and I'm missing something basic.
> 
> I have this:
> 
> lynx -dump $url | grep 'S&P 500' | head -5 | head -1
> 
> which works correctly on the command line.  When I put it in a PErl
> script thusly
> 
> my $line = `lynx -dump $url | grep 'S&P 500' | head -5 | head -1`
> 
> I get the output of the lynx command or  the equivalent of
> 
> my $line = `lynx -dump $url`
> 
> How do I get the proper output into $line?  Or do I have to process the
> lynx output separately inside of Perl?

That's odd.  At first I thought you needed to escape the &, but then I
wrote this little test script and it appears to work correctly:

  #!/usr/local/bin/perl -w
  use strict;
  my $url = 'http://finance.yahoo.com/q?s=%5EGSPC';
  my $line = `lynx -dump $url | grep 'S&P 500' | head -5 | head -1`;
  print "$line\n";

So I guess you must be doing something else wrong...

BTW why are you doing "head -5 | head -1"?  If you want to print the
first line, "head -1" is sufficient.  If you want to print the 5th
line, you could do something like "sed -n 5p".

Walt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.pm.org/pipermail/abe-pm/attachments/20051130/c557159f/attachment.bin


More information about the ABE-pm mailing list