in reply to reading files in @ARGV doesn't return expected output
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.
|
|---|