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:
Switch letters in a variable

 



marco
Novice

Mar 5, 2004, 1:19 PM

Post #1 of 7 (604 views)
Switch letters in a variable Can't Post

I am new to perl. I have spent 3 hours on this simple thing to do... I am tired now Crazy


Here is what I need:

$departuredate: 032004

I have to make it look like this:

$newdeparturedate: 200403

Thanks,

Marco


(This post was edited by marco on Mar 5, 2004, 7:37 PM)


davorg
Thaumaturge / Moderator

Mar 5, 2004, 10:42 PM

Post #2 of 7 (600 views)
Re: [marco] Switch letters in a variable [In reply to] Can't Post

Please define the rule that you are trying to implement.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


marco
Novice

Mar 6, 2004, 6:08 AM

Post #3 of 7 (599 views)
Re: [davorg] Switch letters in a variable [In reply to] Can't Post


In Reply To
Please define the rule that you are trying to implement.



I need to remove the 2 first caracters and place them at the end.

$departuredate = 032004 -> (month)(year)

I need a code that will make it appear like this:

$newdeparturedate = 200403 -> (year)(month)



Thanks


davorg
Thaumaturge / Moderator

Mar 6, 2004, 10:02 AM

Post #4 of 7 (598 views)
Re: [marco] Switch letters in a variable [In reply to] Can't Post

What have you tried? What problems are you having?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


marco
Novice

Mar 6, 2004, 1:02 PM

Post #5 of 7 (595 views)
Re: [davorg] Switch letters in a variable [In reply to] Can't Post


In Reply To
What have you tried? What problems are you having?





I finally found a way to make it. But there must be a simplier way to write it...



my
$dateinverdepart;

($dateinverdepart = $departmois) =~ s/.{2}//;

my $dateinversedepart = $dateinverdepart.$&;




I have been working 2 days on this ! As I told you, I am not a programmer. I like to learn but learning this slow is quite discouraging...


davorg
Thaumaturge / Moderator

Mar 7, 2004, 2:18 PM

Post #6 of 7 (589 views)
Re: [marco] Switch letters in a variable [In reply to] Can't Post


Code
if ($departmois =~ /(\d{2})(\d+)/) { 
$dateinversedepart = $2 . $1;
}


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


marco
Novice

Mar 7, 2004, 3:54 PM

Post #7 of 7 (588 views)
Re: [davorg] Switch letters in a variable [In reply to] Can't Post


In Reply To

Code
if ($departmois =~ /(\d{2})(\d+)/) {  
$dateinversedepart = $2 . $1;
}




Great ! Thanks ! Smile

 
 


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

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