[19934] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2129 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 14 06:05:42 2001

Date: Wed, 14 Nov 2001 03:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1005735909-v10-i2129@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 14 Nov 2001     Volume: 10 Number: 2129

Today's topics:
    Re: -M $file on win32 <mgjv@tradingpost.com.au>
    Re: Accessing NT Network Neighbourhood <s.warhurst@rl.ac.uk>
    Re: CGI links with a single argument <ajb@phxlab.honeywell.com>
    Re: DHCPDISCOVER message in PERL? <goldbb2@earthlink.net>
    Re: ebcdic, was Re: Unencoding <joe+usenet@sunstarsys.com>
    Re: how do I use gzip (Fredrik)
        IBM AS/400 data queue access <dfosdike@nospam.elders.com.au>
        Parsing speed (John Kenyon)
    Re: Parsing speed (Rafael Garcia-Suarez)
    Re: Parsing speed <wyzelli@yahoo.com>
    Re: Problem printing numbers news@roaima.freeserve.co.uk
    Re: RegEx problem -- trying to match To: or From: at be (Anno Siegel)
    Re: Regular Expression BackTracking <bart.lateur@skynet.be>
    Re: Regular Expression BackTracking <mgjv@tradingpost.com.au>
        setuid cgi? <sh@planetquake.com>
    Re: setuid cgi? <nobody@nowhere.com>
    Re: setuid cgi? <nobody@nowhere.com>
    Re: setuid cgi? <sh@planetquake.com>
    Re: setuid cgi? <bart.lateur@skynet.be>
    Re: setuid cgi? <nobody@nowhere.com>
        Simple Question: use variable in regexp (joes)
    Re: Simple Question: use variable in regexp <bernard.el-hagin@lido-tech.net>
    Re: Simple Question: use variable in regexp <peb@bms.umist.ac.uk>
    Re: SQLPLUS via Perl <goldbb2@earthlink.net>
        Value to hex string conversion <marekw@altavista.net>
    Re: Value to hex string conversion <bernard.el-hagin@lido-tech.net>
    Re: Value to hex string conversion <wuerz@yahoo.com>
    Re: WWWBoard alternative?  Images? <tsee@gmx.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 14 Nov 2001 19:01:29 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: -M $file on win32
Message-Id: <slrn9v496p.uf3.mgjv@martien.heliotrope.home>

On Tue, 13 Nov 2001 16:42:53 +0100,
	Lars Oeschey <dump@the-core.net> wrote:
> On Tue, 13 Nov 2001 10:18:16 +0100, "Dr. Peter Dintelmann"
><Peter.Dintelmann@dresdner-bank.com> wrote:
> 
>>    Thus I suspect you wanted to type
>>        if (-f "$localdir/$datei") { ... }
>>    Is this of any help to you?
>>        Peter
> 
> hm, this really solved the problem of the multi-dot-files, I see them
> all now. But with the same construction, the -M doesn't work, I just
> get nothing back...
> this is the code:
> 
> opendir (SAVE, "$localdir");
> while ($datei = readdir (SAVE)) {
> 	if (-f "$localdir/$datei") { 
                ^^^^^^^^
> 		$alter = -M "$localfile/$datei";
                             ^^^^^^^^^^
> 		print $datei . ": " . $alter . "\n";
> 		}
> 	}

Note the difference?

Now, if I were you, I would, before changing anything else, make sure
that I ran Perl with warnings enabled, and under the strict pragma. Both
offer invaluable help debugging problems like this, or preventing
problems like this.

Also, have a look at the special file handle _ (indeed, just an
underscore), mentioned in the entry for -X in perlfunc. That way you
won't have to duplicate that file name.

Martien
-- 
                                | Since light travels faster than
Martien Verbruggen              | sound, isn't that why some people
                                | appear bright until you hear them
                                | speak?


------------------------------

Date: Wed, 14 Nov 2001 08:40:28 -0000
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: Accessing NT Network Neighbourhood
Message-Id: <9stalv$kum@newton.cc.rl.ac.uk>

