http://qs321.pair.com?node_id=11108700


in reply to Parse variables from @output

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.

Replies are listed 'Best First'.
Re^2: Parse variables from @output
by Cisco_Dave (Novice) on Nov 14, 2019 at 22:41 UTC
    Thanks for the quick reply. Will fully read and understand fully tomorrow. Have edited original post to help clarify a little.