[EMAIL PROTECTED]                                             
             h.com                                                         
                                                                        To 
             11/21/2005 02:33          beginners@perl.org                  
             PM                                                         cc 
                                                                           
                                                                   Subject 
                                       Re: rearranging a string            
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           








             Roberto
             Etcheverry
             <[EMAIL PROTECTED]                                          To
             r>                        [EMAIL PROTECTED]
                                                                        cc
             11/21/2005 02:19
             PM                                                    Subject
                                       Re: rearranging a string













[EMAIL PROTECTED] wrote:

>In my situation I have a string like so:
>
>my $string = '20050516';
>
>and I want to rearrange it to look like: 05162005, so I tried:
>
>my $newstring =
>substr($string,0,8).substr($string,0,4).substr($string,8,0);
>
>
>But my problem is: it's leaving 2005 in the beginning of the string to
look
>like 200505162005 when all I need is 05162005
>Any ideas?
>
>
my $newstring = substr($string,4,4).substr($string,0,4);

Should do the trick...

>thx
>
>
>Derek B. Smith
>OhioHealth IT
>UNIX / TSM / EDM Teams
>614-566-4145
>
>
>
>
*********************************************************************
**********************************************************************

thanks Roberto!

that did work.
: )



*********************************************************************
*********************************************************************

However, is one way more efficient that the other. To me Roberto's way
seems easier to read compared to Jeff's:

substr($string, 4, 2) . substr($string, 6, 2) . substr($string, 0, 4)





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to