UPDATE: Would you mind restating, "'home/zentara/bin/claws' shows up as a name 3 in the output.?" I may not have answered anything relevent in the rest of this post.

I don't think split /s\+/ is going to be very robust here. The columns have a certain width and the fields may have spaces in them... A ways back I had written a funny little toy that I seem to use over and over. Perhaps I should make it into a proper module.

package magic_columator; use strict; use Carp; our $TABS_MODE = undef; 1; sub test_fetchrow { my $this = shift; my @row = $this->fetchrow; print Dumper([$this->{format}, @row]), "\n"; } sub fetchrow { my $this = shift; my $fh = $this->{IN}; if( my $line = <$fh> ) { my @a = (); if( $TABS_MODE ) { @a = split(/$TABS_MODE/, $line); } else { @a = unpack($this->{format}, $line); } s/^\s+// for @a; s/\s+$// for @a; return @a; } return (); } sub new { my $class = shift; my $this = bless {}, $class; my $file = shift; croak "couldn't find file \"$file\"" unless -f $file; $this->{file} = $file; $this->find_seps; open $this->{IN}, $this->{file}; return $this; } sub find_seps { my $this = shift; open IN, $this->{file} or die "couldn't open $this->{file} for rea +d: $!"; my @spaces = (); while(<IN>) { my $x = 0; while( m/(.)/g ) { my $c = $1; $x ++; push @spaces, 1 while @spaces < $x; $spaces[$x-1] = 0 unless $c eq ' '; } } close IN; $this->{format} = ""; my $x = 0; for my $c (@spaces) { $x ++; if( $c ) { if( $x>1 ) { $this->{format} .= "A$x"; $x = 0; } $this->{format} .= " "; } } if( $x ) { $this->{format} .= "A$x"; } }

It'd work like so:

use magic_columator; while(my @row = $col->fetchrow) { # do stuff }

This would be a great place to use iterators I think. There are also probably already modules that do this more cleanly. If you were to use it, or something like it, it'd need some major updates and fixes I suspect.

-Paul


In reply to Re: unexplained output from top in batch mode by jettero
in thread unexplained output from top in batch mode by zentara

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.