This is some weird looking code and appears to contain at least one error. To have a clear, concise algorithm, I would go up one level in problem statement and start with the intent of the program in general words.

my %Y; while (<>) { ... my ($y) = ... ; next unless $y; # Add the scalar number of elements in @ARGV to the hash # Always add at least 1 to the hash even if @ARGV contains # no elements # the value $y is meaningless and plays no role if(@ARGV) { # next is always executed regardless of $y eq $_ foreach (@ARGV) { $Y{$y}++,next if $y eq $_; } } else { $Y{$y}++ } }
So, this single statement is possible:

scalar @ARGV ? $Y{$y} += @ARGV : $Y{$y}++;
1. The comma operator serves no purpose in the above code. Prefer ; instead.
2. If you want the test to short circuit, then it should go first, not last!:
foreach (@ARGV) { next if $y eq $_; # don't count any occurrences of # $y $Y{$y}++, }
Or, this is a possibly of what was meant:

scalar @ARGV ? $Y{$y} += (grep $y ne $_, @ARGV) : $Y{$y}++; Without some more English language explanation, I have no idea what the code is supposed to do.


In reply to Re: Code review by Marshall
in thread Code review by Anonymous Monk

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.