Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 examining the Monastery: (10)
As of 2014-10-21 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (95 votes), past polls