I second merlyn's suggestion to use File::Basename for three reasons:

  1. What if they decide to turn on -w (like they should)? They get a "Use of implicit split to @_ is deprecated" warning. That's no fun.
  2. What if they move to a system that doesn't use \ as the directory separating character (like UNIX)? It could happen, and your code doesn't handle /'s. Of course, not chopping off the path would cause the config file to always be stored in the same directory as the script, instead of where ever the script happens to be called from, which might not be such a bad thing after all...
  3. What if they change the name of the script to something that doesn't have a .pl extension (more common on *nix systems)? Your code clobbers the name of the script. For example, if they called their script whatever, your config file would become whate.cfg and I don't think that's what you mean.

merlyn's regexp/File::Basename solution handles all of these cases and it's quite a bit easier to understand. Plus it doesn't modify $0 which could be useful (or not, depending; you can always modify his to do so).

All in all, that certainly was an interesting way of using split and it took me a minute to figure out what you were doing. :-)

Cheers.

bbfu
Seasons don't fear The Reaper.
Nor do the wind, the sun, and the rain.
We can be like they are.


In reply to (bbfu) Re: default config file by bbfu
in thread default config file by Reverend Phil

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.