Why do you want to leave a loop in line 78 (last)? There is no loop!
Why can't you pass the new variable and redo the process? What happens instead?
Took your code and cleaned it up a bit. Looks as if it works as designed...
#!/usr/bin/perl # vi:ts=4 sw=4 et: use strict; use warnings; print "continue [y/N]? "; chomp ( my $answer = <STDIN> ); # any other answer than 'y' or 'Y' results in an termination of the pr +ogram if ( $answer !~ m/[Yy]/ ) { exit 0; } # process first foo( 'foo.txt' ); sub foo { my $file = shift; print "work with '$file'\n"; print "continue [y/N]? "; chomp( $answer = <STDIN> ); if ( $answer !~ m/[yY]/ ) { exit 0; } print "change what? "; chomp( my $to_change = <STDIN> ); if ( defined $to_change ) { print "wanted to change: $to_change\n"; } print "again [Y/n]? "; chomp( $answer = <STDIN> ); if ( $answer !~ m/[Yy]/ ) { exit 0; } print "running again: \n"; # process second foo( 'bar.txt' ); }
In reply to Re: loop problem
by linuxer
in thread loop problem
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |