bob@dhw68k.cts.com (Bob Best) (08/07/88)
Sorry for the additional posting, but I woke up this morning with an idea to reduce the program size in half. --------------cut here---------------- # grep.pl - perl version of grep(1) # written by bob best (bob@dhw68k.cts.com) # Revision 1: used $if_unless to reduce program size in half while ($_ = $ARGV[0], /^-/) { shift; /^-y/ && ($fold='i') && next; /^-v/ && ($nonmatch=1) && next; /^-c/ && ($count=1) && next; /^-n/ && ($line=1) && next; /^-l/ && ($fileonly=1) && next; } $pattern=$ARGV[0]; shift; ++$multifile if $#ARGV > 0; $nonmatch ? ($if_unless = 'unless') : ($if_unless = 'if'); dogrep: { if ($fileonly) { eval "while (<>) { $if_unless (/$pattern/$fold) { print \"\$ARGV\\n\"; close(ARGV);} } "; last dogrep; } if ($count && $multifile) { eval "while (<>) { ++\$cnt $if_unless /$pattern/$fold; if (eof) { print \"\$ARGV:\$cnt\\n\"; \$cnt=0;} } "; last dogrep; } if ($count) { eval "while (<>) { ++\$cnt $if_unless /$pattern/$fold;} print \"\$cnt\\n\"; "; last dogrep; } if ($multifile && $line) { eval "while (<>) { print \"\$ARGV:\$.:\$_\" $if_unless /$pattern/$fold; close(ARGV) if eof; } "; last dogrep; } if ($multifile) { eval "while (<>) { print \"\$ARGV:\$_\" $if_unless /$pattern/$fold; } "; last dogrep; } if ($line) { eval "while (<>) { print \"\$.:\$_\" $if_unless /$pattern/$fold;} "; last dogrep; } eval "while (<>) { print $if_unless /$pattern/$fold; } "; } #end of dogrep block -- Bob Best uucp: ...{trwrb,hplabs}!felix!dhw68k!bob InterNet: bob@dhw68k.cts.com