[11893] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5493 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 27 02:46:26 1999

Date: Mon, 26 Apr 99 22:00:20 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 26 Apr 1999     Volume: 8 Number: 5493

Today's topics:
    Re: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex( <mpersico@erols.com>
    Re: autoincrement magic a..z (Abigail)
    Re: autoincrement magic a..z (Abigail)
    Re: autoincrement magic a..z bgilbert@sgi.com
    Re: cgi development (Abigail)
    Re: cgi script (Abigail)
    Re: cgi script (Abigail)
    Re: Count the number of files in a dir. (Ronald J Kimball)
    Re: Country of a visitor (Abigail)
    Re: Delete line (Abigail)
    Re: Eliminate elements from array with second array? (Abigail)
    Re: Fork goddamit! Fork! (Abigail)
    Re: Help with Code (Abigail)
        HELP! can script use file w/o exposing it? pkuhar@my-dejanews.com
    Re: HELP! can script use file w/o exposing it? (Sam Holden)
    Re: Help! Error message when using C-comment stripper f ebatutis@my-dejanews.com
    Re: How do i print something using perl? (Ronald J Kimball)
    Re: I LOVE YOU!!!! <sergue@ica.net>
        Installing DBD-Pg-0.91 in RH 5.2 gcellis@my-dejanews.com
    Re: Is there Perl code to parse C++ programs? (Andrew Bromage)
        list of list <seugenio@man.amis.com>
        Newbie q: shopping cart w/o using cookies <emytang@411.uptown.com>
    Re: Newbie regex query (Ronald J Kimball)
    Re: pearl sdf spf (Thomas Arneberg)
    Re: problem with single quotes or abuse by programmer <wyzelli@yahoo.com>
    Re: question about guestbook <jglascoe@giss.nasa.gov>
    Re: Simple Question (John Moreno)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Mon, 26 Apr 1999 22:12:53 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
Message-Id: <37251D25.B1BDF4AC@erols.com>

Benjamin Franz wrote:
> 
> In article <3723BA06.76D121D@erols.com>,
> Matthew O. Persico <mpersico@erols.com> wrote:
> >Benjamin Franz wrote:
> >>
> >[snip]
> >> Nor do I. I find pulling a 150+Kbytes for a form decoder to be...excessive.
> >>
> >Um. what about AUTOLOAD? Doesn't that help? And isn't the package
> >AUTOLOADing?
> 
> bash>ls -lta CGI.pm
> -r--r--r--   1 root     root       190905 Apr  6 06:44 CGI.pm
> 
> Hmmm...It got *BIGGER* since the last time a year or so ago when I
> checked it. It is now pushing 190K.
> 
> Yes. It AUTOLOADs via a clever trick that accelerates its
> "time 'til running". Which is not to say you don't still
> pay substantially for it. In my test, it took about 0.20s
> CPU to load my posted Local::JCGI.pm and do nothing. It took
> 0.32s CPU to load CGI.pm and do nothing. And CGI.pm uses 200K
> more memory per process just to load - *before* anything gets
> AUTOLOADed by the calling program.
> 
> --
> Benjamin Franz

Well, that just goes to show you that programming is just
a series of orthogonal choices:

size vs speed vs ease of implementation/maintanence
-- 
Matthew O. Persico
http://www.erols.com/mpersico
http://www.digistar.com/bzip2


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

Date: 27 Apr 1999 02:53:42 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: autoincrement magic a..z
Message-Id: <7g38rm$ro3$2@client2.news.psi.net>

Yeoh Yiu (squid@panix.com) wrote on MMLXIV September MCMXCIII in
<URL:news:oxgg15n2jzp.fsf@panix.com>:
// 
// So I have done what I wanted, but I am puzzled as to why 
// 
// 	for ($i="a"; $i le "z"; $i++) {print "$i";}
// 
// doesn't print ouit a to z.


That's because "aa" is less then "z" ....

   	for ($i="a"; $i le "z"; $i++) {print "$i";}

will stop after printing "yz", as "yz" incremented yields "za", the first
one that isn't less or equal to "z".



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: 27 Apr 1999 02:56:55 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: autoincrement magic a..z
Message-Id: <7g391n$ro3$3@client2.news.psi.net>

Yeoh Yiu (squid@panix.com) wrote on MMLXIV September MCMXCIII in
<URL:news:oxgeml72duj.fsf@panix.com>:
() 
() Why does autoincrement magic applied to "z" return a value
() which is lexigraphically less that "z" ?

For the same reason '9' incremented returns a value which is
lexigraphically less than '9'. ++ and cmp are different orderings.

()                                          Does (autoincrement
() magic applied to characters) not live in legigraphical space ?


That's in the manual.


Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Tue, 27 Apr 1999 04:25:30 GMT
From: bgilbert@sgi.com
Subject: Re: autoincrement magic a..z
Message-Id: <7g3e7n$rqa$1@nnrp1.dejanews.com>

In article <x7btgaamgg.fsf@home.sysarch.com>,
  Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "TM" == Tad McClellan <tadmc@metronet.com> writes:

>   TM>    I think it lives in the "base 26 number system" space.
>
> not exactly, for then 'aa' would be gt 'z'. if it were a number system
> then the strings would be compared left to right with longer strings
> always gt shorter ones. there is no 'signifigant char concept with
> powers of the base being used in the compare. it is a pure left to right
> lexical compare.
>
>   TM>    Incrementing 'z' generates a carry.
>
> but in lexical space.

So in lexical space ... you can go up, but not down?

    for ($i="z"; $i gt "a"; $i--) {print "$i";}

doesn't work, $i-- generates -1 stopping the code next time around ...

Can someone help me understand how the increment works? Is it using ASCII
decimal codes ... and if so how come it can't do the reverse? Thanks.

Ben Gilbert                                     bgilbert(at)sgi.com
Technical Consultant, SGI          http://reality.sgi.com/bgilbert/
-------------------------------------------------------------------
Get out the time fracture wickets Hobbes! We're playing Calvinball!
-------------------------------------------------------------------

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 27 Apr 1999 02:59:06 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: cgi development
Message-Id: <7g395q$ro3$4@client2.news.psi.net>

exorcist1@my-dejanews.com (exorcist1@my-dejanews.com) wrote on MMLXIV
September MCMXCIII in <URL:news:7g2s6l$c4r$1@nnrp1.dejanews.com>:
-- Hello, i really have no experience in programming whatsoever. I'm am opening
-- up a website and i am looking for a programmer who has a good knowledge of
-- cgi who can work with it. Possible $$$ involved. e-mail me at snl1ve@aol.com


Only scalars? No aggregates? How boring....



Abigail
-- 
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'


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

Date: 27 Apr 1999 03:00:36 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: cgi script
Message-Id: <7g398k$ro3$5@client2.news.psi.net>

Gil Zigelman (zgil@cs.technion.ac.il) wrote on MMLXIV September MCMXCIII
in <URL:news:372420CD.B1915BC6@cs.technion.ac.il>:
:: 
:: I am writing a cgi script using perl.
:: In my script, I need to modify a file. The problem is that the script
:: doesn't modify the file unless I give full writing permissions to the
:: file, which is something I obviously to not want.
:: 
:: Does anyone know the correct way to do this?


That's a FAQ. From another group.

One way to solve this problem is using an OS that doesn't have
file permissions.


Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: 27 Apr 1999 03:02:57 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: cgi script
Message-Id: <7g39d1$ro3$6@client2.news.psi.net>

alainch (alain_chiorboli@email.sps.mot.com) wrote on MMLXIV September
MCMXCIII in <URL:news:37242D73.BE04D858@email.sps.mot.com>:
== If you are under unix you can try to set the setgid bit for your cgi
== script: chmod +s cgi_script_name


No, and no. You don't want to set the setgid bit, and you shouldn't
set it that way either.



Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


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

Date: Tue, 27 Apr 1999 00:10:14 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Count the number of files in a dir.
Message-Id: <1dqw6d4.ycablmrgznkwN@p0.block2.tc4.state.ma.tiac.com>

stevenabell <stevenabell@hotmail.com> wrote:

> 1. Is it possible in Perl to count the number of files in a directory
> and assign that to a variable? Because the files are situated in a 
> UNIX directory, I did think of doing something like:

Perhaps

opendir(DIR, '/mydir') or die "Can't open /mydir: $!\n";
$count = @files = readdir(DIR);
closedir(DIR);

or

chdir('/mydir') or die "Can't chdir to /mydir: $!\n";
$count = @files = glob('*');
# I use chdir() so that the examples below will be consistent


> 2. I have a number of files which I must perform a UNIX function on.
> Well, in fact it's a Shell application, called "stoplist". What I need
> to do is apply "stoplist" to each document and then place the treated
> documents in another directory. The original number of files to be
> treated will always vary, but will always be grouped together in the 
> same directory. So for example, if we have the following files:
> 
> /mydir/file1
> /mydir/file2
> /mydir/file3
> 
> I want to apply "stoplist" to them so that I have:
> 
> /stopped/file1.stop
> /stopped/file2.stop
> /stopped/file3.stop

foreach $file (@files) {
  system("stoplist /mydir/$file") and die "stoplist failed: $?\n";
  rename("/mydir/$file", "/stopped/$file.stop")
    or die "Can't rename $file: $!\n";
}


> 
> 3. Because each file is going to have a different directory structure,
> ie - we could have the following:
> 
> /stopped/chair/table/file1.stop
> /stopped/chair/file2.stop
> /stopped/chair/table/file3.stop
> 
> what I need to do is rename each file according to the length of its
> path, so that they are renamed as follows:
> 
> file2.stop     ->      doc1
> file1.stop     ->      doc2
> file3.stop     ->      doc3
> 
> where "doc1", "doc2" etc are written to another unique directory.

Sorry, I don't follow that one...  Do you want to process the files in
order by path length?  You could sort the array by number of directory
separators.


> 4. I have a Perl script set up to reply to a form (written in HTML),
> but when the script generates the results of the form back to the
> user, it continues to search for something else, thereby forcing the
> user to click on "Stop" in the browser (followed by "Transfer
> Interrupted"). Simplified, the script looks something like:
> 
> if {$var eq "red"}
>    &return;
>    exit;
>    else {$var eq "blue"}
>    exit;

That is not even close to being legal Perl.  If your script "looks
something like" that, then my solution looks something like this: "You
have a bug on line 17."

> sub return
> {
> print "<HTML>......"
> }
> 
> Even though I have the "exit"s in the script, when it generates the
> results it still doesn't bomb out.
> 
> 
> Like I said, if the answers to any of these are in the FAQs, then
> please accept my apologies. Any replies / solutions would make it a
> lot easier to sleep at night!

When you want debugging help, copy and paste the actual code, don't
retype something that looks like it.


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
perl -e '$_="\012534`!./4(%2`\cp%2,`(!#+%2j";s/./"\"\\c$&\""/gees;print'


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

Date: 27 Apr 1999 02:01:36 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Country of a visitor
Message-Id: <7g35q0$rl8$1@client2.news.psi.net>

Michael Stillwell (mist@yoyo.cc.monash.edu.au) wrote on MMLXIV September
MCMXCIII in <URL:news:slrn7i86pf.f6i.mist@fangorn.cs.monash.edu.au>:
`` On 26 Apr 1999 01:51:16 GMT, Abigail <abigail@fnx.com> wrote:
`` : selectthree (selectthree@gsig-net.qc.ca) wrote on MMLXII September
`` : MCMXCIII in <URL:news:37222417.3253@gsig-net.qc.ca>:
`` : ## Does anyone know the code to determine the origin country of a visitor
`` : ## (or only it's code, like .com, .ca, .uk, .fr...)?
`` : 
`` : 
`` : You can't.
`` : 
`` : You can of course do a 'gethostbyaddr', but there's nothing that
`` : prevents someone from using 'foo.bar.com', 'foo.bar.ca', 'foo.bar.uk'
`` : and 'foo.bar.fr' as names for the same host.
`` : 
`` : Not to mention that .com, .org and .net are everywhere. And do you 
`` : really thing those .to hosts domains are all located on an island?
`` : 
`` : And what are you going to do with a "visitor" from country A, that
`` : uses a proxy in country B?
`` 
`` In your opinion, what proportion of hosts misrepresent their location?
`` Is this proportion worth worrying about?  
`` 
`` It's nice to have a rough idea of where your visitors are coming from
`` (in the case of a web site).  What's the chance of your figures being
`` more than 15% wrong?  (And I think that the actual error is much less

Just consider the number of .com, .org and .net hosts out there, that
aren't giving you _any_ information at all.


`` than that.)  Sometimes, near enough is good enough, and better than no
`` estimate at all.  (Does your editor do syntax highlighting of perl
`` code?)

Of course not. You'd think I'd like to code in a Christmas tree?


Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: 27 Apr 1999 02:18:36 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Delete line
Message-Id: <7g36ps$rl8$3@client2.news.psi.net>

cryptoman@my-dejanews.com (cryptoman@my-dejanews.com) wrote on MMLXIV
September MCMXCIII in <URL:news:7g28e0$p1k$1@nnrp1.dejanews.com>:
~~ Hi,
~~ 
~~ There is anyone can tell me which function should I use to delete a line in a
~~ text's file. I looked at CPAN and in the Perl CookBook but it doesn't help.


open(), <> and print.


This is a FAQ.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 27 Apr 1999 03:04:53 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Eliminate elements from array with second array?
Message-Id: <7g39gl$ro3$7@client2.news.psi.net>

lou@visca.com (lou@visca.com) wrote on MMLXIV September MCMXCIII in
<URL:news:7g2ku8$57l$1@nnrp1.dejanews.com>:
{} My question concerns finding the best way to eliminate elements from an array
{} if they contain any of a list of strings from another array. Here's the


FAQ.


Abigail
-- 
perl -wlne '}{print$.' file  # Count the number of lines.


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

Date: 27 Apr 1999 02:41:59 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Fork goddamit! Fork!
Message-Id: <7g385n$ro3$1@client2.news.psi.net>

scraig@my-dejanews.com (scraig@my-dejanews.com) wrote on MMLXIV September
MCMXCIII in <URL:news:7g2cg2$t00$1@nnrp1.dejanews.com>:
&& 
&&     The browser could be having a problem with the lack of html tags.
&& Specifically, </html>.


You're just guessing. Popular-browser authors don't know valid HTML even
if you slam it right in their face anyway. They are doing tag soup, and
they don't care about *optional* closing tags not being there.



Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: 27 Apr 1999 02:12:11 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Help with Code
Message-Id: <7g36dr$rl8$2@client2.news.psi.net>

Larry Rosler (lr@hpl.hp.com) wrote on MMLXIV September MCMXCIII in
<URL:news:MPG.118d86fa9273804a98993f@nntp.hpl.hp.com>:
[] In article <7g0hiv$ntk$9@client2.news.psi.net> on 26 Apr 1999 02:04:15 
[] GMT, Abigail <abigail@fnx.com> says...
[] > 
[] > Use s///. Or, to please Larry (no, not him, the other one), y///.
[] 
[] Larry (the other one) would be pleased too, I'm sure.  But I responded 


Really? If I were Larry W, I'd be very displeased there was a significant
difference in efficiency between removing a character with tr/// and
removing a character with s///g. Perl should detect they do the same, and
hence generate the same code.


Abigail
-- 
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
 .qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
 .qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'


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

Date: Tue, 27 Apr 1999 04:16:27 GMT
From: pkuhar@my-dejanews.com
Subject: HELP! can script use file w/o exposing it?
Message-Id: <7g3dmo$rce$1@nnrp1.dejanews.com>

Please help!

I have a data file (passwords.dat) which a perl script (getthem.cgi) opens,
reads into a variable called @passwords, and then closes. @passwords is
then printed. (This is just a test script so I know how to write a
useful one I am planning to write).

However, I can't figure out how to get this done WITHOUT making passwords.dat
vulnerable to the "world" viewing it!

My failing attempt to do this was as follows: I created passwords.dat with
getthem.cgi and set passwords.dat's chmod to 0700, also with getthem.cgi. 
The hope was that getthem.cgi would be considered password.dat's "owner" and
that only getthem.cgi would be able to read, write and execute password.dat,
as I want. BUT when I did this, getthem.cgi fails to read the data! printing
@passwords displays nothing!

So my other attempt was to set chmod of passwords.dat to 0777 just before
reading the data, and then resetting it to 0700 after finished. But I found
that passwords.dat was vulnerable to the "world" WHILE the perl script was
running.

What should I do? I own Perl for Dummies but it only has 2 paragraphs on chmod
and I don't know what else to do.

Thank you very much for any advice
Patrick

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 27 Apr 1999 04:44:06 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: HELP! can script use file w/o exposing it?
Message-Id: <slrn7iag4m.r6m.sholden@pgrad.cs.usyd.edu.au>

On Tue, 27 Apr 1999 04:16:27 GMT, pkuhar@my-dejanews.com wrote:
>Please help!
>
>I have a data file (passwords.dat) which a perl script (getthem.cgi) opens,
>reads into a variable called @passwords, and then closes. @passwords is
>then printed. (This is just a test script so I know how to write a
>useful one I am planning to write).
>
>However, I can't figure out how to get this done WITHOUT making passwords.dat
>vulnerable to the "world" viewing it!
>
>My failing attempt to do this was as follows: I created passwords.dat with
>getthem.cgi and set passwords.dat's chmod to 0700, also with getthem.cgi. 
>The hope was that getthem.cgi would be considered password.dat's "owner" and
>that only getthem.cgi would be able to read, write and execute password.dat,
>as I want. BUT when I did this, getthem.cgi fails to read the data! printing
>@passwords displays nothing!

The owner of the file and the 'owner' of the process are different concepts.
One solution would be to make the perl script suid. That opens up a some
security concerns and would require very careful authoring of the script.
It's a possible solution though. 

If you are just storing passwords that you don't want people to see, then you
are better off storing them in an encrypted form. Perl has a function called
crypt that might be useful for doing that (see perldoc -f crypt). The key
bit of information is that you never actually decrypt the encrypted the 
password, instead you encrypt the user supplied password and see if the
encrypted strings are the same - that way it doesn't have to be possible to
decrypt them in the first place which means having the file world readable
isn't a problem (except for brute force attacks, or bad passwords...).

>
>So my other attempt was to set chmod of passwords.dat to 0777 just before
>reading the data, and then resetting it to 0700 after finished. But I found
>that passwords.dat was vulnerable to the "world" WHILE the perl script was
>running.
>
>What should I do? I own Perl for Dummies but it only has 2 paragraphs on chmod
>and I don't know what else to do.

You have access to the perl documentation since it comes with perl...

chmod is not the solution to your problem. The solution is to find a way in 
which having the file readable is not a problem (or to use suid and all the
security concerns that go with it)...

-- 
Sam

In case you hadn't noticed, Perl is not big on originality.
	--Larry Wall


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

Date: Tue, 27 Apr 1999 03:27:07 GMT
From: ebatutis@my-dejanews.com
Subject: Re: Help! Error message when using C-comment stripper from perlfaq
Message-Id: <7g3aq7$ot2$1@nnrp1.dejanews.com>



I found another problem with the C-comment stripper from the faq:

s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\\])*"|'(\\.|[^'\\])*'|\n+|.[^/"'\\]*)#
$2#g;

