Hi Monks, I am new to perl so trying out number of problems from all over. Here is problem where I can seek some wisdom I have 2 files with following data
FILE 1: NAME,STRIDE_LENGTH,STANCE Euoplocephalus,1.87,quadrupedal Stegosaurus,1.90,quadrupedal Tyrannosaurus Rex,5.76,bipedal Hadrosaurus,1.4,bipedal Deinonychus,1.21,bipedal Struthiomimus,1.34,bipedal Velociraptor,2.72,bipedal FILE 2: NAME,LEG_LENGTH,DIET Hadrosaurus,1.2,herbivore Struthiomimus,0.92,omnivore Velociraptor,1.0,carnivore Triceratops,0.87,herbivore Euoplocephalus,1.6,herbivore Stegosaurus,1.40,herbivore Tyrannosaurus Rex,2.5,carnivore

Question # List all herbivores dinos # List their name and leg_length sorted

I am able to find the dino's that are herbivores but I am unsure how to sort the result based on the length of leg. Is is code right way to solve this problem ?
use Data::Dumper; open my $fh1, '<', '1.csv' or die $!; open my $fh2, '<', '2.csv' or die $!; my $header1 = <$fh1>; my $header2 = <$fh2>; my %app_map; while(my $row = <$fh1>){ my ($name, $leg_len, $diet) = split /\,/, $row; if($leg_len ne ''){ $app_map{$name}{leg_len}=$leg_len; }else{ $app_map{$name}{leg_len}="NA"; } if ($diet ne '') { $app_map{$name}{diet}=$diet; } else {$app_map{$name}{diet}="NA"; } } close $fh1 or die $!; while(my $row = <$fh2>){ my ($name, $str_len, $stance) = split /\,/, $row; if($str_len ne ''){ $app_map{$name}{str_len}=$str_len; }else {$app_map{$name}{str_len}="NA";} if($stance ne ''){ $app_map{$name}{stance}=$stance; }else {$app_map{$name}{stance}="NA";} } close $fh2 or die $!; while ( my ($k, $v) = each %app_map ) { if(defined($app_map{$k}{diet}) && $app_map{$k}{diet} =~/herbivo +re/){ ####SORT BY STR_LEN##################### #print $k." - ".$app_map{$k}{str_len},"\n"; } } #print Dumper \%app_map;

In reply to Merging 2 Hashes finding result sorted by one of the fields by kris1511

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.