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

Hi There, Im new to Perl and can someone help me here. I have a file with following sample text a.txt 4 b.txt 3 z.txt 1 a.txt 5 b.txt 2 b.txt 4 z.txt 2 and i need to process this file and for each file name (a.txt,b.txt,z.txt) in it, i need to display the max value. Output should look like a.txt 5 b.txt 4 z.txt 2 Pls help.Thanks.

Replies are listed 'Best First'.
Re: Need Help in processing a file
by ww (Archbishop) on Apr 10, 2013 at 20:22 UTC

    1. Read how to do that on your own computer: $ perldoc perlintro

    2. Read about PerlMonks -- especially, On asking for help.
    We prefer to help you learn; not to do your work for you.


    If you didn't program your executable by toggling in binary, it wasn't really programming!

Re: Need Help in processing a file
by Kenosis (Priest) on Apr 10, 2013 at 20:23 UTC

    Hi RajasekarV, and welcome to PerlMonks!

    To help us in assisting you, please reformat your sample and output text within <code> tags, as doing so will provide a better picture of your issue(s). Additionally, include any code you've tried.

Re: Need Help in processing a file
by hdb (Monsignor) on Apr 10, 2013 at 20:31 UTC

    Some Perl Poetry for You:

    use strict; my%a;my@a=split/ /,<DATA>; while(@a){ my($a,$n)=splice@a,0,2; $a{$a}=$n>$a{$a}?$n:$a{$a}; } print join " ", %a; __DATA__ a.txt 4 b.txt 3 z.txt 1 a.txt 5 b.txt 2 b.txt 4 z.txt 2

    Now you only need to sort out the sorting...

    UPDATE under Seussian Perl