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

Re: Help with my regex

by SuicideJunkie (Priest)
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. } } }


Comment on Re: Help with my regex
Download Code
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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2014-09-18 19:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (121 votes), past polls