Hi Monks,
I have this sub in my program, and it works almost right, but my problem is, if I refresh the page on the browser, it keeps reentering the information over and over again, the problem you can see on the code where it is but I can't figure it out on how to prevent it from doing it. Can someone take a look at it and let me know, please!
Thanks a lot!
sub save_entry { my $params = shift; my $entryID = $$params{id}; my $text= $$params{text}; #Added entry for the title here: $movie_title = $$params{movie_title}; $img_file = $$params{img_file}; print "1073 ********************************* $img_file ************ +**<br>"; my $user= $$params{user}; my ($mon, $year) = (); $entryID ? (($mon, $year) = (localtime($entryID))[4,5]) : (($mon, $year) = (localtime(time))[4,5]); $mon += 1; $year += 1900; mkdir("$user/$year", 0700); mkdir("$user/$year/$mon", 0700); #J:\ia\images\claims.gif $text =~ s/\n/<br>/g; $movie_title =~ s/\n/<br>/g; if($img_file =~/(.*?)(\w+|\W+)(\.)(\w+)/ig){ print "<br>##### 1=$1 - 2=$2 - 3=$3 - 4=$4 #####<br>"; $img_file = "$2$3$4"; print "<br>&&&& $img_file &&&&"; }else{print "**** NO *****";} print "<br><font color=white>1096&&&&$img_location$img_file&&&&$user +/$year/$mon&&&\$entryID=$entryID^^\$text=$text^^</font>"; #exit; if ($entryID) { if (open(update, "+<$user/$year/$mon/update.pl")) { local $/ = '@:'; my @entries = <update>; seek(update, 0, 0); truncate(update, 0); foreach (@entries) { chomp; next unless $_; my ($header) = split(/\n/, $_, 2); my ($ptime) = split(/:/, $header, 2); ($ptime eq $entryID) ? print update '@:', $ptime, ':', time, ':', $$params{show} ? 1 : 0, +"\n", $text, "\n", $movie_title, "\n", $img_file, "\n" : print update '@:', $_; } close update; } else { print_title({}, "Saving Problem"); print_note("Modifying entry: $!"); print_footer(); } } else { print "<br>1128 &&&& $img_file &&&&$$params{show} ? 1 : 0 , \$text=$ +text , $movie_title, $img_file,****"; if (open(update, ">>$user/$year/$mon/update.pl")) { # I tried here but it doesn't work, but here is where the uncessary up +date is, I know I just need to open the DB file that looks like the s +ample below, and if any part of it match don't update, but how? #unless($text=~/$text/ig){ print update '@:', time, '::', $$params{show} ? 1 : 0, "\n", $text, +"\n", $movie_title, "\n", $img_file, "\n"; #} close update; } else { print_title({}, "Saving Problem"); print_note("Writing entry: $!"); print_footer(); } } }

This is the text in the text db the the code works on it.
@:1107293018::1 Careus Joe careers.gif @:1107442029::1 Title content arrow.gif @:1107442514::1 My new title the content goes here arrow.gif @:1107442517::1 test more text for check arrow.gif

In reply to File Updating Problem 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.