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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|