the file data blocks in same format below file
edit_file content{ val0 data0 val0 data0 val0 data0 val0 data0 val0 data0 }
and code is
my $temp_hash; open fd, "<temp.cfg"; @array = <fd>; foreach $line (@array) { if ($line =~ /\s+(.*?)\s+(.*)/) { foreach $key (keys %tem) { $temp_hash{$1} = $2; } } print $temp_hash; } foreach $array (keys $1) { print "$key $temp_hash{$key}\n"; }
if want parse file hash:
my %data; open $fh, "<", "temp.cfg" or die $!; while ( $line = readline($fh) ) { if ( $line =~ m{^\s+(\s+)\s+(\s+)$} ) { $data{$1} = $2; } } close $fh; foreach $key (keys %data) { print "$key $data{$key}\n"; }
Comments
Post a Comment