CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
basic number parsing question

 



kind1
Deleted

Apr 23, 2000, 11:08 AM

Post #1 of 4 (604 views)
basic number parsing question Can't Post

if I have a date stored in variable $date and it is equal to "20000423" (todays date) how can I store only the last 2 digits (the day of the month) in a new variable? in this example I want the new variable to be equal to "23"

Thank you in advance,
K1


RayStreet
Deleted

Apr 23, 2000, 2:47 PM

Post #2 of 4 (604 views)
Re: basic number parsing question [In reply to] Can't Post

Try the substr (substring) function

$day = substr($date,6,2);



Cure
User

Apr 23, 2000, 5:17 PM

Post #3 of 4 (604 views)
Re: basic number parsing question [In reply to] Can't Post

Hi

You could use the substr() function, or a pattern match, among many other
ways. If you really want the current date, perhaps you should be using localtime().

example of substr:

use $s= substr($date, -2, 2) it will return the last two characters in $s.


Cure


Peter Van Hoecke
Deleted

Apr 27, 2000, 1:59 AM

Post #4 of 4 (604 views)
Re: basic number parsing question [In reply to] Can't Post

OK, I know the problem has been solved, but I'm trying to excercise my regular expressions by trying to solve the problems posted here, anyway...

($last2numb = $date) =~ s/(.*)(\d\d$)/\2/;

Sorry that I posted without reason...

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives