Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Passing a regex from a CGI HTML form [EXAMPLE DATA]

by Linicks (Scribe)
on Aug 31, 2016 at 19:00 UTC ( [id://1170921]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Passing a regex from a CGI HTML form
in thread Passing a regex from a CGI HTML form

OK, seeing as I am 57 in a few months, looks like a lot of people are protecting me ;)

Here follows 2 examples of the junk I need to format:

SWA vs CHE GK WBA @ BOU GK

That is easy to parse and render clean, as all I need is to extract is "SWA,GK" or "WBA,GK" in that example:

$line =~ s/ vs ... /,/; $line =~ s/ \@ ... /,/;

Now, the 'vs' and '@' are (seem) randomly dispersed ~ whether that is a product of the newspapers website database or crappy programming, I don't know.

But this week, this appeared in about 50 places over 4000 lines:

EVE GK

OK, my code failed on this. I could see what has happened, but couldn't fix it at work. If I did have a debug option to pass over a new regex, I could send a '$line =~ s/ GK/,GK/;' which would have fixed it up until I got home (as it was, I frigged around in a spreadsheet to correct it to keep the wolves at bay).

Nick

Replies are listed 'Best First'.
Re^4: Passing a regex from a CGI HTML form [EXAMPLE DATA]
by stevieb (Canon) on Aug 31, 2016 at 19:47 UTC

    Are those full lines? I mean, is this a situation where you can just grab the first and last non-whitespace chars, and just not bother with the stuff in between? ie. does the below code work in your cases, or are there other things that need consideration?

    use warnings; use strict; while (<DATA>){ if (/^(\w+).*\s(\w+)/){ my $line = "$1,$2"; print "$line\n"; } } __DATA__ SWA vs CHE GK WBA @ BOU GK EVE GK EVE 4 87 dwqer *** GK

    Output:

    SWA,GK WBA,GK EVE,GK EVE,GK

      "Are those full lines?"

      I wish, that is one little line... in that format - there are between 5 to 10 for each player that changes randomly, and remember, the data copied 'n' pasted changes quiet a lot on the fly depending on games/injuries/banned/transfers- that is the issue. So I need a way to get new subsititions in for a temporary measure until I can re-code the code when I get home.

      Nick

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (7)
As of 2024-03-28 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found