[19268] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1463 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 8 09:10:31 2001

Date: Wed, 8 Aug 2001 06:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997276215-v10-i1463@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 8 Aug 2001     Volume: 10 Number: 1463

Today's topics:
    Re: Matching Strings in an array (Yves Orton)
    Re: multiple line comments? <godoy@conectiva.com>
    Re: Pattern Matching: Which subpattern (rather than sub (Anno Siegel)
        Perl & Cookies <Jeff@aetherweb.co.uk>
    Re: Perl editor for win32 needed <paul@net366.com>
        Perl PGP routines <Jeff@aetherweb.co.uk>
    Re: Perl PGP routines <tom@leitchy.com>
    Re: perldoc is like Greek to a beginner?? <joeblowing@sPaMmail.com>
    Re: perldoc is like Greek to a beginner?? <john.imrie@pa.press.net>
    Re: Re: Perl editor for win32 needed <somewhere@in.paradise.net>
    Re: Reporting Questionable Programming Activity (Mario Rizzuti)
    Re: String manipulation <krahnj@acm.org>
    Re: String manipulation <paul@net366.com>
    Re: String version of += assignment operator?? (Anno Siegel)
    Re: String version of += assignment operator?? <bart.lateur@skynet.be>
    Re: Using a http proxy <dperham@dperham.eng.tvol.net>
    Re: Where are those !'s coming from? <simon.andrews@bbsrc.ac.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 8 Aug 2001 05:59:21 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Matching Strings in an array
Message-Id: <74f348f7.0108080459.30d90616@posting.google.com>

"Andrew Hamm" <ahamm@sanderson.net.au> wrote in message news:<3b7094b4@news.iprimus.com.au>...
> Yves Orton wrote in message
> <74f348f7.0108070017.2998174@posting.google.com>...
> But having said that, I only reduce parens on what I call command-style
> lines: lines which do open, push, pop or simple shifts into vars etc. When a
> line contains a full-on piece of maths-style code, precedence gets nasty and
> it's time to USE parens for clarity. You'd never find me calling tan or cos
> without parens (actually, in this job, you'd never find me calling tan or
> cos ;-)

Hmm, I more or less go with this one.  Aesthetics sometimes are a
consieration though.

> 
> >Mostly I end up doing things like (credit Tom Christiansen)
> >
> >return (@_) ? ($self->{param}=shift,$self)
> >            : $self->{param};
> >
> 
> With all due respect to TC (and there's bucket-loads of that) I'm not
> impressed with that style of coding. I stopped enjoying reading my genius
> code fragments several years ago. Or more correctly, several years ago I
> realised that even my genius code was unreadable 6 months after I wrote it,
> no matter how compact and clever it seemed at the time. And considering I
> cut my programming teeth on a language called APL, if you know that language
> you will indeed know that my early code was from outer space.

Yes I remember seeing one of friends fathers doing APL on a line
terminal.  He had a great printout on the wall:Torture the Data long
enough it will confess to anything. (He's a prof of statistics)

> 
> I think that line is heaps clearer expressed as:
> 
> $self->{param} = shift if @_;
> return $self->{param};
> 
> or
> 
> @_ and $self->{param} = shift;
> return $self->{param};
> 
> What's the difference? In opcodes, probably nothing or damn little. There's
> still just one conditional. Two references to $self->{param}. Which form is
> easier for a beginner to read? Or even an advanced programmer? I had to
> study your sample for 30 seconds to confirm my gut-feeling about it. 30
> seconds doesn't sound like much, but it sure adds up and each moment of
> thought fries another brain cell for the day.

I think perhaps your have proved your point too well.  TC's method
code actually translates to:

if (@_) {
     $self->{param}=shift;
     return $self;
} else { 
     return $self->{param};
}

And while I agree with your point, I have to admit that the other is
sooo much easier to type.

> I don't think you could have the same problem with my suggestion. The sample
> you give would be something you'd learn to recognise in a blink if you wrote
> it 1000 times, but what about someone who's never seen it before? A whole
> script full of such cleverness just fills me with the heebee-geebees
> (cousins of the Bee Gees, only they sound even worse)

Oops, maybe I should rewrite some of my modules. ;-)  No really, i
think the key is that the key is commenting.  One or two clear
comments strategically placed can make the most magical of notation
clean and clear.

SNIP

> Then it dawned on me one day - well, that's saving 2 physical lines in the
> source code, and it sure is simple. Even in C
> 
> x = b;
> if(a > b) x = a;

I can see the point you are making, although in this instance I would
only do such a thing if b indeed was the 'common' value. On the other
hand I recently got into a bit of a debate with a colleague about
enormous nested and layered ifs. Like so

if ($file_open) {
   #code;
   if ($file_type_correct) {
       #code
       if ($data_type_correct) {
           #code
           if ($dbi_updated) {
                #Do something
                return $something;
           } 
        }
    }
}
return undef;
                
I changed it something like this

return undef unless $file_open;
#code;
return undef unless $file_type_correct;
#code;
return undef unless $data_type_correct;
#code;
return undef unless $dbi_updated;
return $something;

When the code is complicated its the kind of change that makes code go
from convoluted to straightforward.

> A good algorithm will sh!t on a bad one, no matter how many clever
> instant-optimisations have been put into the individual lines. Take a bad
> algorithm containing cleverness, replace it with a good algorithm containing
> simplicity and clarity, and you'll achieve an optimisation that's in the
> order of big numbers, not just a few percent. That's MY kind of
> optimisation - Yeah Baby!

Agreed.

> I'm not sure that understanding obsfucated code would really help your
> programming. Compact and elegant is far different from compact and obscure.
> Which are both different from plain old dense and obscure.

Not my programing, but perhaps my perl.  Some of that stuff uses some
prettty neat concepts.

Yves


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

Date: Wed, 08 Aug 2001 09:50:00 -0300
From: Jorge Godoy <godoy@conectiva.com>
Subject: Re: multiple line comments?
Message-Id: <m3n15a3edj.fsf@dagon.conectiva>

"David Allen" <mda@idatar.com> writes:

> This isn't always great, because actually I prefer commenting by inserting
> "# " and not just "#" but it works great.

You can always change the 'comment-start' using some hook. ;-)


-- 
Godoy. <godoy@conectiva.com>

Solutions Developer       - Conectiva Inc. - http://www.conectiva.com
Desenvolvedor de Soluções - Conectiva S.A. - http://www.conectiva.com.br


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

Date: 8 Aug 2001 12:14:05 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was matched?
Message-Id: <9kraed$adv$1@mamenchi.zrz.TU-Berlin.DE>

According to Simon Best  <barsticus@earthling.net>:
> 
> Hello!
> 
> I'm new here.  But anyway...
> 
> Here's what I want to do.  I want to find out which subpattern in a
> regular expression was the one that matched the matched string, if there
> was a match.  But I don't mean backreferences as such, like $1, $2, etc,
> 'cause they're the matched substrings, not the subpatterns that those
> substrings matched.
> 
> For example, I could have:
> 
> 	$STRING =~ m/($SUBPATTERN1)|($SUBPATTERN2)|($SUBPATTERN3)/;
> 
> and, if $STRING eq "Blah blah blah $SOMETHING_MATCHING_SUBPATTERN2 blah
> blah.", I'd want to know that it was $SUBPATTERN2 that matched.  I'd
> like something like backreferences, but where it's $SUBPATTERN2 that's
> given, not $SOMETHING_MATCHING_SUBPATTERN2.

[...]

Last(?) time this subject came up, Abigail suggested using code
subpatterns to identify various parts of a regex.  It didn't work
then because of a scoping bug, but with 5.6.1 the bug is gone.
So let me re-submit it[1]:

    my $id;
    my $pat = qr/(?:aaa(?{ $id = 1})) # set $id to 1 if "aaa" matches
                 |                    # or
                 (?:bbb(?{ $id = 2})) # set $id to 2 for "bbb"
                 |                    # or
                 (?:ccc(?{ $id = 3})) # set it to 3 for "ccc"
             /x;

    my $str = 'cccxxxaaayyyzzz';
    $str =~ $pat;
    print "id: $id\n";

The bit of Perl code in each "(?{ ...})" is executed whenever the
pattern in front of it matches, so each alternative leaves its
mark in $id.

Since this kind of code interpolation doesn't interfere with the
matching of the regex in any way, it is quite universal and can
be used to identify parts of a regex anywhere.  It doesn't make
the regex more readable.  Well, it isn't free lunch...

Anno

[1] Any errors in the implementation are mine.


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

Date: Wed, 8 Aug 2001 13:30:59 +0100
From: "Jeff Snoxell" <Jeff@aetherweb.co.uk>
Subject: Perl & Cookies
Message-Id: <9krbfb$sol$1@neptunium.btinternet.com>

Hi,

How can I use perl/cgi to get and set cookies (all from one domain name)
which can be read from various pages within my domain. I've read, in the
unofficial cookie FAQ here...http://www.cookiecentral.com/faq/#3.2, that
cookies are stored on a per document basis, and only that document can
access the cookie again.... but it also says that to test if a client can
access cookies, I should set a cookie on one page, and test it on another.

I want to keep track of a user while they're at my site, regardless of the
page.

Any ideas?

Thanks in advance,

--
Jeff Snoxell B.Sc.
Technical Director - Aetherweb Ltd (York)
+44 (0) 1904 656334
+44 (0) 7957 257391

http://www.aetherweb.co.uk




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

Date: Wed, 8 Aug 2001 13:28:21 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: Perl editor for win32 needed
Message-Id: <997273624.26878.0.nnrp-01.d4f094e4@news.demon.co.uk>

I have bought ($49 I think) and really like DzSoft's Perl Editor. I haven't
tried any others, but I used this for 10 minutes and sent my VISA number. I
expect  it will get better, but it DOES instant run/test and things, lets
you set up CGI variables for POST/GET. You can get a trial off the www.

The help file is not very good, and the redisplay at end of page is a bit
sloppy, but apart from that I recommend it.

HTH

"Nikolas Garofil" <nikolas_garofil@hotmail.com> wrote in message
news:h7Pb7.423$gX2.65578@afrodite.telenet-ops.be...
> What is the best editor to write perl scripts in Windows 98
>
>




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

Date: Wed, 8 Aug 2001 13:32:09 +0100
From: "Jeff Snoxell" <Jeff@aetherweb.co.uk>
Subject: Perl PGP routines
Message-Id: <9krbhg$kf9$1@uranium.btinternet.com>

Hi,

Anyone know where I can get hold of a perl.cgi PGP encryption routine so I
can encrypt emails to myself from my ISP's server?

My ISP won't let me install the unix version of PGP on their server.

Thanks in advance,


--
Jeff Snoxell B.Sc.
Technical Director - Aetherweb Ltd (York)
+44 (0) 1904 656334
+44 (0) 7957 257391

http://www.aetherweb.co.uk




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

Date: Wed, 8 Aug 2001 13:42:05 +0100
From: "Tom Leitch" <tom@leitchy.com>
Subject: Re: Perl PGP routines
Message-Id: <8sac7.875$tq.136858@news6-win.server.ntlworld.com>

> Anyone know where I can get hold of a perl.cgi PGP encryption routine so I
> can encrypt emails to myself from my ISP's server?


http://search.cpan.org/doc/BTROTT/Crypt-OpenPGP-0.13/lib/Crypt/OpenPGP.pm

 ...that should do what you are looking for. It's a pure Perl implementation
of PGP.

Cheers,

tom
tom@leitchy.com




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

Date: Wed, 8 Aug 2001 11:30:19 +0100
From: "Joe Blow" <joeblowing@sPaMmail.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <Dw8c7.603$tq.93180@news6-win.server.ntlworld.com>

I myself once found perldoc very confusing, but as soon as you know the
language more intimately, you will find it an invaluable, fast and direct
route to the information. I splashed out and purchased the Perl CD from ORA
which has been my bible until I found perldoc more inviting.

It might be true that it contains complex words and ideas, but it's there as
a fast lookup not a night nurse to beginners.


joe


> A lot of the perldoc documentation is very thorough and people have
> graciously put a lot of time into it.  For this I am grateful but a lot
> of it for someone like me who is a beginner is like Greek.
> Interpolation, unary operator, lexical scope, expected semantics, extent
> of a string...  These are just some of the "Greek" terms in perldoc
> perlop that I saw.  Now I have some idea of what some of these are but
> the point I am making is that it seems to me that another version of the
> documentation needs to be rewritten in common English.  Without so much
> computereese in it.  Especially for us new beginners.




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

Date: Wed, 8 Aug 2001 12:02:10 +0100
From: John Imrie <john.imrie@pa.press.net>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <B%8c7.243$t97.2458@news.uk.colt.net>

perhaps we could do a perldoc perlglosary


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

Date: Wed, 8 Aug 2001 22:31:58 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: Re: Perl editor for win32 needed
Message-Id: <wlac7.33$lI2.1172517@news.interact.net.au>


<194.203.212.8 [demerphq]> wrote in message
news:9kp0u407h5@enews2.newsguy.com...
> > Nikolas Garofil wrote:
> >
> > > What is the best editor to write perl scripts in Windows 98
> > >
> > >
> > >
> > Real perl coders use
> >
> > 'cat > myProg.pl'
> >
> > ;-)
>
> Sorry isnt that (this is dos after all)
>
> Real masochistic dos perl coders use
>
> 'copy con myProg.pl'

