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

Re: grabbing dmidecode memory data - there's got to be a better way

by kennethk (Monsignor)
on Dec 28, 2012 at 19:19 UTC ( #1010735=note: print w/ replies, xml ) Need Help??


in reply to grabbing dmidecode memory data - there's got to be a better way

  1. x is your friend. It will let you insert some white space to add legibility. Maybe not in the one-liner, but certainly during the regex development.
  2. m is your friend. You've got it enabled, but are not actually using it. It's ideal for specifying the end/start of lines that you are doing with $o
  3. s may not be your friend in this case. If you turn off s, then . actually corresponds to the character class [^\n].

While this may not work for the full range of output in your particular case, maybe something like: dmidecode | perl -e 'undef $/;for (split /(?<=\n)\n+/, <STDIN>) {print if /RAM socket/ && !/Not Installed/}' would work. Keep it simple.


#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.


Comment on Re: grabbing dmidecode memory data - there's got to be a better way
Select or Download Code
Re^2: grabbing dmidecode memory data - there's got to be a better way
by Tommy (Chaplain) on Dec 28, 2012 at 19:31 UTC

    Yes, that's cool! First slurp, then split on paragraph chunks, and finally simply match against keywords in the block. That's nice. Could you have not done that without the zero-width positive look-behind? Seems like that would be the best way, but I still wonder...

    --
    Tommy
    $ perl -MMIME::Base64 -e 'print decode_base64 "YWNlQHRvbW15YnV0bGVyLm1lCg=="'
      You could simplify the split to \n\n+ or something similar, but then you need to modify something else to keep the records newline separated. I'm willing to go to pretty extreme lengths to keep print if /RAM socket/ && !/Not Installed/ clean just because of personal taste. TIMTOWTDI.

      dmidecode | perl -e 'undef $/;/RAM socket/ && !/Not Installed/ && s/$/\n\n/ && print for split /\n\n+/, <>'


      #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

        That's another good example. Less clear than your first, but still much less ugly than my original line-by-line cherry picker.

        --
        Tommy
        $ perl -MMIME::Base64 -e 'print decode_base64 "YWNlQHRvbW15YnV0bGVyLm1lCg=="'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1010735]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2014-07-30 23:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (241 votes), past polls