Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Cleaning up the warnings. (was Obfu spoiler: vladb's sig)

by jarich (Curate)
on May 29, 2002 at 05:03 UTC ( #169978=note: print w/ replies, xml ) Need Help??


in reply to Obfu spoiler: vladb's sig (was Re: Deobfuscation for fun and profit)
in thread Deobfuscation for fun and profit

Line 9 prints $\, which, umm, defaults to nothing; here it looks like it's being treated as a newline, though, doesn't it? I've gotta admit: I'm not sure where $\ gets set to \n...

It looks like it's being treated as a newline... but $\ isn't being set to \n in this code. So when we execute this code it prints out the empty string. Perhaps vladb has typoed this, because the resulting print out is a little confusing without the newlines.

[me]$ ls -a .sav* .saves-19639-~ .saves-19896-~ .saves-19896333-~ .saves-22-~ [me]$ perl tmp + ./.saves-22-~- ./.saves-19896333-~+ ./.saves-19639-~- ./.saves-19896 +-~[me]$
You'd notice the uninitialised values if you ran the code with warnings turned on:
[me]$ perl -w tmp Useless use of single ref constructor in void context at tmp line 2. Odd number of elements in hash assignment at tmp line 2. Use of uninitialized value in print at tmp line 3. + ./.saves-22-~Odd number of elements in hash assignment at tmp line 2 +. - ./.saves-19896-~Use of uninitialized value in print at tmp line 3. Odd number of elements in hash assignment at tmp line 2. Use of uninitialized value in print at tmp line 3. + ./.saves-19639-~Odd number of elements in hash assignment at tmp lin +e 2. - ./.saves-19896333-~Use of uninitialized value in print at tmp line 3 +.
If, of course, you can see them through the other mess of warnings. Why are we getting these hash assignment warnings? Well, we can isolate the code that's causing them, it's the ternary operator:
`@$_`?{print"+ $1"}:{print"- $1"}&&`rm $1`;
Perhaps Perl doesn't like blocks here? Or doesn't in my version of Perl (v5.6.1 built for i386-linux). We can't just remove them though, because if we do then we won't print out the file names that we delete.

I can't explain the error messages but I can give an alternate line that doesn't create them:

`@$_`?print"+ $1":print("- $1")&&`rm $1`;
although of course your replacement is much neater. When we run our changed versions with warnings we get a slightly cleaner result:
[me]$ perl -w tmp Use of uninitialized value in print at tmp line 3. + ./.saves-22-~- ./.saves-19896333-~Use of uninitialized value in prin +t at tmp line 3. + ./.saves-19639-~- ./.saves-19896-~Use of uninitialized value in prin +t at tmp line 3.
And then any of the following lines can remove the remaining warning:
print$\; # cause of last warning #replacements print$/; print"\n"; print qq'\n'; #etc.
of course we could put the line $\=$/; somewhere before the for loop and then not even need this print$\; line at all.

With it all cleaned up it works quite nicely

[me]$ perl tmp + ./.saves-22-~ - ./.saves-19896333-~ + ./.saves-19639-~ - ./.saves-19896-~ [@me]$
Anyway, thanks for a great obfu spoiler, it's fun.

jarich


Comment on Cleaning up the warnings. (was Obfu spoiler: vladb's sig)
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://169978]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2014-10-23 10:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls