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:
Writing to __DATA__ section

 



karthigan
New User

Dec 5, 2009, 11:03 PM

Post #1 of 4 (705 views)
Writing to __DATA__ section Can't Post

The __DATA__ section is by default available only for reading. How do I write to the __DATA__ section from my program?

Best Regards,
Karthigan.


FishMonger
Veteran / Moderator

Dec 6, 2009, 5:47 AM

Post #2 of 4 (698 views)
Re: [karthigan] Writing to __DATA__ section [In reply to] Can't Post

Why would you want to?

Exactly what are you needing to accomplish?


karthigan
New User

Dec 6, 2009, 3:36 PM

Post #3 of 4 (688 views)
Re: [FishMonger] Writing to __DATA__ section [In reply to] Can't Post

 
Two reasons:

(1) For appending one line logs to the __DATA__ section rather than maintaining a separate log file.

(2) As part of learning and exploring Perl, if it is possible to write to the __DATA__ section, I would like to know how.

Best Regards,
Karthigan.


FishMonger
Veteran / Moderator

Dec 6, 2009, 4:30 PM

Post #4 of 4 (684 views)
Re: [karthigan] Writing to __DATA__ section [In reply to] Can't Post

As far as I know it is not possible, but you could ask on P5P (Perl 5 Porters).

Even if it is possible, the __DATA__ token is the wrong place to store/maintain log file data.

If you need temporary file storage for your script, you'd be better off using one of Perl's more mainstream methods to implement that storage.

See `perldoc -f open`
Here's the relevant portion.

Quote
As a special case the 3-arg form with a read/write mode and the
third argument being "undef":

open(my $tmp, "+>", undef) or die ...

opens a filehandle to an anonymous temporary file. Also using
"+<" works for symmetry, but you really should consider writing
something to the temporary file first. You will need to seek()
to do the reading.


Also look at File::Temp
http://search.cpan.org/~tjenness/File-Temp-0.22/Temp.pm

 
 


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

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