Hello fasoli

Why you do not simply search and get all files (do not load on @ARGV) just in a list and then simply read them in an array (remove 2nd line) and from there what ever you want.

Since we do not have input data I used dummy text for representation purposes.

#!usr/bin/perl use strict; use warnings; use Data::Dumper; use File::Find::Rule; # use Benchmark qw(:all) ; # WindowsOS # use Benchmark::Forking qw( timethese cmpthese ); # LinuxOS sub get_files { my @dirs = ('.'); my $level = shift // 2; my @files = File::Find::Rule->file() ->name('*.out') ->maxdepth($level) ->in(@dirs); return @files; } my @files = get_files(); # print Dumper \@files if @files; # open files and load them into an array my %HoA; foreach my $path_to_file (@files) { open my $fh, '<', $path_to_file; chomp(my @lines = <$fh>); splice @lines, 1, 1; $HoA{$path_to_file} = \@lines; close $fh; } print Dumper \%HoA; __END__ $ perl test.pl $VAR1 = { 'mySubDir/molec1-cluster2.out' => [ 'This is a sample line 1 + file 2', 'This is a sample line 3 + file 2' ], 'mySubDir/molec1-cluster1.out' => [ 'This is a sample line 1 + file 1', 'This is a sample line 3 + file 1' ] }; # file 1 $ cat mySubDir/molec1-cluster1.out This is a sample line 1 file 1 This is a sample line 2 (to be skipped) file 1 This is a sample line 3 file 1 # file 2 $ cat mySubDir/molec1-cluster2.out This is a sample line 1 file 2 This is a sample line 2 (to be skipped) file 2 This is a sample line 3 file 2

I am using File::Find::Rule to retrieve all the files that I want to process, I also use Data::Dumper to debug and view the data, I also use splice to remove the second line from the array and finally I push all data in HASHES OF ARRAYS.

I would recommend to read through these links that I provided you, if you continue developing you will use them very often.

A minor note, do not re-post questions trying to read files in @ARGV but getting GLOB error! :( as Anonymous Monk noticed. Just update your question or reply on our comments and we will try to assist you resolve your problem.

Hope this helps, let us know, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

In reply to Re: reading files in @ARGV doesn't return expected output by thanos1983
in thread reading files in @ARGV doesn't return expected output by fasoli

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.