local $/ = "Startpoint"; $temp="abc"; while(<INFILE1>){ /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\S+)/s; $PG{$3}{"$1-$2"}{"$cou"} = $4; $cou++; }
The first time you read the record that ends in "Startpoint" there is nothing in the body of the record (at least, as far as I can see from the posted data). You then parse that data with a regex and add data to the hash regardless of whether or not the parse was valid. Try a modification like (untested):
my %PG; my $cou = 0; local $/ = 'Startpoint'; RECORD: while (<INFILE1>) { next RECORD unless # unless valid data extracted from record /[(](\w+)[^(]+[(](\w+)[^:]+:\s+(\w+).*?slack[^-]+(-\S+)/s; $PG{$3}{"$1-$2"}{$cou} = $4; $cou++; }
It would also be wise to check the success of the open statement and die on failure.
Update: To answer your specific question: When the regex fails to match on the first (malformed) record, $1 $2 $3 $4 are all undefined, as is $cou. The undefined value stringifies as '' (the empty string), so you get a hash element of
--------------undefined key of my hash--------------- '' => { '-' => { '' => undef } },
In reply to Re: not defined Hash data came why?
by AnomalousMonk
in thread not defined Hash data came why?
by mak.jordan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |