Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Emulating Unix 'basename' 1

Status
Not open for further replies.

columb

IS-IT--Management
Feb 5, 2004
1,231
EU
I want to do the same as the Unix 'basename' command, i.e. split off the path from a file. I'm trying
Code:
 perl -e 'foreach ( "/path/to/file" ) { s!.+/!!; print "$_\n"; }
and getting
Code:
Modification of a read-only value attempted at -e line 1.
I've tried a number of variations but and re-read 'prelrequick' but I'm not having any success. What should I be doing?

Thanks

On the internet no one knows you're a dog

Columb Healy
 
Hi

I do not understand what are you trying to do there, but taking "[tt]basename[/tt]" as keyword :
Code:
  DB<1> $path="/path/to/file";

  DB<2> ($name=$path)=~s,.*/,,;

  DB<3> print $name;
file

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top