I have to use hash(key,value) concept.

TIMTOWTDI and here is a counter-example.

use strict; use warnings; use Test::More tests => 1; my $in = <<EOIN; # this is a new file { date 14/07/2016 time 11:15 end 11:20 total 30 No "FRUITS" Fruit_Class { Name "fruit 1" fruitName "apple.fru" fruitId "0" fruitCount 5 fruitValue 6 } { Name "fruit 2" fruitName "orange.fru" fruitId "1" fruitCount 10 fruitValue 20 } } EOIN my $want = <<EOWANT; # this is a new file {date 14/07/2016 time 11:15 end 11:20 total 30 No FRUITS Fruit_Class { Name fruit_1 fruitId 0 apple_fru.fruitCount 5 fruitValue 6 } Fruit_Class { Name fruit_2 fruitId 1 orange_fru.fruitCount 10 fruitValue 20 } } EOWANT my $name = ''; my $out = ''; my $nr = 0; for (split "\n", $in) { tr /"//d; s/ (\d)/_$1/ if $nr++ > 5; if (/^\s+fruitName\s+(.*?)$/) { ($name = $1) =~ s/\./_/; next; } s/fruitCount/$name.fruitCount/; s/^$/Fruit_Class/ if $nr > 10; if (/^{/) { $out .= $_; next; } $out .= "$_\n"; } is ($out, $want);

Note that I've removed the arbitrary trailing tabs from both files where they existed before importing. If you need those then it's up to you to implement that part as it is genuinely arbitrary.


In reply to Re^3: Accessing value from a hash table in perl by hippo
in thread Accessing value from a hash table in perl by DAN0207

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.