Hi

Well when I first ran into this problem I thought that it would be a simple problem to solve. but I can't seem to figure it out. The problem occurs when I am using File::Find to recusivly search a direcotry for files. The problem is that when i get to a directory that doesn't exist it prints out.

Can't stat e:\logs: No such file or directory

I have to search many directories and if the program doesn't find one it just spits out this message and goes on to the next one. Well I want to be able to know if it couldn't not find that direcotry.

Well at first i tried setting a variable equal to tbe return value.

my $temp =  find ({wanted =>  \&wanted,bydepth =>0},"e:\\logs",);

But the problem was that even if it worked or if it didn't find the directory it would return zero. So next I tried to eval the statement and to catch the error that way.

eval{ find ({wanted => \&wanted,bydepth =>0},"e:\\logs",) }; warn $@ if $@;
But it didn't catch the error

I know that there is a module out there called "exceptions" to use try and catch but I installed it and it tells me i need to install "methodmaker". And I don't even know if exceptions will work. I know that there is also something that is called "backticks" that is used to get what is outputed to the screen (i think). Is there a simple way to figure out if it returned an error or not??

any help would be great thanks,

Victor

In reply to catching errors from file::find by VicBalta

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.