in reply to Re: parsing an ASP file
in thread parsing an ASP file
this way, each element of the returned array contains three elements: the type (ASP or HTM), the line number, and the block itself.sub get_asp_blocks { my($file) = @_; open(FILE, $file) or die "can't open '$file': $!\n"; my $dot = 1; my @blocks = ( ["HTM", $dot, ""] ); my $state = "HTM"; my $last; while(read(FILE, $char, 1)) { $dot++ if $char eq "\n"; if($last eq "<" && $char eq "%" && $state eq "HTM") { chop $blocks[-1][-1]; $state = "ASP"; push(@blocks, ["ASP", $dot, ""]); } elsif($last eq "%" && $char eq ">" && $state eq "ASP") { chop $blocks[-1][-1]; $state = "HTM"; push(@blocks, ["HTM", $dot, ""]); } else { $blocks[-1][-1] .= $char; } $last = $char; } close(FILE); return @blocks; }
King of Laziness, Wizard of Impatience, Lord of Hubris
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: parsing an ASP file
by Juerd (Abbot) on May 23, 2004 at 22:57 UTC | |
by dada (Chaplain) on May 25, 2004 at 09:21 UTC | |
by Juerd (Abbot) on May 25, 2004 at 14:47 UTC | |
by Juerd (Abbot) on May 25, 2004 at 21:34 UTC |