>>>>> "RM" == Richard Morse <[EMAIL PROTECTED]> writes:
RM> Phoo. Apparently, something stripped out my code.
as i said i bet this list strips attachments. i know mailman will do
that and it is usually a good idea. pasting code is easy enough and it
keeps large binaries from clogging our mailboxes. :)
RM> I've pasted it below...
RM> #!/usr/bin/perl
RM> use strict;
RM> use warnings;
good! :)
RM> my $before = 0;
RM> my $after = 0;
RM> my $pattern = qr/foo/;
RM> my $buffer = [ ];
RM> my $buffer_size = $before + 1 + $after;
RM> # prepopulate the buffor so that the check for $in_match_context will
RM> work
RM> for (1..$buffer_size) {
RM> push @$buffer, [ 0, '', '' ];
RM> }
since we don't care about that ref being a copy (it is read only), the x
op is nice and declare it right here too:
my $buffer = [ ([ 0, '', '' ]) x $buffer_size ] ;
RM> my $in_match_context = 0;
RM> my $separator = '';
RM> my $post_print_count = 0; # needed to make $after lines work
RM> my $count_nonmatched_lines = 0;
RM> while (scalar(@$buffer)) {
drop the scalar as it is redundant. while provides a scalar context
RM> if (defined($buffer->[$before])) {
RM> $in_match_context = $buffer->[$before]->[0] ||
RM> $in_match_context;
RM> }
i will need to look at this more carefully before i make more
deep comments.
RM> my $head_line = shift @$buffer;
as a style thing i always use {} when dereferencing. it is a visual
thing that i think helps. @{$buffer};
regardless of my comments, it is good that you have coded this up. i
would expect the final result to barely look like this. :)
also i will be at oscon so i won't have much time in the next week or so
to work on this. i will take the code with me to study in some spare
time if i have any. i will be on line but not checking mail often.
thanx,
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
_______________________________________________
Boston-pm mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/boston-pm