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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Question On chop.

Status
Not open for further replies.

bretttt

Programmer
Jul 23, 2002
74
0
0
US
Hello, I have a scalar

$blah="blah/blah/blah.bl";

How do i remove up to "blah.bl" and save it is its own scalar? I need to chop up to the first / Im not sure how to do that, I know its simple. Thanks.
 
$blah="blah/blah/blah.bl";
print "$blah\n";
(@bits)=split (/\//,$blah);
print @bits."\n";
$blah=$bits["@bits"-1];
print "@bits->$blah\n";
--Paul
 
or:

Code:
$blah="blah/blah/blah.bl";
($firstbit,$lastbit)=$blah=~/^(.*\/)([^\/]+$/;

or if it's a file path...

Code:
use File::Basename;
$firstbit=dirname($blah);
$lastbit=basename($blah);

what's that expression about skinning cats?
 
You can always use this.

$line = 'bla/bla/bla/bla.pl';
$line =~ m/([a-zA-Z0-9%:.\+\*\~\-_\s]+)\s*$/x;
$line = $1;

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top