Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Running Batch of Files

by tej (Scribe)
on Oct 07, 2010 at 18:17 UTC ( #864057=note: print w/ replies, xml ) Need Help??


in reply to Re: Running Batch of Files
in thread Running Batch of Files

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?


Comment on Re^2: Running Batch of Files
Download Code
Re^3: Running Batch of Files
by marto (Chancellor) on Oct 07, 2010 at 18:22 UTC
Re^3: Running Batch of Files
by tokpela (Chaplain) on Oct 08, 2010 at 02:27 UTC

    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

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2014-07-30 06:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (229 votes), past polls