Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^3: Check if file exists in multiple directories

by hdb (Monsignor)
on May 21, 2015 at 18:19 UTC ( [id://1127374]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Check if file exists in multiple directories
in thread Check if file exists in multiple directories

Your $dir probably has an extra newline at the end, try chomp @tablea; after reading the dirlist file.

Replies are listed 'Best First'.
Re^4: Check if file exists in multiple directories
by Bama_Perl (Acolyte) on May 21, 2015 at 18:26 UTC
    #!/usr/bin/perl use warnings; use Cwd; $out = "outFile"; $newdir = $newdirectory; open(TABLEA, "dirlist"); @tablea = <TABLEA>; foreach $dir (@tablea) { chomp @tablea; chdir $dir; print(cwd); print "\n"; if (glob("*.txt")) { system("mv $out $newdir"); } }
    If I add the chomp and I print the current working directory, the only directory that gets printed is the first directory, multiple times(as many times there are files in the main directory). Any other thoughts? Thanks.

      Can you add a use strict; at the beginning of your code? And where do you assign a value to $newdirectory? As the code stands it is undefined and therefore your target directory is not specified.

      The chomp should be placed before the loop.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1127374]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-03-28 12:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found