Re: a problem about function returning point
- From: Klaus <klaus03@xxxxxxxxx>
- Date: 29 Apr 2007 08:40:07 -0700
On Apr 29, 4:00 pm, "havel.zhang" <havel.zh...@xxxxxxxxx> wrote:
Today I came cross a strange problem about function returning
point.
Like with every strange problem in Perl, first try the following, put
the following two lines at the beginning of your program:
use strict;
use warnings;
Correct all errors (if any) and all warnings (if any) and re-run your
program.
If the problem persists, then proceed as follows:
[ subroutine snipped ]
Then I calling this function in a subroutine. as follows:
... ...
### first we open a text file, and read line by line:
open(F,"<aaa.txt");
while(<F>){
This probably won't make any difference to your problem, but I mention
it anyway:
The open is better written as:
open my $F, '<', 'aaa.txt' or die "Error read 'aaa.txt', $!";
while (<$F>) {
... ...
#according the context we have read, we named function name.
my $progName = $conf->{'feedname'} . '_slicecheck';
#calling the named function
You might have a good reason to call your function indirectly ("&
$progName()"), but if you do so you must accept the increased
complexity of your code.
With regards to your problem, this function call only makes sense if
$progName eq 'p4sup_slicecheck', therefore I stronly recommend to
print out the content of $progName before you actually call the
function, like so:
print STDERR "DEB-01: will call sub $progName\n";
my ($ret,$outline) = &$progName($conf,$data,$store);
Then give a life sign when you return from the function call, like so:
print STDERR "DEB-02: back from sub $progName\n";
if ($ret == 2){
... ...
};
print OUTPUT "$outline\n" if ($ret==0);}
close(F);
Better:
close $F;
close(OUTPUT);
exit(0);
#the calling function name is p4sup:
#
sub p4sup_slicecheck{
my $conf = shift;
my $data = shift;
my $store = shift;
#calling function replace_par,replace the chinese character
$data->{'english_name'} = replace_par($data->{'english_name'}) if
$data->{'english_name'} =~ /\xA3\xA8/
There is no semicolon at the end of the above line. I seriously ask
myself whether you ever compiled your program successfully ?
Anyway, the above function should be written differently to add some
prints, like so:
#calling function replace_par,replace the chinese character
print STDERR "DEB-03: inside p4sup_slicecheck()\n";
if ($data->{'english_name'} =~ /\xA3\xA8/) {
print STDERR "DEB-04: will call sub replace_par()\n";
$data->{'english_name'} = replace_par($data->{'english_name'});
print STDERR "DEB-05: back from sub replace_par()\n";
}
print STDERR "DEB-06: continue p4sup_slicecheck()\n";
$l = length($data->{'english_name'});
$data->{'english_name'} .= ' ' x (100 - $l) if ($l < 100);
... ...
}
then, after calling function replace_par, system should return to
subroutine:p4sup_slicecheck. But the system return to "close(OUTPUT)"
where the line before exit(0) !
Run the program and watch what STDERR reports, that might be useful.
--
Klaus
.
- Follow-Ups:
- Re: a problem about function returning point
- From: havel.zhang
- Re: a problem about function returning point
- References:
- a problem about function returning point
- From: havel.zhang
- a problem about function returning point
- Prev by Date: Re: Rounding up to the next .5
- Next by Date: CGI module redirect defaults to 302 -- why?
- Previous by thread: a problem about function returning point
- Next by thread: Re: a problem about function returning point
- Index(es):
Relevant Pages
|
|