in reply to Backticks without shell

You can use the list syntax for piped open if your perl is recent enough. This works in my 5.8.x,

$ perl -e'open my $fh, "-|", "ls", "-l", glob("READ*") or die $!; prin +t <$fh>' -rw-rw-r-- 1 Zaxo Zaxo 1510 Jan 15 1999 README -rw-rw-r-- 1 Zaxo Zaxo 251 Jan 15 1999 README_FIRST -rw-rw-r-- 1 Zaxo Zaxo 245 Jan 15 1999 README_FIRST.~ +1~ $
while,
$ perl -e'open my $fh, "-|", "ls", "-l", "READ*" or die $!; print <$fh +>' ls: READ*: No such file or directory $
proving that the shell is truly bypassed.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Backticks without shell
by Anonymous Monk on Jan 21, 2004 at 03:36 UTC

    Thanks! I'll probably upgrade just to use this.

    Does anyone know why backticks are an operator in the first place? It seems like the syntax is broken compared with system, because it's a loss of functionality. Wouldn't having stdout( ... ) as a complement to system( ... ) make more sense?

      My guess (No informed ideas here!) that they're a legacy feature from trying to support bash scripters and their backticks as well as it's just a quick simple and above all, lazy way to get the output of a command.
      my $data = `cmd`;
      Is vastly preferable to
      open FH,'cmd |'; my $data; $data.=$_ while(<FH>);
      (or something of that nature).