Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

how do i parse multiple files and write all of the results into single file

by my_perl (Initiate)
on Jul 08, 2005 at 17:57 UTC ( [id://473514]=perlquestion: print w/replies, xml ) Need Help??

my_perl has asked for the wisdom of the Perl Monks concerning the following question:

I have number of files all named in format 2005xxx@xxxxxx.log
How do i parse all of them and write result into one output file. Thanks
  • Comment on how do i parse multiple files and write all of the results into single file

Replies are listed 'Best First'.
Re: how do i parse multiple files and write all of the results into single file
by Transient (Hermit) on Jul 08, 2005 at 18:06 UTC
    my @files = glob( '2005*@*.log' ); die "No files found\n" unless @files; open(OUTPUT, ">output" ) or die "Unable to open output\n$!\n"; foreach my $file (@files) { open( MYFILE, $file ) or die "Unable to open $file\n$!\n"; while (<MYFILE>) { # parse print OUTPUT $parsed_output; } close (MYFILE) or die "Unable to properly close $file\n$!\n"; } close(OUTPUT);
      Transient did a great job giving a generally safe and applicable answer, though a bit wordy for my tastes. Pass the filename wildcard on the command line, and redirect STDOUT:
      #@ARGV = glob( @ARGV ); # needed for DOS while (<>) { s/match this/replace it with this/; print; }

      -QM
      --
      Quantum Mechanics: The dreams stuff is made of

      THank you very much :)
Re: how do i parse multiple files and write all of the results into single file
by halley (Prior) on Jul 08, 2005 at 18:04 UTC
Re: how do i parse multiple files and write all of the results into single file
by Grygonos (Chaplain) on Jul 08, 2005 at 19:36 UTC

    You need to show some effort. Based on the two questions you have posted recently.. I cannot tell that you have ever coded one line of Perl in your life. Show us what you have tried.

    Also, a plea to other monks. Stop doing people's work for them. This site (to me anyhow) is about learning and self-betterment in regards to Perl. Answering someone's question in that fashion when they have shown zero effort does the OP no good.

      I am real beginner, and i really appreciate this forum, because people answer your questions without any prejudice, and whichever level they are at. It is hard for me to show you my code, because i am trying to do something for work, and i don't think that would be proper. I would like to thank one more time to all people that put their time and answered my questions, without judging. As you said this site for you means one thing, for them obviously other, they are willing to help.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://473514]
Approved by sgifford
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-18 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found