http://www.perlmonks.org?node_id=626499

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

Hi Monks, It must be true for me, if you don't use it you lose it. I am trying to find out the hostname of systems that are using this certain software, by querying an application from the program in question. The output looks like the Information below the __DATA__ tag. I am able to get this to work using split but I can not get this to work with a regular expression. My reason for wanting to use a regex is to keep errors down when I have blank lines or lines like this one.(example "--------" ) The excessive use of print is for debugging purposes. This is the code that I have so far.
#!/usr/bin/perl use strict; use warnings; while( <DATA> ) { print "$_"; while ( $_ =~ /(\w+)\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+/g ) { print "Using regex Host is $1\n"; } my ($host, $arch, $proc, $load, $memtot, $memuse, $swap, $swapuse ) += split( " ", $_); if ( $host =~ /\w+/) { print "Using split function Host is $host\n"; } # if ( $arch =~ /\w+/) { # print "Arch is $arch\n"; # } # if ( $proc =~ /\w+/) { # print "Num of processors is $proc\n"; # } # if ( $load =~ /\w+/) { # print "Load is $load\n"; # } # if ( $memtot =~ /\w+/) { # print "Total memory is $memtot\n"; # } # if ( $memuse =~ /\w+/) { # print "Memory used is $memuse\n"; # } # if ( $swap =~ /\w+/) { # print "Total swap is $swap\n"; # } # if ( $swapuse =~ /\w+/) { # print "Swap used is $swapuse\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 chewbacca glinux 4 0.00 2.0G 36.6M 1.9G + 0.0 crusher glinux 2 0.01 2.0G 250.8M 4.0G + 0.0 data glinux 4 0.01 2.0G 586.9M 1.9G + 230.8M 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 nelix glinux 2 - 2.0G - 1.9G + - odo glinux 2 - 2.0G - 15.6G + - picard glinux 2 - 2.0G - 1.9G + - quark glinux 2 0.24 3.4G 177.7M 1.9G + 14.6M r2d2 glinux 2 1.09 3.4G 109.2M 1.9G + 7.0M scottie glinux 2 0.00 2.0G 151.4M 1.9G + 0.0 sisko glinux 2 - 2.0G - 1.9G + - sulu glinux 2 - 493.7M - 1019.7M + -


I got 99 problems, and right now this is number one.