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.

In reply to I have done this before by monk2b

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.