Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: print first column, unique word in each row along with number times that word is repeated in each row

by Eily (Monsignor)
on Jan 10, 2018 at 10:30 UTC ( [id://1207049]=note: print w/replies, xml ) Need Help??


in reply to print first column, unique word in each row along with number times that word is repeated in each row

OK so it looks like you are talking about find common data in multiple files. Could you please give us the code you use from there, in a <readmore> tag? Right now what you want to do is parse the input data, and format it into a file, then parse that file for processing. You could skip the second parsing step if you collect the data in a useful data structure on the first try.

  • Comment on Re: print first column, unique word in each row along with number times that word is repeated in each row

Replies are listed 'Best First'.
Re^2: print first column, unique word in each row along with number times that word is repeated in each row
by mao9856 (Sexton) on Jan 11, 2018 at 03:19 UTC

      Add 2 more columns into the array and shift the others up

      #!/usr/bin/env perl use strict; use warnings; my %data = (); #@ARGV = map { "File$_" }(1..4); my $num = @ARGV; # input for my $i (0..$num-1){ open my $fh,'<',$ARGV[$i] or die "$!"; while (<$fh>) { my ( $key, $value ) = split; $data{$key}[0] = $value; $data{$key}[1] += 1; # count $data{$key}[$i+2] = $value; } close $fh; } # output print join ("\t", 'ID', 'Name','Count', @ARGV),"\n"; foreach my $key ( sort keys %data ) { my @line = map { $_ || '-' } @{ $data{$key} }[0..$num+1]; if (grep $_ eq '-',@line){ print join ("\t", $key, @line),"\n"; } }
      poj

        Hi poj

        When I tried your code it gives output 1 in all rows. Also number of rows are reduced. IDs are printing though (first column) but rows have reduced. And it also prints "-" in second and fourth column.

        I am trying to this code for the output (now my new input) you coded earlier Re^11: find common data in multiple files

        Regards mao9856

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 06:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found