Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

format 1 line per row

by dbs (Sexton)
on Aug 25, 2011 at 15:30 UTC ( [id://922386]=perlquestion: print w/replies, xml ) Need Help??

dbs has asked for the wisdom of the Perl Monks concerning the following question:

I want all my data to stay on one line(row) however many lines as needed but it should start a new line after the "Mount" using format.
use strict; my (@dfary,@stats,$free,$stat); format LOG_TOP = REPORT OF FILESYSTEM USAGE on: @<<<<<<<<<<< my ($host) = qx(hostname) =~ /^([^.]+)/; page @<< $% MBblocks, Free, %Used, Mount, . format LOG = ^* $stat.+"," ~~ . my $DFOUT = new FileHandle "/usr/bin/df -m|" || die "df did not open $ +!"; my $percent = q|30|; while (<$DFOUT>) { next if $. == 1; next if /proc|net/i; for $stat ( (split(" ", $_, 0))[1,2,3,6]) { chomp $stat; ($free) = /(\d+)%/; if ( $free >= $percent ) { write (LOG); #last; #push (@stats, $stat); } else { next; } } } $DFOUT->close; # for (@stats) { # write (LOG); #}
__OUTPUT__
REPORT OF FILESYSTEM USAGE on: xxxxxxxx page 1 MBblocks, Free, %Used, Mount, 8512.00, 3232.28, 63%, /usr, 10240.00, 2367.96, 77%, /var, 4096.00, 1923.06, 54%, /tmp,
should be
MBblocks, Free, %Used, Mount, 8512.00, 3232.28, 63%, /usr, 10240.00,2367.96,77%,/var, etc.
thankU!

Replies are listed 'Best First'.
Re: format 1 line per row
by dbs (Sexton) on Aug 25, 2011 at 18:53 UTC
    I got it working using split.
    for (($mb, $mfre, $used, $mt) = +(split(" ", $_, 0))[1,2,3,6]) {

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://922386]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-19 18:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found