Operating System - HP-UX
1829182 Members
2094 Online
109986 Solutions
New Discussion

Quick perl question. Character strip

 
SOLVED
Go to solution
Steven E. Protter
Exalted Contributor

Quick perl question. Character strip

print ("$refer");

Shows: /certified.shtml

Whats the code to end up with this value in the variable:

certified.shtml

or

certified

Bunny for code that works.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Quick perl question. Character strip

my $refer = "/certified.shmtl";
print "Before: ",$refer,"\n";
$refer =~ tr ?/??d;
print "After : :,$refer,"\n";
If it ain't broke, I can fix that.
Paul F. Carlson
Valued Contributor

Re: Quick perl question. Character strip

Try:

$refer = "/certified.shtml";

$st = substr($refer,1);
print "$st\n";

or:

$pos = index($refer,".");
$st = substr($refer,1,$pos-1);
print "$st\n";
Link down -- cable problem?
Rodney Hills
Honored Contributor

Re: Quick perl question. Character strip

($file,$ext)=$refer=~/\/?([^.]*)\.(.*)/;

HTH

-- Rod Hills
There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: Quick perl question. Character strip

Ooops,

print "After : :,$refer,"\n";

should be:
print "After : ",$refer,"\n";
If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: Quick perl question. Character strip

All answers worked so maximum pointage.

I actually fixed A. Clay's oops when I typed his code. I used cut and paste on the rest. I did hunt through caljd.pl for the answer but did not find it. Not enough time find it in the perl cookbook.

This project will yeild a few more questions I think.

Another ITRC success.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com