Your skill will accomplishwhat the force of many cannot PerlMonks

### Re: check if string is valid with special cases

by kcott (Chancellor)
 on May 16, 2018 at 09:46 UTC ( #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

Create A New User
Node Status?
node history
Node Type: note [id://1214622]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2018-09-25 10:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Eventually, "covfefe" will come to mean:

Results (199 votes). Check out past polls.

Notices?