i have a text file which looks like this.
Parameter 0:
Field 1 : 100
Field 2 : 0
Field 3 : 4
Parameter 1:
Field 1 : 873
Field 2 : 23
Field 3 : 89
I want to write a perl script that parses this file in the following format
Parameter Field1 Field2 Field3
0 100 0 4
1 873 23 89
Can anyone help me with this. Any help will be greatly appreciated. i have tried the following so far
my %hash = ();
my $file = "sample.txt";
open (my $fh, "<", $file) or die "Can't open the file $file: ";
while (my $line =<$fh>)
{
chomp ($line);
my($key) = split(" : ", $line);
$hash{$key} = 1;
}
foreach my $key (sort keys %hash)
{
print "$key\n";
}