in reply to regular expressions query

Hmmm... These are all excellent ideas, but none of them seem to be quite working for me. Another way I was thinking about doing this is to look at the end of the line before this one in the data file: each line before the one where I want to cull data from ends with the text "VALUES FOR". I tried this:
($meanH1, $meanH2) = ($1, $2) if VALUES FOR$\s+(\S+)\s+(\S+)/;
But it doesn't seem to work. From my understanding, the \s+ should also match for newline feeds in addition to whitespace, correct? Any suggestions?

Replies are listed 'Best First'.
Re^2: regular expressions query
by heroin_bob (Sexton) on Jun 30, 2004 at 21:12 UTC
    I just tried the following:
    #!/usr/local/perl $test = " foo bar"; ($var1, $var2) = ($1, $2) if ($test =~ /\s+(\S+)\s+(\S+)/); print "Var1: $var1\nVar2: $var2"; exit;

    ...and it grabbed the text out and printed fine, so I'm not sure what you mean when you say none of the suggestions are working for you, can you be more specific?

    If you're ever lost and need directions, ask the guy on the motorcycle.
Re^2: regular expressions query
by qq (Hermit) on Jun 30, 2004 at 23:24 UTC

    Post your code and a couple of lines of data. The examples given _do_ work. Perhaps we are missing a part of the problem?

    #!/usr/bin/perl while ( <DATA>) { ($a,$b) = split ' '; print "split '$a','$b'\n"; my ($a,$b) = $_ =~ /(\S+)\s+(\S+)/; print "match '$a','$b'\n"; } __DATA__ none bing some bong any bang

    output:

    split 'none','bing' match 'none','bing' split 'some','bong' match 'some','bong' split 'any','bang' match 'any','bang'
Re^2: regular expressions query
by qq (Hermit) on Jun 30, 2004 at 23:35 UTC

    If you are matching across newlines, are you not reading line by line? If the data is in one big string, perhaps you want something more like:

    #!/usr/bin/perl my $txt = ' none bing some bong any bang '; while ( $txt =~ /^ {9}(\S+) {10}(\S+)\s*$/mg ) { print "'$1' '$2'\n"; }

    qq