Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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":



  • 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 or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2022-08-15 09:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?