#!/usr/local/bin/perl # # findrows.p # # reads in an Afile and writes out the ROWS that match the required columns # delivered on command line # usage: # findrows.p 191 331 < ~/code/GHC/C2003g1503 $v=1; # verbosity $c=1; # whether to report the columns too. $rows=1; # whether to report the rows $highlight=1;#whether to highlight the matches. # The aim here is to establish whether the provided list # is equal to a sum of SOME of these rows. # $count = 1 ; # whether to count, in the rows, how often each column appears. # How to override min and max values with command line eval "\$$1=\$2" while $ARGV[0]=~ /^(\w+)=(.*)/ && shift; $i = 0 ; while ( @ARGV ) { $f[$i] = $ARGV[0] && shift; $i ++ ; } $_ = <>; ($L,$M) = split ; print STDERR $L , " " , $M , "\n" ; $_ = <>; $_ = <>; $_ = <>; print "# Columns matching given integers\n" if($v && $c ); for ( $l = 1 ; $l <= $L ; $l ++ ) { $_ = <>; if($c) { foreach $r ( @f ) { if ( $l eq $r ) { print ; } } } } # if($rows){ print "# Rows containing given integers\n" if($v); ROWSLOOP: for ( $l = 1 ; $l <= $M ; $l ++ ) { $_ = <>; if($highlight) { $printme = 0 ; foreach $r ( @f ) { if ( /\s$r\s/ || /^$r\s/ ) { s/(\s)($r)(\s)/$1\($2\)$3/ ; s/^($r)(\s)/\($1\)$2/ ; $printme++ ; } } print if $printme ; } else { foreach $r ( @f ) { if ( /\s$r\s/ || /^$r\s/ ) { print ; next ROWSLOOP ; } } } } }#