in reply to RegEx needed

This is what I'm currently trying to do
foreach (@data) { ($1, $2, $3, $4, $5) = m/($_\s)/g; print $2; }

Replies are listed 'Best First'.
Re: Re: RegEx needed
by nothingmuch (Priest) on Nov 18, 2002 at 23:07 UTC
    You shouldn't assign to the number variables. It won't work, and if i remember well will even raise an exception. The regex engine does it by itself, when you don't apply list context to m//g.

    You can do something like
    m/(\S+\s)(\S+\s)(\S+\s)(\S+\s)(\S+\s)/;

    To be more along the lines of what you've tried, and $1 .. $5 will have the correct values in them. But that is redundant.

    You also placed $_ in the parens for some odd reason. It attempts to find the string within itself. I think you mean

    $_ =~ m//g

    Anyway, best of luck.

    -nuffin
    zz zZ Z Z #!perl