<nobull@mail.com> wrote in message news:u9eln2lfjp.fsf@wcl-l.bham.ac.uk...
> Does open() indicate that it failed?  If so what reason is given for
> the failure?

Well, basically what happens is this:

I set up a test script (it's CGI):

   #!c:/perl/bin/perl

   print "Content-type: text/html\n\n";

   if(open(FILE, ">f:/test.txt")){print "yes"; close(FILE);}else{print $!;}

That returns "Permission Denied" when you try to run it.

I tried running it from the command line and it worked. So it appears to be
something to do with CGI not having
permissions to write to another server. I would have thought the "everyone -
full control" on the target directory would have allowed that.. it might be
that it's actually Apache that's stopping t.. am looking into that side of
things.

I wish for once I could write a script that works from beginning to end
without running up against problems that take hours to fix/workaround <sigh>

Spencer






------------------------------

Date: Tue, 13 Nov 2001 17:11:05 -0700
From: "Austyn Bontrager" <ajb@phxlab.honeywell.com>
Subject: Re: CGI links with a single argument
Message-Id: <20011113.171105.1431419379.23321@phxlab.honeywell.com>

Look at $ENV{QUERY_STRING}, but I agree with Mr Mueller:
'use CGI;' and 'some.cgi?filename=argument'

"Steven" <me@anywhere.com> wrote:
> I was wondering if there is a way to use a link with a single argument
> like
> 
> <a href="http://www.anywhere.com/cgi-bin/some.cgi?argument">xxx</a>
> 
> without using CGI.pm.

<snip>

> Any help appreciated,
> Steve.


------------------------------

Date: Wed, 14 Nov 2001 00:12:42 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: DHCPDISCOVER message in PERL?
Message-Id: <3BF1FD4A.C4DEAE2F@earthlink.net>

jack wrote:
> 
> How to send a DHCPDISCOVER broadcasting message to a subnet in PERL?

The same way you would send a DHCPDISCOVER broadcasting message in C,
but do it in perl.  Where's your perl question?

-- 
Klein bottle for rent - inquire within.


------------------------------

Date: 14 Nov 2001 02:38:01 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: ebcdic, was Re: Unencoding
Message-Id: <m3k7wt3iqu.fsf@mumonkan.sunstarsys.com>

Martien Verbruggen <mgjv@tradingpost.com.au> writes:

> On 13 Nov 2001 20:08:06 -0500,
> 	Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
>
> > [Disclaimer- I've never used an EBCDIC machine; comments below are
> >  based on reading the relevant documentation and source code]
> > 
> > I'd guess you are right, but OTOH something like "%2b" (ASCII)
> 
> I suppose you meant "%02x" ?

No, I meant "%2b" (an ASCII "+" sign in www-urlencoded form).  An
unfortunate choice here; sorry for the confusion.

> 
> > won't directly match %[a-fA-F0-9]{2} on EBCDIC; I think the the 
> > ASCII codeset for the original www-urlencoded string would first 
> > need to be converted to EBCDIC.  Once that's done, then I suspect 
> > the substitution will work as expected.  
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

As Alan pointed out, I'm wrong about that.  The correct approach
is in CGI::Util, and it agrees with your observations later on 
in your post (that I deftly just snipped :).

[...]

> On ASCII systems, pack "C", hex("5A") will give you the character Z,
> but on EBCDIC systems, it won't. 

Right, according to perlebcdic it yields an "!" instead.  AIUI, here's 
the steps in the translation for parsing CGI form-data:

text    ->  web browser  -> http Xport  ->    webserver     -> cgi script
(ascii) -> (url-encoded) ->  (octets)   -> (encoded-ebcdic) -> (ebcdic)

 Z (\x5a)       Z              \x5a             \xe9        -> Z (\xe9)
 + (\x2b)      %2b        \x25 \x32 \x62   \x6c \xf2 \x82   -> + (\x4e)
 % (\x25)      %25        \x25 \x32 \x35   \x6c \xf2 \xf5   -> % (\x6c)

CGI.pm handles the final piece; in order to map an url-encoded character
into an EBCDIC one, it needs an ascii-to-ebcdic octet translator before
passing it along to pack() or chr().  CGI.pm assumes the webserver will 
properly translate the octets to and fro (this is what I was alluding to 
in my earlier post).

[...]

> This decoding process will, irrespective of platform, need to use the
> ASCII table. pack "C" won't do that. 

Yes, that's it exactly.  Sorry again for the confusion; I was thinking
about the question a bit more broadly than you originally posed it,
because there is an obvious discrepancy here between what CGI demands
and mod_perl provides.  But I'm not planning to submit a bug report :)

-- 
Joe Schaefer    "When the end of the world comes, I want to be in Cincinnati.
                          Everything happens ten years later there."
                                               --Mark Twain



------------------------------

Date: 13 Nov 2001 21:30:51 -0800
From: fridden@yahoo.com (Fredrik)
Subject: Re: how do I use gzip
Message-Id: <9ef98ad9.0111132130.677add1c@posting.google.com>

"Terry" <dcsnospam@ntlworld.com> wrote 
> I need to compress a large file on my hosts server and gzip is available.
> How do I call\use gzip from within a .pl script

There are several ways you could accomplish this. Note also that there
is a
module on CPAN which lets you compress and uncompress files directly
from Perl.
(Compress::zlib) and there might be others. 

One way to call an external program is to use the system() function:

   system("gzip -r -9 @list_of_files");

Lookup the documentation with "perldoc -f system" to find out more
about this function.

You could also use the backtick operator. This operator is primarly
used to capture the output of an external program.

    $output = `gzip -r -9 @list_of_files`

You can find out more about backtick operator if you do a "perldoc
perlop" and look for the text "gx/STRING/".

Hope this helps

/Fredrik


------------------------------

Date: Wed, 14 Nov 2001 15:45:19 +1030
From: "David Fosdike" <dfosdike@nospam.elders.com.au>
Subject: IBM AS/400 data queue access
Message-Id: <m5nI7.32$5c2.1560@nsw.nnrp.telstra.net>

Anyone know of  any scripts or modules to access AS/400 data queues from
either  MS, Unix or Linux platform?

Thanx in advance,

David Fosdike
dfosdike@nospam.elders.com.au




------------------------------

Date: 13 Nov 2001 23:28:03 -0800
From: johnkenyon@usa.net (John Kenyon)
Subject: Parsing speed
Message-Id: <5dd9e581.0111132328.5cc0501e@posting.google.com>

Hi,

I have a small chunk of code which converts part of a csv into an
array. It works fine but is very slow indeed. I am new to perl and
would be interested in any tips on how I could optimise this.

I am trying to convert from -
  "j","bob","tall","(","footy","rugby","golf","ski",")"
to an array
  footy
  rugby
  golf
  ski

(Note that there may be any number of items between the quoted
brackets)

Thanks,

John

#!/usr/local/bin/perl
# This is a line read from a csv
$allGroups = "\"j\",\"bob\",\"tall\",\"(\",\"footy\",\"rugby\",\"golf\",\"ski\",\")\"";

# I need to split out just the sport strings into an array
# This is a bit of a mess but does work

$allGroups =~ m/\(",( *".+" *, *)*"\)"/; #" # grab the interesting bit
"(","group1","group2",")"
$allGroups = $&;
$allGroups =~ s/^ *"*\(" *,//; # trim out the leading brackets
$allGroups =~ s/ *"\)" *$//; # trim out trailing brackets
@Groups = split(/" *, *"/,$allGroups); # split to group1,group2
foreach $group (@Groups) {
    $group =~ s/ *^"//; #clean up leading "
    $group =~ s/ *, *$//; #clean up trailing ,
    $group =~ s/ *" *$//; #clean up trailing "
    printf($group."\n");
}


------------------------------

Date: 14 Nov 2001 08:17:01 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Parsing speed
Message-Id: <slrn9v4a53.nmn.rgarciasuarez@rafael.kazibao.net>

John Kenyon wrote in comp.lang.perl.misc:
> 
> I have a small chunk of code which converts part of a csv into an
> array. It works fine but is very slow indeed. I am new to perl and
> would be interested in any tips on how I could optimise this.
> 
[...]
> $allGroups = $&;
[...]

Quoting the perlvar manpage, section about $& :

   The use of this variable anywhere in a program
   imposes a considerable performance penalty on all
   regular expression matches.  See the BUGS manpage.

So I suggest that you avoid using $&, possibly by using $1 etc. instead.
That's a good first step.

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


------------------------------

Date: Wed, 14 Nov 2001 18:09:56 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Parsing speed
Message-Id: <B4qI7.1$7Q.43@vicpull1.telstra.net>

"John Kenyon" <johnkenyon@usa.net> wrote in message
news:5dd9e581.0111132328.5cc0501e@posting.google.com...
> Hi,
>
> I have a small chunk of code which converts part of a csv into an
> array. It works fine but is very slow indeed. I am new to perl and
> would be interested in any tips on how I could optimise this.
>
> I am trying to convert from -
>   "j","bob","tall","(","footy","rugby","golf","ski",")"
> to an array
>   footy
>   rugby
>   golf
>   ski
>
> (Note that there may be any number of items between the quoted
> brackets)

Here is a different approach...

my $string = '"j","bob","tall","(","footy","rugby","golf","ski",")"';
$string =~ s/.*\(",(.*),"\)/$1/;
my @array = $string =~ m/"([^"]*)"/g;
print "@array";



Wyzelli

--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;





------------------------------

Date: 14 Nov 2001 09:48:37 GMT
From: news@roaima.freeserve.co.uk
Subject: Re: Problem printing numbers
Message-Id: <3bf23df5@news.netserv.net>

Blake Brezeale <blake.brezeale@usa.alcatel.com> wrote:
> I am currently running Mandrake 8.1 with the default shell (Bash) [...]
> If I change my shell to Bourne or Korn, I get the correct output.  [...]

> Can anyone tell me what is happening and how to fix the problem without
> changing my shell. Any information would be appreciated.

It sounds like the bash prompt is including an explicit CR ("\r"). Have
a look in your .bash_profile and .bashrc and check/change any references
to the variable PS1.

Ob. on-topic: why don't you just include a "\n" at the end of your output?

Chris


------------------------------

Date: 14 Nov 2001 10:38:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: RegEx problem -- trying to match To: or From: at beginning of line
Message-Id: <9sthio$9jq$1@mamenchi.zrz.TU-Berlin.DE>

According to Mark <admin@asarian-host.net>:
> "jennyw" <donotspam-jen@dangerousideas.com> wrote in message
> news:9spcgl$su1$1@bob.news.rcn.net...
> 
> > Actually, I realized the problem. I need to use:
> >
> > /(^To:)|(^From:)/
> >
> > I'm not sure why the carets (^) need to be inside the parentheses, but it
> > works this way.
> 
> A small word extra. The caret needs to be outside the parentheses. Now you
> are matching two distinct entities: "(either something starting with To,
> followed by a colon), or (something starting with From, followed by a
> colon)."
> 
> But, what you want is this:
> 
> /^(To|From):/i

