in reply to Re^2: Accessing value from a hash table in perl
in thread Accessing value from a hash table in perl

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.