With my perl (Win32 ActiveState version 5.005_03 build 515 - the latest),
perl takes a exception and dies on certain files with the above program.

I've determined that this happens when there are unbalanced single or
double quotes followed by a fair amount of text followed by the end of file.

So, this file will crash my perl given the above program:

--start input
// don't delay!
xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx xxxx
<repeat previous line a hundred times or so>
--end of input

The "xxx" isn't important, it can be any text, or even whitespace, that
doesn't contain any of the important characters in the expression.

The other thing this program doesn't handle properly is continuation
characters in strings. So this input:

---input start
one
" hi there\
/* not a comment! */\
end of string"
two
/* this is a comment! */
three
---input end

gives me this output:

---output start
one
" hi there\
\
end of string"
two

three
---output end

I'm not sure I understand the expression completely, but it seems to me that
it stops looking for an end quote when it hits a backslash. So, it doesn't
support continuations inside quoted strings or characters on purpose. That's
OK with me. I rarely see that in code written by experienced programmers.

If I wanted it to support continuations I would change

"(\\.|[^"\\])*"

to

"(\\.|\\\n|[^"])*"

This allows continuations to work, but I still have a crash.

But, I can fix my crash and not disable any features of the original program
by adding the newline to the list of things that is not allowed to appear in
a quoted thing:

s#/\*[^*]*\*+([^/*][^*]*\*+)*/|("(\\.|[^"\n\\])*"|'(\\.|[^'\n\\])*'|\n+|.[^/"'\\
]*)#defined $2 && $2#ge;

I've adapted the above for the simpler C++ comment case. The following seems
to work pretty well:

s#//[^\n]*|("(\\.|[^"\n\\])*"|'(\\.|[^'\n\\])*'|\n+|.[^/"'\\]*)#defined $2 &&
$2#ge;

No doubt there's a better solution. Anyone?

(Thanks Larry R. for the "defined $2 && $2" thing - you win for shortest
alternative. I was hoping for something like $"2 or somesuch mystical
notation, but what the heck!)


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Tue, 27 Apr 1999 00:10:16 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: How do i print something using perl?
Message-Id: <1dqw7lt.1ghmb161unbfcwN@p0.block2.tc4.state.ma.tiac.com>

Scratchie <upsetter@ziplink.net> wrote:

> Tom Christiansen <tchrist@mox.perl.com> wrote:
> : Ilya, please go soak your head.  Why do we have to listen to 
> : your ranting about why OS/2 is a Gift from God?  I am tired
> : of it.  You still don't get it, and never will, and won't shut up.
> 
> I hope I'm not the only one who sees the irony in this message.

