Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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


In reply to Cleaning up the warnings. (was Obfu spoiler: vladb's sig) by jarich
in thread Deobfuscation for fun and profit by jmcnamara

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (6)
As of 2024-03-28 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found