in reply to Re^3: Counting SubStrings, Style Question
in thread Counting SubStrings, Style Question

I guess I imagined this:

my $parent = 'xxx xxx xxx'; my $count = my @items = split(/ /, $parent); print "$count\n"; # 3 [download] Since you have a count, all you need to check if there are duplicates +is check the count. if ($count < 1) { print "None\n"; } elsif ($count < 2) { print "Unique\n"; } else { print "$count\n"; }

And also missed where the OP agreed that his sample code is wrong...Oh! He hasn't.

Replies are listed 'Best First'.
Re^5: Counting SubStrings, Style Question
by ikegami (Patriarch) on Mar 21, 2010 at 05:09 UTC

    What about it? Now read the rest.

    And also missed where the OP agreed that his sample code is wrong...Oh! He hasn't.

    First you say the following is wrong:

    { my $c = my @c = split 'xxx', 'fred bill xx joe'; print $c };; 1 { my $c = my @c = split 'xxx', 'fred bill xxx joe'; print $c };; 2

    Now you're saying the OP's code is right even though it gives the same results for those inputs.

    I don't understand. Could you explain a bit more clearly please?