[22548] in Perl-Users-Digest
Perl-Users Digest, Issue: 4769 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 27 18:26:16 2003
Date: Thu, 27 Mar 2003 15:25:38 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 27 Mar 2003 Volume: 10 Number: 4769
Today's topics:
Re: print here-documents question <bht@actrix.gen.nz>
Re: print here-documents question (Tad McClellan)
Re: print here-documents question <please@no.spam>
Problem using personal module in Apache? <shah@typhoon.xnet.com>
Re: Problem using personal module in Apache? (Tad McClellan)
Problem with libwin/perflib counter script (Matt Smith)
Question about Schwartzian Transform (JR)
Re: Question about Schwartzian Transform <nobull@mail.com>
Re: Question about Schwartzian Transform <glex_nospam@qwest.net>
Re: Question about Schwartzian Transform (JR)
regex question <gfu@gscmail.gsfc.nasa.gov>
Running Daemon as Different User <goodcall__1@hotmail.com>
Re: Running Daemon as Different User <please@no.spam>
Re: Running Daemon as Different User (Sam Holden)
Re: Running Daemon as Different User <goodcall__1@hotmail.com>
Re: Running Daemon as Different User (David Efflandt)
search and replace long hex string <dougkite@yahoo.com>
Re: search and replace long hex string <krahnj@acm.org>
Re: Simple CGI Select by Date (John South)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 27 Mar 2003 11:29:25 +1200
From: Bernard <bht@actrix.gen.nz>
Subject: Re: print here-documents question
Message-Id: <sk548v03ppncac5l0rn73u1j4gqg6uudcd@4ax.com>
Chris, Thanks a lot.
Avoiding single quotes seems a good solution.
My apologies, I did not understand the following:
- Begin quote -
If you only have one such HTML fragment, then ...
print <DATA>
__DATA__
<HTML>
<SCRIPT>
var newLine = unescape("%0A");
alert("The correct email format is : " + newLine +
username@domain.extension");
</SCRIPT>
</HTML>
- End quote -
The JavaScript code includes a lot of "@" and "\" as part of
JavaScript regular expressions and other constructs.
I currently have to dual-escape them for perl.
Is there a way to avoid this? As I wrote before, my JavaScript string
needs no modification by perl, so the perl scanning of literals would
get in the way here.
Isn't opening up quoted literals to the interpreter for manipulation a
strange concept? I mean I should be able to include "@" without having
to escape it as "\@", shouldn\'t I:)
Many thanks again,
Bernard
bht\@actrix.gen.nz
Chris Lowth <please@no.spam> wrote:
>Bernard wrote:
>
>> Hi,
>>
>> I am looking for a way to avoid escaping of HTM/JavaScript text in
>> perl here-documents.
>>
>> In other words I am not interested in the perl parser scanning the
>> here-document for special characters e.g. backslash "\" and @.
>>
>> The purpose of this is to cut and paste static text that works in the
>> browser without having to alter it to keep perl happy. For me such
>> alterations cause an undesired maintenance overhead.
>> External .js files are not an option for performance reasons.
>>
>>
>> The following example illustrates the dilemma. What is perfectly valid
>> in JavaScript as you see it here gets rejected and truncated by perl.
>>
>> This version does not work but it illustrates what is required:
>>
>> print <<"EOF"
>> <HTML>
>> <SCRIPT>
>> alert("The correct email format is : \nusername@domain.extension");
>> </SCRIPT>
>> </HTML>
>> EOF
>>
>> Escaped version works (note the additional JavaScript code "var
>> newLine..." and "\@":
>>
>> print <<"EOF"
>> <HTML>
>> <SCRIPT>
>> var newLine = unescape("%0A");
>> alert("The correct email format is : " + newLine +
>> "username\@domain.extension");
>> </SCRIPT>
>> </HTML>
>> EOF
>>
>> The escaped version still works standalone without perl, reflecting my
>> desire to maintain only a single version. But I don't like the result
>> as it is inefficient and bulky.
>>
>>
>> I am using more and more regular expressions in JavaScript routines.
>> Having to escape these just to keep perl happy is a lot of work and in
>> some cases forces me to keep 2 versions of the same code - you know
>> how bad that is.
>>
>> I would be very grateful if someone could show me a way out of this.
>>
>> Bernard
>> bht@actrix.gen.nz
>
>If you only have one such HTML fragment, then ...
>
>print <DATA>
>__DATA__
><HTML>
><SCRIPT>
>var newLine = unescape("%0A");
>alert("The correct email format is : " + newLine +
>username@domain.extension");
></SCRIPT>
></HTML>
>
>Or, just use single quotes (provided you HTML contains no single quotes)..
>
>print '<HTML>
><SCRIPT>
>var newLine = unescape("%0A");
>alert("The correct email format is : " + newLine +
>username@domain.extension");
></SCRIPT>
></HTML>
>';
>
>or use single quotes round your EOF rather than doubles..
>
>print <<'EOF'
><HTML>
><SCRIPT>
>var newLine = unescape("%0A");
>alert("The correct email format is : " + newLine +
>username@domain.extension");
></SCRIPT>
></HTML>
>EOF
>
>Chris
------------------------------
Date: Wed, 26 Mar 2003 19:23:33 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: print here-documents question
Message-Id: <slrnb84kkl.2dq.tadmc@magna.augustmail.com>
[ Please do not top post.
Folks around here do not like it.
]
Bernard <bht@actrix.gen.nz> wrote:
> Avoiding single quotes seems a good solution.
> The JavaScript code includes a lot of "@" and "\" as part of
> JavaScript regular expressions and other constructs.
>
> I currently have to dual-escape them for perl.
Not if you use single quotes you won't.
> Is there a way to avoid this?
Use single quotes.
[ begin TOFU }
> Chris Lowth <please@no.spam> wrote:
[snip some of the TOFU]
>>or use single quotes round your EOF rather than doubles..
>>
>>print <<'EOF'
>><HTML>
>><SCRIPT>
>>var newLine = unescape("%0A");
>>alert("The correct email format is : " + newLine +
>>username@domain.extension");
>></SCRIPT>
>></HTML>
>>EOF
Avoiding single quotes is not a good solution.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 27 Mar 2003 07:26:14 +0000
From: Chris Lowth <please@no.spam>
Subject: Re: print here-documents question
Message-Id: <hJxga.1085$8s6.10463@newsfep4-glfd.server.ntli.net>
Bernard wrote:
> My apologies, I did not understand the following:
>
> - Begin quote -
>
> If you only have one such HTML fragment, then ...
>
> print <DATA>
> __DATA__
> <HTML>
> <SCRIPT>
> var newLine = unescape("%0A");
> alert("The correct email format is : " + newLine +
> username@domain.extension");
> </SCRIPT>
> </HTML>
>
If perl sees the magic string "__DATA__" on a line by itself, it treats
everything that follows as if it was in a text file pre-openned using the
file handle DATA. So..
while ( <DATA> ) {
print "$_\n";
}
will print all the lines in the script following the "__DATA__" tag. Heres a
Hello world example..
while ( <DATA> ) {
print $_;
}
__DATA__
Hello world,
Wouldnt you rather be on holiday?
So - you could put all your HTML in a text file, or simply stick the text
file on to the end of the script using the __DATA__ tag (as above).
For me, the better solution is..
print <<'END';
The variable is $name
My address is someome@somehost.somewhere.com
END
This works because of the single quotes round the word "END". Single quotes
mean DONT expand the dollars etc in the here-doc. If you use double quotes
round "END", then the "$" and "@" will be expanded (try it, both ways and
you'll see the difference).
Hope this clarifies things.
--
My real address is: chris at lowth dot sea oh em
-> OpenSource e-mail virus protection : http://protector.sourceforge.net
-> iptables configuration wizards : http://www.lowth.com/LinWiz
------------------------------
Date: Thu, 27 Mar 2003 16:12:23 +0000 (UTC)
From: Hemant Shah <shah@typhoon.xnet.com>
Subject: Problem using personal module in Apache?
Message-Id: <b5v7t7$smr$1@flood.xnet.com>
Folks,
We have apache server and I am using CGI.pm to to create web pages,
I created my own perl module so I could put comonly used functions in it.
I wrote a funciton to create Cookie.
Here is a small fragment of the perl module MyLib.pm:
---------cut-------------cut-------------cut-------------cut----
package MyLib;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
CreateNewCookie
);
$VERSION = 1.00;
delete @ENV{qw(IFS CDPATH ENV PATH DB2DBDFT DB2INSTANCE)};
$ENV{PATH} = "/bin:/usr/bin";
use CGI qw(:all);
use CGI::Cookie;
sub CreateNewCookie
{
# Create new cookie.
$TimeCookie = new CGI::Cookie( -name => "MyCookie",
-values => "TestCookie",
-path => "/cgi-bin/",
-expires => "+8h",
-secure => "1"
);
return($TimeCookie);
}
1;
---------cut-------------cut-------------cut-------------cut----
In my perl script I have following code:
---------cut-------------cut-------------cut-------------cut----
#!/usr/local/bin/perl -w
BEGIN {
use FileHandle;
STDOUT->autoflush(1);
STDERR->autoflush(1);
use CGI::Carp qw(fatalsToBrowser carpout);
open(LOGFILE, "> /tmp/MyApp.log");
carpout(LOGFILE);
}
# Clean up environment variables, make %ENV safer.
delete @ENV{qw(IFS CDPATH ENV PATH)};
$ENV{PATH} = "/bin:/usr/bin";
use lib "/path/to/directory/lib";
use MyLib;
use CGI qw(:all);
use CGI::Cookie;
$MyCookie = MyLib::CreateNewCookie();
print "Cookie - $MyCookie\n";
close(LOGFILE)
ecit(0);
---------cut-------------cut-------------cut-------------cut----
In the log file I get error message that $MyCookie is undefined.
Perl finds my module and the function because I do not see any other errors.
If take the code from CreateNewCookie() function nad use it in the
perl program, it successfully creates the cookie.
$MyCookie = new CGI::Cookie( -name => "MyCookie",
-values => "TestCookie",
-path => "/cgi-bin/",
-expires => "+8h",
-secure => "1"
);
What am I doing wrong?
Thanks.
--
Hemant Shah /"\ ASCII ribbon campaign
E-mail: NoJunkMailshah@xnet.com \ / ---------------------
X against HTML mail
TO REPLY, REMOVE NoJunkMail / \ and postings
FROM MY E-MAIL ADDRESS.
-----------------[DO NOT SEND UNSOLICITED BULK E-MAIL]------------------
I haven't lost my mind, Above opinions are mine only.
it's backed up on tape somewhere. Others can have their own.
------------------------------
Date: Thu, 27 Mar 2003 13:57:06 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem using personal module in Apache?
Message-Id: <slrnb86lsi.4es.tadmc@magna.augustmail.com>
Hemant Shah <shah@typhoon.xnet.com> wrote:
> In my perl script I have following code:
> #!/usr/local/bin/perl -w
use strict; # ask for all the help you can get
> open(LOGFILE, "> /tmp/MyApp.log");
You should always, yes *always*, check the return value from open():
open(LOGFILE, "> /tmp/MyApp.log" or die "could not open '/tmp/MyApp.log' $!";
(or carp() instead of die(), but some appropriate action)
> ecit(0);
^
^
> I do not see any other errors.
I am finding that hard to believe at this point...
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 26 Mar 2003 19:55:03 GMT
From: webguymatt@netscape.net (Matt Smith)
Subject: Problem with libwin/perflib counter script
Message-Id: <3e8204a4.607398372@news.ca.nortel.com>
Hi all,
I'm trying to use a Perl script to look at a few different counters
(specifically "Current Connections" under "Web Services") on remote
Windows 2000 boxes. The problem I'm having is that my script works
fine when run from my laptop (running Windows 2000 Pro, Perl 5.8.0 and
libwin 0.20) but not *from* any of our servers (running Windows 2000
Server, Perl 5.6.1 and libwin 0.18).
In both cases I've got the script set to talk to the Windows 2000
Server in question. From my laptop, the script is able to pull back
all of the counters and parse for the Current Connections one. From
the server itself, the script doesn't seem to pull back the full list
of counters it can't find the Current Connections one. Exact same
script... and Perfmon works fine from both boxes.
Has anybody seen something like this? Is it a versioning issue?
Cheers,
Matt
------------------------------
Date: 27 Mar 2003 09:23:24 -0800
From: jrolandumuc@yahoo.com (JR)
Subject: Question about Schwartzian Transform
Message-Id: <b386d54b.0303270923.3e30c4c3@posting.google.com>
Can someone put into laymans terms for me what the "$_->[0]" does in
the Schwartzian Transform? I am clear about every line of the
Schwartzian Transform, except for this line. I read in this newsgroup
that "->[0] accesses the first element of the inner arrays, so $_->[0]
is the first element of each inner anon array which is the original
data," but I'm not quite following this. In the below example, the
first map statement (map { $_->[0] }) will receive three sorted
anonymous arrays, but I don't understand how "map { $_->[0]"
transforms these sorted anonymous arrays into dereferenced sorted
output (why wouldn't the first element ([0]), in the below example, of
the each anonymous array be 3, 3 and 9, respectively?).
Here's my test script:
----------------------------------------------------------------------
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
my @data = <DATA>;
my @data = map { $_->[0] }
sort { $a->[1] <=> $b->[1] || # second column-numeric
$a->[2] <=> $b->[2] || # third column-numeric
$a->[3] <=> $b->[3] # fourth column-numeric
}
map { [ $_, (split)[1, 2, 3, 0] ] } @data;
print for @data;
__DATA__
ignoreA 9 6 3
ignoreB 3 9 9
ignoreC 3 6 3
=output1
ignoreC 3 6 3
ignoreB 3 9 9
ignoreA 9 6 3
=output1
----------------------------------------------------------------------
Here's an explanation of the "$_->[0]" that I found in this newsgroup.
"3. The sort routine does not modify the data inside the array
elements, so
we still need to convert them to their original data. The sorted array
that
is returned by sort is passed to another map to transform it. This map
puts
the first element of the inner arrays in the place of the inner array
as a
whole, so the outer array is not an array of references any more, but
a
sorted array of the original data. ->[0] accesses the first element of
the
inner arrays, so $_->[0] is the first element of each inner anon array
which
is the original data. The array returned by map is assigned to @data."
I appreciate any advice anyone may be able to give to clear this up
for me! Thanks very much.
JR
------------------------------
Date: 27 Mar 2003 17:59:07 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Question about Schwartzian Transform
Message-Id: <u9el4svggk.fsf@wcl-l.bham.ac.uk>
jrolandumuc@yahoo.com (JR) writes:
> (why wouldn't the first element ([0]), in the below example, of
> the each anonymous array be 3, 3 and 9, respectively?).
>
> Here's my test script:
> ----------------------------------------------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
> use diagnostics;
>
> my @data = <DATA>;
>
> my @data = map { $_->[0] }
> sort { $a->[1] <=> $b->[1] || # second column-numeric
> $a->[2] <=> $b->[2] || # third column-numeric
> $a->[3] <=> $b->[3] # fourth column-numeric
> }
> map { [ $_, (split)[1, 2, 3, 0] ] } @data;
^^^
You are clearly not seeing this bit.
>
> print for @data;
>
> __DATA__
> ignoreA 9 6 3
> ignoreB 3 9 9
> ignoreC 3 6 3
>
> =output1
> ignoreC 3 6 3
> ignoreB 3 9 9
> ignoreA 9 6 3
> =output1
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 27 Mar 2003 12:29:58 -0600
From: Jeff D Gleixner <glex_nospam@qwest.net>
Subject: Re: Question about Schwartzian Transform
Message-Id: <LnHga.1237$1O3.26124@news.uswest.net>
JR wrote:
> Can someone put into laymans terms for me what the "$_->[0]" does in
> the Schwartzian Transform? I am clear about every line of the
> Schwartzian Transform, except for this line. I read in this newsgroup
> that "->[0] accesses the first element of the inner arrays, so $_->[0]
> is the first element of each inner anon array which is the original
> data," but I'm not quite following this. In the below example, the
> first map statement (map { $_->[0] }) will receive three sorted
> anonymous arrays, but I don't understand how "map { $_->[0]"
> transforms these sorted anonymous arrays into dereferenced sorted
> output (why wouldn't the first element ([0]), in the below example, of
> the each anonymous array be 3, 3 and 9, respectively?).
$_->[0] comes from the map{[$_, ... ]} with @data. Sort returns
the entire list, after applying all the rules. The list consists of
references to each array created from the bottom most map{} (it's
first one that's executed).
If you look only at the last line, and forget about the
sort and the other map, it should make more sense where
$_->[0] is coming from.
map { [ $_, (split)[1, 2, 3, 0] ] } @data;
for each element in @data, create an array reference
with the original element ($_) as the first [0] element in
the new array reference, along with 4 more elements,
which split returns.
How do you access the first element in an array
reference? $ref->[0] or $_->[0], in this case.
The following may make it more clear:
#!/usr/local/bin/perl
my @data = ('ignoreA 9 6 3', 'ignoreB 3 9 9', 'ignoreC 3 6 3');
my (@new_data) = map { [ $_, (split)[1, 2, 3, 0] ] } @data;
foreach (@new_data)
{
print $_->[0], "\n",
"the first column is:", $_->[1], "\n";
"the ignore part is:", $_->[4], "\n";
}
For the data you show the '0', with the split, isn't needed,
because the sort doesn't use it, but I printed it $_->[4] just to
show it's in there.
See ya
------------------------------
Date: 27 Mar 2003 14:46:36 -0800
From: jrolandumuc@yahoo.com (JR)
Subject: Re: Question about Schwartzian Transform
Message-Id: <b386d54b.0303271446.47a1fb0c@posting.google.com>
Jeff D Gleixner <glex_nospam@qwest.net> wrote in message news:<LnHga.1237$1O3.26124@news.uswest.net>...
> JR wrote:
> > Can someone put into laymans terms for me what the "$_->[0]" does in
> > the Schwartzian Transform? I am clear about every line of the
> > Schwartzian Transform, except for this line. I read in this newsgroup
> > that "->[0] accesses the first element of the inner arrays, so $_->[0]
> > is the first element of each inner anon array which is the original
> > data," but I'm not quite following this. In the below example, the
> > first map statement (map { $_->[0] }) will receive three sorted
> > anonymous arrays, but I don't understand how "map { $_->[0]"
> > transforms these sorted anonymous arrays into dereferenced sorted
> > output (why wouldn't the first element ([0]), in the below example, of
> > the each anonymous array be 3, 3 and 9, respectively?).
>
>
> $_->[0] comes from the map{[$_, ... ]} with @data. Sort returns
> the entire list, after applying all the rules. The list consists of
> references to each array created from the bottom most map{} (it's
> first one that's executed).
>
> If you look only at the last line, and forget about the
> sort and the other map, it should make more sense where
> $_->[0] is coming from.
>
> map { [ $_, (split)[1, 2, 3, 0] ] } @data;
>
> for each element in @data, create an array reference
> with the original element ($_) as the first [0] element in
> the new array reference, along with 4 more elements,
> which split returns.
>
> How do you access the first element in an array
> reference? $ref->[0] or $_->[0], in this case.
>
> The following may make it more clear:
>
> #!/usr/local/bin/perl
> my @data = ('ignoreA 9 6 3', 'ignoreB 3 9 9', 'ignoreC 3 6 3');
> my (@new_data) = map { [ $_, (split)[1, 2, 3, 0] ] } @data;
> foreach (@new_data)
> {
> print $_->[0], "\n",
> "the first column is:", $_->[1], "\n";
> "the ignore part is:", $_->[4], "\n";
> }
>
> For the data you show the '0', with the split, isn't needed,
> because the sort doesn't use it, but I printed it $_->[4] just to
> show it's in there.
>
> See ya
This makes it perfectly clear. Thanks for the explanation.
--JR
------------------------------
Date: Thu, 27 Mar 2003 16:59:53 -0500
From: Gary Fu <gfu@gscmail.gsfc.nasa.gov>
Subject: regex question
Message-Id: <3E837459.2010102@gscmail.gsfc.nasa.gov>
Hi,
if $xx = 'ABC 123 a b c', I want $id = 123 and $txt = 'b c';
if $xx = 'ABC 123 a c c', I want $id = 123 and don't care about $txt
I cannot figure out how to do this with something like
($id, $txt) = $xx =~ /ABC (\d+) (b c)/ # I won't get $id for the 2nd case.
Thanks.
Gary
--
------------------------------
Date: Thu, 27 Mar 2003 07:20:27 GMT
From: "Jack D." <goodcall__1@hotmail.com>
Subject: Running Daemon as Different User
Message-Id: <%Cxga.53266$UV6.3880631@news1.telusplanet.net>
I'm nearly finished writing a file-monitor daemon for use on Linux. Since I
intend to have this start via inittab, then naturally it will default to being
run by user root. I think I need this program to be run by a 'lesser' authority
(i.e some other user). Here's why:
On RH7.2 consider the following (where /tmp/somefile has been chmod'd to 000)
[/tmp] > ---------- 1 ops 1381 Aug 29 22:59 somefile
if (-r /tmp/somefile) {
print "File is readable\n";
}
else {
print "File is not readable\n";
}
User 'root' prints the first statement ? i.e. the file is still readable by root
even with a 0000 permissions?
However, any other user will print the second statement.
Does anyone know how I can either:
1. Get the true 'NON-readability' of a file under any user?
or
2. Run a perl daemon program by a user other than root?
One last query -- I searched CPAN and couldn't find any sort of file-monitor
daemon. (i.e. run a task/program when a file changes)
Something like this must have been written long ago -- any hints as to where?
--
Jack D.
Remove '__' from address if replying by e-mail.
------------------------------
Date: Thu, 27 Mar 2003 07:46:12 +0000
From: Chris Lowth <please@no.spam>
Subject: Re: Running Daemon as Different User
Message-Id: <%%xga.1089$8s6.10113@newsfep4-glfd.server.ntli.net>
Jack D. wrote:
>
> Does anyone know how I can either:
>
> 2. Run a perl daemon program by a user other than root?
To do it in code, use ...
use POSIX;
$user = "nobody";
($login,$pass,$uid,$gid) = getpwnam($user);
die "User $user unknown" unless (defined $gid);
setgid($gid) or die "Cant set gid";
setuid($uid) or die "Cant set uid";
For this to work, the script must be started by root in the first place.
root is then allowed to change user/group to anyone else he wishes.
As with all things perl, there are many ways to solve the same problem -
this is just one.
Chris
--
My real address is: chris at lowth dot sea oh em
-> OpenSource e-mail virus protection : http://protector.sourceforge.net
-> iptables configuration wizards : http://www.lowth.com/LinWiz
------------------------------
Date: 27 Mar 2003 08:02:46 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Running Daemon as Different User
Message-Id: <slrnb85c16.2mk.sholden@flexal.cs.usyd.edu.au>
On Thu, 27 Mar 2003 07:20:27 GMT, Jack D. <goodcall__1@hotmail.com> wrote:
> I'm nearly finished writing a file-monitor daemon for use on Linux. Since I
> intend to have this start via inittab, then naturally it will default to being
> run by user root. I think I need this program to be run by a 'lesser' authority
> (i.e some other user). Here's why:
>
> On RH7.2 consider the following (where /tmp/somefile has been chmod'd to 000)
>
> [/tmp] > ---------- 1 ops 1381 Aug 29 22:59 somefile
>
> if (-r /tmp/somefile) {
> print "File is readable\n";
> }
> else {
> print "File is not readable\n";
> }
>
> User 'root' prints the first statement ? i.e. the file is still readable by root
> even with a 0000 permissions?
>
> However, any other user will print the second statement.
>
> Does anyone know how I can either:
>
> 1. Get the true 'NON-readability' of a file under any user?
By reading the documentation that comes with perl that describes the -r file
test operation.
perldoc -f -r
Especially the paragraph starting:
Also note that, for the superuser on the local filesystems, the "-r",
"-R", "-w", and "-W" tests always return 1
Which contains advice on how to do that test as the superuser.
>
> or
>
> 2. Run a perl daemon program by a user other than root?
See "perldoc perlvar" for the $< and $> variables.
--
Sam Holden
------------------------------
Date: Thu, 27 Mar 2003 08:16:34 GMT
From: "Jack D." <goodcall__1@hotmail.com>
Subject: Re: Running Daemon as Different User
Message-Id: <Cryga.53280$UV6.3886060@news1.telusplanet.net>
"Sam Holden" <sholden@flexal.cs.usyd.edu.au> wrote in message
news:slrnb85c16.2mk.sholden@flexal.cs.usyd.edu.au...
> On Thu, 27 Mar 2003 07:20:27 GMT, Jack D. <goodcall__1@hotmail.com> wrote:
> > Does anyone know how I can either:
> >
> > 1. Get the true 'NON-readability' of a file under any user?
>
> By reading the documentation that comes with perl that describes the -r file
> test operation.
>
> perldoc -f -r
>
> Especially the paragraph starting:
>
> Also note that, for the superuser on the local filesystems, the "-r",
> "-R", "-w", and "-W" tests always return 1
Whoa - how did I miss that one!
Always go to the source...perldoc. Thanks.
I'll have to check tomorrow - but I don't think this was mentioned
"prominently" in the camel. (which was the only place I checked)
>
> Which contains advice on how to do that test as the superuser.
>
> >
> > or
> >
> > 2. Run a perl daemon program by a user other than root?
>
> See "perldoc perlvar" for the $< and $> variables.
Between this and Chris's reply - I have what I need. Thanks again.
--
Jack D.
Remove '__' from address if replying by e-mail.
------------------------------
Date: Thu, 27 Mar 2003 18:13:22 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Running Daemon as Different User
Message-Id: <slrnb86fq2.9fd.efflandt@typhoon.xnet.com>
On Thu, 27 Mar 2003 07:46:12 +0000, Chris Lowth <please@no.spam> wrote:
> Jack D. wrote:
>
>>
>> Does anyone know how I can either:
>>
>> 2. Run a perl daemon program by a user other than root?
>
> To do it in code, use ...
>
> use POSIX;
> $user = "nobody";
> ($login,$pass,$uid,$gid) = getpwnam($user);
> die "User $user unknown" unless (defined $gid);
> setgid($gid) or die "Cant set gid";
> setuid($uid) or die "Cant set uid";
>
> For this to work, the script must be started by root in the first place.
> root is then allowed to change user/group to anyone else he wishes.
I do not even have to use POSIX for deamon that needs root to bind to low
port, then changes effective id before spawning children:
my $runas = 'nobody'; # user to run as (near beginning of script)
# Change effective id
$> = getpwnam($runas);
logmsg "by", scalar getpwuid($<), "running as", scalar getpwuid($>);
# sub logmsg: flocks and logs to file owned by $runas 644.
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: Thu, 27 Mar 2003 16:24:54 -0500
From: Doug Kite <dougkite@yahoo.com>
Subject: search and replace long hex string
Message-Id: <3E836C26.1020608@yahoo.com>
How can you search and replace a long hex string in a binary file?
Something like the following works:
perl -i -pe 's{\x24}{\x14}g' /foo/bar
but not *every* 0x24 needs to be replaced.
If you can specify a longer string, like 0xb301001624f0 replace with
0xb301001614f0 that would work better.
The following did not seem to work:
perl -i -pe 's{\x{24f0}}{\x{14f0}}g' /foo/bar
Thanks for any ideas,
Doug
------------------------------
Date: Thu, 27 Mar 2003 22:07:47 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: search and replace long hex string
Message-Id: <3E837630.22E6C410@acm.org>
Doug Kite wrote:
>
> How can you search and replace a long hex string in a binary file?
>
> Something like the following works:
>
> perl -i -pe 's{\x24}{\x14}g' /foo/bar
>
> but not *every* 0x24 needs to be replaced.
>
> If you can specify a longer string, like 0xb301001624f0 replace with
> 0xb301001614f0 that would work better.
>
> The following did not seem to work:
> perl -i -pe 's{\x{24f0}}{\x{14f0}}g' /foo/bar
It looks like you have an endian problem. Instead of specifying an
integer \x24F0 that may be translated to \xF024, specify the bytes
individually.
perl -i -pe 's{\x24\xf0}{\x14\xf0}g' /foo/bar
Or even better, use positive look-ahead:
perl -i -pe 's{\x24(?=\xf0)}{\x14}g' /foo/bar
And positive look-behind:
perl -i -pe 's{(?<=\xb3\x01\x00\x16)\x24(?=\xf0)}{\x14}g' /foo/bar
John
--
use Perl;
program
fulfillment
------------------------------
Date: 27 Mar 2003 05:28:37 -0800
From: jsouth@cix.co.uk (John South)
Subject: Re: Simple CGI Select by Date
Message-Id: <d2aa22df.0303270528.756218db@posting.google.com>
Simon Oliver <simon.oliver@nospam.umist.ac.uk> wrote in message news:<3E81CA46.6080308@nospam.umist.ac.uk>...
> John South wrote:
> > I've little experience of CGI and Perl, but I need a script that will
> > build a Web page taking mostly static html, and selecting some table
> > data from a text (or xml) file based on a date field (or equivalent
> > numeric field).
> >
> > It's just a list of avaiable recruitment jobs that needs to only show
> > those before the interview date.
> >
> > I'm sure this is possible and probably very easy. Can someone show me
> > a nice simple routine?
> >
> There are so many ways to do this. Here's a quick example....
>
> Assuming your input format is like this:
>
> 2005-7-04 My fourth job
> 2003-9-02 My second job
> 2004-10-01 My third job
> 2002-8-03 My first job
>
> The following script should get you started:
>
> use strict;
> use POSIX qw(mktime);
> use HTML::Entities qw(encode_entities);
>
> my $title = "Avaiable Recruitment Jobs";
> my $file = "jobsfile.tab";
>
> print "Content-Type: text/html\n\n";
>
> print <<EOT;
> <HTML>
> <HEAD><TITLE>$title</TITLE></HEAD>
> <BODY>
> <H4>$title</H4>
> EOT
>
> if (open FH, "<$file") {
> my @records;
> while (<FH>) {
> chomp;
> my ($date, $text) = split(/\t/) or next;
> my ($year, $mon, $mday) = split(/[\/-]/,$date);
> my $time = mktime(0,0,0,$mday,$mon-1,$year-1900);
> push(@records, [$time,$date,$text]) if time() < $time;
> }
> if (@records) {
> print '<TABLE BORDER="1"><TR><TH>Date</TH><TH>Text</TH></TR>';
> foreach (sort {$a->[0] cmp $b->[0]} @records) {
> my $date = $_->[1];
> my $text = encode_entities($_->[2]);
> print "<TR><TD>$date</TD><TD>$text</TD>";
> }
> print "</TABLE>\n</BODY>\n</HTML>";
> } else {
> print "<H4>No records in job file!</H4></BODY></HTML>";
> }
> } else {
> print "<H4>Error opening job file!</H4></BODY></HTML>";
> die "Error opening job file '$file':$!";
> }
Thanks Simon. That looks just the job. I assume it doesn't need any libraries
that are not standard on Unix Web servers. Anyhow I'll be able to try it soon.
Thanks
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4769
***************************************