Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Argument "" Isn't numeric in numeric eq (==)

by Jim (Curate)
on Feb 09, 2014 at 19:07 UTC ( [id://1074152]=note: print w/replies, xml ) Need Help??


in reply to Argument "" Isn't numeric in numeric eq (==)

No warnings! ☺

use strict; use warnings; my $success_pattern = qr{ ^ (?: 1,1,\d*,\d*,\d*,\d* | \d*,\d*,1,1,\d*,\d* | \d*,\d*,\d*,\d*,1,1 ) $ }x; my $failure_pattern = $success_pattern; $failure_pattern =~ s/(?<=1,)1/2/g; my $count_of_success_records = 0; my $count_of_failure_records = 0; while (my $record = <DATA>) { $count_of_success_records++ if $record =~ $success_pattern; $count_of_failure_records++ if $record =~ $failure_pattern; } print "Total success records: $count_of_success_records\n"; print "Total failure records: $count_of_failure_records\n"; exit 0; __DATA__ 1,1,,,, 1,2,,,, 3,4,1,1,, 1,1,1,1,, 5,6,3,4,1,2 1,1,,,, 1,1,1,1,1,1

Update:  I shortened the regex patterns.

use strict; use warnings; my $success_pattern = qr/^(?:\d?,\d?,){0,2}1,1/; my $failure_pattern = qr/^(?:\d?,\d?,){0,2}1,2/; my $count_of_success_records = 0; my $count_of_failure_records = 0; while (my $record = <DATA>) { $count_of_success_records++ if $record =~ $success_pattern; $count_of_failure_records++ if $record =~ $failure_pattern; } print "Total success records: $count_of_success_records\n"; print "Total failure records: $count_of_failure_records\n"; exit 0; __DATA__ 1,1,,,, 1,2,,,, 3,4,1,1,, 1,1,1,1,, 5,6,3,4,1,2 1,1,,,, 1,1,1,1,1,1

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1074152]
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: (3)
As of 2024-04-25 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found