[VPM] Printing one line over several lines

Carl B. Constantine cconstan at csc.UVic.CA
Wed Mar 26 17:56:16 CST 2003


I'm working on improving the perl code for the program I was talking
about at the last meeting. I'm not quite ready to put it out for all to
read yet as I have to change a bunch of data to protect people's privacy
and I just haven't gotten around to doing that.

One of the things my boss wants me to do is rework the print queue
headings. Here are the gory details:

I have an array that contains a list of all of our printers. Some of the
printer names (print queue names really) are fairly long. For example:
tp-colour-tr, where as others are relatively short, ie: tp.

When I print the report out for each prof (using some ugly centering
code to make sure everything lines up properly), the header looks like
this:

Page Rate ==>   (0.07)    (0.00)    ( 0.07)    ( 0.00)    (   0.50)    (      0.50)    (      0.00)    
Student Login       rp        tp    rp-test    tp-test    rp-colour    rp-colour-tr    tp-colour-tr    Total
=======================================================================================================================

Now, what my boss would like is that for print queue names that have a
hyphan in them, print the queue name over multiple lines while still
lining things up like so:

Page Rate ==>   (0.07)    (0.00)    (0.07)    (0.00)    ( 0.50)    ( 0.50)    ( 0.00)
Student Login       rp        tp       rp-       tp-        rp-        rp-        tp-
                                      test      test     colour     colour    colour-
                                                                       tr-        tr-     Total
===============================================================================================



the idea being to try and fit the report into 80 columns as much as
possible. Quit frankly that header could be slightly different, like say
the rp & tp and the test printers down a line or two, but the principle
is the same.


right now, when I'm printing this header, I have really ugly code that
looks like this:

print "Page Rate ==>\t";
  foreach $queue (@allPrinters) {
    if (exists $profHash{$leftOver}{$queue}) {
      $len = length($queue);
      if ($len <= $rateLen) {
        printf "(%2.2f)    ",$printCost{$queue}/100;
      } else {
        $len -= 2; # subtract 2 from the total length to take the ( & ) into account when printing
        printf "(%".$len.".2f)    ",$printCost{$queue}/100;
      }
    }
  }
  print "\n";
  print "Student Login\t";
  my $count = 0;
  my $length = 0;
  foreach $queue (@allPrinters) {
    if (exists $profHash{$leftOver}{$queue}) {
      $len = length($queue);
      if ($len < $rateLen) {
        printf "%".$rateLen."s    ",$queue;
  $length += $rateLen;
      } else {
        printf "%".$len."s    ",$queue;
  $length += $len;
      }
      $count++;
    }
  }
  print "Total\n";
  $length += ($count * 6) + 13 + 5; # this hack really needs to be fixed
  print "=" x $length;              # it doesn't work right anyway.
  print "\n\n";

any ideas, help are greatly appreciated.

-- 
Carl B. Constantine         University of Victoria
Programmer Analyst          http://www.csc.uvic.ca
UNIX System Administrator   Victoria, BC, Canada
cconstan at csc.uvic.ca        ELW A220, 721-8753



More information about the Victoria-pm mailing list