Hi,
Am writing a basic webserver where I need to check if a the requested URI has a slash at the end or not and respond appropriately according to the condition.
my $DOCROOT = '/home/agn/htdocs'; if (-e $DOCROOT.$uri) { if (-f $DOCROOT.$uri) { if (-r $DOCROOT.$uri) { logme("200 HTTP OK\n"); $status_code = 200; } else { logme("403 Forbidden\n"); $status_code = 403; } } elsif (-d $DOCROOT.$uri) { if (-r $DOCROOT.$uri && -x $DOCROOT.$uri && ($DOCROOT.$uri !~ /\/$/)) { logme("301 Moved Permanently\n"); $status_code = 301; } elsif (-r $DOCROOT.$uri && -x $DOCROOT.$uri) { logme("200 HTTP OK\n"); $status_code = 200; } else { logme("403 Forbidden\n"); $status_code = 403; } } else { logme("406 Not Acceptable\n"); $status_code = 406; } } else { logme("404 Not Found\n"); $status_code = 404; } } return 0; }
The problem is that whether the $DOCROOT.$uri contains a / at the end or not, it always sets $status_code to 301.
$DOCROOT.$uri !~ m/\/$/
The above condition isn't being checked. Or if it is, I have a bug in the RE. Any ideas ?

In reply to problem with if condition by agn

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.