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

I have multiple emacs/ASCII files named iron-Fe17-4.pro, iron-Fe17-4.2.pro, iron-Fe17-4.4.pro. . . .iron-Fe17-9.2.pro in directory desktop/programs/data. Each file has columns of numbers (written in scientific notation:1.3e-4) separated by tabs. I want to put the number from the 3rd row, 4th column from each emacs/ASCII file into one (26-row 1-column) array. Could someone please help me with the commands for this? Please leave in "trivial" lines too, for I just started learning Perl.;;;;;;;;;;;;;;Thanks, Max

Replies are listed 'Best First'.
Re: Extracting from Multiple Files
by davido (Cardinal) on Aug 09, 2005 at 20:05 UTC

    Are you learning Perl, or are you seeking a fully written script? If it's the former, please specify what part of the problem you are stuck on. We're glad to help with specific stumbling blocks. But if it's the latter, and you are just requesting that someone write the script for you, you're at the wrong place, and might have better luck at a for-pay site such as http://answers.google.com, or by hiring someone at http://jobs.perl.org.

    To learn how to accomplish the task you're discussing, I would recommend picking up a copy of the Llama book, from O'Reilly & Associates, Learning Perl, by Randal Schwartz. Just about everything you're asking is addressed in that book, and it will take you only a few days to get through it. If you're intent on learning Perl, that's a minimal investment of time, but worthwhile, and practically a requirement before you can get to a point where you find yourself actually learning Perl rather than staring blankly at scripts others have written. You will also find a lot of good information in the Plain Old Documentation (POD) that comes with Perl:

    • perlintro - Introduction to programming Perl.
    • perlopentut - Introduction / tutorial for opening files.
    • split - This is where you can learn how to split a line up based on tab delimiters among others.
    • perlrequick - An introduction to Regular Expressions... also helpful when learning how to use split
    • push - This is where you can learn how to push elements onto an array.
    • open - More detail on opening files.
    • perlop - Pay attention here to the diamond operator <FILEHANDLE>. You can use that to read from files.

    I hope that's enough to get you started. Let us know when you run into something for which you need further clarification.


    Dave

Re: Extracting from Multiple Files
by aukjan (Friar) on Aug 09, 2005 at 20:44 UTC

    And just to get you started look at the following commands/syntax..
    my @array = (); for $file ( qw(file1 file2 file3) ){ open(IN,'<',$file) while(IN){ chomp; split; } close (IN) }
    Use these to make some script, and when you have something we'll comment on it to help you make it better/function ;-)

    --
    Go Fish!