in reply to Re^3: returning to a loop later on
in thread returning to a loop later on
this is the exact code that im running:syntax error at output.pl line 2, at EOF Execution of output.pl aborted due to compilation errors.
#!usr/local/bin/perl use strict; use warnings; my $output = "data"; my $out; for (;;) { print("Do you want to output to (S)creen or to (F)ile? "); chomp( $out = uc( <STDIN> ) ); last if $out eq 'S' or $out eq 'F'; print("Invalid input. Please type either S or F.\n"); } if ($out eq 'S') { print $output; } else # $out eq 'F' { for (;;) { print("Please enter filename: "); chomp( my $save = <STDIN> ); if ( $save !~ /^[a-zA-Z][a-zA-Z_0-9]*\Z/ ) { print("Invalid input. Please begin with a letter and do no +t add extension, it will be added automatically.\n"); redo; } $save .= ".ext"; if ( -e $save ) { my $overwrite; for (;;) { print("Filename exists. Overwrite? (Y) or (N) "); chomp( $overwrite = uc( <STDIN> ) ); last if $out eq 'Y' or $out eq 'N'; print("Invalid input. Please type either Y or N.\n") } redo if $overwrite eq 'N'; } open( my $fh_out, '>', $save ) or die "Unable to create $save: $!\n"; print $fh_out $output; last; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: returning to a loop later on
by Not_a_Number (Prior) on Sep 07, 2006 at 12:23 UTC | |
by Yoda_Oz (Sexton) on Sep 07, 2006 at 14:38 UTC | |
|
Re^5: returning to a loop later on
by imp (Priest) on Sep 07, 2006 at 14:51 UTC | |
by Yoda_Oz (Sexton) on Sep 07, 2006 at 21:25 UTC | |
by ikegami (Patriarch) on Sep 07, 2006 at 22:02 UTC | |
by Yoda_Oz (Sexton) on Sep 08, 2006 at 07:04 UTC | |
by ikegami (Patriarch) on Sep 08, 2006 at 07:31 UTC | |
|