Solved

last 3 chars

Posted on 2000-02-17
3
165 Views
Last Modified: 2010-03-05
how do i assign a new variable to be the last three characters of a variable

ie if $old is "hello.txt"
then $new becomes "txt"

thanks
0
Comment
Question by:boofulls
3 Comments
 

Accepted Solution

by:
spreq earned 50 total points
ID: 2530734
1. get total character
2. simple mathematic to get location for the first of last three character
3. use substring

eg
$old = "hello.txt";
$long=length($old);   #total char
$FirstOfThree=$long-3;  #simple math
$new=substr($FirstOfThree,0,3); #get the last char



0
 

Author Comment

by:boofulls
ID: 2530779
even though there was an error in the last line....;)
0
 
LVL 84

Expert Comment

by:ozo
ID: 2533152
$new=substr($old,-3);  #unless what you really want are all characters after the last '.'
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl split by | 2 91
unable to remove invisible characters with perl 2 77
Perl tar error 8 51
read an xml file in perl 2 15
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now