in reply to Is it possible to modify __DATA__ via the DATA file handle or otherwise?
DATA is a plain, ordinary file handle to the source file, but it's open for reading (not writing). I don't know how to convert a handle opened for reading into a handle opened for writing (if it's even possible), but you can open a new handle to the current file, and use tell(DATA) to find the location of the start of the data.
die("Not safe for setuid") if ${^TAINT}; open(my $fh, ">>", __FILE__) or die("open: $!\n"); ( my $data_pos = tell(DATA) ) >= 0 or die("tell: $!\n"); truncate($fh, $data_pos) or die("truncate: $!\n"); say($fh "bar") or die("say: $!\n"); __DATA__ foo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Is it possible to modify __DATA__ via the DATA file handle or otherwise?
by LanX (Saint) on Feb 10, 2018 at 12:29 UTC | |
by haukex (Archbishop) on Feb 10, 2018 at 12:44 UTC | |
by LanX (Saint) on Feb 10, 2018 at 13:13 UTC | |
by haukex (Archbishop) on Feb 10, 2018 at 19:16 UTC | |
by ikegami (Patriarch) on Feb 12, 2018 at 22:51 UTC | |
|
Re^2: Is it possible to modify __DATA__ via the DATA file handle or otherwise?
by YenForYang (Beadle) on Feb 16, 2018 at 19:20 UTC | |
by ikegami (Patriarch) on Feb 17, 2018 at 00:14 UTC |