A
Alan Mead
I recently created a script that did a lot of this sort of thing:
my $dataref = get_data($filename1) if ($condition==1);
my $dataref = get_data($filename2) if ($condition==2);
foreach my $datum (keys %$dataref) { ...
Which didn't raise an exception but $dataref was always nil. I had to
write:
my $dataref;
$dataref = get_data($filename1) if ($condition==1);
$dataref = get_data($filename2) if ($condition==2);
I'm not sure I understand precisely why the first one didn't work but
also failed to raise an error when run under the strict pragma. I
mean, if it was a scoping thing then shouldn't the reference to
%$dataref in the foreach loop trigger an exception?
Anyway, the second method fixed the problem but it's a bit ungainly. Is
there a more idiomatic way to do this?
Thanks,
-Alan
my $dataref = get_data($filename1) if ($condition==1);
my $dataref = get_data($filename2) if ($condition==2);
foreach my $datum (keys %$dataref) { ...
Which didn't raise an exception but $dataref was always nil. I had to
write:
my $dataref;
$dataref = get_data($filename1) if ($condition==1);
$dataref = get_data($filename2) if ($condition==2);
I'm not sure I understand precisely why the first one didn't work but
also failed to raise an error when run under the strict pragma. I
mean, if it was a scoping thing then shouldn't the reference to
%$dataref in the foreach loop trigger an exception?
Anyway, the second method fixed the problem but it's a bit ungainly. Is
there a more idiomatic way to do this?
Thanks,
-Alan