Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: splitting on win32 linefeeds aka pass the crackpipe!

by buckaduck (Chaplain)
on Feb 14, 2002 at 02:25 UTC ( #145345=note: print w/replies, xml ) Need Help??


in reply to splitting on win32 linefeeds aka pass the crackpipe!

Update: Mea culpa. I wasn't paying attention to the .* in the regex. Sigh. But I'll leave my post intact, to preserve my mistake for posterity...

Off topic, but:

my $file = $filename; # can't remember why I do this, always +have $file =~ s!^.*(\\|\/)!!; # something about cleaning stuff up
...is pretty ugly. If you're trying to trim a trailing slash, it's easier to read like this:
my $file = $filename; $file =~ s![\\/]$!!;
If you can't tell what your own regex is doing, it's time to clean it up.

buckaduck

Replies are listed 'Best First'.
Re: Re: splitting on win32 linefeeds aka pass the crackpipe!
by chipmunk (Parson) on Feb 14, 2002 at 04:05 UTC
    The original substitution doesn't actually remove a trailing slash; rather, it removes the directory path leaving just the name of the file. If $filename is '/usr/local/bin/perl', $file will be 'perl'.

    This is better done with File::Basename.

Re: Re: splitting on win32 linefeeds aka pass the crackpipe!
by vek (Prior) on Feb 14, 2002 at 05:14 UTC
    chipmunk++ for pointing out File::Basename.

    mr.dunstan, you'd probably be better off with this:
    my ($actualFileName, $filePath) = fileparse ($filename);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://145345]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2019-06-26 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (108 votes). Check out past polls.

    Notices?