No, you're not.

In fact, there's probably only one who doesn't.

-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Mon, 26 Apr 1999 22:20:25 -0700
From: serguei <sergue@ica.net>
Subject: Re: I LOVE YOU!!!!
Message-Id: <37254919.AB42AA0@ica.net>

I'd like to apologise for my subject line.
I understood my fault.
Matt
Thanks for your help.

Serguei
***********************************************

Matt Sergeant wrote:

> serguei wrote:
> >
> > Hi everybody
> >
> > CGI.pm modul does not  support  the HTTP-EQUIL type of <META> tag
> > How can I modify the HTTP header directly with meta tag
> > <meta http-equiv="Content-Type content ="text/html;
> > charset=windows-1251">
> >
> > My version is like this, but it does not work
> > print $query->header;
> > print $query->start_html(-title=>'Catalog page',
> >                                      -meta=>{'charset'=>'windows-1251',
> >
> > 'Content-Type'=>'text/html'});
> >
> > Can somebody give me suggestion about it
>
> First off, please don't use such ridiculous subject lines. We're
> supposed to be perl proffesionals, and you're less likely to get help
> that way.
>
> Try:
>
> print $query->header(-type => 'text/html; charset=windows-1251');
>
> which does exactly what you want, and is safer/better than using a meta
> tag.
>
> --
> <Matt email="msergeant@ndirect.co.uk" />
>
> | Fastnet Software Ltd              |   Perl in Active Server Pages   |
> | Perl Consultancy, Web Development |   Database Design   |    XML    |
> | http://come.to/fastnet            |    Information Consolidation    |





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

