• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1033
  • Last Modified:

Using wildcards in perl

How do I use a wild card in this case?

The file always equals /home/inside/DVD*/bla_bla.txt. I'm looking for it to look at any DVD but it's not. bla_bla.txt is really in /home/inside/DVD3/bla_bla.txt

my $dir = "/home/inside/DVD*";
my $file = "bla_bla.txt";

  if (-f $dir/$file) {  
     move ("$dir/$file","${other_dvd}/.") || die "Can't copy $dir/$file $!\n";
  }

0
ckaspar
Asked:
ckaspar
  • 6
  • 6
  • 2
  • +4
1 Solution
 
ozoCommented:
for( <$dir/$file> ){
    move ($_,"${other_dvd}/.") || die "Can't copy $_ $!\n";  
}
0
 
mjcoyneCommented:
Is there more than one bla_bla.txt, and you're trying to move them all?
0
 
ozoCommented:
If you're not trying to move them all, which do you want to move?
is your move sub from File::Copy?
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
NorCal2612Commented:
Ozo, you're a maniac. You never sleep! :D
0
 
ravenplCommented:
Do You want use glob?

my $dir = "/home/inside/DVD*";
my $file = "bla_bla.txt";
my @MATCH = glob("$dir/$file");
foreach $m (@MATCH) {
  if (-f $m) {  
     move ("$m","${other_dvd}/.") || die "Can't copy $m $!\n";
  }
}
0
 
ravenplCommented:
OT: Ozo! You really maniac - what is YoursTZ?
0
 
TintinCommented:
Assuming you want to check for a single file, then simply do

my $dir = "/home/inside/DVD*";
my $file = "bla_bla.txt";

if (-f <$dir/$file>) {  
     move ("$dir/$file",$other_dvd) or die "Can't copy $dir/$file to $other_dvd $!\n";
}
0
 
ckasparAuthor Commented:
OK,
     I'm looping the content of a file.....

my $dir = "/home/inside/DVD*";

  open (FH, "$list") || die "can't open $list $! \n";
  while (<FH>) {
    chomp;
    @list = split / /;
    $files = $list[0];
   
  if (-f $dir/$file) {  
     move ("$dir/$file","${other_dvd}/.") || die "Can't copy $dir/$file $!\n";
  }


0
 
ozoCommented:
 while (<FH>) {
    $file = (split)[0];
   
    for( <$dir/$file> ){
       move ($_,"${other_dvd}/.") || die "Can't copy $_ $!\n" if -f;
    }
  }
0
 
ckasparAuthor Commented:
ozo,

Your last post is giving

Modification of a read-only value attempted at test.pl line 216, <FH> line 1.

move ($_,"${other_dvd}/.") || die "Can't copy $_ $!\n" if -f; is line 216

Any ideas?
0
 
ozoCommented:
how do you define move?
Is there anything else near line 216?
0
 
ckasparAuthor Commented:
if ( <$dir/$file> ){
0
 
ckasparAuthor Commented:
how do you define move? using File::Copy
0
 
ozoCommented:
I said for( <$dir/$file> ){  not if( <$dir/$file> ){
0
 
ckasparAuthor Commented:
Right, I tried both and none of them worked

for ( <$dir/$file> ){

if( <$dir/$file> ){

and still getting

Modification of a read-only value attempted at test.pl line
0
 
ozoCommented:
That's very strange, because
move ($_,"${other_dvd}/.") || die "Can't copy $_ $!\n" if -f;
does not attempt to modify anything
What else is in the program?
0
 
ckasparAuthor Commented:
Ok I figured out one way to do this.

I'm not getting Modification of a read-only value attempted at test.pl line

my $dir = "/home/inside/DVD*";

  open (FH, "$list") || die "can't open $list $! \n";
  while (<FH>) {
  $file = (split)[0];

  $new_dir = qx(ls $dir/$file);
   chomp ($new_dir);
   
  if (-f $new_dir ) {  
     move ("$new_dir","${other_dvd}/.") || die "Can't copy $new_dir $!\n";
  }
0
 
Computer101Commented:
PAQed with points refunded (500)

Computer101
EE Admin
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 6
  • 6
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now