in reply to Running Batch of Files

Maybe something like this:
#!/usr/bin/perl my $dir = '.'; my $pattern = '.jpg$'; #Filenames ending in .jpg opendir DIR, $dir or die "Cannot readdir $dir:$!\n"; my @files = grep /$pattern/,(readdir DIR); closedir DIR; print "@files\n"; foreach my $file (@files){ system ("somecommand $file"); }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^2: Running Batch of Files
by tej (Scribe) on Oct 07, 2010 at 18:17 UTC

    Thanks zentara..This is almost working fine

    Only problem is i am getting error like can not open file..

    My code is as below

    my $dir = "INPUT"; my $pattern = '.txt'; opendir DIR, $dir or die "cant open dir"; my @files = grep /\.txt/,(readdir DIR); closedir DIR; #print "@files\n"; foreach my $file (@files){ print "$file\n"; open (INF, $file)||warn "Can not open $file"; $data=join ("", <INF>); print "$data\n"; }
    when i run this file i get error like "Can not open file" Could you please help me with this?

      Your problem is that you are only using the filename to open the file not the fullpath.

      my $dir = "INPUT"; my $pattern = '.txt'; opendir DIR, $dir or die "cant open dir"; my @files = grep /\.txt/,(readdir DIR); closedir DIR; #print "@files\n"; foreach my $file (@files){ my $filepath = "$dir/$file"; print "$filepath\n"; open (INF, $filepath)||warn "Can not open $filepath"; $data=join ("", <INF>); print "$data\n"; }

        Thank you marto and tokpela. Its Working fine now