Search Files from Array and link to original location in Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search Files from Array and link to original location in Perl
# 1  
Old 06-20-2011
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
Code:
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");
Code:
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.

Last edited by Franklin52; 06-20-2011 at 06:42 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 06-20-2011
Hi

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

Guru.
This User Gave Thanks to guruprasadpr For This Post:
# 3  
Old 06-20-2011
With "use warnings;" you got useful information like

"Useless use of push with no values at <SCRIPT> line <#>"
This User Gave Thanks to yazu For This Post:
# 4  
Old 06-20-2011
Thank you.

It worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Search and replace a array values in perl

Hi, i want to search and replace array values by using perl perl -pi -e "s/${d$i]}/${b$j]}" *.xml i am using while loop for the same. if i excute this,it shows "Substitution replacement not terminated at -e line 1.". please tell me what's wrong this line (1 Reply)
Discussion started by: arindam guha
1 Replies

2. Shell Programming and Scripting

Restoring a file to its original location

Hello everyone, I am attempting to make a recycling bin type application in shell script (tcsh). I have the whole part of the application done where someone can recycle files from one location to the recycling bin (the lower half of the program), this is not a problem. However I wanted to make... (7 Replies)
Discussion started by: tastybrownies
7 Replies

3. Shell Programming and Scripting

Find command to search and delete files older than 1 days at a desired location

Hello All, Can someone please help me out in creating the find command to search and delete files older than 1 days at a desired location. Thanks in advance for your help. (3 Replies)
Discussion started by: Pandee
3 Replies

4. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

5. UNIX for Dummies Questions & Answers

how to copy files and record original file location?

:EDIT: I think my post name should have been labeled: how to copy files and record original file location. not "retain". Hello, this is my first post! I searched the forums a lot before posting, but was unable to answer my question. Here's my problem: There are several hundred text files... (4 Replies)
Discussion started by: willie8605
4 Replies

6. UNIX and Linux Applications

Perl Script to read an excel file into an array and search in the UNIX directories

Hi, I want the Perl script with versions 5.8.2 and 5.8.5 starting with #!/usr/bin/perl The Perl program should read the excel file or text file line by line and taking into an array and search in the UNIX directories for reference file of .jsp or .js or .xsl with path .The Object names... (2 Replies)
Discussion started by: pasam
2 Replies

7. Shell Programming and Scripting

Shell Script for Copy files from one location to another location

Create a script that copies files from one specified directory to another specified directory, in the order they were created in the original directory between specified times. Copy the files at a specified interval. (2 Replies)
Discussion started by: allways4u21
2 Replies

8. Shell Programming and Scripting

Perl : Search for next occurence of a word in an array

I have an array as follows: Space: ABC Name: def Age: 22 Type: new Name: fgh Age: 34 Type: old Space: XYZ Name: pqr Age: 44 Type: new : : How can I separate the array with elements starting from Space:ABC until Space: XYZ & put them in a different array & so on... (4 Replies)
Discussion started by: deo_kaustubh
4 Replies

9. Shell Programming and Scripting

search of string from an array in Perl

Hi All I want to search a string from an array in Perl. If a match occurs, assign that string to a variable else assign 'No match'. I tried writing the script as follows but it's in vain. Please help me.. #!/usr/bin/perl use strict; my $NER; my @text=("ORG","PER"); ... (4 Replies)
Discussion started by: my_Perl
4 Replies

10. UNIX for Advanced & Expert Users

copy files from one location to similar location

I need help in forming a script to copy files from one location which has a sub directory structure to another location with similar sub directory structure, say location 1, /home/rick/tmp_files/1-12/00-25/ here 1-12 are the number of sub directories under tmp_files and 00-25 are sub... (1 Reply)
Discussion started by: pharos467
1 Replies
Login or Register to Ask a Question