in reply to Reaped: count total number of occurrence in all files

hello umaykulsum

As you do not ask for something nor point to particular errors i can only guess:

first i cannot understand how your data sample can be splitted using \t\s pattern (ah ok you are setting $/ for this..).

second i do not see where you are opening files (maybe the script is run under -nl ?)

If each file just contains 2 lines you can simply do:

my $key = <$filehandle>; # first line my $value = <$filehandle>; # second line

You also have no need to iterate over an array to get the count: @array in scalar context returns the numbers of elements. Also $#array contains the index of the last element ( so $#array + 1 == scalar @array ).

You also want the name of the file to be preserved somehow: you can read about $ARGV or you must create a sub that given the filename as arg, open it process it and store the filename along results.

A pray to you and to ALL BIONFORMATICS here around: sample data can be AGATC instead of a line of hundreds of chars? have readable data as sample help my eyes a lot!

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^2: count total number of occurrence in all files
by Eily (Monsignor) on May 09, 2016 at 09:35 UTC

    Hello Discipulus :). Actually there is no need for -n, because that's what while (<>) { } does (and -n just adds that loops around your code, as can be seen with -MO=Deparse). It opens each file passed as an argument in the filehandle ARGV, or reads from STDIN is @ARGV == 0.

      Ah! i forgot this part, thanks Eily for the comment.

      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^2: count total number of occurrence in all files
by AnomalousMonk (Archbishop) on May 09, 2016 at 13:08 UTC
    A pray to you and to ALL BIONFORMATICS here around: sample data can be AGATC instead of a line of hundreds of chars? have readable data as sample help my eyes a lot!

    Yea and amen to that, gentle brother Discipulus!


    Give a man a fish:  <%-{-{-{-<