Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Using perl to extract data from multiple .txt files

by rjt (Deacon)
on Nov 14, 2012 at 15:55 UTC ( #1003843=note: print w/ replies, xml ) Need Help??


in reply to Using perl to extract data from multiple .txt files

Here's a short working example you can go from:

for (<*.txt>) { open my $fh, '<', $_ or die "Can't open $_: $!"; my $record = join(', ', map { chomp; $_ } (<$fh>)); # <== HERE print "$_: $record\n"; close $fh; }

Just replace the line marked <== HERE with your code. This writes to STDOUT, so you can redirect your output wherever you like, or just add an open and select to automate it if you'll always be writig to the same location.

Take care that the <*.txt> glob does not match your output file.


Comment on Re: Using perl to extract data from multiple .txt files
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2014-08-23 21:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls