Well, that's definitely a better way. The thing that annoys me is that i know that way, i've done it before. It didn't seem to work for some reason when i originally tried it (even though it does now; thanks Murphy ;-)

thanks much,
jynx

Update:ok, after everyone's replies i finally realized what happened. In a coding frenzy i wanted to solve one problem and when i switched to a different technique i didn't drop some of the old artifacts (oops).

Basically, i'm trying to keep track of whether or not a value is acceptable for grep without having to declare the arrays(this was for an obfuscation-only purpose). The fix was to declare the arrays, because of the reasons mentioned and because otherwise nothing would get passed through grep the first time through...

My main problem is that i check for $new{$_}+1, i should be checking for $new{$_}-1.

If anyone's interested, the resulting (admittedly horrible) code is:

sub beautify { %old = %new; sort { $a <=> $b } grep { $new{$_}++; $old{$_}++ unless exists $old{$_}; ($new{$_} == $old{$_}) ? 1 : ($new{$_}-1 == $old{$_}) ? 1 : 0; } @_; }
This still declares the arrays, just not the same way. Oh well, nothing's perfect, it has lumps in it ;-)

As also noted, this is *not* the best way to do this, for normal projects of course one would use strict; and warnings.

Thanks for the help,
jynx


In reply to Re: Re: quandery about a grep statement by jynx
in thread quandery about a grep statement by jynx

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.