M
Michael TEpperis
I call a function of an modul inside an eval-statement and catch $@
after returning.
_croak_ works in the cases marked as ONE and THREE. if
I pass a wrong file name, I suspect an error in case TWO too,
but I fail. ($class->{'error_out'} is set to 1)
this is the function:
....--------------------------------------------
sub parse_doc
{
my $class = shift;
ONE my $file_name = shift || croak "Usage: parse_doc(file_name,
[\%attr])";
my $attr = shift; # %attr (headings, sub_char)
eval {open FILE_CSV, "$file_name";};
$csvxml_error = "Couldn't open file: $file_name. $@" if $@;
TWO croak "$csvxml_error" if ($class->{'error_out'} == 1 && $@);
my @col_headings;
$attr->{headings} = 0 unless (exists($attr->{headings}));
if ($attr->{headings} == 0) ### No headings to be used from file
{
if ($class->{column_headings})
{
@col_headings = @{$class->{column_headings}};
}
}
my $line;
if ($attr->{headings} != 0)
{
$line = <FILE_CSV>;
my $cols_returned = $get_header->($line, \@col_headings,
defined($attr->{sub_char})? $attr->{sub_char}:undef );
$csvxml_error = "There were no columns returned for headers, please
check your CSV file" if (!$cols_returned);
THREE croak "$csvxml_error" if ($class->{'error_out'} == 1);
return 0 if (!$cols_returned);
}
return 1;
}
....--------------------------------------------
any ideas?
tia
michael
after returning.
_croak_ works in the cases marked as ONE and THREE. if
I pass a wrong file name, I suspect an error in case TWO too,
but I fail. ($class->{'error_out'} is set to 1)
this is the function:
....--------------------------------------------
sub parse_doc
{
my $class = shift;
ONE my $file_name = shift || croak "Usage: parse_doc(file_name,
[\%attr])";
my $attr = shift; # %attr (headings, sub_char)
eval {open FILE_CSV, "$file_name";};
$csvxml_error = "Couldn't open file: $file_name. $@" if $@;
TWO croak "$csvxml_error" if ($class->{'error_out'} == 1 && $@);
my @col_headings;
$attr->{headings} = 0 unless (exists($attr->{headings}));
if ($attr->{headings} == 0) ### No headings to be used from file
{
if ($class->{column_headings})
{
@col_headings = @{$class->{column_headings}};
}
}
my $line;
if ($attr->{headings} != 0)
{
$line = <FILE_CSV>;
my $cols_returned = $get_header->($line, \@col_headings,
defined($attr->{sub_char})? $attr->{sub_char}:undef );
$csvxml_error = "There were no columns returned for headers, please
check your CSV file" if (!$cols_returned);
THREE croak "$csvxml_error" if ($class->{'error_out'} == 1);
return 0 if (!$cols_returned);
}
return 1;
}
....--------------------------------------------
any ideas?
tia
michael