|
Prev: Perl Integer Length
Next: FTP PUT with proxy?
From: John Nurick on 8 Jan 2006 07:04 On 7 Jan 2006 02:04:36 -0800, "Brian McCauley" <nobull67(a)gmail.com> wrote: >Newsgroup Reader wrote: >> Hi: Does anyone know how to read a perl script from within itself? >You can abuse the DATA handle. [snip] > seek(DATA,0,0); Please excuse my ignorance, but why is this preferable to open $theScript, "<", $0 ?
From: Dr.Ruud on 8 Jan 2006 07:35 John Nurick: > Brian McCauley: >> Newsgroup Reader: >>> Hi: Does anyone know how to read a perl script from within itself? >> >> You can abuse the DATA handle. >> seek(DATA,0,0); > > Please excuse my ignorance, but why is this preferable to > > open $theScript, "<", $0 First show how you would set $theScript. Then show how you assure to have reading rights on it at the open(), even when it is not stored on some encrypted device. -- Affijn, Ruud "Gewoon is een tijger."
From: John Nurick on 8 Jan 2006 09:33 On Sun, 8 Jan 2006 13:35:33 +0100, "Dr.Ruud" <rvtol+news(a)isolution.nl> wrote: >> open $theScript, "<", $0 > >First show how you would set $theScript. Then show how you assure to >have reading rights on it at the open(), even when it is not stored on >some encrypted device. Thank you.
From: Brian McCauley on 8 Jan 2006 07:45 John Nurick wrote: > On 7 Jan 2006 02:04:36 -0800, "Brian McCauley" <nobull67(a)gmail.com> > wrote: > > >Newsgroup Reader wrote: > >> Hi: Does anyone know how to read a perl script from within itself? > > >You can abuse the DATA handle. > > [snip] > > > seek(DATA,0,0); > > Please excuse my ignorance, but why is this preferable to > > open $theScript, "<", $0 $0 is not reliably a full path name that can be used to find the script file. A more relable path name can be found using the FindBin module. But even that's not 100% relialble (for details "perldoc FindBin"). Besides, even if it were 100%, why reopen the file?
From: Newsgroup Reader on 9 Jan 2006 14:34
Hi Paul: The source code control repository puts in this version number as a comment, so I cannot use the variable. The code looks like: # $Revision: 1.9 $ Rehan |