S
Stephen Moon
Hi,
Can you help me with the below error? Thanks in advance.
-Steve
input file:
====================================================
flintstones: lead=fred pal=barney
jetsons: lead=george wife=jane boy=elroy
simpsons: lead=homer wife=marge kid=bart
perl source code:
====================================================
#!/usr/bin/perl -w
use strict;
my %HoH; #hash table for the data structure
my $rfwho;
if($#ARGV != 1) {
die("Invalid number of arguments\nUsage: perl test.pl <input_file>
<output_file>\n");
}
my $infile = $ARGV[0];
my $outfile = $ARGV[1];
open(DATA_IN,"$infile") || die("could not open $infile\n");
open(DATA_OUT,">$outfile") || die("could not open $outfile\n");
while ( my $line = <DATA_IN> ) {
chomp($line);
if($line =~ /^(.*?):\s*/){
my $who = $1;
$rfwho = \$who;
my $rfrec = {};
$HoH{$who} = $rfrec;
for my $field ( split /\s+/, $line) {
my ($key, $value) = split /=/,$field;
$rfrec->{$key} = $value;
}
}
}
foreach my $family ( keys %HoH ) {
print "$family: ";
foreach my $role ( keys %{ $HoH{$family} } ) {
printf(DATA_OUT "$role=$HoH{$family}{$role}"); <= error here
}
printf(DATA_OUT "\n");
}
output error:
====================================================
Use of uninitialized value in concatenation (.) or string at test.pl
line 34, <DATA_IN> line 3.
Use of uninitialized value in concatenation (.) or string at test.pl
line 34, <DATA_IN> line 3.
Use of uninitialized value in concatenation (.) or string at test.pl
line 34, <DATA_IN> line 3.
Can you help me with the below error? Thanks in advance.
-Steve
input file:
====================================================
flintstones: lead=fred pal=barney
jetsons: lead=george wife=jane boy=elroy
simpsons: lead=homer wife=marge kid=bart
perl source code:
====================================================
#!/usr/bin/perl -w
use strict;
my %HoH; #hash table for the data structure
my $rfwho;
if($#ARGV != 1) {
die("Invalid number of arguments\nUsage: perl test.pl <input_file>
<output_file>\n");
}
my $infile = $ARGV[0];
my $outfile = $ARGV[1];
open(DATA_IN,"$infile") || die("could not open $infile\n");
open(DATA_OUT,">$outfile") || die("could not open $outfile\n");
while ( my $line = <DATA_IN> ) {
chomp($line);
if($line =~ /^(.*?):\s*/){
my $who = $1;
$rfwho = \$who;
my $rfrec = {};
$HoH{$who} = $rfrec;
for my $field ( split /\s+/, $line) {
my ($key, $value) = split /=/,$field;
$rfrec->{$key} = $value;
}
}
}
foreach my $family ( keys %HoH ) {
print "$family: ";
foreach my $role ( keys %{ $HoH{$family} } ) {
printf(DATA_OUT "$role=$HoH{$family}{$role}"); <= error here
}
printf(DATA_OUT "\n");
}
output error:
====================================================
Use of uninitialized value in concatenation (.) or string at test.pl
line 34, <DATA_IN> line 3.
Use of uninitialized value in concatenation (.) or string at test.pl
line 34, <DATA_IN> line 3.
Use of uninitialized value in concatenation (.) or string at test.pl
line 34, <DATA_IN> line 3.