Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Regular expression assistance

by agentorange (Sexton)
on Dec 07, 2012 at 15:56 UTC ( #1007767=note: print w/ replies, xml ) Need Help??


in reply to Re: Regular expression assistance
in thread Regular expression assistance

Thanks.

Sorry didn't explain it fully but whilst I can pattern match ok I cannot see how to pattern match and pull out the 8th field in the line of which <space> is the separator char.


Comment on Re^2: Regular expression assistance
Replies are listed 'Best First'.
Re^3: Regular expression assistance
by kennethk (Abbot) on Dec 07, 2012 at 16:26 UTC
    Okay, much better. Assuming you want to do this in the midst of a script and not just piping one liners about, I would use more operations rather than be super sparse on characters. First, since you have a string that is internally-delimited by newlines, you can use . to match any character that is not a new line. This means you can actually grab your line using $cdp =~  m/(.*0x01.*)/, storing the line in $1. You could then split that on whitespace and grab the 8th field with (split /\s+/, $1)[7]. So collecting all your 8th field matches:
    my @switch; while ($cdp =~ m/(.*0x01.*)/g) { push @switch, (split /\s+/, $1)[7]; }
    If this is not your intent and the way forward is unclear, post explicit desired output so the goal is clear.

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

      Ah perfect thank you.

      I hadn't appreciated I could reference the 8th element with 7 around split()

      Many thanks

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2015-08-01 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls