Are you sure this is what you want?
my ($username, $imagename) = $ENV{REQUEST_URI} =~ /\/(.*)\/(.*)/;
The reason I'm asking is because you need to consider the following input possibilities:
""
"/"
"//"
"///"
"/a/b"
"/a/b/"
"/a/b/c"
"/a/b/c/"
"a//"
"a/b/"
...
You see, your regex would match any string with 2 or more slashes no matter where they occur. Also, you have a greedy * which will match the longest string.

Example: "/a/b/c/d/e" => $user = "a/b/c/d", $img = "e" which may not be what you want.

You may need to put more constraints on the check. I think the regex you're looking for is in the neighbourhood of:

my ($user, $img) = $ENV{REQUEST_URI} =~ m#^/([^/]+)/([^/]+)$#;
It may look more complex than your original regex, but should do the job. Of course, look at perlre for all the details.

Hope this helps,,,

Update: If you're using $user as a directory name, beware of people passing it "/../something" as that would open a door for people to access other information.


In reply to Re: When art thy variables defined? by abstracts
in thread When art thy variables defined? by caedes

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.