Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Cisco_Dave:

You don't specify what's wrong, so I can only guess: I'm thinking that line 15 should be:

$details{'Main Memory'} = $1 if (/^\S+ Intel (\S+)/i);

You have only one capture group (i.e., part of the regular expression inside parenthesis), so the captured value can only be in $1. For example:

$ cat fluffy.pl use strict; use warnings; my $t = "Now is the time for all good men to come to the aid"; if ($t =~ /^(\w+) (\w+) (\w+) (\w+) (\w+) (\w+)/) { print "Words: 2='$2', 4='$4', 1='$1'\n"; } else { print "*** no match! ***\n"; }

when you run it, you should get:

$ perl fluffy.pl Words: 2='is', 4='time', 1='Now'

In order to get better answers, it's helpful to include a bit more information. Especially if you can make a simple bit of code that can demonstrate the problem as I just did here. I hope I guessed correctly, but if not, update the code in your original question to make it clear. You could do so by putting something like:

use strict; use warnings; my @output = ( "a few lines of data that I cut\n", "and pasted from a screen capture that I want to\n", "process.\n", );

at the front, and something like:

print "Chassis: <$details{'Chassis'}>\n"; print "Main Memory: <$details{'Main Memory'}>\n";

at the end to show what you actually get. Then specify what you actually wanted instead, so we can clearly see the problem. Note the angle brackets I put in the output: whitespace handling errors (especially newlines and carriage returns) are so common that it's helpful to put something before and after the string so you can see if there are unwanted characters in your output.

...roboticus

When your only tool is a hammer, all problems look like your thumb.


In reply to Re: Parse variables from @output by roboticus
in thread Parse variables from @output by Cisco_Dave

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, 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, 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.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others drinking their drinks and smoking their pipes about the Monastery: (7)
    As of 2020-11-30 14:22 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?