... I'd like to understand why it's not working rather than just getting a quick fix to the problem.

It doesn't work because there is only (and can only ever be) a single element in the  @data array. This is because join returns a single string from all the sub-strings it joins together. (Update: If there were no sub-strings to join together, e.g., if the match had failed, join would still return a single (empty) string.)

c:\@Work\Perl\monks>perl -wMstrict -le "use Data::Dump qw(dd); ;; $_ = '2015-08-13 17:53:45 blah yada'; my @data = join('', $_ =~ /^(\d\d\d\d)-(\d\d)-(\d\d) (\d+):(\d+):(\d+ +)/); ;; print 'number of elements in array: ', scalar @data; ;; print qq{element at index $_: '$data[$_]'} for 0 .. $#data; ;; dd \@data; " number of elements in array: 1 element at index 0: '20150813175345' [20150813175345]
So in a sense your code does work: it loops through the single element in the array and determines that that element is, indeed, exactly equal to itself: one duplicate.

Update: So the take-away lesson is know your data. What was in the array to begin with? Tools like Data::Dumper and Data::Dump are life-savers when it comes to debugging questions like this for yourself. For a bright, confident outlook on life, dump early and dump often.


Give a man a fish:  <%-(-(-(-<


In reply to Re: How do I count the number of occurrences of each string in an array? by AnomalousMonk
in thread How do I count the number of occurrences of each string in an array? by aschwa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.