I tried with the following code.# 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 } }
This is not working and i am getting the following output.#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash_table; my $name; my $file = '/tmp/fruitdir/fruit1.txt'; open my $fh, "<", $file or die "Can't open $file: $!"; while (<$fh>) { chomp; if (/^\s*fruitName/) { ($name) = /(\".+\")/; next; } s/(fruitCount|fruitValue)/$name\.$1/; my ($key, $value) = split /\s+/, $_, 2; $hash_table{$key} = $value; } print Dumper(\%hash_table);
$VAR1 = { '' => undef, 'time' => '11:15 ', 'date' => '14/07/2016', '{' => undef, '#' => 'this is a new file', 'total' => '30 ', 'end' => '11:20 ', 'No' => '"FRUITS"', 'Fruit_class' => undef, '}' => undef };
In reply to Re^6: Accessing value from a hash table in perl
by DAN0207
in thread Accessing value from a hash table in perl
by DAN0207
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |