Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by Kenosis (Priest)
on Nov 14, 2012 at 21:22 UTC ( #1003891=note: print w/ replies, xml ) Need Help??


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

Hi, lalalala1, and welcome to PerlMonks!

Excellent suggestions above. The following incorporates almost all of them, and avoids a collision with the output file by grepping the glob (sounds like a horror movie title...).

It opens each text file for the data you need, and that data is pushed onto an array that's written out to the output file:

use strict; use warnings; my $outFile = 'extractedData.txt'; my @sampleLines; for my $file ( grep !/^\Q$outFile\E$/, <*.txt> ) { open my $fh, '<', $file or die $!; # Get data from file... push @sampleLines, $data; close $fh; } open my $outFH, '>', $outFile or die $!; print $outFH @sampleLines; close $outFH

I know that this is more than you requested, but I hope it's helpful.


Comment on Re: Using perl to extract data from multiple .txt files
Select or Download Code
Re^2: Using perl to extract data from multiple .txt files
by lalalala1 (Initiate) on Nov 15, 2012 at 14:27 UTC

    Thank you guys, I'll give your suggestions a try and let you know how it worked out.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-09-19 00:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (128 votes), past polls