Sponsored Content
Top Forums Shell Programming and Scripting Perl: script to work with files with the same name in different directories Post 302885109 by elgo4 on Thursday 23rd of January 2014 02:25:17 PM
Old 01-23-2014
Perl: script to work with files with the same name in different directories

Hi All,

I would like to use a Perl (not Bash) script to work with multiple files of the same name in different directories (all in the same parent directory). I tried to create a loop to do so, but it isn't working.

My code so far:

Code:
while (defined(my $file = glob("./*/filename.txt")) or die "Could not open file './*/filename.txt' $!" ) {
 open my $input, "<", $file; 
#rest of code


Unfortunately I get this error message:
Could not open file './*/file.txt' Not a directory at ./script3.pl line 8.
Do I need to use opendir or something else?

Thanks!
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modify Perl script to work with txt - Permissions script

Hi I have this code, and i want work with a ls -shalR output in .txt What i need read to do this?? Where start? #!/usr/bin/perl # Allrights- A perl tool for making backups of file permissions # Copyright (C) 2005 Norbert Klein <norbert@acodedb.com> # This program is free... (1 Reply)
Discussion started by: joangopan
1 Replies

2. Shell Programming and Scripting

Run perl script on files in multiple directories

Hi, I want to run a Perl script on multiple files, with same name ("Data.txt") but in different directories (eg : 2010_06_09_A/Data.txt, 2010_06_09_B/Data.txt). I know how to run this perl script on files in the same directory like: for $i in *.txt do perl myscript.pl $i > $i.new... (8 Replies)
Discussion started by: ad23
8 Replies

3. Shell Programming and Scripting

Generate script perl mail log not work

Dear unix forum members, I'm working on a script that will parse a mail machine's logs and print a list of email addresses in this format: authen@domain.com | sender@domain | recipient@domain exam account1@domain1.com | sender2@domain2.com |... (3 Replies)
Discussion started by: puka
3 Replies

4. Shell Programming and Scripting

Perl - work with open files or write to @lists first?

I am dealing will many thousand fairy small files. I need to search them for various matches and depending on what I find, may need to search some files again for additional matches. Generally speaking, is it better to write a txt file to an @array/@list and then work with it (multiple... (1 Reply)
Discussion started by: OldGaf
1 Replies

5. Shell Programming and Scripting

Perl Script not working on all directories

Hi Folks, I have a script that I am using. The files are in Directory c:\files\change\options In that directory I have many other sub folders like R1 R2 R5 E4 etc... When I run this script in windows, It looks like its just changing the first folder R1 and not the rest. Can I get an... (6 Replies)
Discussion started by: richsark
6 Replies

6. Shell Programming and Scripting

Perl script for finding directories with mtime

Need assistance in the perl script . Below script gives me the results of all the files and directories with mtime with no issues . But i wanted to have a file and specify all the directory locations and use that file as reference and get results . Any ideas are highly Appreciated . ... (6 Replies)
Discussion started by: ajayram_arya
6 Replies

7. Shell Programming and Scripting

How to run perl script on multiple files of two directories?

Hi I have 100 files under file A labled 1.txt 2.txt.....100.txt(made up name) I have 1 files under file B labled name.txt How can i run the same perl script on 100 files and file name.txt I want to run perl script.pl A/1.txt B/name.txt perl script.pl A/2.txt B/name.txt ....... perl... (3 Replies)
Discussion started by: grace_shen
3 Replies

8. Shell Programming and Scripting

Executing perl files in many directories.

Good morning! I need your help again. I have some perl file. This file, to work, needs to be executed in appropriate directory, e.g. /mnt/disck/new files/abc/003 I need a shell script which: 1) will go to /mnt/disk2/new files/abc/003/perl.pl 2) execute it 3) go to the next directory... (7 Replies)
Discussion started by: ramirez987
7 Replies

9. Shell Programming and Scripting

Move directories in script.sh doesn't work

Dear All, I would like move some directories in another location. Basically, my ls -lis drwxr-xr-x 3 XXXXXXXXXXXXXXXXXXXX 4096 Feb 24 02:18 data.N701_N502.ABCDE -rw-r--r-- 1 XXXXXXXXXXXXXXXXXXXX 185865797 Feb 23 11:27 data.N701_N502.ABCDE_file1 -rw-r--r-- 1 XXXXXXXXXXXXXXXXXXXX... (2 Replies)
Discussion started by: giuliangiuseppe
2 Replies

10. Shell Programming and Scripting

Having trouble getting my interactive perl script to work properly

So I'm making an interactive perl script, but I can't get it to work properly. I'm trying to make a script that tell the user to input either 'q' or 'Q' to terminate the program, or 'c' to continue it. If they input anything other than those three keys, it should prompt the user again and again... (5 Replies)
Discussion started by: Eric1
5 Replies
Perl::Critic::Policy::InputOutput::RequireCheckedOpen(3pUser Contributed Perl DocumentatPerl::Critic::Policy::InputOutput::RequireCheckedOpen(3pm)

NAME
Perl::Critic::Policy::InputOutput::RequireCheckedOpen - Write "my $error = open $fh, $mode, $filename;" instead of "open $fh, $mode, $filename;". AFFILIATION
This Policy is part of the core Perl::Critic distribution. DESCRIPTION
The perl builtin I/O function "open" returns a false value on failure. That value should always be checked to ensure that the open was successful. my $error = open( $filehandle, $mode, $filename ); # ok open( $filehandle, $mode, $filename ) or die "unable to open: $!"; # ok open( $filehandle, $mode, $filename ); # not ok use autodie; open $filehandle, $mode, $filename; # ok You can use autodie, Fatal, or Fatal::Exception to get around this. Currently, autodie is not properly treated as a pragma; its lexical effects aren't taken into account. CONFIGURATION
This Policy is not configurable except for the standard options. AUTHOR
Andrew Moore <amoore@mooresystems.com> ACKNOWLEDGMENTS
This policy module is based heavily on policies written by Jeffrey Ryan Thalhammer <jeff@imaginative-software.com>. COPYRIGHT
Copyright (c) 2007-2011 Andrew Moore. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of this license can be found in the LICENSE file included with this module. perl v5.14.2 2012-06-07 Perl::Critic::Policy::InputOutput::RequireCheckedOpen(3pm)
All times are GMT -4. The time now is 07:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy