Why not simply have a list of possible locations the file is allowed to reside, and check them in a well-defined (and documented) order until you hit one? This is a good idea because it won't require any additional logic if you choose to support another OS (with yet another path). Example:

# I assume 'snmpauto' is the name of a file. use File::Spec; my $snmp_file = find_snmpauto(); sub find_snmpauto { my $filename = 'snmpauto'; my @paths = qw(c:\\ /root); for (@paths) { my $name = File::Spec::catfile($_,$filename); return $name if -f $name; } # we hit here only if no file was found. die "Can't find a file '$filename' in the search path (path includ +es:" .join(', ',@paths) .")\n"; }

This will result in the first filename you find to be correct being stored in $snmp_file; it will die (with a list of acceptable paths) if it fails. This way, if you add a new location, you only have to add to the @paths array.

<-radiant.matrix->
A collection of thoughts and links from the minds of geeks
The Code that can be seen is not the true Code
I haven't found a problem yet that can't be solved by a well-placed trebuchet

In reply to Re: how to recognize windows and linux os by radiantmatrix
in thread how to recognize windows and linux os by Manjunath

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.