grep using Perl

I'm using perl to do a grep of each line in a vendor file and find its occurrences in a specific directory. Any values found is saved in @dir.

.....(file opened, etc.)
....
while ($line=<FILE>){
@dir = `grep $line * `;
}

It's the specific usage of the system grep that I'm having trouble with in Perl.
Is scaler variables' interpolation going to occur correctly with this?
It isn't coming back out of the while loop.

please see its usage from perldoc -f grep.
anyway, you don't have to use grep. just simple regex will do. perldoc perlre

looks like you're trying to search for a line from a file in all other files in
the directory???

what practical application does this have?

Actually, what I'm trying to do is determine if specific vendor numbers exist in a specific directory. There are multiple files in the directory. One found, save in another file.

So, in Unix the grep would be

grep "myvendor" mydir/*

But I cannot get the syntax down using Perl. Newbie.

are the vendor numbers part of the file name ?
or do they exist in text within the files ?

something like this:? ( here i'm searching for the string "perl". You can substitute a variable for "perl". )


@a_junk = `grep -l perl *`;

foreach ( @a_junk ){
  print "found $_ \n";
  }

Are you searching in the files for something or only searching for filenames in a directory?

I would be searching within all the files of a specific directory.

Thanks for everyone's help. The issue was with the data in the scalar.
I used chomp to remove the newline and everything started working after that.

:slight_smile: