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 hippo (Canon)
on May 15, 2018 at 11:07 UTC ( #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
Node Status?
node history
Node Type: note [id://1214542]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2018-11-14 07:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (164 votes). Check out past polls.

    Notices?