Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: check if string is valid with special cases

by hippo (Bishop)
on May 15, 2018 at 11:07 UTC ( [id://1214542]=note: print w/replies, xml ) Need Help??


in reply to check if string is valid with special cases

If I've understood your specification correctly then this should perform the tests you require.

use strict; use warnings; use Test::More tests => 2; my $valid_in = 'a,b,c,d,e,f'; my $invalid_in = 'a,b,c,d,,f'; ok (test_it ($valid_in), "'$valid_in' is a valid argument"); ok (!test_it ($invalid_in), "'$invalid_in' is an invalid argument"); sub test_it { my ($string) = @_; my @fields = split (/,/, $string); my $emptyfields = grep { $_ eq '' } @fields; if (scalar @fields == 6 && $emptyfields == 0) { return @fields; } return 0; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-20 01:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found