in reply to Re: simple search problem (but not for me!!)
in thread simple search problem (but not for me!!)

Thanks very much for your reply. I've been trying to apply your solution to my script though without success. I turned it into a standalone script but it still keeps failing and I can't track down the reason why (I've checked for syntax errors etc and it comes out ok) so I'm obviously off base with mu application still. What I have is:
#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; $prepage = "/path/to/page"; print "Content-type: text/html\n\n"; #open file: open (PAGE, "$prepage") || die "Couldn't get prepage ched"; @prep=<PAGE>; while( my $line = <PAGE> ) { if( $line =~ /<!--a -->/ ) { # could do index(), if looking for exact match like this suba(); last; } elsif( $line =~ /<!--b -->/ ) { # ditto subb(); last; } } close (PAGE); sub suba{ print "suba says hi!"; } sub subb{ print "subb says hi!"; }
So what am I doing wrong now?!!

Replies are listed 'Best First'.
Re: Re: Re: simple search problem (but not for me!!)
by BrowserUk (Patriarch) on Oct 12, 2002 at 23:09 UTC

    In the first line after your open, you do @prep=<PAGE>;. This reads your whole file into the array @perp. You then completely ignore this array and attempt to process the file line by line with while( my $line = <PAGE> ) { but you have already read the whole file, so there is nothing left to read. Try commenting out (or simply deleting) that first line after the open and see what difference that makes.

    open (PAGE, "$prepage") || die "Couldn't get prepage ched"; @prep=<PAGE>; # <<<< Why???? while( my $line = <PAGE> ) {

    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!