[25211] in Perl-Users-Digest
Perl-Users Digest, Issue: 7456 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 27 18:06:03 2004
Date: Sat, 27 Nov 2004 15: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: 7456
Today's topics:
500 Can't connect to search.cpan.org:80 (Bad protocol ' <param_nirvana@hotmail.com>
Re: [OT] Difference between XHTML and HTTP (WAS: charac <matthew.garrish@sympatico.ca>
Re: counting words in a file ioneabu@yahoo.com
Re: Dat files help "Att James" hope@hope.com
Re: Dat files help "Att James" <tadmc@augustmail.com>
Re: Email script separates words with + instead of a sp <matternc@comcast.net>
FAQ 3.4: How do I find which modules are installed on m <comdog@panix.com>
FAQ 5.29: How can I tell whether there's a character wa <comdog@panix.com>
Re: Managing PERL5LIB with multiple perl installation <No_4@dsl.pipex.com>
Matt's formail not working outside domain (Mortgageloan2004)
Re: Matt's formail not working outside domain <apeiron@comcast.net>
Re: Matt's formail not working outside domain <bik.mido@tiscalinet.it>
Re: Matt's formail not working outside domain <1usa@llenroc.ude.invalid>
Re: Redirecting STDOUT to Scalar behaves not as expecte <zaphod@s4r.de>
Re: Redirecting STDOUT to Scalar behaves not as expecte <bik.mido@tiscalinet.it>
Re: Redirecting STDOUT to Scalar behaves not as expecte <bik.mido@tiscalinet.it>
sorting objects with "sort" and subroutine (Jay Eckles)
Re: sorting objects with "sort" and subroutine <and11@rol.ru>
Transiting from Perl: Learn Python or Ruby? (Goh, Yong Kwang)
Re: Transiting from Perl: Learn Python or Ruby? <apeiron@comcast.net>
Re: Transiting from Perl: Learn Python or Ruby? <comdog@panix.com>
Re: Transiting from Perl: Learn Python or Ruby? <bik.mido@tiscalinet.it>
Re: Use of uninitialized value in subroutine entry at C <bik.mido@tiscalinet.it>
Use of uninitialized value in subroutine entry at C:/Pe <param_nirvana@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 27 Nov 2004 18:37:25 +0000
From: Nirvana <param_nirvana@hotmail.com>
Subject: 500 Can't connect to search.cpan.org:80 (Bad protocol 'tcp') at web.pl line 24.
Message-Id: <coahh5$occ$1@newsg3.svr.pol.co.uk>
#!C:/Perl/bin/perl.exe -w
use LWP::Simple;
use HTML::Parse;
use HTML::Element;
use HTML::Parser;
use HTML::FormatText;
use Socket;
$ENV{"SYSTEMROOT"} = "C:/WINDOWS/system32";
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://search.cpan.org/');
if ($response->is_success) {
print $response->content; # or whatever
}
else {
die $response->status_line;
}
I'm getting following error:
500 Can't connect to search.cpan.org:80 (Bad protocol 'tcp') at web.pl
line 24.
Any help ?
------------------------------
Date: Sat, 27 Nov 2004 14:27:02 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: [OT] Difference between XHTML and HTTP (WAS: character encoding in CGI.pm)
Message-Id: <3y4qd.84152$Le1.1743474@news20.bellglobal.com>
"Shawn Corey" <shawn.corey@sympatico.ca> wrote in message
news:A0Fpd.52178$Ro.2133284@news20.bellglobal.com...
> Alan J. Flavell wrote:
>> A truly remarkable castle that you've built in the air there; have you
>> read XHTML/1.0 Appendix C, by any chance?
>
> Please explain what XHTML/1.0 Appendix C has to do with HTTP.
>
In other words, you haven't read the appendix. See section C.9 if it's so
painful to you to actually read something in its entirety.
Matt
------------------------------
Date: 27 Nov 2004 14:05:16 -0800
From: ioneabu@yahoo.com
Subject: Re: counting words in a file
Message-Id: <1101593116.600342.14570@f14g2000cwb.googlegroups.com>
That's a slightly easier problem I think. If you want the total of the
two:
#!/usr/bin/perl
$fn = "/textucation/moby10b.txt";
open (INF, $fn) or die "error: $!";
my $c;
for (<INF>){$c++ while /descry|descried/gi;}
print "found $c";
I get 26 total.
Sorry for the poor posting format, I was forced into it by the new
Google Groups2 beta. It gets the posts up much faster, but it forces
this format in a reply to a post. Hopefully they will fix it so people
can reply in the format consistent with the group they are posting too.
wana
------------------------------
Date: Sat, 27 Nov 2004 17:03:11 GMT
From: hope@hope.com
Subject: Re: Dat files help "Att James"
Message-Id: <uubhq0h6bri7m8m9mnvh3unh6rjiu6vmu4@4ax.com>
On Fri, 26 Nov 2004 16:34:59 -0600, Tad McClellan <tadmc@augustmail.com>
wrote:
>> What I have is this
>> 1....I have a load of dat files in a folder called users this is in the
>> cgi folder like
>> c:\apache\apache2\cgi-bin\data\users\1234.dat 5678.dat etc
>
>
> my @dat_files = glob 'c:/apache/apache2/cgi-bin/data/users/*.dat';
SO from me trying to read about this have I got this right?
1...........You are defining "my @dat_files"
2........... look in the folder named users,with all extensions of .dat.
>> 2.....Inside each of these dat files
>
>
> foreach my $fname ( @dat_files ) { # untested
> print "found '$fname'\n"; # for debugging
> open DAT, $fname or die "could not open '$fname' $!";
> while ( <DAT> ) {
> # do something with the line in the $_ variable
> }
> close DAT;
> }
So now it has gone and looked in that folder and found all files with a
extension of .dat pull the information out of them and put it in a
variable called $fname
Then once it is in the variable I can do what I want with it.
If I have got this wrong then I'm going to call it a day and get some
one to do it for me, as I'm just going round in circles.
>
>
>> I have information like
> ^^^^
>
>We do not have enough information about the details of your data
>to help you with actual code. You should have posted some sample data.
>
Ok here is the data as I see it in the dat files
I hope that is what you mean
#########################################
Tom.dat file under folder called users
This is how it looks when I open the dat file
BUT not with the information I have put at the side so the dat file
would look like
######################################
lalala
tom@tom.co.uk
Birmingham
W Midlands
UK
0
921118491647
941118491567
1051118491458
351117134695
#########################################
Password lalala
Email tom@tom.co.uk
Space
Space
Location Birmingham
W Midlands
Space
Country UK
Space
Ref 0
Dat files for this users 921118491647
941118491567
1051118491458
351117134695
###############################################
This is from the dat folder, file named 921118491647.dat
#######################################################
My work,so far
0.00
1.00
Hello , This is my work so far, I have done a load like this and I hope
you like it (I do Ha Ha) Most of the time a take my pics, then
paint them
http://toms.com.com/pics/1.jpg
http://toms.com/
Birmingham
W Midlands
UK
########################################################
Title My work,so far
Ref Number 0.00
Posts 1.00
Details ALL ON ONE LINE Hello , This is my work so far, I have
done a load like this and I hope you like it (I do Ha Ha) Most of
the time a take my pics, then paint them
Pic location http://toms.com.com/pics/1.jpg
Home Page http://toms.com/
Location Birmingham
W Midlands
Country UK
Hope I have given you enough information
>
>> 3.....Now what I want to do is fetch the above info out of the dat files
>> and do one of two things
>
>> 2......Make a text/csv file
>
>> If you could give me some pointers on how to do this OR point me in the
>> right direction to where I could get some examples please
>
>
>The very first stop whenever you find your self wanting to
>do "whatever" is to see if there is a module that already
>does that "whatever".
>
>If you can find one, you get all of that coding for free!
>
> http://search.cpan.org/search?query=CSV
Ok will go and have a look to see if I can understand them
Many thanks for your time with me
John
------------------------------
Date: Sat, 27 Nov 2004 13:39:59 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Dat files help "Att James"
Message-Id: <slrncqhm0f.6su.tadmc@magna.augustmail.com>
hope@hope.com <hope@hope.com> wrote:
> On Fri, 26 Nov 2004 16:34:59 -0600, Tad McClellan <tadmc@augustmail.com>
> wrote:
>
>>> What I have is this
>>> 1....I have a load of dat files in a folder called users this is in the
>>> cgi folder like
>>> c:\apache\apache2\cgi-bin\data\users\1234.dat 5678.dat etc
>>
>>
>> my @dat_files = glob 'c:/apache/apache2/cgi-bin/data/users/*.dat';
>
>
> SO from me trying to read about this have I got this right?
> 1...........You are defining "my @dat_files"
> 2........... look in the folder named users,with all extensions of .dat.
Right.
>>> 2.....Inside each of these dat files
>>
>>
>> foreach my $fname ( @dat_files ) { # untested
>> print "found '$fname'\n"; # for debugging
>> open DAT, $fname or die "could not open '$fname' $!";
>> while ( <DAT> ) {
>> # do something with the line in the $_ variable
>> }
>> close DAT;
>> }
>
> So now it has gone and looked in that folder and found all files with a
> extension of .dat pull the information out of them and put it in a
> variable called $fname
Wrong.
I wouldn't call it "fname" if it contained file _contents_.
$fname is the file_name_ of one of the .dat files.
> Then once it is in the variable I can do what I want with it.
You get one line from the file into $_, then you can do whatever
you want with that line.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 27 Nov 2004 13:09:17 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Email script separates words with + instead of a space
Message-Id: <paudnV92asNQXzXcRVn-qQ@comcast.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?
>
GAH, my eyes!
<code mercifully snipped>
I think you made a wrong turn somewhere. The Obfuscated Perl Challenge
is the *third* door on the left.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
------------------------------
Date: Sat, 27 Nov 2004 17:03:02 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.4: How do I find which modules are installed on my system?
Message-Id: <coac06$594$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.4: How do I find which modules are installed on my system?
You can use the ExtUtils::Installed module to show all installed
distributions, although it can take awhile to do its magic. The standard
library which comes with Perl just shows up as "Perl" (although you can
get those with Module::CoreList).
use ExtUtils::Installed;
my $inst = ExtUtils::Installed->new();
my @modules = $inst->modules();
If you want a list of all of the Perl module filenames, you can use
File::Find::Rule.
use File::Find::Rule;
my @files = File::Find::Rule->file()->name( '*.pm' )->in( @INC );
If you do not have that module, you can do the same thing with
File::Find which is part of the standard library.
use File::Find;
my @files;
find sub { push @files, $File::Find::name if -f _ && /\.pm$/ },
@INC;
print join "\n", @files;
If you simply need to quickly check to see if a module is available, you
can check for its documentation. If you can read the documentation the
module is most likely installed. If you cannot read the documentation,
the module might not have any (in rare cases).
prompt% perldoc Module::Name
You can also try to include the module in a one-liner to see if perl
finds it.
perl -MModule::Name -e1
--------------------------------------------------------------------
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 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 5.29: How can I tell whether there's a character waiting on a filehandle?
Message-Id: <cob135$cco$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.
--------------------------------------------------------------------
5.29: How can I tell whether there's a character waiting on a filehandle?
The very first thing you should do is look into getting the
Term::ReadKey extension from CPAN. As we mentioned earlier, it now even
has limited support for non-portable (read: not open systems, closed,
proprietary, not POSIX, not Unix, etc) systems.
You should also check out the Frequently Asked Questions list in
comp.unix.* for things like this: the answer is essentially the same.
It's very system dependent. Here's one solution that works on BSD
systems:
sub key_ready {
my($rin, $nfd);
vec($rin, fileno(STDIN), 1) = 1;
return $nfd = select($rin,undef,undef,0);
}
If you want to find out how many characters are waiting, there's also
the FIONREAD ioctl call to be looked at. The *h2ph* tool that comes with
Perl tries to convert C include files to Perl code, which can be
"require"d. FIONREAD ends up defined as a function in the *sys/ioctl.ph*
file:
require 'sys/ioctl.ph';
$size = pack("L", 0);
ioctl(FH, FIONREAD(), $size) or die "Couldn't call ioctl: $!\n";
$size = unpack("L", $size);
If *h2ph* wasn't installed or doesn't work for you, you can *grep* the
include files by hand:
% grep FIONREAD /usr/include/*/*
/usr/include/asm/ioctls.h:#define FIONREAD 0x541B
Or write a small C program using the editor of champions:
% cat > fionread.c
#include <sys/ioctl.h>
main() {
printf("%#08x\n", FIONREAD);
}
^D
% cc -o fionread fionread.c
% ./fionread
0x4004667f
And then hard code it, leaving porting as an exercise to your successor.
$FIONREAD = 0x4004667f; # XXX: opsys dependent
$size = pack("L", 0);
ioctl(FH, $FIONREAD, $size) or die "Couldn't call ioctl: $!\n";
$size = unpack("L", $size);
FIONREAD requires a filehandle connected to a stream, meaning that
sockets, pipes, and tty devices work, but *not* files.
--------------------------------------------------------------------
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 16:45:55 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: Managing PERL5LIB with multiple perl installation
Message-Id: <41a8af43$0$16583$cc9e4d1f@news-text.dial.pipex.com>
Ben Morrow wrote:
>>I am not sure what an interlude is. can you please elaborate on it?
>
>
> A more usual (or perhaps simply more modern?) term would be 'shell
> script' or 'batch file', depending on OS.
Which would be wrong if the interlude were, in fact a C program.
An interlude is anything which comes between what you and what you
finally end up running. The intend is to do something consistent/useful for
you without you needing to think about it. Particularly useful in
multi-user, multi-application environments when this interlude can be
maintained by the individual application maintainer to do-the-right-thing
and hence avoid requiring users to do things, or worry about
inter-application problems when setting things such as PERL5LIB or
LD_LIBRARY_PATH for specific applications (and perl is just an application
in this sense).
--
-*- Just because I've written it here doesn't -*-
-*- mean that you should, or I do, believe it. -*-
------------------------------
Date: 27 Nov 2004 19:36:48 GMT
From: mortgageloan2004@aol.com (Mortgageloan2004)
Subject: Matt's formail not working outside domain
Message-Id: <20041127143648.21945.00001339@mb-m06.aol.com>
I have READ all his documentation carefully. It works within my domain. But
when I send the form contents to another domain, it never arrives. It comes
back with a "permanent error".
Subject: Mail delivery failed: returning message to sender
From: "Mail Delivery System" <Mailer-Daemon@naos.lunarpages.com>
Date: Sat, November 27, 2004 11:20 am
To: mortga20@naos.lunarpages.com
Priority: Normal
Options: View Full Header | View Printable Version
This message was created automatically by mail delivery software.
A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:
mortgageloan2004@aol.com
SMTP error from remote mailer after end of data:
host mailin-01.mx.aol.com [205.188.159.57]: 554-:
(RLY:FA) http://postmaster.info.aol.com/errors/554rlyfa.html
554 TRANSACTION FAILED
There are only 2 things to configure in this program .This is from my program:
$mailprog = '/usr/sbin/sendmail -i -t';
# @referers allows forms to be located only on servers which are defined #
# in this field. This security fix from the last version which allowed #
# anyone on any server to use your FormMail script on their web site. #
@referers = ('mortgage-applications-online.com');
# @recipients defines the e-mail addresses or domain names that e-mail can #
# be sent to. This must be filled in correctly to prevent SPAM and allow #
# valid addresses to receive e-mail. Read the documentation to find out how #
# this variable works!!! It is EXTREMELY IMPORTANT. #
@recipients = ('^mortgageloan2004\@aol\.com');
I hard coded recipients exactly the way it says in the faq at his site.
scriptarchive.com for the formail. I only want the form going to 1 email
address.
This is from the faq:
@referers = ('scriptarchive.com','YOUR_IP');
This array allows you to define the domains on which you allow forms to
reside and use this installation of FormMail. If a user tries to put a form on
another server, that is not scriptarchive.com, they will receive an error
message when someone tries to fill out their form. By placing scriptarchive.com
in the @referers array, this also allows www.scriptarchive.com,
ftp.scriptarchive.com, any other http address with scriptarchive.com in it and
scriptarchive.com's IP address to access this script as well, so no users will
be turned away.
NOTE: This is not a security check. Referer headers can EASILY be faked.
Rather, it prevents someone on xyznotyou.com from using the FormMail on your
server to process forms on their server on a regular basis. It remains in the
script as a remnant of earlier versions when it was used for security, but the
@recipients variable is now used to specify exactly who can receive e-mail from
this installation.
As of version 1.7, the domains listed here are also used as the defaults when
checking valid recipient e-mail addresses. You should either include all domain
names that you wish to have FormMail send e-mails to in your @referers array or
tailor the @recipients array by hand.
I ONLY WANT CERTAIN ADDRESSES TO WORK!
Let's say you only want yourself@yourdomain.com to be able to receive any form
submissions. You should then set the @recipients array to:
@recipients = ('^yourself\@yourdomain\.com'); #this is what I did
Now the only valid recipient is that one e-mail address.
If there are several, simply do:
@recipients = ('^user1\@yourdomain\.com',
'^user2\@their\.domain\.com');
and here is my html form:
<input type=hidden name="required"value="Name, Email, Comments">
<input type=hidden name="redirect" value="../members/comments_sent.htm">
<input type=hidden name="recipient" value="mortgageloan2004@aol.com">
<INPUT TYPE="hidden" NAME="subject" VALUE="*Comments from member at
mortgage-applications-online.com"> <INPUT TYPE=submit VALUE="Send In">
<INPUT TYPE=reset VALUE="Reset">
Why isn't this working?
------------------------------
Date: 27 Nov 2004 20:08:48 GMT
From: Christopher Nehren <apeiron@comcast.net>
Subject: Re: Matt's formail not working outside domain
Message-Id: <slrncqhnmg.l0f.apeiron@prophecy.dyndns.org>
On 2004-11-27, Mortgageloan2004 scribbled these
curious markings:
> I have READ all his documentation carefully. It works within my domain. But
> when I send the form contents to another domain, it never arrives. It comes
> back with a "permanent error".
Please, for the love of dromedaries everywhere, don't use Matt's code.
Ever. There's a growing archive of replacement scripts which Matt
himself recommends which perform the same operations as his code in a
more secure, and generally better fashion. Check out
http://nms-cgi.sourceforge.net/scripts.shtml .
> Why isn't this working?
The polite answer: because Matt's code is buggy.
The impolite answer: insert expletives at will into the above.
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
Linux: "How rebellious ... in a conformist sort of way."
Unix is user friendly. However, it isn't idiot friendly.
------------------------------
Date: Sat, 27 Nov 2004 23:02:30 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Matt's formail not working outside domain
Message-Id: <upshq0djbtkq5vjff88bd1ivirsj05o9ru@4ax.com>
On 27 Nov 2004 19:36:48 GMT, mortgageloan2004@aol.com
(Mortgageloan2004) wrote:
>Subject: Matt's formail not working outside domain
Whatever the content of your post may be, before even reading it it's
worth pointing out that Matt's scripts are known to be severely
unsecure/buggy/broken in many different ways.
Matt himself is now redirecting people to better replacements which
IIRC are available at <http://mms.sourceforge.net> (sorry, I can't
check right now, and I've already drank too many beers to be sure! ;-)
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 22:28:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Matt's formail not working outside domain
Message-Id: <Xns95AEB1B72D74Casu1cornelledu@132.236.56.8>
mortgageloan2004@aol.com (Mortgageloan2004) wrote in
news:20041127143648.21945.00001339@mb-m06.aol.com:
> I have READ all his documentation carefully.
No one cares.
> Why isn't this working?
Your problem, not ours.
--
A. Sinan Unur
1usa@llenroc.ude.invalid
(remove '.invalid' and reverse each component for email address)
------------------------------
Date: Sat, 27 Nov 2004 18:38:46 +0100
From: zaphod <zaphod@s4r.de>
Subject: Re: Redirecting STDOUT to Scalar behaves not as expected. Why?
Message-Id: <pan.2004.11.27.17.38.46.290000@s4r.de>
On Sat, 27 Nov 2004 11:05:19 +0100, Michele Dondi wrote:
Hi Michele,
Thank you for your short tutorial, but I think you have not got the point.
I was not asking about optimizing my code for a recent perl version, but
why I can redirect the output of the piped perl program into a file but
not into a string. I am sorry, when I was not saying this clear enough.
> 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.
How recent? I am using perl 5.6, the code I started this script with came
originally from perl 5.0.
>># 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)?
I am sorry, I did not put "I know about HERE doc" in P.S. ;-)
I was using an array, because I wanted to print the code line by line
into |perl, this is close to the behaviour of the 'real' program. In the
'real' programm there will be no embeded code.
>># 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!
Sorry about that - I missed to change this when putting the sample code
together.
>># 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?
This is the most interesting part of the code: the piped perl also
produces output to STDOUT. In demo2.pl I do not find it in the $scalar,
while in demo1.pl (which uses a file instead of $scalar) it goes into the
file as wanted.
>>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
But did you notice, that it does not work? Under perl 5.6 it will not run
at all, but with perl 5.8 it does.
So when I try your code I get:
--------------------------
Hello again!
$scalar: Hi
--------------------------
instead of
--------------------------
Hello again!
$scalar: HiHello World!
1
2
3
4
5
--------------------------
So I thought, this might be a Win32-issue, but on linux I get the same
results. Thats why I framed $scalar in >>> <<<.
>
>>PS.: I know about the existance of "eval", so please no comments about it.
>
> I don't think I've made any! ;-)
But a lot of others ;-)
> 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__
>
>
A nice other example for redirecting to a string, but not more. I added
the |perl-part and got another result. Like in your example before 'Hi'
goes to $scalar, but while the output of |perl is supressed, here it still
goes to the terminal as if STDOUT has not been redirected.
Thanks anyway, now I know a little more about perl 5.8.
Regards
Thomas
------------------------------
Date: Sat, 27 Nov 2004 20:41:54 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Redirecting STDOUT to Scalar behaves not as expected. Why?
Message-Id: <c22hq09i1gvrpdli7e1unsch1avro1qhhe@4ax.com>
On Sat, 27 Nov 2004 11:05:19 +0100, Michele Dondi
<bik.mido@tiscalinet.it> wrote:
> open my $fh, '>', \$scalar or
> die "$0: Couldn't open STDOUT in memory\n";
[ashamed]
Of course, even if these were meant to be *minimal* examples, I forgot
including in ordieish statements $!, which would have been a Very Good
Thing(TM) anyway.
Also, *this* message is misleading (and incorrect!): it was left over
from the first script that I quickly edited to obtain the second one.
Sorry,
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 23:02:26 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Redirecting STDOUT to Scalar behaves not as expected. Why?
Message-Id: <5buhq01tq5qumdpispdjiv8m1mvqkau62f@4ax.com>
On Sat, 27 Nov 2004 18:38:46 +0100, zaphod <zaphod@s4r.de> wrote:
>On Sat, 27 Nov 2004 11:05:19 +0100, Michele Dondi wrote:
>
>Hi Michele,
>
>Thank you for your short tutorial, but I think you have not got the point.
>I was not asking about optimizing my code for a recent perl version, but
>why I can redirect the output of the piped perl program into a file but
>not into a string. I am sorry, when I was not saying this clear enough.
Sorry then! The answer is that with standard Perl functions/operators
you can't both pipe *into* a program and *out* of it. Rumors have it
that File::Open{2,3} supply this kind of facility. I don't think that
the other modules you were using "do that kinda things"...
>> 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.
>
>How recent? I am using perl 5.6, the code I started this script with came
>originally from perl 5.0.
5.6 should do it!
>>>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)?
>
>I am sorry, I did not put "I know about HERE doc" in P.S. ;-)
>I was using an array, because I wanted to print the code line by line
>into |perl, this is close to the behaviour of the 'real' program. In the
>'real' programm there will be no embeded code.
Using an HERE doc or anything more readable/maintainable than an array
of strings full of "\n"s would be just as close to it. This is the
point I wanted to stress...
>> 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?
>
>This is the most interesting part of the code: the piped perl also
>produces output to STDOUT. In demo2.pl I do not find it in the $scalar,
Ahhhhh!!!
That's the point: but it produces output to *its own* STDOUT which has
"nothing" to do with the main script's one. Then see the cmt at the
beginning.
>while in demo1.pl (which uses a file instead of $scalar) it goes into the
>file as wanted.
I've not checked, but personally I would think of *that* as the
*wrong* behaviour. This is why I didn't even understand what you were
after in the first place. To make things clear: there's no (or there
should not be) such a thing like a "system-wide STDOUT".
>> All in all see if the following suits your needs:
[snip code]
>> Sorry, I can't answer to that for it was easier for me to rewrite the
>> program from scratch
>
>But did you notice, that it does not work? Under perl 5.6 it will not run
>at all, but with perl 5.8 it does.
Sorry, I've begun with 5.6.1, and I haven't noticed any macroscopic
change up to 5.8.*. I must admit I haven't the slightest idea why it
doesn't work for 5.6, sorry!
>So when I try your code I get:
>
>--------------------------
>Hello again!
>$scalar: Hi
But this is what I expected. And I didn't expect you were expecting
anything different. See the cmt at the beginning again!
>> Last, isn't it that you just need to know about select()? See this
>> example:
[snip code]
>A nice other example for redirecting to a string, but not more. I added
>the |perl-part and got another result. Like in your example before 'Hi'
>goes to $scalar, but while the output of |perl is supressed, here it still
>goes to the terminal as if STDOUT has not been redirected.
Again, it does what it is supposed to do, that is what I *thought* you
were after anyway: it redirects the script's STDOUT. Of course it
doesn't redirect the output of the forked perl process. And as far as
I'm concerned I don't see any reason why it should!
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 10:55:56 -0800
From: j.eckles@computer.org (Jay Eckles)
Subject: sorting objects with "sort" and subroutine
Message-Id: <f98fc400.0411271055.5c49f5f1@posting.google.com>
I'm having some difficulty figuring out why a bit of code isn't
working. I'm hoping you can help.
I have a funciton that retuns an array of objects. I have defined the
class myself (the definition is below, it's quite short). I want to
sort that array, using a subroutine to define how the objects should
be sorted. Here's the line I use to call sort:
@events = sort calendar::timeCompare @events
Where calendar::timeCompare is the subroutine I've defined in a
package I called calendar.
The problem is that in timeCompare, I'm not able to access any of the
members of the objects $a and $b. For example,
package calendar ;
...
sub timeCompare{
print STDERR "a when: $a->{'when'}\n" ;
print STDERR "a summary: $a->{'summary'}\n" ;
...
gives me the following output:
a when:
a summary:
(I know that the object have values for 'when' and 'summary' because I
use the objects, after the sort call, and they have values).
Without access to these members, I can't sort the objects. Is there
any trick to sorting objects as opposed to scalar values?
Thanks for any assistance you can lend.
Jay Eckles
PS - here's the class definition:
###Event class
package Event ;
sub new {
my($class) = shift;
bless {
"date" => undef,
"when" => undef,
"location" => undef,
"summary" => undef,
"details" => undef
}, $class;
}
PPS - this is part of an open source project called CGI Calendar,
http://sourceforge.net/projects/cgicalendar
------------------------------
Date: Sat, 27 Nov 2004 22:03:06 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: sorting objects with "sort" and subroutine
Message-Id: <coaj5o$jnl$1@news.rol.ru>
Jay Eckles wrote on 27 Ноябрь 2004 18:55:
> I'm having some difficulty figuring out why a bit of code isn't
> working. I'm hoping you can help.
>
> I have a funciton that retuns an array of objects. I have defined the
> class myself (the definition is below, it's quite short). I want to
> sort that array, using a subroutine to define how the objects should
> be sorted. Here's the line I use to call sort:
>
> @events = sort calendar::timeCompare @events
>
> Where calendar::timeCompare is the subroutine I've defined in a
> package I called calendar.
>
> The problem is that in timeCompare, I'm not able to access any of the
> members of the objects $a and $b. For example,
>
> package calendar ;
> ...
> sub timeCompare{
> print STDERR "a when: $a->{'when'}\n" ;
> print STDERR "a summary: $a->{'summary'}\n" ;
> ...
>
> gives me the following output:
>
> a when:
> a summary:
>
> (I know that the object have values for 'when' and 'summary' because I
> use the objects, after the sort call, and they have values).
>
> Without access to these members, I can't sort the objects. Is there
> any trick to sorting objects as opposed to scalar values?
>
> Thanks for any assistance you can lend.
>
> Jay Eckles
>
> PS - here's the class definition:
>
> ###Event class
> package Event ;
>
> sub new {
> my($class) = shift;
>
> bless {
> "date" => undef,
> "when" => undef,
> "location" => undef,
> "summary" => undef,
> "details" => undef
> }, $class;
> }
>
> PPS - this is part of an open source project called CGI Calendar,
> http://sourceforge.net/projects/cgicalendar
because $a, $ba variables produced by 'sort' are in global namespace.
Access them as $main::a and $main::b.
--
Andrew
------------------------------
Date: 27 Nov 2004 08:13:15 -0800
From: gohyongkwang@hotmail.com (Goh, Yong Kwang)
Subject: Transiting from Perl: Learn Python or Ruby?
Message-Id: <354933d6.0411270813.47318132@posting.google.com>
Hi.
I've got this problem which may of us could have faced before. I must
first emphasize that I'm not trying to provoke any kind of unnecessary
debates over which language is better.
Let me explain my situation and why I'm trying to move away from Perl
for a particular application I'm developing. I've got an application
that I've built to automate the updating and generation for my
personal web site (text replacement and templating task) and I've
added in features such as incremental build (not re-generating files
that are not modified), automatic organization of files and
contemplating FTP upload feature. Hence it has grown from a 100 lines
script to 700+ lines file. In a way, it has outgrown Perl, which seems
to be getting less suitable for it. Making it object-oriented seems to
be the solution to the overly long and complex program.
But Perl's approach to OO is making the program messy and hard to read
as well, using a lot of arcane manipulation of @ISA and shift and
unshift for methods' parameters, clever but hard-to-read references
for class variables. It's support for OO looks more of clever hack and
a temporary ugly workaround rather than a consistent, clean and
elegant syntax for OO. I know this sounds offensive to Perl fans out
there but just my personal opinion, I may be wrong. Perhaps Perl 6
will address all these but I've yet to go check it up yet.
Not saying that Perl is bad and Python or Ruby is better. Nope that's
not my point. Perl is good for a quick, and short script that you want
to hack up in an hour to do something useful; hence flexibility in its
syntax is its strength. But for larger program which demands code to
be easily comprehensible and clean, Perl's flexibility becomes its
liability.
Therefore, I'm contemplating learning a new language, either Python or
Ruby, which promise cleaner and consistent syntax. So just seeking
opinion from experienced Perl programmers and developers here on which
would be a better choice for an existing Perl programmer and program
and why.
Thanks.
------------------------------
Date: 27 Nov 2004 16:58:23 GMT
From: Christopher Nehren <apeiron@comcast.net>
Subject: Re: Transiting from Perl: Learn Python or Ruby?
Message-Id: <slrncqhchf.3ar.apeiron@prophecy.dyndns.org>
On 2004-11-27, Goh, Yong Kwang scribbled these
curious markings:
> Hi.
>
> I've got this problem which may of us could have faced before. I must
> first emphasize that I'm not trying to provoke any kind of unnecessary
> debates over which language is better.
>
> Let me explain my situation and why I'm trying to move away from Perl
> for a particular application I'm developing. I've got an application
> that I've built to automate the updating and generation for my
> personal web site (text replacement and templating task) and I've
> added in features such as incremental build (not re-generating files
> that are not modified), automatic organization of files and
> contemplating FTP upload feature. Hence it has grown from a 100 lines
man make
(or info make, if you're "blessed" with GNU Make's Texinfo
"documentation")
--
I abhor a system designed for the "user", if that word is a coded
pejorative meaning "stupid and unsophisticated". -- Ken Thompson
Linux: "How rebellious ... in a conformist sort of way."
Unix is user friendly. However, it isn't idiot friendly.
------------------------------
Date: Sat, 27 Nov 2004 13:48:08 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Transiting from Perl: Learn Python or Ruby?
Message-Id: <271120041348080584%comdog@panix.com>
In article <354933d6.0411270813.47318132@posting.google.com>, Goh, Yong
Kwang <gohyongkwang@hotmail.com> wrote:
> But Perl's approach to OO is making the program messy and hard to read
> as well, using a lot of arcane manipulation of @ISA and shift and
> unshift for methods' parameters, clever but hard-to-read references
> for class variables.
I don't know what you are doing, but that sounds like a
programmer's problem of style and design.
As for which language to learn next, why not both? You'll find,
however, that each has their own problems, just like Perl has
its problems.
--
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com
------------------------------
Date: Sat, 27 Nov 2004 23:02:28 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Transiting from Perl: Learn Python or Ruby?
Message-Id: <skshq095o1dv0hl22vdvimauone3og5907@4ax.com>
On 27 Nov 2004 08:13:15 -0800, gohyongkwang@hotmail.com (Goh, Yong
Kwang) wrote:
>I've got this problem which may of us could have faced before. I must
>first emphasize that I'm not trying to provoke any kind of unnecessary
>debates over which language is better.
[snip]
>But Perl's approach to OO is making the program messy and hard to read
>as well, using a lot of arcane manipulation of @ISA and shift and
>unshift for methods' parameters, clever but hard-to-read references
>for class variables. It's support for OO looks more of clever hack and
>a temporary ugly workaround rather than a consistent, clean and
>elegant syntax for OO. I know this sounds offensive to Perl fans out
>there but just my personal opinion, I may be wrong. Perhaps Perl 6
>will address all these but I've yet to go check it up yet.
[snip]
>not my point. Perl is good for a quick, and short script that you want
>to hack up in an hour to do something useful; hence flexibility in its
>syntax is its strength. But for larger program which demands code to
>be easily comprehensible and clean, Perl's flexibility becomes its
>liability.
Well, that's your *very* humble opinion. As far as you're concerned
just choose the language you'll find most suitable for your needs and
we will continue to be friends as before.
However in the experience of most of us I think that your claims will
sound plainly and definitely false. In other words I'm sure what that
you think to be shortcomings of [Pp]erl for most of us plainly do not
exist, period. So I doubt that we share a common starting basis upon
which we can build any answer that you will find acceptable.
So, in a certain sense, indeed you can avoid an unneccessary and
futile debate about which language is the best, but you can't avoid a
comment about the fact that Perl is perfectly suited for tasks well
beyond quick hacks and short scripts.
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 23:02:29 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Use of uninitialized value in subroutine entry at C:/Perl/site/lib/HTML/Parse.pm line 127.
Message-Id: <ieshq01q6oebgmmbgt48ql6qg5oo320g7v@4ax.com>
On Sat, 27 Nov 2004 17:24:16 +0000, Nirvana
<param_nirvana@hotmail.com> wrote:
>perl script i'm getting this error:
>
>Use of uninitialized value in subroutine entry at
It's not an error. It's a warning, and by far one of the most common
ones. In fact the code that generates it often needs to be enclosed in
a
{
no warnings 'uninitialized';
# ...
}
block. If (and only if) you get a correct output you can silently
ignore it. FWIW I remember some Tk module *incorrectly* not being
protected against it some time ago... (and I did ignore it!)
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 17:24:16 +0000
From: Nirvana <param_nirvana@hotmail.com>
Subject: Use of uninitialized value in subroutine entry at C:/Perl/site/lib/HTML/Parse.pm line 127.
Message-Id: <coad81$83j$1@news7.svr.pol.co.uk>
Hello all,
I'm using Active state perl on Windows XP and while running a simple
perl script i'm getting this error:
Use of uninitialized value in subroutine entry at
C:/Perl/site/lib/HTML/Parse.pm line 127.
Here is my script
#!C:/Perl/bin/perl.exe -w
use LWP::Simple;
use HTML::Parse;
use HTML::Element;
use HTML::Parser;
use HTML::FormatText;
use strict;
use warnings;
my $url= "http://www.google.com";
print parse_html(get $url)->format;
------------------------------
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 7456
***************************************