Any neat PLI code for this? 
Author Message
 Any neat PLI code for this?

Someone recently wanted to do something similiar to below but I dont recall
seeing a adequate response
to his inquiry, so below continues my project to edify pliers how easily
fortran can manipulate strings.
Anyone able to translate below into non-clunky PLI version?

program find_reformat_date
character(60) :: text = ' contains date imbedded somewhere  07/04/2002
within'

write (*,*) getdate(text)  ! outputs exactly 10char=  2002/07/04
stop

contains
function getdate (s)  result (date)  ! find and re-format date to yyyy/mm/dd
character(*) :: s
character(10) :: date
integer :: n

n = index(s,'/')    ! get index of 1st "/" encountered in string
date = s(n+4:n+7) // '/' // s(n-2:n+2)    ! re-arrange string fields
end function
end program



Sun, 19 Dec 2004 20:48:23 GMT  
 Any neat PLI code for this?
I don't know just why you have this obsession with proving that FORTRAN
has been slowly (and clumsily) adding features that PL/I has had for
over thirty years.

find_reformat_date: procedure options (main);
   declare text char(60)
    init (' contains date imbedded somewhere 07/04/2002');
   put (getdate (text));
   getdate: procedure (s) returns (char(10));
     declare i fixed bin, s char(*);
     i = index (s, '/');
     return substr (s, i + 4, 4) || '/' || substr (s, i - 2, 5);
   end getdate;
end find_reformat_date;

(This program also has the same bugs your version does.)

Quote:

> Someone recently wanted to do something similiar to below but I dont recall
> seeing a adequate response
> to his inquiry, so below continues my project to edify pliers how easily
> Fortran can manipulate strings.
> Anyone able to translate below into non-clunky PLI version?

> program find_reformat_date
> character(60) :: text = ' contains date imbedded somewhere  07/04/2002
> within'

> write (*,*) getdate(text)  ! outputs exactly 10char=  2002/07/04
> stop

> contains
> function getdate (s)  result (date)  ! find and re-format date to yyyy/mm/dd
> character(*) :: s
> character(10) :: date
> integer :: n

> n = index(s,'/')    ! get index of 1st "/" encountered in string
> date = s(n+4:n+7) // '/' // s(n-2:n+2)    ! re-arrange string fields
> end function
> end program

--
John W. Kennedy
Read the remains of Shakespeare's lost play, now annotated!
http://pws.prserv.net/jwkennedy/Double%20Falshood.html


Sun, 19 Dec 2004 21:49:49 GMT  
 Any neat PLI code for this?
dcl text char (60) static init (' contains date imbedded somewhere
2002/07/04');

put edit
(substr(text(index(text,'/')+4,4),'/',substr(text(index(text,'/'-2),5)) (a);

LOOKS AWFULLY DAMN SIMPLE (AND FAR MORE EFFICIENT) IN PL/I

David,  please take your fortran marbles and play somewhere else.

= = = = =  = = = =  ==

Quote:

> Someone recently wanted to do something similiar to below but I dont recall
> seeing a adequate response
> to his inquiry, so below continues my project to edify pliers how easily
> Fortran can manipulate strings.
> Anyone able to translate below into non-clunky PLI version?

> program find_reformat_date
> character(60) :: text = ' contains date imbedded somewhere  07/04/2002
> within'

> write (*,*) getdate(text)  ! outputs exactly 10char=  2002/07/04
> stop

> contains
> function getdate (s)  result (date)  ! find and re-format date to yyyy/mm/dd
> character(*) :: s
> character(10) :: date
> integer :: n

> n = index(s,'/')    ! get index of 1st "/" encountered in string
> date = s(n+4:n+7) // '/' // s(n-2:n+2)    ! re-arrange string fields
> end function
> end program



Sun, 19 Dec 2004 23:16:19 GMT  
 Any neat PLI code for this?

Quote:
>I don't know just why you have this obsession with proving that FORTRAN
>has been slowly (and clumsily) adding features that PL/I has had for
>over thirty years.
>find_reformat_date: procedure options (main);
>   declare text char(60)
>    init (' contains date imbedded somewhere 07/04/2002');

If I were actually doing this, under most environments, I would
start with a regular expression parser.  To be able to find the
date somewhere in a string.

Note that the string might have '/' in it other than dates.
There is still the ambiguous day/month problem for days of
12 or less, though.

I don't know of a regular expression parser in PL/I though.

-- glen



Sat, 25 Dec 2004 01:33:27 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Any neat PLI code for this?

2. Making Code Neat

3. Kinda neat code [repost]

4. Neater entry point code

5. VisualAge PLI Enterprise vs. VisualAge PLI Personal

6. PLI-32 Alpha 3.10 (Single message ZIP file (30K)) - pli-32.zip (0/1)

7. PLI-32 Alpha 3.10 (Single message ZIP file (30K)) - pli-32.zip (1/1)

8. PLI-32 For NT, alpha 3.10 (ZIP File: 378K] - pli-32.zip (10/10)

9. PLI-32 For NT, alpha 3.10 (ZIP File: 378K] - pli-32.zip (06/10)

10. PLI-32 For NT, alpha 3.10 (ZIP File: 378K] - pli-32.zip (05/10)

11. PLI-32 For NT, alpha 3.10 (ZIP File: 378K] - pli-32.zip (09/10)

12. PLI-32 For NT, alpha 3.10 (ZIP File: 378K] - pli-32.zip (01/10)

 

 
Powered by phpBB® Forum Software