Wimp!  See http://ars.userfriendly.org/cartoons/?id=19990508





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

Date: 8 Aug 2001 03:47:05 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: Re: Reporting Questionable Programming Activity
Message-Id: <42f3ee2.0108080247.2f38cf21@posting.google.com>

gurm@intrasof.com (Smiley) wrote in message news:<3b672381.218715906@news1.on.sympatico.ca>...
> The company I'm working for purchased a Perl CGI Script that turns out
> to be seriously faulty - so much so that my boss asked me to
> investigate whether there's any international agency or organization
> set up that we can report this kind of thing to.
> 
> Does anybody know?  Thanks :)

Just to know, what script is it?

---
Mario Rizzuti


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

Date: Wed, 08 Aug 2001 10:26:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: String manipulation
Message-Id: <3B7113DC.6EBB73E@acm.org>

Micheal Hue wrote:
> 
> I want to convert a string with the format YYYYMMDDHHMMSS into an
> array, first item contains 4 digits, the rest 2 digits.
> 
> my @dstr = $my_string =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/;
> 
> Is there better way ?

I don't know if this is "better".

my @dstr = unpack 'a4a2a2a2a2a2', $my_string;



John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 8 Aug 2001 12:08:46 +0100
From: "Paul Fortescue" <paul@net366.com>
Subject: Re: String manipulation
Message-Id: <997268847.24902.0.nnrp-01.d4f094e4@news.demon.co.uk>

