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

So basically, when you encounter a special comment tag in your html file, you jump to a subroutine, eh? Sounds kinda bizarre, but anyway...

sub foo { # ....initialization stuff...., blah blah while( my $line = <SOURCE> ) { if( $line =~ /<!--a -->/ ) { # could do index(), if looking f +or exact match like this sub_a(); last; } elsif( $line =~ /<!--b -->/ ) { # ditto sub_b(); last; } } }

Replies are listed 'Best First'.
Re: Re: simple search problem (but not for me!!)
by jonnyfolk (Vicar) on Oct 12, 2002 at 22:46 UTC
    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?!!

      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!