[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Data section of a script



At 11:10 -0500 1999.10.18, Robert Sweeney wrote:
>Is there a convienant way to write to the data section of a script?

No, it is read-only.  Well, you could try to open $0 and then try to find
__END__ or __DATA__:

  open FILE, "< $0" or die $!;
  while (<FILE>) {
    push @file, $_;
    last if /^__(?:DATA|END)__$/;
  }
  close FILE;

  open FILE "> $0" or die $!;
  print FILE @file;
  print FILE $mydata;

But that is really really dangerous.

>I'd
>like to store some information in my script without using an additional
>external file. I suppose I could open the script's own file, read
>through until I see the __END__ into a @buffer, print open the script
>file for writing, print out @buffer, and then replace everything past that
>with new text.
>
>However, I'm leary of the script writing over itself.

And you should be.  :)  Best to use another file.

-- 
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org