You have said this twice, explaining correctly why the caret must be
where it is.  However, you haven't explained why you propose the /i
modifier.  It shouldn't be there, IMHO.

Anno


------------------------------

Date: Wed, 14 Nov 2001 08:57:40 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Regular Expression BackTracking
Message-Id: <rfc4vtkvrffm14io4g7cuj0frc6dab33g9@4ax.com>

Martien Verbruggen wrote:

>my $word_digit = qr/\w+\d/;
>
>while (<DATA>)
>{
>	if (m/($word_digit)\s+($word_digit)/)

I'd still use the /o option, if I were you.

-- 
	Bart.


------------------------------

Date: Wed, 14 Nov 2001 21:44:28 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Regular Expression BackTracking
Message-Id: <slrn9v4ioc.uf3.mgjv@martien.heliotrope.home>

On Wed, 14 Nov 2001 08:57:40 GMT,
	Bart Lateur <bart.lateur@skynet.be> wrote:
> Martien Verbruggen wrote:
> 
>>my $word_digit = qr/\w+\d/;
>>
>>while (<DATA>)
>>{
>>	if (m/($word_digit)\s+($word_digit)/)
> 
> I'd still use the /o option, if I were you.

You are right, but the /o option is overrated :)

Perl already does quite a good job at not unnecessarily recompiling
patterns.

$ perl -Mre=debug -e '$pat = q/\w/; /$pat/ for 1 .. 2'
Freeing REx: `,'
Compiling REx `\w'
size 2 first at 1
   1: ALNUM(2)
   2: END(0)
stclass `ALNUM' minlen 1 
Matching REx `\w' against `1'
  Setting an EVAL scope, savestack=9
   0 <> <1>               |  1:  ALNUM
   1 <1> <>               |  2:  END
Match successful!
Matching REx `\w' against `2'
  Setting an EVAL scope, savestack=9
   0 <> <2>               |  1:  ALNUM
   1 <2> <>               |  2:  END
Match successful!
Freeing REx: `\w'

Note that the pattern is compiled only once. If however, $pat changes:

$ perl -Mre=debug -e '$pat = q/\w/ x $_, /$pat/ for 1 .. 2'
Freeing REx: `,'
Compiling REx `\w'
size 2 first at 1
   1: ALNUM(2)
   2: END(0)
stclass `ALNUM' minlen 1 
Matching REx `\w' against `1'
  Setting an EVAL scope, savestack=9
   0 <> <1>               |  1:  ALNUM
   1 <1> <>               |  2:  END
Match successful!
Freeing REx: `\w'
Compiling REx `\w\w'
size 3 first at 1
   1: ALNUM(2)
   2: ALNUM(3)
   3: END(0)
stclass `ALNUM' minlen 2 
Freeing REx: `\w\w'

In this case, perl compiles the pattern for each time the contents of
$pat change. Note that even if $pat is reassigned a new value, that if
it is identical to the previous value, the pattern will not be
recompiled [1]. (Also note that there isn't even a pattern match attempt
when the pattern is longer than the string. Cool hmm?)


The behaviour is the same when creating the patterns with qr//. As long
as they don't change, there's no recompilation.

I seem to recall some posts from Ilya Zakharevich a year or so ago,
maybe a bit more, on this very issue. I'm too lazy to look it up.

This was all on perl 5.6.1, but it works the same under 5.005_03 and
5.6.0. I am not sure about 5.004_05, because its re pragma doesn't have
the debug option yet.


Now, I am in no way advocating leaving the /o option off, I just wanted
to point out that it hasn't really been needed in most cases for a while
now. I think the documentation should probably be updated to reflect
this, unless the p5p believe that they make take this optimisation away
again, in a future release.

Martien

[1] To see that there is no recompilation if the string is reassigned,
but identical in content, try for example:

perl -Mre=debug -e \
  '$pat = $_ == 1 ? q/\w\w/ : q/\w/.q/\w/, /$pat/ for "01" .. "02"'

The "01" .. "02" is there to assure that there is at least a match
attempt. 1 .. 2 instead of "01".."02" gives some, well, surprising
output that I don't pretend to understand. Ilya?

-- 
                                | 
Martien Verbruggen              | Freudian slip: when you say one thing
                                | but mean your mother.
                                | 


------------------------------

Date: Wed, 14 Nov 2001 05:39:27 GMT
From: "Sean Hamilton" <sh@planetquake.com>
Subject: setuid cgi?
Message-Id: <jsnI7.1058$c4.181908@news0.telusplanet.net>

Greetings,

Firstly, this may not pertain directly to perl.

I'm trying to execute a perl script from Apache, and I need it to be able to
set its uid and gid.

The few things I have tried haven't been successful... any ideas?

sh




------------------------------

Date: Wed, 14 Nov 2001 16:27:40 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: setuid cgi?
Message-Id: <M6oI7.249572$8x1.52250@newsfeeds.bigpond.com>

"Sean Hamilton" <sh@planetquake.com> wrote in message
news:jsnI7.1058$c4.181908@news0.telusplanet.net...
> Greetings,
>
> Firstly, this may not pertain directly to perl.
>
> I'm trying to execute a perl script from Apache, and I need it to be able
to
> set its uid and gid.
>
> The few things I have tried haven't been successful... any ideas?
>
> sh

This is a perennial problem.
1. Try an ISP with a chi wrapper. Cobble Line compes with it built in. (I'm
using this at the moment)
2. Look up wrapper in perlsec
http://www.perldoc.com/perl5.6/pod/perlsec.html
3. Talk to you ISP about installing a wrapper.

gtoomey




------------------------------

Date: Wed, 14 Nov 2001 16:32:34 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: setuid cgi?
Message-Id: <mboI7.249853$8x1.52252@newsfeeds.bigpond.com>

"Gregory Toomey" <nobody@nowhere.com> wrote in message
news:M6oI7.249572$8x1.52250@newsfeeds.bigpond.com...
> 1. Try an ISP with a chi wrapper. Cobble Line compes with it built in.

Err, that should read:
Try an ISP with a cgi wrapper. Cobalt Linux comes with it built in.
http://cobalt.com

gtoomey





------------------------------

Date: Wed, 14 Nov 2001 07:42:28 GMT
From: "Sean Hamilton" <sh@planetquake.com>
Subject: Re: setuid cgi?
Message-Id: <EfpI7.1407$HE3.247674@news1.telusplanet.net>

> Err, that should read:
> Try an ISP with a cgi wrapper. Cobalt Linux comes with it built in.

Geez, how did you manage to do that?

I have root to this box, it's mine. Is it at all possible to do this with
just configuration, no special installations? Ideally I could just set the
setuid bit on the script, but then I just get "can't do setuid" in my Apache
logs. (/usr/bin/suidperl is chmod 6555)

Running FreeBSD 4.4R.

sh




------------------------------

Date: Wed, 14 Nov 2001 09:06:07 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: setuid cgi?
Message-Id: <3jc4vtse8nfmf9dmksut14bpjsjkl00tao@4ax.com>

Sean Hamilton wrote:

> Is it at all possible to do this with
>just configuration, no special installations? Ideally I could just set the
>setuid bit on the script, but then I just get "can't do setuid" in my Apache
>logs. (/usr/bin/suidperl is chmod 6555)

I think many OS'es don't allow running scripts with SetUID, only
compiled programs.

Anyway, since it's your box, look up suEXEC in the Apache docs:

	<http://httpd.apache.org/docs/suexec.html>

-- 
	Bart.


------------------------------

Date: Wed, 14 Nov 2001 20:05:24 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: setuid cgi?
Message-Id: <TirI7.251895$8x1.53718@newsfeeds.bigpond.com>

"Sean Hamilton" <sh@planetquake.com> wrote in message
news:EfpI7.1407$HE3.247674@news1.telusplanet.net...
> > Err, that should read:
> > Try an ISP with a cgi wrapper. Cobalt Linux comes with it built in.
>
> Geez, how did you manage to do that?
>
> I have root to this box, it's mine. Is it at all possible to do this with
> just configuration, no special installations? Ideally I could just set the
> setuid bit on the script, but then I just get "can't do setuid" in my
Apache
> logs. (/usr/bin/suidperl is chmod 6555)
>
> Running FreeBSD 4.4R.

One way is to use a C wrapper like the one below that uses the setuid
method. It is what I used on my old ISP but you still have taint problems.

Cobalt uses an Addhandler directive to Apache
http://support.bb4.com/archive/200108/msg00061.html
i.e. AddHandler cgi-wrapper .cgi

With Cobalt, you don't worry about setuid, taint or anything else. Perl
programs just work the same as they do at the command line :-))


