Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^3: Perl split on regex match

by GotToBTru (Prior)
on Jan 03, 2017 at 15:17 UTC ( [id://1178854]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Perl split on regex match
in thread Perl split on regex match

while (my $line = <DATA>) { print $line if (split /\./,$line) < 3; }
But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

Replies are listed 'Best First'.
Re^4: Perl split on regex match
by 1nickt (Canon) on Jan 03, 2017 at 15:35 UTC

    while (<DATA>) { print if (split /\./) < 3; }
    (but use a CSV parser!)


    The way forward always starts with a minimal test.
Re^4: Perl split on regex match
by Random_Walk (Prior) on Jan 03, 2017 at 17:36 UTC

    That is assuming the '.' will not occur in any of the other fields.

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!

      An assumption supported by all supplied test data. The #1 objection I have with my post is it continues the bad practice of not using a proper CSV module. Overkill, if the example data is truly representative of all this program will ever have to deal with, but of course that's rarely the case. Assuming only the one column will contain periods is the least of my sins.

      And, as 1nickt demonstrated, even my oversimplification could be simplified further.

      But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)

        Aye, an assumption supported by a rather small sample (5). I could randomly pick five humans and there is a ~1 in 16 chance that my sample would tell me there is only one gender. :-)

        Cheers,
        R.

        Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-04-25 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found