Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: I have done this before

by toolic (Bishop)
on Jul 13, 2007 at 18:42 UTC ( #626507=note: print w/replies, xml ) Need Help??


in reply to I have done this before

I added a blank line to your data, and removed some data lines for simplicity. I know you said you wanted to use regex instead of split, but I do not understand why. Is this what you are trying to achieve?
#!/usr/bin/env perl use strict; use warnings; while ( <DATA> ) { next if /^HOSTNAME/; # skip title line next if /^\-/; # skip lines which start with "-" s/^\s+//; # remove whitespace at start of line s/\s+$//; # remove whitespace at end of line next if /^$/; # skip blank lines my ($host, $arch, $proc, $load, $memtot, $memuse, $swap, $swapuse +) = split; print "Using split function Host is $host\n"; } __DATA__ HOSTNAME ARCH NPROC LOAD MEMTOT MEMUSE SWAPTO + SWAPUS ---------------------------------------------------------------------- +--------- global - - - - - - + - Luke glinux 2 0.70 3.4G 919.5M 1.9G + 681.6M bobafett glinux 2 0.00 3.4G 205.8M 1.9G + 0.0 bones glinux 2 0.01 2.0G 150.9M 1.9G + 0.0 c3p0 glinux 2 0.37 3.4G 101.6M 1.9G + 7.2M dax glinux 4 0.81 2.0G 438.0M 1.9G + 272.1M geordi glinux 4 - 2.0G - 1.9G + - han glinux 2 0.53 3.4G 373.6M 1.9G + 243.3M janeway glinux 2 0.00 7.3G 351.9M 16.0G + 0.0 lando glinux 4 1.27 7.3G 445.8M 1.9G + 6.9M sisko glinux 2 - 2.0G - 1.9G + - sulu glinux 2 - 493.7M - 1019.7M + -
gives me this output:
Using split function Host is global Using split function Host is Luke Using split function Host is bobafett Using split function Host is bones Using split function Host is c3p0 Using split function Host is dax Using split function Host is geordi Using split function Host is han Using split function Host is janeway Using split function Host is lando Using split function Host is sisko Using split function Host is sulu

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-08-14 03:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?