Don't know anything about newsgroups, nor Perl actually :) But here is my
offering to you. It's not meant to be a good one, it's just good practise 4
me, I hope you don't mind. At least it's on one line and almost totally
unreadable, which is what I perceive Perl to be good at.
$my_string[$i?-1+$i++:$i++].=$1 while($d=~/(\d\d)/g);

where @my_string is the result, $d is the date.

Regards - Tim Toady
He he.


"Micheal Hue" <huem@mailandnews.com> wrote in message
news:ed2010db.0108080059.737c3c7c@posting.google.com...
> Hi,
>
> I want to convert a string with the format YYYYMMDDHHMMSS into an
> array, first item contains 4 digits, the rest 2 digits.
>
> my @dstr = $my_string =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/;
>
> Is there better way ?
>
> Thanks.
>
> Micheal H.




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

Date: 8 Aug 2001 10:27:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: String version of += assignment operator??
Message-Id: <9kr476$1vf$1@mamenchi.zrz.TU-Berlin.DE>

According to Tad McClellan <tadmc@augustmail.com>:
 
> Because you can combine _any_ operator with assignment. Since they

Oh.  That's why ,= is a synonym for push :)

Anno, who wonders what to make of == under this aspect


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

Date: Wed, 08 Aug 2001 11:35:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: String version of += assignment operator??
Message-Id: <du82nt8u05bne6bdthfu2cu0cpmdfgtl4k@4ax.com>

