This line is confusing to me, my $md5 = md5_hex( do{ local( @ARGV, $/) = $file; <> } );

This bit: do{ local( @ARGV, $/) = $file; <> } reads the contents of the file whose name is $file.

By all means spread that out across multiple lines if you prefer; Or perhaps use File::Slurp.

I get "use of uninitialized value $_ in substitution (s///)

It is very hard to see how that could happen, given that $_ isn't referenced anywhere in the line that has the substitution operator?

why replacing the number with the md5 of that number is a poor idea?

Let's say you have file joe_1.jpg and you rename it to joe_c4ca4238a0b923820dcc509a6f75849b,jpg, then next week joe uploads a new photo and calls it joe_1.jpg. Different photo, but same name. Overwrite.

People tend to be very lazy and will likely stick to numbers if the low thousands, the potential for clashes is huge.

But even if all the images are tiny, say just 10k bytes, that means there are 2.3836626600959079364564032010142e+24660 possibilities.

Even with MD5 reducing that to 3.4028236692093846346337460743177e+38 the chances of collision are minuscule.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

In reply to Re^5: Renaming an image file by BrowserUk
in thread Renaming an image file 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.