in reply to Re: returning to a loop later on
in thread returning to a loop later on

i get the error: "syntax error at output.pl line 3, at EOF Execution of output.pl aborted due to compilation errors." when i run the code above. any ideas why? also, for some reason warning isnt in my distribution of perl. if i include use warning it comes up with the error: "Can't locate warning.pm in @INC (@INC contains: /System/Library/Perl/5.8.6/darwin-thread-multi-2level /System/Library/Perl/5.8.6 /Library/Perl/5.8.6/darwin-thread-multi-2level /Library/Perl/5.8.6 /Library/Perl /Network/Library/Perl/5.8.6/darwin-thread-multi-2level /Network/Library/Perl/5.8.6 /Network/Library/Perl /System/Library/Perl/Extras/5.8.6/darwin-thread-multi-2level /System/Library/Perl/Extras/5.8.6 /Library/Perl/5.8.1/darwin-thread-multi-2level /Library/Perl/5.8.1 .) at output.pl line 3. BEGIN failed--compilation aborted at output.pl line 3." thanks for the help!

Replies are listed 'Best First'.
Re^3: returning to a loop later on
by Not_a_Number (Prior) on Sep 07, 2006 at 08:32 UTC

    It's a typo in ikegami's code. Change line 3 to:

    use warnings;
      haha, yeah! didnt even notice!
      anyway, the code still doesnt work. i just get an error saying that:
      syntax error at output.pl line 2, at EOF Execution of output.pl aborted due to compilation errors.
      this is the exact code that im running:
      #!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; } }

        That's strange, I just copied and pasted the code and I don't get that error message at all!

        However, there is another mistake in the code, in the block that starts with:

        if ( -e $save ).

        the line that says:

        last if $out eq 'Y' or $out eq 'N';

        should of course read:

        last if $overwrite eq 'Y' or $overwrite eq 'N';

        Once that is corrected, the code works perfectly on my WinXP machine.

        #!usr/local/bin/perl
        Should be
        #!/usr/local/bin/perl
        (Or wherever you have perl installed)