Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Help with my regex

by SuicideJunkie (Vicar)
on Jul 31, 2013 at 20:54 UTC ( #1047313=note: print w/replies, xml ) Need Help??

in reply to Help with my regex

Every line there except for the blank one, does indeed have either "power" or "status" somewhere in it.

If your set is as small as the example, you might be best off listing all of the options in a long enough form to make them unique. This specifies exactly what should be found before the first colon on the line.

# Maybe make the values here a sub reference defining what to call whe +n you see the line in question. my %wantedInfoHash = ('Controller Status' => undef, 'Status of logical device' => undef, ...); while ($line = <>) { if ($line =~ /([^:]):/) { # grabbed everything up to the first colon into $1 if (exists $wantedInfoHash{$1}) { # Found something we wanted, so do something with it. } } }

Replies are listed 'Best First'.
Re^2: Help with my regex
by cspctec (Sexton) on Jul 31, 2013 at 21:13 UTC
    I'm not sure how to get "Power State" only without also grabbing "Supported Power State" since they both have the same string in them. I just need the shorter one.
      m/^Power State:/

      The ^ is an anchor to 'beginning of line'.

      The match in that code above grabs everything up to the first colon. Which means it will get "Supported Power State" on that line, which will then not exist in the hash of things you want. Later it will get "Power State" on the shorter line, and that will exist in the hash of things you want.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2016-10-25 06:38 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (315 votes). Check out past polls.