/*      Author: G. Toomey
        Name:   mycgi.c

        This program executes  perl program with the same basename
        but with a .pl extension.
        Given the permissions below,
        the perl program will execute as the given user.

        Usage (assuming the perl program is program.pl):
        cc -o program.cgi  mycgi.c
        chmod 6755 program.cgi
        chmod 0755 program.pl

*/
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
char pl_file[100];
main (int argc, char *argv[]) {
  fflush (stdout);
  strncpy(pl_file,argv[0],strlen(argv[0])-4);
  strcat(pl_file,".pl");
  execl ("/usr/bin/perl", "/usr/bin/perl",
         pl_file, 0);
}

gtoomey




------------------------------

Date: 14 Nov 2001 01:57:41 -0800
From: joes@bluewin.ch (joes)
Subject: Simple Question: use variable in regexp
Message-Id: <26760a3e.0111140157.3462af51@posting.google.com>

Hello there 

this is a simple question and no one could give an answear to me. Also
others in the newsgroups did not get an answear.

I want to replace a part of astring with a current value of my
variable like this,which not would work:

 $hex = variable value
 tr/&H.*/$hex/;       does not work
 tr/&H.*/\Q$hex/;     does also not work
  
any suggestions ?

thanks
Mark


------------------------------

Date: Wed, 14 Nov 2001 10:04:15 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Simple Question: use variable in regexp
Message-Id: <slrn9v4jdo.3il.bernard.el-hagin@gdndev25.lido-tech>

