Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
at first :
my $file = "@_" || die(sub_usage($funcName));
and then, later , in sub_usage :
die("\n\tThis function requires that you call ".
where do you really want to die? :-)

Aside from this, I've always interpreted "base filename" and "extention" to be 2 particular and discrete things, so if you do have a file named foo.bar.baz.quux, you've got a base filename of "foo.bar.baz" and an extention of "quux"; do you have a particular need or use to split on every dot, or were you being (lowercase) lazy?

in any case, it really seems like you're doing too much work here. Additionally, I would not use any module that required me to declare a DEBUG variable (or constant, in this case) in my own package, but perhaps this could be addressed if you make your File::Basename::foo package. File::Basename::foo::DEBUG would be ok with me.

here's a AWTDI, using sexegers, for comparison.

use Carp; ($f, $e) = &sex_ext ($ARGV[0]); print "fname : $f ; ext : $e\n"; sub sex_ext { local $_ = reverse $_[0] or carp "no filename supplied to sex_ext!\n"; #no period or ext found, return original arg return $_[0] unless /(.*?)\.(.+)/; my $fname = reverse$2; my $ext= reverse $1; return ($fname, $ext); }
Update : You could also reverse and split /./,$_,2 rather than use the regex in the unless line... so many ways... :-)

In reply to Re: Parse out the extension of a filename - return base of filename. (boo) by boo_radley
in thread Parse out the extension of a filename - return base of filename. by snafu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-03-29 10:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found