Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

uG posted:

code:
while( $play =~ m/\b(?:penalty|penalized)\b.*?(?<yards>$RE{num}{int}) yards?\b.*?(?:(?!penalty)|(?!penalized)|\Z)/gi ) {
    my $yards = $+{yards};
    $penalty_yards = (defined $penalty_yards)?($penalty_yards + $yards):$yards;      
}
The above code is not properly ignoring the line:
'Joe Shmoe rush for 10 yards, penalty MICHIGAN -420 yards declined'

Instead of trying to wrestle that regex into doing what you want, you might try to break it into smaller pieces. Something like:

Perl code:
while ($play =~ m/penal(?:ty|ized)(.*?)(?:penal(?:ty|ized)|\Z)/gi){
    my $penalty_phrase = $1;
    next if ($penalty_phrase =~ /declined/i);
    $penalty_phrase =~ m/($RE{num}{int}) yards/;
    $penalty_yards += $1;
}

Extortionist fucked around with this message at 23:01 on Apr 29, 2014

Adbot
ADBOT LOVES YOU

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

uG posted:

I tried that after getting frustrated with this but it doesn't iterate over the matches like I want. The code you posted lacks negative lookahead so it will take "penalty smu 10 yards blah blah, penalty msu 5 yards", then the first match will be "penalty smu 10 yards blah blah, penalty", leaving "msu 5 yards" not to get iterated over. Adding negative lookahead leaves the (.*?) (aka $1 aka $penalty_phrase) to always capture nothing.
Oops, yeah, it'll do that. You'd want to use a positive look-ahead instead:

Perl code:
while ($play =~ m/penal(?:ty|ized)(.*?)(?=penal(?:ty|ized)|\Z)/gi){

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Hughmoris posted:

Thanks for this.

I asked this question in #perl IRC, and seemingly opened up a huge can of worms. Ended up being told to go learn OO in small talk or ruby.
Really if your goal is learning OO programming, you might be better off with another language. OO support is pretty hacked in in perl (see the recommendations above requiring the use of non-core libraries) and might not translate well to general OO practices across other languages.

Those are good suggestions if you're married to perl for whatever reason, but you might look elsewhere if you're looking for more general learning.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Mithaldu posted:

Entirely disagree.
Really my objections come from personal experience maintaining ostensibly OO-code written by people who learned OO coding exclusively with perl. You can surely learn it and learn it well with perl, but perl's ethos also lets you learn it poorly and think you're learning it well, regardless of whatever atrocities you're committing.

I really think someone new to OO programming would be better off learning its paradigms in a language where its paradigms are more commonly used and are more strictly enforced.

Extortionist
Aug 31, 2001

Leave the gun. Take the cannoli.

Mithaldu posted:

You're reflecting on the people involved, the learning resources they chose and your own lack of knowledge on quality OO Perl learning resources; not on anything inherent to Perl. In which case, yeah, i agree. If the person learning is generally lazy, and happy to start learning from the first google hit that presents to them, it's a good recommendation to go with a language that puts them in a straight-jacket. Otherwise Perl is fine to learn OO with, especially when sticking to the links i gave.

However note that your first post explained none of that, and made the false assertion of the OO support being "hacked" and OO practices not "translating well to other languages".
So, I was already familiar with all of the resources you linked and probably would have included some of them myself if it hadn't been redundant. You'll note that I said they were all good resources if someone's sticking to perl. Thanks for assuming I'm ignorant, though.

Perl's flexibility is a huge handicap against learning (yes, I am arguing that the issue here is something inherent to perl). I don't think it has much to do with the laziness you imply, so much as it has to do with the difficulty of learning various concepts and perl's willingness to let you put together something that entirely contradicts best practices but also solves the problem you're trying to solve (this is probably also one of perl's biggest strengths--just not so much when it comes to learning). I deal with the consequences of this too often in my daily work to assume that someone trying to learn something blindly in such a permissive language will magically fall into best practices. Surely someone can do it if they're smart and diligent enough--but probably they'd also have an easier time of it if the language didn't fool them about what they were doing.

I will stand by my assertion that perl's OO support is hacked. The core language plainly isn't designed to properly support OO, and you can easily blow apart any OO code in perl intentionally or accidentally.

  • Locked thread