Search Files from Array and link to original location in Perl

Hello,

Question is related to Perl:

I need to search few of the files from the array of file names.

And after grepping the file names from an array I need to link these files to original location. The original location in this case is ref_path as input from the user.

##$ref_path is input path from the user

opendir(DIR,$ref_path);
my @ref_files = readdir(DIR);
closedir(DIR);

@ref_files is an array with files names as elements; may be 50 elements.

@filestosearch = ("asicfile1", "asicfile2", "asicfile3", "gtdesign");

foreach (@filestosearch){

 for ($index = 0; $index <= $#ref_files; $index++) {
  
push @ref_paths, if $ref_files[$index] =~ /$_/;
  }
 }

The above code is just for grepping the file name, but it is not working. Any help would be appreciated for the above code and for linking the files to original location too.

Hi

push @ref_paths, $_, if $ref_files[$index] =~ /$_/;

Guru.

1 Like

With "use warnings;" you got useful information like

"Useless use of push with no values at <SCRIPT> line <#>"

1 Like

Thank you.

It worked.