Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Split on a new line

by odrm (Novice)
on Jul 03, 2007 at 15:29 UTC ( #624716=note: print w/replies, xml ) Need Help??

in reply to Split on a new line

Idiomatic perl uses split() when you know what you want to throw away and a regular expression match when you know what you want.

Putting a "zero or more characters from this class" regular expression into split (as in split /\n\r\l*/) effectively splits a string into individual characters - the regex is true between every single character. Your code would get further if you tried split /\n\r\l+/ ....

Using regular expression matches, you could do something like:

#!/usr/bin/perl use strict; use warnings; undef $/; # read whole file at once our $cert = <>; our ($info) = $cert =~ m/X509v3 Basic Constraints:\s+([^\n]+)/; print "Constraints = $info\n";

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2023-04-01 04:35 GMT
Find Nodes?
    Voting Booth?

    No recent polls found