Date: Tue, 27 Apr 1999 03:12:58 GMT
From: gcellis@my-dejanews.com
Subject: Installing DBD-Pg-0.91 in RH 5.2
Message-Id: <7g39vn$o8r$1@nnrp1.dejanews.com>

I am linux newbie (4 months but I have done quite a lot of reading) trying to
install DBD-Pg 0.91 on a RH5.2 systen with DBI 1.06 and Perl
5.004.04 with postgresql 6.4.2. I installed postgresql 6.4.2 using RPMs.
Postgresql is properly installed as I am able to create and maintain databases
and tables using psql. I get the following:

output from 'perl Makefile.PL'

Configuring Pg
Remember to actually read the README file !
$POSTGRES_HOME not defined. Searching for PostgreSQL...
Found PostgreSQL in
Writing Makefile for DBD::Pg

******

output from 'make'

cc -c -I/include -I/usr/local/include/pgsql -I/usr/include/pgsql
-I/usr/lib/perl 5/site_perl/i386-linux/auto/DBI
-I/usr/lib/perl5/i386-linux/5.00404/DBI -I/auto/ DBI -I/DBI -Dbool=char
-DHAS_BOOL -I/usr/local/include -O2  -DVERSION=\"0.91\" 
-DXS_VERSION=\"0.91\" -fpic -I/usr/lib/perl5/i386-linux/5.00404/CORE  Pg.c In
file included from Pg.xs:13: Pg.h:13: libpq-fe.h: No such file or directory
make: *** [Pg.o] Error 1