Carlos C. Gonzalez wrote:

> It's a hassle to use perldoc on 
>Windows.  It comes up in this archaic DOS window which scrolls off the 
>screen with every page and that I cannot readily page up on.  

Use a text editor with capability of running external programs ("tools")
and capturing the output into an editor window.

-- 
	Bart.


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

Date: 08 Aug 2001 08:51:35 -0400
From: Doug Perham <dperham@dperham.eng.tvol.net>
Subject: Re: Using a http proxy
Message-Id: <81g0b2d8a0.fsf@wgate.com>

Matthew Braid <nc@uq.net.au> writes:

> Hi all,
> 
> I need to write a program that will fetch webpages via a proxy.
> 
> The way I do it on the command line is similar to:
> 
> # telnet proxy 80
> GET http://www.somesite.com/index.html HTML/1.0
> 
> <BLAH>
> 
> I had great trouble trying to do this in perl (I just couldn't send
> stuff to telnet, whether I redirected info from a file with a '<', or
> passed it in by using:
> 
> open(TH, "|telnet proxy 80 >  temp_file");
> print TH 'GET http://www.somesite.com/index.html HTML/1.0', "\n\n";
> 
> (temp_file always ended up with just the connection messages and nothing
> else)

I think your problem has to do with the buffering of your output. It is
a problem that is present in every example from your original post.

You need to unbuffer your output. otherwise, your print statement is
executed, but the actual output is sitting in a buffer somewhere waiting
to accumulate a bunch of output to send altogether.

unbuffering can be achieved by

my $oldfh = select TH;
$|=1;
select $oldfh;
 
or even better, look at the FileHandle module, and IO::Socket modules

  perldoc FileHandle
  perldoc IO::Socket



then you can just do

  $fh->autoflush();

-- 
Doug Perham                                          o{..}o     
dperham@wgate.com                                moo! (oo)___   
WorldGate Communications, Inc.                        (______)\ 
                                                      / \  / \  


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

Date: Wed, 08 Aug 2001 13:42:20 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: Where are those !'s coming from?
Message-Id: <3B7133AC.D5A805A8@bbsrc.ac.uk>

Eric M wrote:
> 
> I am a Professor of Biochemistry, and this is only my second cgi
> script. What I am doing seems so frightfully simple, I can't figure
> out what is wrong. I am using this code:
> 
> open DATA_FILE_db, ">> $DATA_FILE_db" or die "Cannot append to File:
> $!";
> flock DATA_FILE_db, LOCK_EX;
> 
> print DATA_FILE_db ("$date \| $Abstract \| $keywords \n ");
> 
> to create a flat file database where the fields are separated by
> pipes.
> 
> $Abstract sometimes has several thousand characters.  During the print
> somehow ! followed by a newline is being sent to the file. I can print
> $Abstract back to the browser and the !'s are not there. The !'s do
> not come at a fixed distance from each other. The distance between !'s
> can be 50 to 1000 characters.

Not wishing to make a silly suggestion, but as others have pointed out
that the problem doesn't appear to be in the script you posted an
alternative thought arises.  Some text editors use a ! to denote that a
line was wrapped, thus a ! can just indicate that there's too much data
on a line for the editor to display.  The ! would not be there in your
actual data.

You say that everything is OK when you print back to the browser - so
could it just be the application you are using to view your data??

Just a suggestion...

Simon.


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

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


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