in reply to Re: Re: Using UNIX commands inside Perl scripts, with Perl variables
in thread Using UNIX commands inside Perl scripts, with Perl variables

I think Mr. Østergaard meant this:
# Note -- bad way to do this open(IN, "ls -l |"); my @IN = <IN>; close(IN);
For a better way of getting directory contents, see perlfunc:opendir and perlfunc:readdir.

Which is a bit off-topic...

stephen

  • Comment on Re: Re: Re: Using UNIX commands inside Perl scripts, with Perl variables
  • Download Code

Replies are listed 'Best First'.
Re: Using UNIX commands inside Perl scripts, with Perl variables
by Anonymous Monk on Jun 08, 2001 at 02:38 UTC
    Nah, I meant this:
    # $command can be any system command, that would produce an acceptable output
    my $string = "my email is";
    my $dir = "/home/erik/*";
    my $command = "grep -ri '".$string."' ".$dir;
    open(IN, $command." |");
    my @IN = <IN>;
    close(IN);

    Better, Stephen? =) I agree, that opening dirs isn't the best purpose for this method.

    Erik