svend_ok has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, oh wise monks

This is no doubt a shamefully elementary question, but can someone tell me what's wrong with this code (taken from http://www.opensourcetutorials.com/tutorials/Server-Side-Coding/Perl/perl-scripts-regex/page3.html)?

I'm getting the "pattern not terminated" error on the last line). The text file is just "Lorem ipsum"-type text.

my $filename = "C:\\temp\\testdata.txt"; open ( FILE, $filename) or die "Cannot open file: $!"; while ( $line = <FILE> ) { # i is case insensative # ([^>]*) match zero or more characters but not '>' $line =~ s/ying/yang/gi; push(@outLines, $line); } close FILE; open ( OUTFILE, ">$filename" ); print ( OUTFILE @outLines ); close ( OUTFILE ); ?>

Thanks.

Replies are listed 'Best First'.
Re: "search pattern not terminated " error
by almut (Canon) on Feb 25, 2010 at 19:00 UTC

    Tha last line (?>) doesn't make any sense. Just remove it and you'll be fine.

      Thank you.

        Specifically, Perl thinks you have opened a special 'match-only-once' regex (or else maybe a weird  ?: ternary operator).
        See ?PATTERN? in perlop.