[25209] in Perl-Users-Digest
Perl-Users Digest, Issue: 7455 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 27 11:06:08 2004
Date: Sat, 27 Nov 2004 08:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 27 Nov 2004 Volume: 10 Number: 7455
Today's topics:
Re: (Perl) FILE/IO and grep causes 100% CPU <sundstrom@invalid.invalid>
Re: counting words in a file <someone@example.com>
Re: counting words in a file (wana)
Re: counting words in a file (Anno Siegel)
Email script separates words with + instead of a space (Mortgageloan2004)
Re: Email script separates words with + instead of a sp <spamtrap@dot-app.org>
Re: Email script separates words with + instead of a sp <jurgenex@hotmail.com>
Re: Email script separates words with + instead of a sp <tadmc@augustmail.com>
FAQ 3.11: Where can I get Perl macros for vi? <comdog@panix.com>
Re: for Richard Gration <bik.mido@tiscalinet.it>
Graph-Layout-Aesthetic <amead@comcast.net>
Help: making images with perl? (Giancarlo)
Re: Help: making images with perl? <bastard@uni-koblenz.de>
Re: Help: separate difference length of spaces between <usenet@morrow.me.uk>
Re: making images with perl? <gnari@simnet.is>
perl trim function <noreply@nowhere.com>
Re: perl trim function <tassilo.von.parseval@rwth-aachen.de>
Re: perl trim function <tadmc@augustmail.com>
Re: post into hash table <noreply@gunnar.cc>
Re: recursive bruteforce ASCII range <bik.mido@tiscalinet.it>
Re: Redirecting STDOUT to Scalar behaves not as expecte <bik.mido@tiscalinet.it>
Re: source filters at runtime <fxn@hashref.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 27 Nov 2004 21:14:52 +1300
From: "Peter Sundstrom" <sundstrom@invalid.invalid>
Subject: Re: (Perl) FILE/IO and grep causes 100% CPU
Message-Id: <30qr94F341j4aU1@uni-berlin.de>
<mark@gowans.org> wrote in message
news:1101382051.588878.7620@f14g2000cwb.googlegroups.com...
> Hi There..
>
> I've a perl script which amongst other things searches for text strings
> in a large number of files. The problem I've got is, while the script
> is running - idle cpu% drops to 0. (A mix of user and kernel usage).
> The code is:
>
> #!/usr/bin/perl
> use strict;
> my @files = `ls -lart /app/EV4/data/db/u* | awk '{print \$NF}'`;
> foreach my $file (@files) {
> chomp ($file);
> (my $date) = $file =~ m/.*\.(.*)/;
> my @result = `grep anicol $file`;
> }
I've decided to create a SWIP (Shell Wrapped in Perl) page.
Congratulations, you earn the honour of holding the first entry in the list.
------------------------------
Date: Sat, 27 Nov 2004 05:19:35 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: counting words in a file
Message-Id: <H7Upd.8846$VL6.1118@clgrps13>
ioneabu@yahoo.com wrote:
> Anno Siegel wrote:
>> wana <ioneabu@yahoo.com> wrote in comp.lang.perl.misc:
>>
>>> $words{lc $1}++ while /(\w+)/gi;
>>
>>The /i modifier does nothing and shouldn't be there.
>
> don't you need the /i so words like 'The' and 'the' are counted as the
> same word?
The \w character class includes all upper and lower case letters so using /i
is superfluous.
John
--
use Perl;
program
fulfillment
------------------------------
Date: 27 Nov 2004 06:19:58 -0800
From: ioneabu@yahoo.com (wana)
Subject: Re: counting words in a file
Message-Id: <bf0b47ca.0411270619.c47c6d4@posting.google.com>
> > > my $fn = "/textucation/moby10b.txt";
> > > open (INF, $fn) or die "error: $!";
> > > my %words;
> > > for (<INF>)
> > > {
> > > $words{lc $1}++ while /(\w+)/gi;
> >
> > The /i modifier does nothing and shouldn't be there.
>
> don't you need the /i so words like 'The' and 'the' are counted as the
> same word?
I feel dumb about this one. Right after posting, I realized that it
doesn't matter if 'The' and 'the' are not matched as the same word.
They will be counted as the same word in the hash when they are
converted first by the lc function. Either way, it still wouldn't
matter since I am not looking for a particular word but using (\w+).
Now I remember, this was left over from the original version where I
was just counting a single word.
>
> >
> > I'd use split without arguments for that. You break "gable-ended
> > Spouter-Inn" into "gable" and "ended" plus "Spouter" and "Inn", split
> > keeps the hyphenated words.
do you mean like this?:
for (<INF>) {$words{lc $_}++ for split}
I tried this and also got a lot of words with punctuation stuck to
them. Like:
"the
really?
also,
oh.
maybe I could use a locale where - is a word character or just specify
my character set to match:
for (<INF>) {$words{lc $1}++ while /([-a-zA-Z0-9]+)/g}
or even leave out the numbers:
for (<INF>) {$words{lc $1}++ while /([-a-zA-Z]+)/g}
or find dates only:
for (<INF>) {$words{lc $1}++ while /([0-9]{4})/g}
A little Perl could probably be really useful for some English
professors and students who hate computers and programming :-) Then
again, they might not care about finding interesting patterns in
classic literature :-(
Maybe a quick way to look for mispellings and other problems for book
editors?
> > Scratch everything after the counting loop and simply do
> >
> > my @k = sort { %words{ $b} <=> %words{ $a} } keys %words;
>
works great...Thanks!
------------------------------
Date: 27 Nov 2004 15:52:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: counting words in a file
Message-Id: <coa7r6$gdg$1@mamenchi.zrz.TU-Berlin.DE>
wana <ioneabu@yahoo.com> wrote in comp.lang.perl.misc:
[...]
> do you mean like this?:
>
> for (<INF>) {$words{lc $_}++ for split}
>
> I tried this and also got a lot of words with punctuation stuck to
> them. Like:
> "the
> really?
> also,
> oh.
Sure. But that's *more* differentiation than you want and could be
corrected even after the fact. If you split too much, you
irretrievably count parts of a compound with the partial words.
> maybe I could use a locale where - is a word character or just specify
> my character set to match:
>
> for (<INF>) {$words{lc $1}++ while /([-a-zA-Z0-9]+)/g}
>
> or even leave out the numbers:
>
> for (<INF>) {$words{lc $1}++ while /([-a-zA-Z]+)/g}
>
> or find dates only:
>
> for (<INF>) {$words{lc $1}++ while /([0-9]{4})/g}
There is a lot one can do, even more with alphabets that aren't
entirely ASCII. Then there's hyphenated words at the end of a line...
Here's my approximation (untested):
for ( <INF> ) {
$words{ lc()} ++ for split /[.,;:!?)]?\s+[(]?/;
}
(No it doesn't deal with hyphen-separation. That would require a
line-spanning action, always a nuisance.) It does deal with single
punctuation characters at the and of a word and with single parentheses.
The tendency is to be conservative and register funny words as such,
but unify the most predictable cases.
> A little Perl could probably be really useful for some English
> professors and students who hate computers and programming :-) Then
> again, they might not care about finding interesting patterns in
> classic literature :-(
>
> Maybe a quick way to look for mispellings and other problems for book
> editors?
Oh, I suppose they have all the software they can use, from standard
word processors (possibly with specialized spelling lists) to high-prized
proprietary software. It would take more than a casual word counting
algorithm to offer something interesting to these folks.
But here's something I'd like to know. When I read (a good part of)
Moby Dick a while back, one of the words I had to look up was "descry".
I had never heard it before, but it came up again and again -- Melville
seems to love it. So, what's the count of "descry" and "descried" in
Moby Dick, please?
Anno
------------------------------
Date: 27 Nov 2004 06:51:00 GMT
From: mortgageloan2004@aol.com (Mortgageloan2004)
Subject: Email script separates words with + instead of a space
Message-Id: <20041127015100.06040.00000669@mb-m19.aol.com>
I have this little script that does emails. It sends the 3 fields but the the
email received has words separated by + signs instead of spaces. Can anyone
lend a clue why this is?
#!/usr/bin/perlmy $subject = "";read(STDIN,$in,$ENV{'CONTENT_LENGTH'});if
(length($in) < 3){ print <<InForm;Content-type:
text/html<html><head><br><title>Contact Form -
Mortgage-Applications-Online.com</title></head><body
background="../pics/ocean.jpg"><hr size=5 width=90%><table width="55%"
align="center"><tr><td align="center"><h2>Please use this text box to email
your questions or comments to admin. </h2></td></tr></table> </center><hr
size=5 width=90%><FORM METHOD="POST" ACTION="email.cgi"><center><table><tr>
<TD align="right">Name :</TD> <TD align="left"><INPUT NAME="N"
SIZE="40" MAXLENGTH="40"></TD></tr><tr> <TD align="right">E-mail
address :</TD> <TD align="left" COLSPAN=2><INPUT NAME="E" SIZE="40"
MAXLENGTH="40"></td></tr></table> <TEXTAREA NAME="C" ROWS="8" COLS="55"
WRAP="VIRTUAL" VALUE="Please type in any comments or questions
here"></TEXTAREA></P> <INPUT TYPE=submit VALUE="Send In"> <INPUT
TYPE=reset VALUE="Reset"></center><br><br><br><br><br><br><FONT SIZE=-1><hr
size=5 width=100%>
Mortgage-Applications-Online.com<br>2004 All Rights Reserved
</b></FONT></FORM>InForm exit;}@f = split("&",$in);for ($i=0; $i<8; $i++){
($k,$v) = split("=",@f[$i],2); $v =~ s/,//g; $v =~ s/%2C//g; $aa{$k} =
$v;}$aa{E} =~ s/ //;if (!($aa{E} =~ /\@/ && $aa{E} =~ /\./)){ print
<<BadEmail;Content-type: text/html<head><title>Bad E-Mail
Address</title></head><body
background='../pics/ocean.jpg'><center><br><br><H2>We're sorry, but your E-Mail
Address <i>$aa{E}</i> was Invalid<br><br>Please use your back button and
re-enter your email address</h2></center>BadEmail
exit;}open(SM,"|/usr/sbin/sendmail -oi -t");print SM "From: $aa{E} \n";print SM
"To: mortgageloan2004\@aol.com \n";print SM "Subject: Comments from $aa{N} to
$subject \n\n";print SM "Comments: $aa{C} \n\n";close(SM);print
<<Header;Content-type: text/html<head><title>Your information has been
E-Mailed</title></head><BODY
BACKGROUND="../pics/ocean.jpg"><center><BR><BR><BR><H1>Your Message Has Been
Forwarded <BR>To Mortgage-Applications-Online.com</H1><br><br><br><br><A
href="../members/index.htm">Return to Control Panel</A><p>Header
------------------------------
Date: Sat, 27 Nov 2004 02:29:46 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Email script separates words with + instead of a space
Message-Id: <LtOdnQsd6cx2sTXcRVn-jw@adelphia.com>
Mortgageloan2004 wrote:
> I have this little script that does emails. It sends the 3 fields but the the
> email received has words separated by + signs instead of spaces. Can anyone
> lend a clue why this is?
>
> #!/usr/bin/perlmy $subject = "";read(STDIN,$in,$ENV{'CONTENT_LENGTH'});if
> (length($in) < 3){ print <<InForm;Content-type:
> text/html<html><head><br><title>Contact Form -
Your script looks like an explosion in an ASCII factory. Add "use
strict;" and "use warnings;" to your code. Dump the homemade CGI parsing
and use one of the standard modules for that. Clean up the formatting.
Have you read the posting guidelines that appear here frequently?
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sat, 27 Nov 2004 12:43:10 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Email script separates words with + instead of a space
Message-Id: <yD_pd.479$wr6.478@trnddc04>
Mortgageloan2004 wrote:
> I have this little script that does emails. It sends the 3 fields but
> the the email received has words separated by + signs instead of
> spaces. Can anyone lend a clue why this is?
>
> #!/usr/bin/perlmy $subject =
> "";read(STDIN,$in,$ENV{'CONTENT_LENGTH'});if (length($in) < 3){
> print <<InForm;Content-type: text/html<html><head><br><title>Contact
> Form - Mortgage-Applications-Online.com</title></head><body
[more lines of compacted ASCII-jumble deleted]
Your script doesn't even parse
syntax error at t.pl line 3, near "){"
Can't find string terminator "InForm" anywhere before EOF at t.pl line
3.
let alone compile or pass strictures and warnings.
jue
------------------------------
Date: Sat, 27 Nov 2004 08:27:17 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Email script separates words with + instead of a space
Message-Id: <slrncqh3m5.66m.tadmc@magna.augustmail.com>
Mortgageloan2004 <mortgageloan2004@aol.com> wrote:
> I have this little script that does emails.
Did you write it?
> It sends the 3 fields but the the
> email received has words separated by + signs instead of spaces. Can anyone
> lend a clue why this is?
You are not doing the URL-decoding properly. Use a module instead.
[ snip a bunch or horridly formatted code. Nobody is going to take the
time to read the code if you don't take the time to present the
code in a readable format. You're on your own until then.
]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 27 Nov 2004 11:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.11: Where can I get Perl macros for vi?
Message-Id: <co9mt6$snq$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
3.11: Where can I get Perl macros for vi?
For a complete version of Tom Christiansen's vi configuration file, see
http://www.cpan.org/authors/Tom_Christiansen/scripts/toms.exrc.gz , the
standard benchmark file for vi emulators. The file runs best with nvi,
the current version of vi out of Berkeley, which incidentally can be
built with an embedded Perl interpreter--see
http://www.cpan.org/src/misc/ .
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Sat, 27 Nov 2004 11:05:16 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: for Richard Gration
Message-Id: <1dhgq05a9h0c1qjlakdh9r7ijanmaqgbv4@4ax.com>
On Fri, 26 Nov 2004 16:34:10 -0500, "daniel kaplan"
<nospam@nospam.com> wrote:
>ok, if i may follow-up with one more question then? is there one newsserver
>that is more relieable than the others? for instance, google? although i
>would love one i can log into with OE...but beggers can't be chosers.
I don't have the slightest idea. Personally I'm fine with
<news:news.individual.net> (free).
HTH,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 27 Nov 2004 02:28:32 -0600
From: Alan Mead <amead@comcast.net>
Subject: Graph-Layout-Aesthetic
Message-Id: <pan.2004.11.27.08.28.31.365265@comcast.net>
Has anyone ever used this module? I want to make graphs of a changing
class heirarchy. It looks like I can do this with this module (with force
ParentLeft) but I'd appreciate some help getting started off-line (or
on-line if others want to hear).
-Alan
------------------------------
Date: 27 Nov 2004 06:29:26 -0800
From: amor99@iname.com (Giancarlo)
Subject: Help: making images with perl?
Message-Id: <dbfb676.0411270629.22309a55@posting.google.com>
Hello,
I am able to program a little bit in perl and I can write cgi's that
make HTML pages whose content depend on the inputs of the visitors.
But that's all what I am able to do: I am not expert at all.
At this time I need to write a perl cgi that makes simple geometrical
images (they are very simple and may be black/white). I wonder how I
can do this in perl.
Actually I am able to do this in a very stupid way, that is: I have a
1 pixel white bmp file, and a 1 pixel black bmp file, and then I run a
perl cgi that makes a HTML page (!) placing side by side these images,
depending on the figure I need to build. For example:
<img src = white.bmp><img src = black.bmp><img src = white.bmp><img
src = white.bmp> and so on... and <br> at the end of the first row of
pixels.
Actually it works: the real imagine appears into the browser! It is
made of thousands of 1-pixel bmp files (white.bmp and black.bmp) that
are placed side by side.
I understand that this is a stupid way, but I am not able to do better
than this, due to my ignorance.
Can I do something better, provided that I can't study very much about
this matter? Is perl useful to do this, or should I use javascript?
But I don't know anything about it... Or even java? (I hope not).
Thanks for any suggestion (please write in a simple way, I don't know
perl very well).
Giancarlo
------------------------------
Date: Sat, 27 Nov 2004 17:11:50 +0100
From: Dimitri Papoutsis <bastard@uni-koblenz.de>
Subject: Re: Help: making images with perl?
Message-Id: <coa6gr$vd5$1@news.uni-koblenz.de>
Giancarlo wrote:
> Hello,
>
> I am able to program a little bit in perl and I can write cgi's that
> make HTML pages whose content depend on the inputs of the visitors.
> But that's all what I am able to do: I am not expert at all.
>
> At this time I need to write a perl cgi that makes simple geometrical
> images (they are very simple and may be black/white). I wonder how I
> can do this in perl.
> Actually I am able to do this in a very stupid way, that is: I have a
> 1 pixel white bmp file, and a 1 pixel black bmp file, and then I run a
> perl cgi that makes a HTML page (!) placing side by side these images,
> depending on the figure I need to build. For example:
> <img src = white.bmp><img src = black.bmp><img src = white.bmp><img
> src = white.bmp> and so on... and <br> at the end of the first row of
> pixels.
> Actually it works: the real imagine appears into the browser! It is
> made of thousands of 1-pixel bmp files (white.bmp and black.bmp) that
> are placed side by side.
> I understand that this is a stupid way, but I am not able to do better
> than this, due to my ignorance.
>
> Can I do something better, provided that I can't study very much about
> this matter? Is perl useful to do this, or should I use javascript?
> But I don't know anything about it... Or even java? (I hope not).
>
> Thanks for any suggestion (please write in a simple way, I don't know
> perl very well).
>
> Giancarlo
You should install ImageMagick and download the Perl-Module that provides an
interface to ImageMagick...
dnp
------------------------------
Date: Thu, 25 Nov 2004 22:58:15 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Help: separate difference length of spaces between words
Message-Id: <7l4i72-546.ln1@osiris.mauzo.dyndns.org>
Quoth KKramsch <karlUNDERSCOREkramsch@yahooPERIODcom.invalid>:
>
> So, Lei, here's another important lesson: to get the real scoop in
> CLPM, don't ask. Just post your best guess as fact, and someone
> who really knows will go ballistic and post the correct answer.
*plonk*
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk The Levellers, 'Believers'
------------------------------
Date: Sat, 27 Nov 2004 15:54:35 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: making images with perl?
Message-Id: <coa7qv$ttt$1@news.simnet.is>
"Giancarlo" <amor99@iname.com> wrote in message
news:dbfb676.0411270629.22309a55@posting.google.com...
> [asks how to do graphics with cgi]
first look at the modules that are available on cpan.
when you have chosen the one you want, download it and install it
along with any libraries in may need.
a common method is to point your <img> src attribute to a cgi script
that produces the image.
gnari
------------------------------
Date: Sat, 27 Nov 2004 07:51:01 GMT
From: Shailesh Humbad <noreply@nowhere.com>
Subject: perl trim function
Message-Id: <FlWpd.2971$M16.1889@fe1.columbus.rr.com>
Does this look right? Any suggestions?
http://www.somacon.com/blog/page14.php
------------------------------
Date: Sat, 27 Nov 2004 09:22:27 +0100
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: perl trim function
Message-Id: <slrncqgea3.1s0.tassilo.von.parseval@localhost.localdomain>
Also sprach Shailesh Humbad:
> Does this look right? Any suggestions?
>
> http://www.somacon.com/blog/page14.php
Which is:
sub trimwhitespace($)
{
my $string;
$string = pop(@_);
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
That looks right, yes. The argument handling is a bit clumsy, though.
The prototype of $ means the function always receives one argument,
never more, never less. The pop() suggests otherwise:
sub trimwhitespace ($) {
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
Another thing you could do is add some convenience to the function, for
example by checking in which context it was called. If it was called in
void context, trim the argument in-place:
sub trim ($) {
if (! defined wantarray) {
$_[0] =~ s/^\s+//;
$_[0] =~ s/\s+$//;
return;
}
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
That will allow:
my $s1 = my $s2 = " \t string \n\n";
trim $s1; # $string trimmed in-place
$s2 = trim $s2; # returns trimmed string (does some copying)
But you could get fatal errors at runtime when doing this:
trim(" \t string \n\n");
In void context, the argument must not be read-only.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 27 Nov 2004 08:18:11 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl trim function
Message-Id: <slrncqh353.66m.tadmc@magna.augustmail.com>
Shailesh Humbad <noreply@nowhere.com> wrote:
> Does this look right? Any suggestions?
>
> http://www.somacon.com/blog/page14.php
The forward declaration is unnecessary when the sub is called
the way you are calling it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 27 Nov 2004 07:25:50 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: post into hash table
Message-Id: <30qlebF333grvU1@uni-berlin.de>
John Bokma wrote:
> Gunnar Hjalmarsson wrote:
>> Bob Walton wrote:
>>> Bremse wrote:
>>>> I'm trying to put values (from form) posted by post method into
>>>> hash
>>>
>>> One possibility: The query string could use the ; character to
>>> separate key-value pairs rather than the & character (either is
>>> permitted and possibly generated by a web server).
>>
>> The query string is probably empty, since it's a form submission
>> via the POST method, and forms always use & as the separator.
>
> Sometimes I call POST forms using GET, sometimes I use a script.
> Don't rely on what you think is on your page.
My point is that splitting on & only can't be causing the OPs problem.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sat, 27 Nov 2004 10:05:14 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: recursive bruteforce ASCII range
Message-Id: <v29fq05i44kcbpo875mhv2eaije23du8cs@4ax.com>
On 26 Nov 2004 08:50:27 -0800, bernd@thebc.ch (bernd) wrote:
># but there must be a smarter, solution than writing the same stuff
># over and over again. i'd tried some recursive stuff but failed.
>#
># any help really appreciated!
>#
># greez bernd (who just didn't see the solution)
recursive, general purpose, certainly not terribly efficient!
sub range;
sub range {
my $n=shift;
return '' if $n == 0;
map { my $c=$_;
map $c.$_, range $n-1, @_ } @_;
}
print for range 3, 'a'..'z';
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Sat, 27 Nov 2004 11:05:19 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Redirecting STDOUT to Scalar behaves not as expected. Why?
Message-Id: <aohgq0ddjigd77s8cvucafsf5dcca7agcb@4ax.com>
On Sat, 27 Nov 2004 01:24:07 +0100, zaphod <zaphod@s4r.de> wrote:
>This is the first version, which does exactly what I want to do except,
>that it writes STDOUT to a file:
[snip]
>use IO::File;
If you like the OO UI of IO::File better, then fine. But for your
purposes recent enough perls support lexical FHs out of the box, so
IMHO no need to use it.
># My Little Programm
>my @PROGRAMM = (
> "# This is a demo-Programm\n",
> "print \"Hello World!\\n\";\n",
> "for my \$i (1..5){\n",
> " print \"\$i\\n\";\n",
> "}\n"
> );
As a side note, what about a HERE doc (or DATA section)?
># Saving STDOUT
>open(OLDOUT,">&STDOUT") || die("[$PROGNAME] Couldn't dup STDOUT\n");
^^^^^^^^^
^^^^^^^^^
Is this a real *working* minimal example? I don't think so... well, on
a second thought I do think so, since we're not under warnings and
strictures. But no real harm done... so please do not take any offence
for this comment!
># Redirecting STDOUT to file
[snip]
># Open Pipe to Perl
[snip]
># Run Programm
[snip]
># Restore STDOUT
As a side note, I hope I'm not missing anything obvious, but aren't
the "Redirecting STDOUT to file then Restore STDOUT" and "Open Pipe to
Perl then Run Programm" businesses orthogonal to each other?!? So what
has opening a pipe to perl to do with your redirecting STDOUT
concerns?
>now I try to redirect the output to a scalar variable, which works for the
>simple print statement, but not for the output of the perl-interpreter
>where the programm is piped to:
[snip]
>use IO::File;
>use IO::Scalar;
No need for IO::Scalar either, for recent enough perls support
open()ing scalar references "in memory" straight out of the box.
All in all see if the following suits your needs:
#!/usr/bin/perl -l
use strict;
use warnings;
open my $oldout, '>&STDOUT' or
die "$0: Couldn't dup STDOUT\n";
close STDOUT;
my $scalar;
open STDOUT, '>', \$scalar or
die "$0: Couldn't open STDOUT in memory\n";
print 'Hi';
{
open my $perl, '|-', 'perl' or
die "$0: Couldn't pipe into perl\n";
print $perl <<'EOPERL';
# This is a demo-Programm
print "Hello World!\n";
for my $i (1..5) {
print "$i\n";
}
EOPERL
}
close STDOUT;
open STDOUT, '>&', $oldout or
die "$0: Couldn't restore STDOUT\n";
print 'Hello again!';
print '$scalar: ', $scalar;
__END__
>What I do not understand is, why there is a different behaviour in the two
>versions of the programm and what I can do to capture the result of piping
>the programm to perl into $scalar.
Sorry, I can't answer to that for it was easier for me to rewrite the
program from scratch.
>PS.: I know about the existance of "eval", so please no comments about it.
I don't think I've made any! ;-)
Last, isn't it that you just need to know about select()? See this
example:
#!/usr/bin/perl -l
use strict;
use warnings;
my $scalar;
open my $fh, '>', \$scalar or
die "$0: Couldn't open STDOUT in memory\n";
my $oldout=select $fh;
print 'Hi';
select $oldout;
print '$scalar: ', $scalar;
__END__
HTH,
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 27 Nov 2004 01:19:29 -0800
From: "Xavier Noria" <fxn@hashref.com>
Subject: Re: source filters at runtime
Message-Id: <1101547169.867564.237640@f14g2000cwb.googlegroups.com>
Thank you very much! I knew how filters work in general (I wrote
Acme::Pythonic in fact), but lacked the C side of this.
>It should be self-understood that it is impossible to apply
>a source filter after the source has already been tokenized
>and parsed. And that is the reason why it has to happen at
>compiletime. Therefore, it only works with 'use' or 'require'
>put into a BEGIN block.
The problem to self-understand that (that originated I wanted to
doubled check my assumption) is that from the view of a person that
does not know perl's internals, as me, there's no reason to assume perl
cannot remember the necessary context to be able to reenter the
compilation process and redo the entire optree at runtime. In fact I
don't know whether that's technically nonsense, or doable but really
hard, or easily doable but nobody wrote it, ....
Not that my question meant I think that would be desirable, I was
preparing a talk[*] about source filters and happened that l couldn't
explain technically why they didn't work at runtime for certain.
Thank you Tassilo!
-- fxn
[*] In Catalan: http://www.hashref.com/tlk/fdc/filtres_de_codi.pdf
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 7455
***************************************