in reply to Re: quandery about a grep statement
in thread quandery about a grep statement


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

Replies are listed 'Best First'.
Re: Re: Re: quandery about a grep statement
by extremely (Priest) on Mar 30, 2001 at 02:21 UTC
    Well, if you are doing an obfus then you may wanna blow off declaring hash arrays and use ones that are floating around and don't cause errors. See the three examples below...
    perl -we 'use strict; %_ = %ENV; print $_{TERM},$/' perl -we 'use strict; %@ = %ENV; print $@{USERNAME},$/' perl -we 'use strict; %% = %ENV; print $%{HOME},$/'

    Yes, I'm ashamed that I know about those. =) Also, just for fun, try this one on:

    perl -we 'use strict; %$ = %ENV; print ${$}{SHELL},$/' # note the extra {} on this one to keep the parser from # making the normally correct left turn of ${${SHELL}} and # crying that $SHELL isn't declared...

    --
    $you = new YOU;
    honk() if $you->love(perl)