?
Solved

Using wildcards in perl

Posted on 2006-11-03
19
Medium Priority
?
962 Views
Last Modified: 2008-02-01
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
Comment
Question by:ckaspar
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +4
19 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 17871313
for( <$dir/$file> ){
    move ($_,"${other_dvd}/.") || die "Can't copy $_ $!\n";  
}
0
 
LVL 17

Expert Comment

by:mjcoyne
ID: 17872044
Is there more than one bla_bla.txt, and you're trying to move them all?
0
 
LVL 84

Expert Comment

by:ozo
ID: 17872058
If you're not trying to move them all, which do you want to move?
is your move sub from File::Copy?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:NorCal2612
ID: 17872378
Ozo, you're a maniac. You never sleep! :D
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17872534
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
 
LVL 43

Expert Comment

by:ravenpl
ID: 17872537
OT: Ozo! You really maniac - what is YoursTZ?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 17874426
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
 

Author Comment

by:ckaspar
ID: 17875094
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
 
LVL 84

Expert Comment

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

Author Comment

by:ckaspar
ID: 17877987
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
 
LVL 84

Expert Comment

by:ozo
ID: 17878462
how do you define move?
Is there anything else near line 216?
0
 

Author Comment

by:ckaspar
ID: 17890851
if ( <$dir/$file> ){
0
 

Author Comment

by:ckaspar
ID: 17891661
how do you define move? using File::Copy
0
 
LVL 84

Expert Comment

by:ozo
ID: 17892635
I said for( <$dir/$file> ){  not if( <$dir/$file> ){
0
 

Author Comment

by:ckaspar
ID: 17895200
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
 
LVL 84

Expert Comment

by:ozo
ID: 17895228
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
 

Author Comment

by:ckaspar
ID: 17895317
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
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18136331
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question