Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: check if string is valid with special cases

by kcott (Archbishop)
on May 16, 2018 at 09:46 UTC ( [id://1214622]=note: print w/replies, xml ) Need Help??


in reply to check if string is valid with special cases

G'day ovedpo15,

You can do your validation with this condition:

$string =~ y/,/,/ == -1 + grep length y/ //dr, split /,/, $string

I ran these tests based on the ever-shifting goal posts throughout this thread. :-)

$ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -E' $ perle 'my $x = "a,b,c"; say +($x =~ y/,/,/ == -1 + grep length y/ // +dr, split /,/, $x) ? "Y" : "N"' Y $ perle 'my $x = "a,b ,c"; say +($x =~ y/,/,/ == -1 + grep length y/ / +/dr, split /,/, $x) ? "Y" : "N"' Y $ perle 'my $x = "a, ,c"; say +($x =~ y/,/,/ == -1 + grep length y/ / +/dr, split /,/, $x) ? "Y" : "N"' N $ perle 'my $x = "a, ,c"; say +($x =~ y/,/,/ == -1 + grep length y/ // +dr, split /,/, $x) ? "Y" : "N"' N $ perle 'my $x = "a,,c"; say +($x =~ y/,/,/ == -1 + grep length y/ //d +r, split /,/, $x) ? "Y" : "N"' N

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2024-04-25 12:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found