******

I am hoping somebody has done this or seen it before and will be able to help
me. I have been trying to do this for the last 4 days, including all weekend
and I am desperate.

TIA

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 27 Apr 1999 02:59:59 GMT
From: bromage@cs.mu.oz.au (Andrew Bromage)
Subject: Re: Is there Perl code to parse C++ programs?
Message-Id: <7g397f$i36$1@mulga.cs.mu.OZ.AU>

G'day all.

"Matthew Blais" <matt'@'exotech.com> writes:

>Is there Perl code available to parse C++ programs?  Or, where would I find
>the C++ grammar to use with yacc?

To answer your first question: I don't know.

To answer your second question: C++ grammar is nowhere near LR(1).  There
are whole companies who only produce C++ parsers for a living.  Yacc doesn't
cut it.

Cheers,
Andrew Bromage


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

Date: Tue, 27 Apr 1999 04:34:11 GMT
From: "Sheila  Eugenio" <seugenio@man.amis.com>
Subject: list of list
Message-Id: <01be9067$1bec8830$2bbe10ac@amipnet>

Hi everyone!
	I have a list of list as a result of fetchall_arrayref fetch  in DBI. My
problem is I want to compute the average (1st col) and sum(2nd col)  of
every 2 rows.  Ex.
@array = (
	     ["34668", "637299"],
	     ["67290", "620574"],
	     [ "97331", "620574"],
	     ["102327", "564416"],
	     ) 
	I already have a script but my looping doesn't work the way I want it. It
