steph_bow has asked for the wisdom of the Perl Monks concerning the following question:
Dear Monks
I have made a subroutine that works properly, but when I use "or die", then it dies after the first call ! When I do not use "or die" then the all results are printed. Could you explain ? Thanks
Here is the structure of the code
my $element; foreach $element(@Elements){ &process($element) or die; } sub process{ chdir("$path_to_the_data_directory")or die; my $outfile; #the $outfile name depends on $reg; open my $OUTFILE, q{>}, $outfile; my $infile = "data.txt"; open my $INFILE, q{<}, $infile; while (my $line = <$INFILE>){ # several operations which produce "$results" print $OUTFILE "$results\n"; } close $OUTFILE; chdir("$path_to_the_script_directory") or die; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: &process or die
by moritz (Cardinal) on Apr 18, 2008 at 12:49 UTC | |
by steph_bow (Pilgrim) on Apr 18, 2008 at 12:56 UTC | |
by toolic (Bishop) on Apr 18, 2008 at 16:42 UTC | |
|
Re: &process or die
by mscharrer (Hermit) on Apr 18, 2008 at 12:57 UTC | |
by steph_bow (Pilgrim) on Apr 18, 2008 at 15:42 UTC | |
by chromatic (Archbishop) on Apr 18, 2008 at 16:36 UTC | |
|
Re: &process or die
by FunkyMonk (Bishop) on Apr 18, 2008 at 13:05 UTC | |
|
Re: &process or die
by Fletch (Bishop) on Apr 18, 2008 at 13:43 UTC | |
|
Re: &process or die
by rowdog (Curate) on Apr 18, 2008 at 20:36 UTC | |
|
Re: &process or die
by Anonymous Monk on Apr 18, 2008 at 14:11 UTC |