substituting string with current date 
Author Message
 substituting string with current date

Hello..

I'm trying to do a simple substitution.  Replacing a string with the
current date.

my program grabs the contents of a file, looks for a string matching
/dat.*/ and substitutes with the current date.
I invoke 'date' by using the system function i.e system("date +%Y%m&d)

the file contains the date hard coded like so: Date = 19820506
(yyyymmdd)

so I have

<snip>

if ($_ = /Dat.*/) {
      $_ = s/\d.*/system("date +%Y%m%d");

Quote:
}

the digits following "Date=" in my file become substituted
with "system('date +%y%m%d')".

How can I substitute it with what the function should do?

fatima.



Sat, 10 Nov 2001 03:00:00 GMT  
 substituting string with current date

Quote:
>Hello..

>I'm trying to do a simple substitution.  Replacing a string with the
>current date.

>my program grabs the contents of a file, looks for a string matching
>/dat.*/ and substitutes with the current date.
>I invoke 'date' by using the system function i.e system("date +%Y%m&d)

>the file contains the date hard coded like so: Date = 19820506
>(yyyymmdd)

>so I have

><snip>

>if ($_ = /Dat.*/) {
>      $_ = s/\d.*/system("date +%Y%m%d");
>}

>the digits following "Date=" in my file become substituted
>with "system('date +%y%m%d')".

No it doesn't. Not with that code anyway...

$_ = is not what you want. Your missing a / as well. Y ne y.

Have a look at the perlop documentation (perldoc perlop) for information
on the use of s/// and how to evaluate the substitution...

Have a look at perlfunc documentation (perldoc -f system) for information
on why system() does not do what you want.

Have a look at perlop again for information on how to capture the output of
an external program, like the system documentation tells you to.

Have a look at the perlre documentation for information on why \d.* is
probably not what you want to replace (though it might be I guess).

--
Sam

So I did some research. On the Web, of course. Big mistake...
        --Larry Wall



Sat, 10 Nov 2001 03:00:00 GMT  
 substituting string with current date


Quote:

>>Hello..

>>I'm trying to do a simple substitution.  Replacing a string with the
>>current date.

>>my program grabs the contents of a file, looks for a string matching
>>/dat.*/ and substitutes with the current date.
>>I invoke 'date' by using the system function i.e system("date +%Y%m&d)

>>the file contains the date hard coded like so: Date = 19820506
>>(yyyymmdd)

>>so I have

>><snip>

>>if ($_ = /Dat.*/) {
>>      $_ = s/\d.*/system("date +%Y%m%d");
>>}

>>the digits following "Date=" in my file become substituted
>>with "system('date +%y%m%d')".

>No it doesn't. Not with that code anyway...

>$_ = is not what you want. Your missing a / as well. Y ne y.

>Have a look at the perlop documentation (perldoc perlop) for information
>on the use of s/// and how to evaluate the substitution...

>Have a look at perlfunc documentation (perldoc -f system) for information
>on why system() does not do what you want.

>Have a look at perlop again for information on how to capture the output of
>an external program, like the system documentation tells you to.

>Have a look at the perlre documentation for information on why \d.* is
>probably not what you want to replace (though it might be I guess).

You might also take a look at the perlfunc documentation to see if
there are any Perl functions that would stop you having to call an
external function at all. [hint: localtime].

Dave...
--

<http://www.dave.org.uk>



Sat, 10 Nov 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. split and substitute, substitute, substitute

2. date string to date format

3. Getting the current date.

4. Displaying current date and time in specific format

5. Current Date & Time

6. How do I get the current date?

7. Get current date / time?

8. Calling Current Date in MACPERL

9. current date

10. Current Date

11. Date::Manip and pwd: cannot determine current directory!

12. perl/cgi help - need current date function

 

 
Powered by phpBB® Forum Software