computed for the sum & avg of all 4 rows. I know there's an easier and
better way to do it. Thanks for all the help!



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

Date: Tue, 27 Apr 1999 12:17:24 +0800
From: emytang <emytang@411.uptown.com>
Subject: Newbie q: shopping cart w/o using cookies
Message-Id: <37253A54.82339AA0@411.uptown.com>


--------------852C9AEB9535BE8A29D137EF
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

I want to develop a shopping cart without using cookies. How can I store
the user's info so as to remember what clients have been selected?

TIA
Emy


--------------852C9AEB9535BE8A29D137EF
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<FONT SIZE=-1>Hi,</FONT><FONT SIZE=-1></FONT>
<P><FONT SIZE=-1>I want to develop a shopping cart without using cookies.
How can I store the user's info so as to remember what clients have been
selected?</FONT><FONT SIZE=-1></FONT>
<P><FONT SIZE=-1>TIA</FONT>
<BR><FONT SIZE=-1>Emy</FONT>
<BR><FONT SIZE=-1></FONT>&nbsp;</HTML>

--------------852C9AEB9535BE8A29D137EF--



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

Date: Tue, 27 Apr 1999 00:10:17 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: Newbie regex query
Message-Id: <1dqw7ur.1avb7e43rxypoN@p0.block2.tc4.state.ma.tiac.com>

Jonathan Stowe <gellyfish@gellyfish.com> wrote:

> David Cantrell <NukeEmUp@ThePentagon.com> wrote:
> > On Sat, 24 Apr 1999 08:00:15 -0400, tadmc@metronet.com (Tad McClellan)
> > enlightened us thusly:
> > 
> >>Andy Elvey (andyelv@ibm.net) wrote:
> >>
> >>: !#/usr/bin/perl
> >>  ^^
> >>  ^^ transposed
> >>
> >>   Something tells me that we are not looking at the code
> >>   that you are looking at.
> > 
> > If he's using a MS platform the shebang isn't necessary, so this could
> > well be real code.
> > 
> 
> Its still wrong though only a warning (with -w):
> 
>    Useless use of not in void context at blah.pl line 3.

That depends on the next line of code...

At least twice posters here have complained about the following problem:

~> perl
!#/usr/local/bin/perl
$foo = $bar;
__END__
Can't modify not in scalar assignment at - line 2, near "$bar;"


-- 
 _ / '  _      /       - aka -
( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
    /                                http://www.tiac.net/users/chipmunk/
      "Remember, Perl doesn't write bad programs; programmers do."


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

Date: 27 Apr 1999 02:48:28 GMT
From: toma@cray.com (Thomas Arneberg)
Subject: Re: pearl sdf spf
Message-Id: <7g38hs$2ga$1@walter-fddi.cray.com>

In article <3724A297.AB942A11@halcyon.com> Grant Erwin <grant_erwinREMOVETHIS@halcyon.com> writes:
>Thomas Arneberg wrote:
> 
>> Wow...I thought "surely, this newbie must be mistaken.  There's no way a
>> CAD company would name a product 'Pearl'!  Must be a typo."
>
>The name "Pearl" predated "Perl" coming into common usage. It was
>named at a university. Cadence bought the tool and hired its
>development team. I'm sure they considered changing the name but
>the name already had become known, and brand name familiarity
>costs money ..

Oh.  Shows what I know.   I guess I feel a little better that it wasn't
some cheap ploy to leverage off the name of an existing computer
language.

Still, my vote would've been to change the name...

  - Tom A.
--------------------------------------------+---------------------
;-) I'd rather be ____  Thomas R. Arneberg  | Only 384 more days 
:-) singing in a |____| toma@arneberg.com   |   until my sabbatical!
:-) Barbershop  _|   _| sqi/Cray IC Design  | (But who's counting?)
:-) Quartet!   (_)  (_) Chippewa Falls, WI  | http://arneberg.com 
--------------------------------------------+---------------------


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

