Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use Time::Local; use CGI qw(:standard); require "/u/web/cmpsf/cgi-local/schedules/cleaners/FileDB.pm"; my $fileDB = FileDB->new( FILE => $fileName ,DELIMITER => "::"); print_search_results($fileDB); sub print_search_results{ my ($db)= @_; my @records = $db->get_all(); foreach(sort{$a->[0]cmp$b->[0]}map{["$_->[3]#$_->[2]",$_]}@records) { my $rec = $_->[1]; push @{$values{$rec->[3]}}, $rec->[2]; if ($rec->[3]== 1) { my $full_name = $rec->[1].' '.$rec->[2]."," ; push(@data_one,$full_name); }; } } sub words{ my @data_one; my @data_two; my ($item, $cols, $rows, $maxlen); my ($xpixel, $ypixel, $mask, @data); my($database) = ($_[0]); getwinsize(); # first gather up every line of input, # remembering the longest line length seen $maxlen = 1; open(DATABASE, "$database"); while (<DATABASE>) { my $mylen; s/\s+$//; $maxlen = $mylen if (($mylen = length) > $maxlen); push(@data, $_); } $maxlen += 1; # to make extra space # determine boundaries of screen $cols = int($cols / $maxlen) || 1; $rows = int(($#data+$cols) / $cols); # pre-create mask for faster computation $mask = sprintf("%%-%ds ", $maxlen-1); # subroutine to check whether at last item on line sub EOL { ($item+1) % $cols == 0 } # now process each item, picking out proper piece for this position for ($item = 0; $item < $rows * $cols; $item++) { my $target = ($item % $cols) * $rows + int($item/$cols); my $piece = sprintf($mask, $target < @data ? $data[$target] : ""); $piece =~ s/\s+$// if EOL(); # don't blank-pad to EOL print $piece; print "\n" if EOL(); } # finish up if needed print "\n" if EOL(); # not portable -- linux only sub getwinsize { my $winsize = "\0" x 8; my $TIOCGWINSZ = 0x40087468; if (ioctl(STDOUT, $TIOCGWINSZ, $winsize)) { ($rows, $cols, $xpixel, $ypixel) = unpack('S4', $winsize); } else { $cols = 80; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: passing an array to a subroutine
by sauoq (Abbot) on Jul 10, 2003 at 23:25 UTC | |
|
Re: passing an array to a subroutine
by Zaxo (Archbishop) on Jul 10, 2003 at 22:18 UTC | |
|
Re: passing an array to a subroutine
by CountZero (Bishop) on Jul 10, 2003 at 22:24 UTC | |
by Anonymous Monk on Jul 10, 2003 at 22:32 UTC | |
|
Re: passing an array to a subroutine
by pzbagel (Chaplain) on Jul 10, 2003 at 22:31 UTC | |
by Anonymous Monk on Jul 10, 2003 at 22:34 UTC |