Fellow Perlmonks,

Updated
Ok, so does anyone have any other suggestions for -
if finding a file recursively doesn't exist, create it.
if it does exist, move on.

Trying to put together some code that looks for a file matching a pattern, and if it doesn't exist, creates it with the content stored in a variable. The &wanted sub below does a pattern search as /$currentstoryid/. The problem is it keeps looking for the same $currentstoryid. Never gets updated by the foreach loop, like it's some kind of private variable that gets stuck. Any ideas? Any help is appreciated.

ILC

if (my @entries = $html->content =~ /<h2><a href="\/entry.*?<br \/>\s+ +?<br \/>/gs) { @entries = reverse @entries; foreach my $entry (@entries) { $entry =~ /<h2><a href="\/entry\/(\d+)\/"/; my $currentstoryid = $1; my $exists; &find(\&wanted, $sitedir); sub wanted { if (/$currentstoryid/) { $exists = 1; return $exists; } } if ($exists) { my $datedir = strftime "%Y/%m/%d", localtime; my $freshentry="$sitedir/$datedir/$currentstoryid.txt"; print " Creating ", $freshentry, "\n"; system ("mkdir", "-p", "$sitedir/$datedir"); open(NEWSTORY, ">> $freshentry"); print NEWSTORY "<font color=\"#dd3333\">$site</font>\n +"; print NEWSTORY "$entry\n"; close (NEWSTORY); } } }
Buddha bless you.

In reply to file::find subroutine not getting new values by ilovechristy

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.