Date: Tue, 27 Apr 1999 11:45:46 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: problem with single quotes or abuse by programmer
Message-Id: <m59V2.3$TQ2.3418@vic.nntp.telstra.net>

It would seem to me that maximum portability would be achieved by \\ rather
than / as those of us with 'dain-bread' systems wouldn't have a helluva time
re-writing scripts to make them work.  Naturally you are forced into \'
anyway...
:^)

Wyzelli

Larry Rosler wrote in message ...
>[Posted and a courtesy copy sent.]
>
>In article <37250AF5.5DA010B6@dataflo.net> on Mon, 26 Apr 1999 19:55:17
>-0500, fire@dataflo.net <fire@dataflo.net> says...
>> This version of code fails......???
>> BEGIN {
>>      push(@INC, 'C:\inetpub\wwwroot\mck-shared\');
>>      push(@INC, 'C:\inetpub\wwwroot\test-mck\mck-cgi\');
>> }
>>
>> This version of code works....
>>
>> BEGIN {
>>      push(@INC, 'C:\inetpub\wwwroot\mck-shared');
>>      push(@INC, 'C:\inetpub\wwwroot\test-mck\mck-cgi');
>> }
>>
>> Aren't single quotes supposed to be SACRED?
>>
>> The error messages make it very clear to me that the \ before the '
>> causes it to not be interpreted as a single quote paired with previous
one.
>> Is this because it is in pre compile stage?
>
>No.  I don't know what you mean by 'pre compile stage".
>
>It is because \' is how one writes a single-quote inside a single-quoted
>string.  Read the following from perldata:
>
>"String literals are usually delimited by either single or double
>quotes. They work much like shell quotes: double-quoted string literals
>are subject to backslash and variable substitution; single-quoted
>strings are not (except for \' and \\ )."
>
>So if you want to end your string with a backslash, use two of them.
>But why not just use forward slashes in the first place?  It seems to be
>one of the best-kept of the many secrets of PoBdom that except for the
>dain-bread so-called command interpreters, forward slashes work fine.
>
>--
>(Just Another Larry) Rosler
>Hewlett-Packard Company
>http://www.hpl.hp.com/personal/Larry_Rosler/
>lr@hpl.hp.com




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

Date: Mon, 26 Apr 1999 15:18:32 -0400
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: "S.L. de Vries" <devries-devries@wxs.nl>
Subject: Re: question about guestbook
Message-Id: <3724BC08.5AC92457@giss.nasa.gov>

[posted and cc'd]

hi Sjoerd,

I'm afraid the typical answer to your typical question is:
"the error is on line 17"
Line 17 is the "13th floor" of Perl programs.  ;^)

But seriously, how can anyone tell what the problem is unless
you post the code.  But *please* don't post the entire program.
Instead, try to reduce the problem to its essence, maybe a
few lines of code.  If you do that, I guarantee you'll get tons
of answers.


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

Date: Mon, 26 Apr 1999 23:57:10 -0400
From: planb@newsreaders.com (John Moreno)
Subject: Re: Simple Question
Message-Id: <1dqw7c6.1hckp0ppm5af7N@roxboro0-0029.dyn.interpath.net>

Tad McClellan <tadmc@metronet.com> wrote:

> John Moreno (planb@newsreaders.com) wrote:
> : Jason Simms <ffchopin@worldnet.att.net> wrote:
> 
> : > Shashank Tripathi <mkshanx@ust.hk> wrote in message
> : > news:7g0ngo$620@ustsu10.ust.hk...
> : > > Is there a way to scour through every file in a specified directory
> : > > on my computer thru perl?
> : > 
> : > Sure...  Use the File::Find module that comes standard with Perl.
> : > Read the
> 
> : How about doing the same thing on a remote computer?
> 
>    Sure.
> 
>    But we (actually you) would need to know what protocols the
>    "remote computer" understands.
> 
>    Got some particular protocol in mind?

telnet and ftp.

-- 
John Moreno


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5493
**************************************

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