Mailing List Archive

is this a bug in perl or in my brain?
run this on an html file. it gets into an infinite loop.

#!/usr/bin/perl -n00

while ( ($tag, $level, $text) = m{
< (h(\d)) >
(.*?)
< /\1 >
}gsix
)
{
$fill = " " x $level;
$text =~ s/^/$fill/gm;
$text =~ s/^\s+//; $text =~ s/\s+$//;
print "\n----\n\U$tag\E: $text\n";
}
Re: is this a bug in perl or in my brain? [ In reply to ]
Excerpts from the mail message of Tom Christiansen:
) run this on an html file. it gets into an infinite loop.

This has been a while but I finally looked at it and haven't
seen a reply so...

) #!/usr/bin/perl -n00
)
) while ( ($tag, $level, $text) = m{
) < (h(\d)) >
) (.*?)
) < /\1 >
) }gsix
) )
) {
) $fill = " " x $level;
) $text =~ s/^/$fill/gm;
) $text =~ s/^\s+//; $text =~ s/\s+$//;
) print "\n----\n\U$tag\E: $text\n";
) }

Both the versions below work. In other words, //m only interates
if in a scalar context so if you want to get at what matched your
subexpressions then you either have to get them all at once in an
array context or use $1, $2, etc.

#!/usr/bin/perl -n00
@_= m{
< (h(\d)) >
(.*?)
< /\1 >
}gsix;
while ( ($tag, $level, $text) = splice(@_, 0, 3) )
{
$fill = " " x $level;
$text =~ s/^/$fill/gm;
$text =~ s/^\s+//; $text =~ s/\s+$//;
print "\n----\n\U$tag\E: $text\n";
}

#!/usr/bin/perl -n00
while ( m{
< (h(\d)) >
(.*?)
< /\1 >
}gsix
)
{
($tag, $level, $text) = ($1, $2, $3);
$fill = " " x $level;
$text =~ s/^/$fill/gm;
$text =~ s/^\s+//; $text =~ s/\s+$//;
print "\n----\n\U$tag\E: $text\n";
}

--
Tye McQueen tye@metronet.com || tye@doober.usu.edu
Nothing is obvious unless you are overlooking something
http://www.metronet.com/~tye/ (scripts, links, nothing fancy)
Re: is this a bug in perl or in my brain? [ In reply to ]
> Excerpts from the mail message of Tom Christiansen:
> ) run this on an html file. it gets into an infinite loop.

> This has been a while but I finally looked at it and haven't
> seen a reply so...

> ) #!/usr/bin/perl -n00
> ) while ( ($tag, $level, $text) = m{
> ) < (h(\d)) >
> ) (.*?)
> ) < /\1 >
> ) }gsix

> Both the versions below work. In other words, //m only interates
> if in a scalar context so if you want to get at what matched your
> subexpressions then you either have to get them all at once in an
> array context or use $1, $2, etc.

Duh. It was a bug in my brain.

I dunno what to say, except that even I missed the scalar/list
context. No wonder my students run away screaming.

--tom