On 14 Nov 2001 01:57:41 -0800, joes <joes@bluewin.ch> wrote:
> Hello there 
> 
> this is a simple question and no one could give an answear to me. Also
> others in the newsgroups did not get an answear.
> 
> I want to replace a part of astring with a current value of my
> variable like this,which not would work:
> 
>  $hex = variable value
>  tr/&H.*/$hex/;       does not work
>  tr/&H.*/\Q$hex/;     does also not work
>   
> any suggestions ?


You're using tr/// where you probably want to use s///.


Cheers,
Bernard


------------------------------

Date: Wed, 14 Nov 2001 10:08:55 +0000
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: Simple Question: use variable in regexp
Message-Id: <3BF242B7.21762E98@bms.umist.ac.uk>

joes wrote:
> 
> Hello there
> 
> this is a simple question and no one could give an answear to me. Also
> others in the newsgroups did not get an answear.
> 
> I want to replace a part of astring with a current value of my
> variable like this,which not would work:
> 
>  $hex = variable value
>  tr/&H.*/$hex/;       does not work
>  tr/&H.*/\Q$hex/;     does also not work
> 
> any suggestions ?


could you give us an example of the substitution you are hoping for?

One thing that stands out is that you are using the tr/// operator as if
it were the s/// operator.

$replacement = 'worked';
$string = 'Has this &H?';
$string =~ s/&H/$replacement/;

