Greetings to all, I am trying to pass the array @data_one from the sub print_search_results{) to another subroutine I found as a program named &words() that I ran acrossed in the O'REILLY perl cookbook. I really liked the formatting of the text. I can get the words() program to work ok passing a hard coded filename.
I am still new to perl . What am I doing wrong.
Thanks for any help Tim
#!/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; } } }

In reply to passing an array to a subroutine by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.