[19278] in Perl-Users-Digest
Perl-Users Digest, Issue: 1473 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 9 06:10:38 2001
Date: Thu, 9 Aug 2001 03:10:15 -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: <997351815-v10-i1473@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 9 Aug 2001 Volume: 10 Number: 1473
Today's topics:
Re: perldoc is like Greek to a beginner?? (Eric Bohlman)
Re: perldoc is like Greek to a beginner?? (Tad McClellan)
Re: perldoc is like Greek to a beginner?? <miscellaneousemail@yahoo.com>
Problem using the module Expect.pm <d.wetzler@dawe-computer.de>
Re: q: converting strings <jasper@guideguide.com>
Reaping zombies in Win32 Perl CGIs (Moth Mann)
Re: RegEXP's (Eric Bohlman)
Re: replacing hex characters within a string with their <dianne@dogmac.com>
Tk MainWindow options??? <sky@mail.lviv.ua>
Uppercasing extended characters <Francisco.Alcala@undcp.orgg>
Re: urllist & install <ilya@martynov.org>
Variable reference prob - could u help? :) (^CooL^)
Re: Variable reference prob - could u help? :) <Tassilo.Parseval@post.rwth-aachen.de>
Re: Where are those !'s coming from? (Eric M)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 9 Aug 2001 04:07:41 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <9kt2ad$8q2$1@bob.news.rcn.net>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
> If by programming fundamentals you mean control structures, compiling
> verses interpretation, structure programming verses objection oriented
^^^^^^^^^^^^^^^^^^
> programming, using control structures like while and if statements, I
^^^^^^^^^^^
> completely agree.
I think you inadvertently created a rather useful phrase here...
I remember a thread on the xml-dev mailing list where people were talking
about going beyond certain dogmatic aspects of object-oriented programming
and, given that everything new that people do has to have a trendy name
now, they suggested it might be called Post Object-Oriented Programming.
A shame it leads to such a shitty acronym.
------------------------------
Date: Thu, 9 Aug 2001 00:22:31 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <slrn9n4407.onj.tadmc@tadmc26.august.net>
Carlos C. Gonzalez <miscellaneousemail@yahoo.com> wrote:
>In article <997308301.595097878016531.gnarinn@hotmail.com>, gnari at
>gnarinn@hotmail.com says...
>> C has regular expressions?
>
>Perhaps I am not understanding Perl regular expressions or even regular
>expressions for that matter.
You are correct in that you don't have a handle on either. Let's
take care of that :-)
This is all "standard" CS curriculum fare BTW...
... and luckily, Perl programmers don't have to bother with
knowing it, but it helps on rare occasions (like when something
isn't working right).
>To me a regular expression has been and is
>just an expression.
No no no. The use of the word "expression" in both places is
coincidental. It does not indicate a very similar relationship.
Part of the problem is that "regular expression" is an overloaded
term, we may need to be careful to avoid misunderstanding. I'll
use initial caps for the most formal meaning (the less formal
meaning is the "default" in a Perl neighborhood though).
Regular Expression:
Corresponds to a Regular Grammar (that is, it can "recognize"
strings in the corresponding grammar). Can be implemented
with a Finite State Automata.
regular expressions:
Used for string pattern matching.
There are mathematical "rules" that must be followed to be
classified as "regular". No memory is one of the rules. Since
Perl has added capturing parenthesis (memory), Perl's regular
expressions are not Regular Expressions anymore. They are
just called that for historical reasons.
If you want to know "How Regexes Work", that is, how they
are often implemented internally, then see:
http://www.plover.com/~mjd/perl/Regex/
>Such as if ($string eq "Hi there") to something more
>complicated such as s/^\s+/;.
^^^^^^^^
Syntax error.
:-)
>C's regular expressions (i.e. just expressions)
C does not have regular expressions.
"regular" is a well defined mathematical term here, not its
usual day-to-day meaning of: customary, usual, or normal.
>were and are easier for
>me to follow than Perl's. For the time being at least.
It is not the language's syntax that is hard. It is that what
you want _to do_ (pattern matching) is hard. It is the nature
of the beast.
There _is no_ (AFAIK) "easier" syntax for expressing what
patterns to match.
If you want to say "Perl is hard compared to <other lang>", then either:
1) <other lang> has regular expressions (pattern matching)
or
2) you compare some language feature other than pattern matching.
Otherwise you are comparing apples to rocks.
>> it is best to keep regular expression syntax totally separate in your
>> mind from usual programming syntax, just like format syntax.
Inside the "language" that is Perl, there is another little language
(grammar) known as "regular expressions". Inside of _that_ is
yet another, even smaller, language called "character classes".
What a character in source code means depends on what language
is being use when the character appears:
in Perl: dot is the string concatenation operator
in RE: dot matches any character except newline
in char class: dot matches dot (dot is not "special" in the
char class language).
in Perl: hyphen means subtraction
in RE: hyphen matches a hyphen (is not special)
in char class: hyphen forms a range (unless first or last in the class)
>I might be mixing up regular expression syntax and usual programming
>syntax. I am not sure.
You are, don't be unsure :-)
>I guess the important point for me gnari is that
>I believe without a doubt that stuff can be made much simpler so that
>more and more people will want to try Perl and succeed in it.
If "stuff" is pattern matching, then bring it on! Let's see it.
Pllllennnnty of people have cast about for a dissertation topic
over the years that regexs have been around. If there was a
"better way" someone would have found it by now. This is not
new science.
>There are
>a lot of people out there who are not computer scientists who could use
>the benefits of this language.
There are a lot of people out there who are not computer scientists who
are using the benefits of this language.
Sure we should make it as "easy as possible".
But I submit that with regards to pattern matching, what we
currently have is already as easy as possible.
Pattern matching is powerful. Power has its price.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 09 Aug 2001 08:59:38 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <MPG.15dbf09687f0cfa198971d@news.edmonton.telusplanet.net>
In article <slrn9n4407.onj.tadmc@tadmc26.august.net>, Tad McClellan at
tadmc@augustmail.com says...
> You are correct in that you don't have a handle on either. Let's
> take care of that :-)
>
Thanks a lot Tad. I appreciate your insight and explanation very much.
I am rather humbled truly that you would take the time to explain some of
these things to me. What you say makes a lot of sense.
> No no no. The use of the word "expression" in both places is
> coincidental. It does not indicate a very similar relationship.
Interesting....
> >I might be mixing up regular expression syntax and usual programming
> >syntax. I am not sure.
>
>
> You are, don't be unsure :-)
:=)
> >I guess the important point for me gnari is that
> >I believe without a doubt that stuff can be made much simpler so that
> >more and more people will want to try Perl and succeed in it.
>
>
> If "stuff" is pattern matching, then bring it on! Let's see it.
I am not sure how I ended up seeming to say that I thought regular
expressions could be made simpler or more explainable in terms of the
symbols used in them. Or even in the way they are done. I never meant
to say such a thing. I didn't even know there was a difference between
Regular Expressions and regular expressions as you and gnari explained.
What I was referring to was the way computereese seems to be all over the
place in the documentation. For someone like me from a non-CS background
it's a bit tough. Not impossible. Just a bit tough and frustrating.
I could in my mind, without a doubt, rewrite some of the documentation to
make it easier for a newbie to understand but only by expanding the
computereese into more understandable terms (or at least making
computereese words into links that would open up newbie
explanations of each term). That's what I meant by "stuff" Tad. It
would be utterly presumptous of me to even think that I could come up
with a better way to do pattern matching. The thought did not even cross
my mind.
> Pllllennnnty of people have cast about for a dissertation topic
> over the years that regexs have been around. If there was a
> "better way" someone would have found it by now. This is not
> new science.
Ditto to that. I wouldn't even consider tackling the creation of a better
way to make regexs.
> But I submit that with regards to pattern matching, what we
> currently have is already as easy as possible.
In this I would tend to agree with you Tad in so far as I understand
pattern matching. At least in terms of practical use. But I think the
*explanation* of how to use pattern matching could be improved upon.
Especially for newbies.
Thanks.
--
Carlos
www.internetsuccess.ca
------------------------------
Date: Thu, 9 Aug 2001 11:03:33 +0200
From: Daniel Wetzler <d.wetzler@dawe-computer.de>
Subject: Problem using the module Expect.pm
Message-Id: <9ktj2m$h8s$1@news.rrz.Uni-Koeln.DE>
Hi,
I have a strange problem, using the perl module "Expect.pm".
I had no problems starting a program, normally running under console under
Expect and
automating the user input with my perl script.
The Program I want to operate via Expect.pm is written in Fortran and only
asks the user several times for
input, creates a data-file and writes the users data in a special format
into it.
After the last input of the user it throws out a short message and stops
automatically.
My problem is, that if the program is called by Expect it doesn't want to
stop.
It runs further and further, producing tons of output in form of billions
of the last message....
The data file is written correctly so the program runs but doesn't stop at
the time.
The perl script isn't further executed.So I don't have the possibility to
send a
$program->hard_close();
to stop the program.
What's going wrong ?
How can I handle this problem ?
I hope someone can help me.
Greetings, Daniel
------------------------------
Date: Thu, 09 Aug 2001 10:28:45 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: q: converting strings
Message-Id: <3B7257CD.AAADB957@guideguide.com>
Tad McClellan wrote:
>
> Jasper McCrea <jasper@guideguide.com> wrote:
> >Malcolm Dew-Jones wrote:
> >>
> >> Oliver (ow22@nospam-cornell.edu) wrote:
> >> : how do i convert a string to an int? thanks
> >>
> >> In perl, if the string looks like a number then it is a number.
> >>
> >
> >This is a little misleading.
>
> Not nearly as misleading, IMO, as your comments that follow...
>
> >$one = "twelve";
> >$two = "12";
> >
> >both are strings, and look like numbers to me.
> ^^^^^
>
> I suggest that perhaps you are in the minority then.
Malcolm wrote 'if the string looks like a number then it is a number'.
I suggest that 'twelve' looks like a number, and you disagree. I find
that extremely odd.
Would you say I was in a minority if I said that 'aebbc' looked like a
number, too?
All I should have said was that if you really want it to, perl will
convert your string into something it can perform numerical operations
on, if you ask it too. It's just that if your string contains anything
other than digits, you mightn't get what you want, possibly quite
rightly (up to Larry, I guess).
Perhaps I was being a little facetious (and I'll continue in that vein).
> Addition is defined for numbers. If you don't have numbers, then
> you don't know what "addition" means.
my $string = "a";
++$string;
print "$string\n";
In the non-perl world, I could add a chapter to the book I'm writing.
Jasper
--
split//,'019617511192'.
'17011111610114101114'.
'21011141011840799901'.
'17101174';
foreach(0..
$#_){$_[$_
++]^=$_[$_
--]^=$_[$_
]^=$_[++ $_]if!($_%
2)}$g.=$_ ,chr($g)=~
/(\w)/&&($o.=$1and
$g='')foreach@_;
print"$o\n"
------------------------------
Date: Thu, 9 Aug 2001 01:05:21 -0700
From: mothman@attack.of.the.clones.invalid (Moth Mann)
Subject: Reaping zombies in Win32 Perl CGIs
Message-Id: <1exul3k.1c3fsi7edpf4N%mothman@attack.of.the.clones.invalid>
I'm writing a CGI in Perl that wants to send mail. Unfortunately, I
have to do it under some wierd operating system marketed by MicroSoft.
(It's the misnamed Windows 2000.) And this wierd OS does not have
sendmail. So I use Net::SMTP to send the mail, which works.
But! Sending the mail through the local SMTP sever takes a few seconds,
which means that the web page takes a few seconds to come back, and
that's a little annoying.
So! I came up with the bright idea of forking off a child process to do
the actual talking to the SMTP server so I can return a page quickly and
still have the mail be sent. Thanks to the heroic efforts of people I
have never met, I can do this in ActiveState Perl 5.6.1 for lame Win32.
But, now I'm wondering about zombies. In Unix, you should reap zombies
by handling the child exit signal. But Winblows doesn't have signals
like this. Do I need to worry about zombies? The child process
shouldn't take more than a few seconds to finish. Is there a danger of
having a bunch of zombie mailmen trying to deliver mail eating up my
computer's resources?
------------------------------
Date: 9 Aug 2001 04:41:53 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: RegEXP's
Message-Id: <9kt4ah$8q2$2@bob.news.rcn.net>
Tad McClellan <tadmc@augustmail.com> wrote:
> #!/usr/bin/perl -w
> use strict;
> use HTML::TokeParser;
> my $string = 'this is my great <b>string</b> with lots of <a
> href="http://www.foo-bar.com/index.php?action=listall&user=foo">links</a> in
> it to some place on the net.';
> my $p = HTML::TokeParser->new( \$string) || die "parsing problem... $!";
> my @array;
> while ( my $token_ref = $p->get_token() ) {
> my $tokentype = $token_ref->[0];
> if ( $tokentype eq 'T' ) { # Text (#PCDATA)
> push @array, split(' ', $token_ref->[1])
> }
> elsif ( $tokentype eq 'E' ) { # End tag
> push @array, "</$token_ref->[1]>";
> }
> elsif ( $tokentype eq 'S' ) { # Start tag
> my( undef, $gi, $attr, $attrseq, $text) = @$token_ref;
> my $tag = "<$gi";
> foreach my $attrname ( @$attrseq ) {
> $tag .= qq( $attrname="$attr->{$attrname}");
> }
> $tag .= '>';
> push @array, $tag;
> }
Note that the last element of the token for start and end tags is the
originally-parsed string, so the last two elsifs could be replaced with:
elsif ($tokentype =~ /[SE]/) {
push @array,$token_ref->[-1];
}
> }
> print "$_: $array[$_]\n" for 0..$#array;
> ---------------------------------------------
> The above does not preserve newlines within tags though.
> (And it shouldn't.)
with my change, it would.
------------------------------
Date: Thu, 9 Aug 2001 14:48:56 +1000
From: "Dianne van Dulken" <dianne@dogmac.com>
Subject: Re: replacing hex characters within a string with their ascii equivalent
Message-Id: <YCoc7.1448$813.67605@ozemail.com.au>
"Dianne van Dulken" <dianne@dogmac.com> wrote in message
news:RXnc7.1439$813.66485@ozemail.com.au...
> Hi all
>
> I am having a bit of a problem with a querystring variable that I need to
> save into a database. A typical string being passed might be:
>
> %3Cdel_phone%3E%28020%200202%2000202%3C/del_phone%3E
Sorry to reply to my own post, but I just found the answer
$string =~ s/%(..)/chr hex $1/eg;
Though the real problem was how the data was being called initially, so I
changed the parsing there.
Thanks!
Di
------------------------------
Date: Thu, 09 Aug 2001 10:53:43 +0300
From: Roman Khutkyy <sky@mail.lviv.ua>
Subject: Tk MainWindow options???
Message-Id: <3B724187.E309F76C@mail.lviv.ua>
Does enybody know how to made MainWindow with fixed width, heign
and non resizeble?
------------------------------
Date: Thu, 9 Aug 2001 11:43:55 +0200
From: "Curro" <Francisco.Alcala@undcp.orgg>
Subject: Uppercasing extended characters
Message-Id: <QXsc7.1$%X.85@stuart.coltnet.at>
I am trying ot uppercase ASCII characters like ñ.
This character has the HTML character entity representation ñ, the
ASCII code 164 or the character code \361 on my Solaris box.
Why isn't the uc function uppercasing it?
$string = "ñ";
print uc($string);
It outputs the same character in small case.
Does this have anything to do with my locale? This is the only thing I
haven't played around with.
Thanks,
Curro
------------------------------
Date: 09 Aug 2001 12:29:14 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: urllist & install
Message-Id: <87pua58wmd.fsf@abra.ru>
FL> Hi,
FL> I'm trying to install a program which requires the installation of two
FL> perl modules. In the 1st step of the installation, using 'perl
FL> Makefile.PL', I was asked to give the URL of a CPAN site. Unfortunately,
FL> I entered a wrong URL and I couldn't have the 1st step of the
FL> installation to complete because it couldn't download the two required
FL> perl modules. In the warning message, it is said that it's possible to
FL> edit the urllist in the configuration file. However, I was not able to
FL> localize the configuration file. Do you know where to find the
FL> configuration file and how to edit the urllist ?
You need to find CPAN/Config.pm file. It should be Perl module search
paths. Use 'perl -V' to find where Perl will search for its modules.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 9 Aug 2001 00:29:22 -0700
From: cool133@hotmail.com (^CooL^)
Subject: Variable reference prob - could u help? :)
Message-Id: <211c8e3f.0108082329.7432a95b@posting.google.com>
Hi.
Please consider the following code snippet:
my @records;
for (my $i=0; $i < 10; $i++) {
my %hash;
$hash{recordnum} = $i;
$hash{firstname = ...
...
$records[$i] = \%hash;
}
So, here's what I'm trying to do:
I am trying to create 10 different hash arrays, and store them into an
array. Or rather, since (as far as I know) it is not possible to store
the actual hash arrays into the variable, I store a reference to each
hash.
However, this is what is ACTUALLY happening:
On each iteration, the value of %hash changes, but its pointer
doesn't, since I am merely changing the elements within the same hash
array! So I end up with a @records array containing the same hash
reference in each of its elements, a reference pointing to a hash
containing the values set in the last iteration of the loop!
What I would need here is to create a new instance of a variable
without loosing the old one! How can I do this? Or any other solutions
please?
I would appreciate if you would help me out!
Regards,
Clyde.
------------------------------
Date: Thu, 09 Aug 2001 10:23:29 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Variable reference prob - could u help? :)
Message-Id: <3B724881.9040101@post.rwth-aachen.de>
^CooL^ wrote:
> Hi.
>
> Please consider the following code snippet:
>
> my @records;
> for (my $i=0; $i < 10; $i++) {
> my %hash;
> $hash{recordnum} = $i;
> $hash{firstname = ...
> ...
>
> $records[$i] = \%hash;
> }
>
> So, here's what I'm trying to do:
>
> I am trying to create 10 different hash arrays, and store them into an
> array. Or rather, since (as far as I know) it is not possible to store
> the actual hash arrays into the variable, I store a reference to each
> hash.
Hmmh, no. Your above code creates an array with 10 elements, each
containing a reference to a hash.
>
> However, this is what is ACTUALLY happening:
>
> On each iteration, the value of %hash changes, but its pointer
> doesn't, since I am merely changing the elements within the same hash
> array! So I end up with a @records array containing the same hash
> reference in each of its elements, a reference pointing to a hash
> containing the values set in the last iteration of the loop!
No. You (correctly) my()ed the hash inside the loop so this will create
a new hash on each iteration and thus also create different references.
However, more Perlish would be: (untested)
my @array;
for (1 .. 10) {
$array[$_]->{key1} = $_;
$array[$_]->{key2} = $_;
# etc...
}
@array will contain references to hashes. So you can directly write to
the hash references in the array with the above syntax.
The structure will look like:
@array = ( { key1 => 1, key2 => 2 ... },
{ key1 => 1, key2 => 2 ... },
...
);
I hope you are aware of the fact, that all hash-refs in the array are
identical. That is not because they reference to the same hash but
because you fill them with the same key/value pairs. So when thinking
about your problem, I tend to say that you should do something
interesting inside the for-loop and not just creating the same hash over
and over again.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 8 Aug 2001 23:10:27 -0700
From: emuller@u.washington.edu (Eric M)
Subject: Re: Where are those !'s coming from?
Message-Id: <5adbbbf7.0108082210.745e5ab1@posting.google.com>
Just to finish the thread.
I need to add
Encoding =>'quoted-printable'
to encode the messages properly. I went back and looked at the
document with MIME-Lite. Other forms of encoding are really for lines
less than 1000 characters. The !'s were coming from problems with the
encoding.
------------------------------
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 1473
***************************************