print $string, "\n";

this outputs 

Has this worked?

HTH

Paul


------------------------------

Date: Wed, 14 Nov 2001 00:33:18 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: SQLPLUS via Perl
Message-Id: <3BF2021E.2764D440@earthlink.net>

John Menke wrote:
> 
> I need to execute a script designed for SQLPLUS in Perl and return the
> output of the script back into the perl environment (meaning I want to
> examine the output from perl)
[snip]

You are opening a filehandle as a pipe from a program, but not checking
the return value of close to see if the program succeeded.  When you do
open(FOO, "something|"), the return value of that only says if you
successfully created the new environment for "something" to run in, not
whether that program actually started correctly.  You have to look at
the results of the close() call to see if it started and completed ok.

Also, considering this is on windows, I would point out that open() does
not actually run the other program as a seperate process, in parallel
with the current one.  It runs it [using system, I think], putting it's
output to a temp file, then reads in that temp file.  Use open2 to have
it actually run in parallel with your perl process.

Lastly, I would suggest that DBI might be a better solution than running
an external program.

-- 
Klein bottle for rent - inquire within.


------------------------------

Date: Wed, 14 Nov 2001 08:35:00 +0100
From: "Marek Wojcik" <marekw@altavista.net>
Subject: Value to hex string conversion
Message-Id: <9st6u3$4so$1@news.tpi.pl>

Hi

    Does anybody know how to solve this problem in an easy way?

    input:
            my $a = 366;

    expected result:
            print $result;   #  it prints string 16E

Thanks for your help

Mark




------------------------------

Date: 14 Nov 2001 07:50:04 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Value to hex string conversion
Message-Id: <slrn9v4bi9.3il.bernard.el-hagin@gdndev25.lido-tech>

