Baek, Steve <[EMAIL PROTECTED]> wrote:
:
: I'm trying to break apart the command `df -k` data
: and display it into an html table:
:
: Filesystem kbytes used avail capacity Mounted on
: /dev/dsk/c0t2d0s0 3008783 83669 2864939 3% /
: /dev/dsk/c0t2d0s3 4032654 886633 3105695 23% /usr
: /proc 0 0 0 0% /proc
: mnttab 0 0 0 0% /etc/mnttab
: fd 0 0 0 0% /dev/fd
: /dev/dsk/c0t2d0s7 19808378 250080 19360215 2% /var
: swap 594216 104 594112 1% /var/run
: swap 594448 336 594112 1% /tmp
: /dev/dsk/c0t2d0s6 1985487 532663 1393260 28% /export
: /dev/dsk/c0t2d0s5 1985487 356649 1569274 19% /opt
: /dev/dsk/c0t2d0s4 7057565 914628 6072362 14% /usr/local
: Would anyone happen to know the best way to do this?
Not the "best" way, No.
: I'm thinking of putting each line into an array...
Sounds like a plan ...
The most obvious method to break this apart is using 'split'.
Since "Mounted on" contains a space we need to limit the split to
6 columns:
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper 'Dumper';
while ( <DATA> ) {
chomp;
print Dumper [ split ' ', $_, 6 ];
}
__END__
Filesystem kbytes used avail capacity Mounted on
/dev/dsk/c0t2d0s0 3008783 83669 2864939 3% /
/dev/dsk/c0t2d0s3 4032654 886633 3105695 23% /usr
/proc 0 0 0 0% /proc
mnttab 0 0 0 0% /etc/mnttab
fd 0 0 0 0% /dev/fd
/dev/dsk/c0t2d0s7 19808378 250080 19360215 2% /var
swap 594216 104 594112 1% /var/run
swap 594448 336 594112 1% /tmp
/dev/dsk/c0t2d0s6 1985487 532663 1393260 28% /export
/dev/dsk/c0t2d0s5 1985487 356649 1569274 19% /opt
/dev/dsk/c0t2d0s4 7057565 914628 6072362 14% /usr/local
CGI.pm provides a td() function for cell data. It accepts
a reference to an array for multiple cells.
use CGI qw( table Tr td );
my @rows;
while ( <DATA> ) {
chomp;
push @rows,
Tr(
td( [ split ' ', $_, 6 ] )
);
}
print table( @rows );
Or as a subroutine:
use CGI qw( table Tr td );
print table_ize( *DATA );
sub table_ize {
my $file_handle = shift;
my @rows;
while ( <$file_handle> ) {
chomp;
push @rows,
Tr(
td( [ split ' ', $_, 6 ] )
);
}
return table( @rows );
}
: Does anyone have any thoughts?
Not on a Saturday, no.
HTH,
Charles K. Clarkson
--
Mobile Homes Specialist
254 968-8328
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>