Hello Perlmonks! I am trying to read a file with user information categorized under a location, I want to fill in the some of the fields using user input and output the file while keeping the fields under each location intact for eg - file
[California] ;;Name $;FIrst_Name = ;;Last_name $;Last_Name= ;;Age of member $;Age = [NewYork] ;;Name $;FIrst_Name = ;;Last_name $;Last_Name= ;;Age of member $;Age = [Washington] ;;Name $;FIrst_Name = ;;Last_name $;Last_Name= ;;Age of member $;Age =
Once user provides input from command line it should look it
[California] ;;Name $;FIrst_Name = Jack ;;Last_name $;Last_Name= Daner ;;Age of member $;Age = 27 [NewYork] ;;Name $;FIrst_Name = Jill ;;Last_name $;Last_Name= XYZ ;;Age of member $;Age = 30 [Washington] ;;Name $;FIrst_Name = Kim ;;Last_name $;Last_Name= ABC ;;Age of member $;Age = 25
The order of First_Name, Last_Name and Age within each location can change and even order of locations can change, but each location section should remain separate and intact. I wrote following code so far and some of my code works for taking whole file in one hash, but i am not able to preserve each location section within it! I tried using two hashes - can someone please help me this complex problem! Thanks a lot.
open($input.file, "<$InputFile") or die "Error! Cannot open $InputFile + for reading: $!"; while (<$input.file>) { $_ =~ s/\s+$//; next if ($_ =~ /^#/); next if ($_ =~ /^$/); if ($_ =~ m/^\[(\S+)\]$/) { $sComponent = $1; next; } elsif ($_ =~ m/^;;\s*(.*)/) { $sDesc .= "$1."; next; } elsif ($_ =~ m/\$;(\S+)\$;\s*=\s*(.*)/) { $sParam = $1; $sValue = $2; } $sParam = $sValue = $sDesc = ""; next; } }

In reply to Read an input file in two hashes to retain order by Bioinfocoder

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.