On Wed, 14 Nov 2001 08:35:00 +0100, Marek Wojcik <marekw@altavista.net> wrote:
> Hi
> 
>     Does anybody know how to solve this problem in an easy way?
> 
>     input:
>             my $a = 366;
> 
>     expected result:
>             print $result;   #  it prints string 16E
> 
> Thanks for your help


Check out the printf function:


perldoc -f printf


Cheers,
Bernard


------------------------------

Date: 14 Nov 2001 02:58:48 -0500
From: Mona Wuerz <wuerz@yahoo.com>
Subject: Re: Value to hex string conversion
Message-Id: <m3snbh941z.fsf@DCCMBX01.njitdm.campus.njit.edu>

"Marek Wojcik" <marekw@altavista.net> writes:

>     input:
>             my $a = 366;

              my $result = sprintf "%X", $a;

>     expected result:
>             print $result;   #  it prints string 16E

(1) avoid using $a and $b (see perldoc -f sort)
(2) perldoc -f sprintf

-- 
$_="\n,rekcah egnufeB rehtona tsuJ";#v1<?>g\:pv-<5<
s s\S+(?:B)sunpack'u',q q$;')E4qsee;#>60#^<(v!<)g6<
print scalar reverse,$@ unless m,[+;#]55,;m:_,:#^1<


------------------------------

Date: Wed, 14 Nov 2001 10:19:23 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: WWWBoard alternative?  Images?
Message-Id: <9stctn$9ku$06$1@news.t-online.com>

"Jay S." <hawk_214@mailandnews.com> schrieb im Newsbeitrag
news:5ae90e89.0111131713.3b27774c@posting.google.com...
| I have a WWWBoard running OK, but I would like users to be able to
| post images within messages.  I know I can now post a URL, but I would
| rather be able to put the image directly into the message.
|
| It would be great to be able to put something like /image name/ within
| the message, and then when they press submit, it prompts me for a file
| name from their hard drive.  I have heard that Discus can do this, but
| it is *so* complex for a simple board like mine.

Hi,

first, what you're asking is a CGI question. You can do that in
Perl/PHP/C/C++/Java/... hell, if you're sick, you might try that in
Brainfuck! Next time, please ask such questions in
comp.infosystems.www.authoring.cgi.

What springs to my mind is that /image name/ is going to be quite a problem.
Suppose text:

Hello, I'm Steffen from Hessen/Germany. My phone number is 555/12345.

This would consider "Germany. My phone number is 555" a file name. Also, why
do you want to use a file name in there in the first place? The server has
to manage its file names itself (base them on the localtime or an
incremented number for example) and the user has to select the file from his
hard drive anyway. So, something like [:picture:] would be more unique.
Then, having users upload images to the server of a www board is usually not
a good idea in itself. CGI.pm can limit the file size (if you tell it to!),
but assuming that you don't have a dedicated server with some gigs of space
to spare, your account might be full of old images rather soon.
Have you ever considered what'll happen if somebody uploads an image of
humongeous proportions that'll blow your web site's design? You don't want
to check the size of each and every image using Image::Magick, do you?
When done badly, file uploads can be quite a security hazard, so I'd suggest
(if you really need images in there) you offer a syntax like this:
[picture:URL] where URL is the URL of some image on the web. Do not allow
HTML constructs in your board, it'll blow. Let your script parse those
[picture:URL] thingies and relpace it with '<img src="URL" alt="Picture">'.
If you're paranoid, you could check whether the URL points at an image using
LWP.
You might be able to replace those commands with the following regex: (in a
single line)
s/\[picture:(http:\/\/.+)\]/<img src=\"$1\" alt=\"Picture\">/g
It's simple minded, untested, and not guaranteed to work.
The CGI.pm module will help you with the file uploads if you still want
them. Read the security considerations in the docs of the module.

HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;print"\n";$o=$_;push@o,substr($o,$_*8,
8)for(0..24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\n";$i++}#st_m





------------------------------

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 2129
***************************************


home help back first fref pref prev next nref lref last post