Monks, I'm using the following to create filenames from article titles. I look through the database to find if the filename exists, then add a 2 to the end of the filename (filename2.html) if it does. BUT, this only works on the first duplicate. What if there are 3 titles that are the same. Is there a better way to do this?
@words = split (/ /, $base_title); $filename = $dateadded."-" . join("-",@words) . ".html"; $filename_base = $filename; $filename_base =~ s/\.html//g; # check to see if filename is being used $SQL = "SELECT * FROM $database_table WHERE filename = '$filename' +"; &Do_SQL; $i=2; while ($pointer = $sth->fetchrow_hashref){ $filename = $filename_base."$i.html"; $i++; $SQL = "SELECT * FROM $database_table filename = '$filename'"; &Do_SQL; } $SQL = "INSERT INTO $database_table (filename) VALUES ('fi +lename')"; &Do_SQL;

Any help would be appreciated. It might be simple, but I'm stumped. Thanks!


In reply to Avoiding duplicate filenames by htmanning

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.