kaushik9918 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to call a subroutine in a loop, but its exiting after executing the sub only once. Any idea why? Or can someone point me to a similar question posted before in this forum?
the array corners contains: @corners= AAA BBB CCC DDD
and my code is :while(<CORNERS_LIST>){ $_=~ s/\s+/ / ; chop $_; push @corners, $_ ; print "\n@corners\n"; } my $corner; foreach(@corners){ $corner=$_; &loading_tsc; } sub loading_tsc{ chdir($corner) or die "\n $!\n"; print "\n"; print `pwd`; print "\n"; }
But the result I am getting is :
/file/path/is/AAA No such file or directory
The desired result I wanted to see is
/file/path/is/AAA /file/path/is/BBB /file/path/is/CCC /file/path/is/DDD
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: calling subroutine inside loop - ERROR - subroutine executes only once
by Discipulus (Canon) on Dec 24, 2014 at 08:19 UTC | |
by kaushik9918 (Sexton) on Dec 24, 2014 at 09:07 UTC | |
|
Re: calling subroutine inside loop - ERROR - subroutine executes only once
by LanX (Saint) on Dec 24, 2014 at 11:41 UTC | |
|
Re: calling subroutine inside loop - ERROR - subroutine executes only once
by Laurent_R (Canon) on Dec 24, 2014 at 18:42 UTC | |
by kaushik9918 (Sexton) on Dec 30, 2014 at 07:20 UTC |