Skip to content
Snippets Groups Projects
Select Git revision
  • dc3e3b251005453d863690264bfb75e0001403df
  • master default protected
  • dev-lkugler
  • teaching-2024
  • old_config_2023-05 protected
  • v2025.2
  • v2024.6
  • v2024.2.20
8 results

clusters.py

Blame
  • Matrix.pm 5.61 KiB
    #
    
    Util::Matrix::set_border_style ('Redmine');
    # $Id: Matrix.pm,v 1.12 2017/03/26 05:35:49 gonter Exp $
    #
    
    package Util::Matrix;
    
    my $VERSION= 0.03;
    
    # formatted matrix output
    my $border_left=   my $header_left=   '| ';
    my $border_inter=  my $header_inter= ' | ';
    my $border_right=  my $header_right= ' |';
    my $border_lx= '+';
    my $border_rx= '-+';
    my $border_lines= 1;
    my $border_header= 1;
    
    my $header_style= 'default';
    
    =head2 print ($column_names, $data)
    
    $data = ref to array of arrays
    
    =cut
    
    sub print
    {
      my $column_names= shift;
      my $d= shift;
      my $fh= shift || *STDOUT;
    
      my @l= get_column_lengths ([$column_names], $d);
      my (@fmt_l, @fmt_r);
      my $fmt_x= @l-1;
      foreach my $l (@l)
      {
        push (@fmt_l, "%-${l}s");
        push (@fmt_r, "%${l}u"); # TODO: allow signed, unsigned, float
        $fmt_x += $l;
      }
    
      my $hl;
      # print 'd: ', Dumper ($d), "\n";
      if ($header_style ne 'none' && defined ($column_names))
      {
        $hl= $border_lx;
        foreach my $l (@l)
        {
          $hl .= '-'x($l+2). '+';
        }
        # print $border_rx;
        my $i= 0;
    
        print $fh $hl, "\n" if ($border_lines);
    
        print $fh $header_left if ($header_left);
        foreach my $n (@$column_names)
        {
          print $fh $header_inter if ($i);
          printf $fh ($fmt_l[$i], $n);
          $i++;
        }
        print $fh $header_right if ($header_right);
    
        print $fh "\n";
        print $fh $hl, "\n" if ($border_header);
      }