[23034] in Perl-Users-Digest
Perl-Users Digest, Issue: 5254 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 22 03:05:53 2003
Date: Tue, 22 Jul 2003 00:05:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 22 Jul 2003 Volume: 10 Number: 5254
Today's topics:
Can't read from open2 (Pranab Mehta)
Re: generalizing cgi handling <me@home.com>
Re: generalizing cgi handling <me@home.com>
Re: Get file extention from path <his_ron@yahoo.com>
Re: Get file extention from path <asu1@c-o-r-n-e-l-l.edu>
Re: JOIN problem ? (2nd attempt to post) <uri@stemsystems.com>
Larry W... out of work ?? Impossible... or... (stu7)
Re: Larry W... out of work ?? Impossible... or... <asu1@c-o-r-n-e-l-l.edu>
Re: Larry W... out of work ?? Impossible... or... <kkeller-spammmm@wombat.san-francisco.ca.us>
Re: Larry W... out of work ?? Impossible... or... <bernie@fantasyfarm.com>
Re: Larry W... out of work ?? Impossible... or... <mgjv@tradingpost.com.au>
Re: Larry W... out of work ?? Impossible... or... user@domain.invalid
Re: Larry W... out of work ?? Impossible... or... (Randal L. Schwartz)
Multiple object types in a single .pm? <bernie@fantasyfarm.com>
Re: not recursing dir's using File::Find (david)
Re: not recursing dir's using File::Find <wasell@bahnhof.se>
Re: Please critique my 2nd Perl program (generates an a (Tad McClellan)
Re: Please critique my 2nd Perl program (generates an a <spamblock@junkmail.com>
Re: Please critique my 2nd Perl program (generates an a <xaonon@hotpop.com>
Re: Please critique my 2nd Perl program (generates an a <tassilo.parseval@rwth-aachen.de>
Re: recompile Perl, with new function names ? <uri@stemsystems.com>
Re: Using 'my' within nested loops <spamblock@junkmail.com>
why doesn't HTML::HeadParser include a parse_file funct <jidanni@jidanni.org>
Re: why doesn't HTML::HeadParser include a parse_file f <tassilo.parseval@rwth-aachen.de>
Re: Why is 'last' not allowed here (Ronald Fischer)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Jul 2003 20:52:45 -0700
From: pranab@employees.org (Pranab Mehta)
Subject: Can't read from open2
Message-Id: <eebac6cb.0307211952.4292e697@posting.google.com>
Hi All,
I'm trying to automate data entry to a windows app using wine from my
linux machine. I'm not very proficient with my Perl, hence this post.
Pretty simple scenario, I kick off a process, write to it, and then
want to read from it. But nothing ever prints in the output. Here's
the code in question -
$pid = open2(READHDLR, WRITEHDLR, "wine win_app.exe") or die "can't
run command: $!";
WRITEHDLR->autoflush();
READHDLR->autoflush();
print "PID = $pid\n";
print WRITEHDLR $PIN;
print WRITEHDLR "\x0d\x0a";
$got=<READHDLR>;
print "output = $got";
Now if I were to replace READHDLR with a FILEHANDLE for writing, like
this:
open(OUTFILE, "> outfile");
open2(">&OUTFILE", ...);
I can see _all_ the data from the win_app in the file. Then why can't
I read this data from READHDLR ?
Further, I don't know if this is valid, but if I pipe the output of
READHDLR to a file, like this:
open(READHDLR, "| tee outfile");
the file turns out empty.
What am I missing ?
Please someone set me on the right path ...
Thanks much,
Pranab
------------------------------
Date: Mon, 21 Jul 2003 21:08:34 -0700
From: Steve in NY <me@home.com>
Subject: Re: generalizing cgi handling
Message-Id: <drdphvo4lg74p8qdve1h782af82ls5vlt1@4ax.com>
Hi Eric,
First off, thank you for taking the time to explain these things to me. I did
some research on the net and found that a lot of people warn to stay away from
symbolic references, as did people here.
But it is very interesting to know the internals of these things. I think you
gave me some good pointers...I will explore further the concept of a typeglob,
and I really like the idea of references, althought I am not sure how to use
them yet.
And I located the exporter pm, found the same line on line 59, and started to
learn more about namespaces and the symbolic table.
All in all, I think it will take me some time to really understand it all, but
its fun to learn ;-)
------------------------------
Date: Mon, 21 Jul 2003 21:15:14 -0700
From: Steve in NY <me@home.com>
Subject: Re: generalizing cgi handling
Message-Id: <96ephvov90emn545jiji5hqdbgom8miud6@4ax.com>
Hi Jeff,
Thanks to you and Eric, I am starting to understand more about pointers and the
dangers of symbolic references. From what I found on the net, it seems a lot of
newbies (like myself) come running to this newsgroup asking how to do them...I
found several pages devoted to warning people off.
Hey...it is very generous to give me this link! I think it has about all you can
want to know to write some decent CGI.
http://www.pobox.com/~japhy/articles/ideas/CGI.html
Oh...I will tell you something that really stumped me the first time doing a big
cgi program (which was only the past few weeks) is permissions and how to handle
having user "apache" own the file.
The photo in devarticles wasn't bad at all, but I agree they did some bad
formating to your code. I like the link you gave me above better.
Thanks again!
------------------------------
Date: Tue, 22 Jul 2003 01:12:52 GMT
From: "Ron" <his_ron@yahoo.com>
Subject: Re: Get file extention from path
Message-Id: <oc0Ta.93830$hV.6769674@twister.austin.rr.com>
Thanks Sinan,
I am so new I did not even know about TFM.
I did take the time to read the posting guide lines & thought of you when I
read the first paragrah.
" A note to newsgroup ``regulars'':
Do not use these guidelines as a "license to flame" or other
meanness. It is possible that a poster is unaware of things
discussed here. Give them the benefit of the doubt, and just
help them learn how to post, rather than assume"
"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message
news:Xns93BFD05838C85asu1cornelledu@132.236.56.8...
> "Ron" <his_ron@yahoo.com> wrote in news:kE_Sa.93625$hV.6718211
> @twister.austin.rr.com:
>
> > "Tina Mueller" <usenet@expires082003.tinita.de> wrote in message
> > news:bfhqic$etufn$3@ID-24002.news.uni-berlin.de...
> >> Ron wrote:
> >> > I need to get the file extension from a path(file location+file
> >> > name+extension)
> >>
> >> perldoc File::Basename
> >> (function fileparse())
> >>
> >> hth, tina
> > Thanks Tina although I am not sure who to put that into code I tried
> >
> > my $ext1 = $FILE1(function fileparse());
> >
> > How do I use it?
>
> First, do not top-post.
>
> Second, do read the posting guidelines for this group. They are posted
here
> regularly, and available at:
>
> http://mail.augustmail.com/~tadmc/clpmisc.shtml
>
> Third, RTFM!
>
> http://www.perldoc.com/perl5.6/lib/File/Basename.html
>
> Sinan.
>
> --
> A. Sinan Unur
> asu1@c-o-r-n-e-l-l.edu
> Remove dashes for address
> Spam bait: mailto:uce@ftc.gov
------------------------------
Date: 22 Jul 2003 03:00:22 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Get file extention from path
Message-Id: <Xns93BFEA09DB19asu1cornelledu@132.236.56.8>
"Ron" <his_ron@yahoo.com> wrote in
news:oc0Ta.93830$hV.6769674@twister.austin.rr.com:
> Thanks Sinan,
>
> I am so new I did not even know about TFM.
>
> I did take the time to read the posting guide lines & thought of you
> when I read the first paragrah.
>
> " A note to newsgroup ``regulars'':
> Do not use these guidelines as a "license to flame" or other
> meanness. It is possible that a poster is unaware of things
> discussed here. Give them the benefit of the doubt, and just
> help them learn how to post, rather than assume"
Hmmmm ... my post was no flame.
And please stop top-posting.
BTW,
> my $ext1 = $FILE1(function fileparse());
is profoundly weird, and indicated to me that you spent no effort. A simple
Google search for fileparse returns the link I gave you as the first match:
http://www.google.com/search?sourceid=navclient&q=fileparse
so you did not even have to know where the docs are located on your
computer.
Sinan.
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Tue, 22 Jul 2003 06:40:07 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: JOIN problem ? (2nd attempt to post)
Message-Id: <x7oeznoyig.fsf@mail.sysarch.com>
>>>>> "s" == stu7 <stuseven@hotmail.com> writes:
s> *** ...sets out a bowl of sugar water, to attract more ***
s> style-spammers
nah, you just made sure no one would help you by your attitude. i don't
kill file but your posting style makes it easy for me to ignore you. try
to get help here and you probably will not get it except from the
newbies or clueless who don't know you yet.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 21 Jul 2003 20:16:47 -0700
From: stuseven@hotmail.com (stu7)
Subject: Larry W... out of work ?? Impossible... or...
Message-Id: <d7dd90b0.0307211916.2feb9d1b@posting.google.com>
+
...or is it ?
Lets look at what are likely the top reasons his book
company would have laid Larry off... well, first things
first... book sales down... but why ? Isn't PERL the most
popular thing to come around since email ? Sure... but,
who is it popular with ?
I first saw Perl the day it was released... I was IRCing
and somebody came around announcing this new thing, Perl, so
I checked it out... I forget what it offered at that time.
Since then, of course, Perl has grown immensely, and to
anyone willing to look, it is obvious that Perl now offers
an excellent programming framework, and endless specialized
support modules - Perl has, in addition, become a world effort...
but, to a commercial venture - a book publisher, for instance,
Perl is a gooey spit-out... it's a top grade product, with the
unfortunate reputation of being an internet no-no... why ?
Perl is NOT a professional offering... trying to make it
on a commercial level... there simply are no official
repesentatives of Perl - to anyone looking for help, we either
"buy a book", or, more often, [consult an internet Perl user
group]... this is where the goo gets sticky.
I would guess there aren't one-in-twenty prospective perl
users, who, after consulting one of the "internet Perl sources",
has had the positive response they expected, or even remains
very interested in using or learning Perl thereafter... goodbye
Perl reputation... Perl, suddenly, doesn't have any commercial
viability, when all it means is getting berated by a group of
self-styled technique experts, "discussion leaders", and, again,
anything BUT the [support people] any newcomer might expect
for real computer programming material.
There are other serious issues with Perl, not the least of
which was the prosecution of one of it's principals for "hacking"...
this charge never seemed entirely warranted, but the story doesn't
make Perl any more attractive, commercially.
Perl, I feel, remains unappreciated by most people, whether
or not they have used it extensively... but the real point of
this message was to bail out Larry W... or at least explain his
plight, and offer a possible answer. I, for one, find it
unlikely he would sacrifice economic security for the sake of
developing a new Perl framework... maybe, part of the new Perl
was to exclude some of the amateurish, stiflingly ineffacious
"expert documentation", or developmental directions...
...otherwise, it can't really be argued - Perl has real
usefulness, and there are likely endless business ventures who
could offer L.W. substantial monetary aid in exchange for his
expertise... but what is the real issue here ?
Is it even Perl related ? Is it open-source versus MicroSoft ?
Is it possible one gigantic freeware package is simply enough to
expect of one person in their lives ?
Linus got a job... why shouldn't Larry ? :)
I don't think either of them would, or should, opt for
dependency on an uncertain thing like the WWW/Internet... why
the whole Dot/Com blowout, do we imagine ? Its the same problem...
no permanence, solidity, or lasting value there... a boom market
with it's own built-in bust clientele.
I hope L.W. finds his way out of whatever problem it is,
sooner than later. Perl is perhaps as valuable as a lesson to
those who (wrongly) accept the Internet as an opportunity it
never proved itself to be.
------------------------------
Date: 22 Jul 2003 03:40:16 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Larry W... out of work ?? Impossible... or...
Message-Id: <Xns93BFF0CDCA9B7asu1cornelledu@132.236.56.8>
stuseven@hotmail.com (stu7) wrote in
news:d7dd90b0.0307211916.2feb9d1b@posting.google.com:
> I first saw Perl the day it was released... I was IRCing
> and somebody came around announcing this new thing, Perl, so
> I checked it out...
Do you mean December 1987?
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Mon, 21 Jul 2003 21:00:09 -0700
From: Keith Keller <kkeller-spammmm@wombat.san-francisco.ca.us>
Subject: Re: Larry W... out of work ?? Impossible... or...
Message-Id: <9scifb.r7i.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
In article <d7dd90b0.0307211916.2feb9d1b@posting.google.com>, stu7 wrote:
> +
> ...or is it ?
[many many lines snipped]
You must be out of work, as well, to have wasted all that time
writing so much tripe. Good luck finding a new job.
(or perhaps you're upset at your perceived mistreatment by some
other folks in the newsgroup?...)
- --keith
- --
kkeller-mmmspam@wombat.san-francisco.ca.us
(try just my userid to email me)
alt.os.linux.slackware FAQ: http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org
iEYEARECAAYFAj8ctscACgkQhVcNCxZ5ID/8zQCfdeP6aiwmkyRyvLL0Itp+IZXs
UxIAoJGXIfFibk9ivZChSU8yHMcIhHs2
=WV7h
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 21 Jul 2003 23:59:33 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: Larry W... out of work ?? Impossible... or...
Message-Id: <hfdphvkvktie6ia75jaoqlioac7ktggf42@library.airnews.net>
stuseven@hotmail.com (stu7) wrote:
} I first saw Perl the day it was released... I was IRCing
} and somebody came around announcing this new thing, Perl, so
} I checked it out... I forget what it offered at that time.
Wait a second -- IRC didn't appear until 1988 and Perl came out in 1987..
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: 22 Jul 2003 04:08:36 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Larry W... out of work ?? Impossible... or...
Message-Id: <slrnbhpe66.1le.mgjv@verbruggen.comdyn.com.au>
On Mon, 21 Jul 2003 23:59:33 -0400,
Bernie Cosell <bernie@fantasyfarm.com> wrote:
> stuseven@hotmail.com (stu7) wrote:
>
> } I first saw Perl the day it was released... I was IRCing
> } and somebody came around announcing this new thing, Perl, so
> } I checked it out... I forget what it offered at that time.
>
> Wait a second -- IRC didn't appear until 1988 and Perl came out in 1987..
This guy is not only utterly clueless, he's also a troll. Ignore him.
Martien
--
|
Martien Verbruggen | We are born naked, wet and hungry. Then
Trading Post Australia | things get worse.
|
------------------------------
Date: Tue, 22 Jul 2003 04:19:17 GMT
From: user@domain.invalid
Subject: Re: Larry W... out of work ?? Impossible... or...
Message-Id: <9X2Ta.2870$yb5.1140@newssvr22.news.prodigy.com>
Keith Keller wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> In article <d7dd90b0.0307211916.2feb9d1b@posting.google.com>, stu7 wrote:
>
> [many many lines snipped]
>
> You must be out of work, as well, to have wasted all that time
> writing so much tripe. Good luck finding a new job.
>
> (or perhaps you're upset at your perceived mistreatment by some
> other folks in the newsgroup?...)
>
> - --keith
yikes boy, his post meandered a bit, but he made some sense. i think
you're the type of poster he was referring to :)
------------------------------
Date: Tue, 22 Jul 2003 04:41:13 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Larry W... out of work ?? Impossible... or...
Message-Id: <40ddfa96a9a18724999cbc0c222a6056@free.teranews.com>
>>>>> "stu7" == stu7 <stuseven@hotmail.com> writes:
stu7> I first saw Perl the day it was released... I was IRCing
stu7> and somebody came around announcing this new thing, Perl, so
stu7> I checked it out... I forget what it offered at that time.
This is your first factual mistake, and it only goes downhill from
here. Perl has been around since long before IP packets were flowing
near your sorry hiney.
The rest of the post is just the usual FUD from someone who has been
burned. Pay no heed.
Nice try. Move along. Nothing to see here.
print "Just another Perl hacker,";
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 21 Jul 2003 22:11:40 -0400
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Multiple object types in a single .pm?
Message-Id: <o97phvs6ev0bdjh4sk4uvr8ci60sgdmset@library.airnews.net>
I have two very closely related classes that I'd like to implement in a
single .pm. I realize that the usual setup is that if you're going to do
"use Type", that the file better be called "Type.pm" and you need to have
"package Type" in there... I looked through our site_perl and toot, but I
didn't see anything that quite addressed this.
The thing is that the two classes are related [and will, indeed, share some
"cross class variables"] and I think it'd be cleaner to have both in a
single .pm file, but I'm not sure on the right syntax [much less idioms] to
get new, import, Exporter, etc... to all work.
I can do it brute force, and maybe that's the best I can do:
Class1.pm:
package Class1
sub import { Class1a::import();
Class1b::import();
}
[shared stuff between the classes]
package Class1a
first class
package Class1b
second class
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: 21 Jul 2003 19:11:06 -0700
From: dwlepage@yahoo.com (david)
Subject: Re: not recursing dir's using File::Find
Message-Id: <b09a22ae.0307211811.3a56d2c8@posting.google.com>
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<QYJSa.49016$kI5.38746@nwrddc02.gnilink.net>...
> david wrote:
> > Im trying to find all files ONLY in the current directory that are
> > called
> > "today.txt" or "sub.txt" and copy them to a different directory. Im
> > trying to do so using File::Find and File::Copy, but I cannot seem to
> > get this not to recurse through the directory structure. (There may be
> > other "today.txt" files below the current dir.
>
> In that case I wouldn't use File::Find but a simple glob().
> If standard filename expansion is not powerful enough for your needs then
> you can always filter the result using grep() in a second step.
>
> jue
Thank you. That does work better. Now my next question is, now that I
can properly find and copy my files with:
use strict;
use File::Copy;
my $targetdir="./floppy";
my $today="./current/today.txt";
open(OUT, ">>$today") || die "$!";
while ( <*.txt> ) {
copy $_, $targetdir if /today.+\.txt/i || die "Cant copy";
print OUT $_ if /today.+\.txt/i;
}
How can I iterate through each *.txt (today.+\.txt) line by line?
Thanks!
------------------------------
Date: Tue, 22 Jul 2003 05:50:20 +0200
From: Thomas Wasell <wasell@bahnhof.se>
Subject: Re: not recursing dir's using File::Find
Message-Id: <MPG.1986d288a8b4792198970e@news.bahnhof.se>
In article <b09a22ae.0307211811.3a56d2c8@posting.google.com>, david
<dwlepage@yahoo.com> wrote:
>"Jürgen Exner" <jurgenex@hotmail.com> wrote in message news:<QYJSa.49016$kI5.38746@nwrddc02.gnilink.net>...
>> david wrote:
>> > Im trying to find all files ONLY in the current directory that are
>> > called
>> > "today.txt" or "sub.txt" and copy them to a different directory. Im
>> > trying to do so using File::Find and File::Copy, but I cannot seem to
>> > get this not to recurse through the directory structure. (There may be
>> > other "today.txt" files below the current dir.
>>
>> In that case I wouldn't use File::Find but a simple glob().
>> If standard filename expansion is not powerful enough for your needs then
>> you can always filter the result using grep() in a second step.
>>
>> jue
>
>Thank you. That does work better. Now my next question is, now that I
>can properly find and copy my files with:
>
>use strict;
>use File::Copy;
>
>my $targetdir="./floppy";
>my $today="./current/today.txt";
>
>open(OUT, ">>$today") || die "$!";
What's the point of this line?
>while ( <*.txt> ) {
>copy $_, $targetdir if /today.+\.txt/i || die "Cant copy";
^^ ^^
That's the same as
copy($_, $targetdir) if (/today.+\.txt/I || die("Cant copy"));
isn't it? Are you sure that's what you want? Besides, your pattern will
match 'todayRANDOM_CHARACTERS.txt', but not 'today.txt' as in your original
question.
Why not simply do
foreach ('today.txt', 'sub.txt') {
next unless -e;
copy $_, $targetdir or die "Can't copy '$_': $!\n";
}
instead of bothering with globs?
>print OUT $_ if /today.+\.txt/i;
>}
>
>How can I iterate through each *.txt (today.+\.txt) line by line?
What do you mean? Do you want to open them and work with their contents?
>Thanks!
>
--
Thomas Wasell | Chihuahuas drive me crazy. I can't stand anything that
wasell@bahnhof.se | shivers when it's warm.
------------------------------
Date: Mon, 21 Jul 2003 21:39:54 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Please critique my 2nd Perl program (generates an auction description)
Message-Id: <slrnbhp8vq.f20.tadmc@magna.augustmail.com>
David Oswald <spamblock@junkmail.com> wrote:
> I am hoping for comments, suggestions, stylistic critiques, and a few hints.
> bin/perl -w
Is that really what the first line in the file looks like?
> use strict;
> use warnings;
Turning on warnings twice is not necessary.
If you have the warnings pragma available, then lose the
command line switch.
> # Declare the subroutines.
You don't need to declare the subroutines.
> # Top level variables:
> my ( %options,
> $headline,
> $subhead,
> @teaser,
> @features,
> @summary,
> @image_links,
> @document,
> $input );
Only $input is used outside of the do-block, so it is the
only one that needs file scope.
>
> # --- Begin main block ---
>
> do {
> %options = get_options();
> $headline = get_headline();
> $subhead = get_subhead();
> @teaser = get_teaser();
> @features = get_features();
> @summary = get_summary();
> @image_links = get_image_links();
> @document = create_html( \%options,
> $headline,
> $subhead,
> \@teaser,
> \@features,
> \@summary,
> \@image_links );
Why not just modify the subroutines to return a reference to
the appropriate data structure directly?
Then you can avoid all the temporary variables and reference-taking.
# untested
my @document = create_html( get_options(),
get_headline(),
get_subhead(),
get_teaser(),
get_features(),
get_summary(),
get_image_links()
);
> sub get_options {
> my %options = (
Aren't you getting a warning here?
[ snip rest of get_options() code. ]
> return %options;
return \%options; # return the right type of reference
> }
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Jul 2003 20:52:44 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: Please critique my 2nd Perl program (generates an auction description)
Message-Id: <vhpddkf2lndjc4@corp.supernews.com>
[Quoted text and code is edited for brevity. Original post contains entire
code segment.]
"Tad McClellan" <tadmc@augustmail.com> wrote:
> David Oswald <spamblock@junkmail.com> wrote:
>
> > I am hoping for comments, suggestions, stylistic critiques, and a few
hints.
>
> > bin/perl -w
> Is that really what the first line in the file looks like?
Actually, it's
#!/usr/bin/perl -w
I must have cut off the first little bit as I pasted.
> > use warnings;
> Turning on warnings twice is not necessary.
> If you have the warnings pragma available, then lose the
> command line switch.
I didn't realize they were identical in function. Thanks for the tip.
> > # Declare the subroutines.
> You don't need to declare the subroutines.
Doesn't use strict force me to predeclare the subs? ...and is it not
considered a good practice, or am I just reverting back to old comp. sci.
classes in the pre-Perl days?
> > # Top level variables:
> > my ( %options,
> > $headline,
> > $subhead,
> > @teaser,
> > @features,
> > @summary,
> > @image_links,
> > @document,
> > $input );
>
>
> Only $input is used outside of the do-block, so it is the
> only one that needs file scope.
Great point. I didn't really like the idea of all those file-scope
variables hanging around anyway.
> > # --- Begin main block ---
> >
> > do {
> > %options = get_options();
> > $headline = get_headline();
> > $subhead = get_subhead();
> > @teaser = get_teaser();
> > @features = get_features();
> > @summary = get_summary();
> > @image_links = get_image_links();
> > @document = create_html( \%options,
> > $headline,
> > $subhead,
> > \@teaser,
> > \@features,
> > \@summary,
> > \@image_links );
>
>
> Why not just modify the subroutines to return a reference to
> the appropriate data structure directly?
>
> Then you can avoid all the temporary variables and reference-taking.
>
> # untested
> my @document = create_html( get_options(),
> get_headline(),
> get_subhead(),
> get_teaser(),
> get_features(),
> get_summary(),
> get_image_links()
> );
>
Yes, that is a lot less clunky, isn't it? Thanks.
> > sub get_options {
> > my %options = (
> Aren't you getting a warning here?
Should I be? A list in hash context becomes a hash of key/value pairs
doesn't it? Well, I mean it does, but why should this give me a warning?
On the other side of the coin, a hash in list context becomes an array of
key1 followed by value1, followed by key2, and so on. ..At any rate, I'm
not getting a warning, but maybe I should be?
> [ snip rest of get_options() code. ]
> return \%options; # return the right type of reference
Thanks for the suggestions. As I mentioned before, my goal here is to learn
and refine, and your comments help to achieve that. Being stubborn, I like
to flesh it out on my own until I get something working, and then ask, now
how could I have done this better? Of course that opens a whole can of
worms, but at least the can is guided into a context that applies to my
approach to building my knowledgebase. To what end? None, it's just for
fun, for me. In my real life I'm a buyer.
Dave
------------------------------
Date: Tue, 22 Jul 2003 04:02:56 GMT
From: Xaonon <xaonon@hotpop.com>
Subject: Re: Please critique my 2nd Perl program (generates an auction description)
Message-Id: <slrnbhpdqe.bqn.xaonon@xaonon.local>
Ned i bach <vhpddkf2lndjc4@corp.supernews.com>, David Oswald
<spamblock@junkmail.com> teithant i thiw hin:
> > > # Declare the subroutines.
>
> > You don't need to declare the subroutines.
>
> Doesn't use strict force me to predeclare the subs? ...and is it not
> considered a good practice, or am I just reverting back to old comp. sci.
> classes in the pre-Perl days?
It's probably not a bad idea, especially if you later want to add prototypes
to the functions, in which case you *will* need to declare them in order for
the prototype checking to work properly; a warning will be issued otherwise.
--
Xaonon, EAC Chief of Mad Scientists and informal BAAWA, aa #1821, Kibo #: 1
Visit The Nexus Of All Coolness (i.e. my site) at http://xaonon.dyndns.org/
"This is the most disturbing surprise Barry Bostwick has pulled on us since
that robot dragonfly came out of his nose on `Lexx'." -- James "Kibo" Parry
------------------------------
Date: 22 Jul 2003 05:38:22 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Please critique my 2nd Perl program (generates an auction description)
Message-Id: <bfiike$m9m$1@nets3.rz.RWTH-Aachen.DE>
Also sprach David Oswald:
> [Quoted text and code is edited for brevity. Original post contains entire
> code segment.]
Yes, thank you. :-)
> "Tad McClellan" <tadmc@augustmail.com> wrote:
>> David Oswald <spamblock@junkmail.com> wrote:
>>
>> > I am hoping for comments, suggestions, stylistic critiques, and a
>> > few hints.
>> >
>> > bin/perl -w
>
>> Is that really what the first line in the file looks like?
>
> Actually, it's
> #!/usr/bin/perl -w
> I must have cut off the first little bit as I pasted.
>
>> > use warnings;
>
>> Turning on warnings twice is not necessary.
>>
>> If you have the warnings pragma available, then lose the
>> command line switch.
>
> I didn't realize they were identical in function. Thanks for the tip.
Strictly speaking, they aren't equivalent. The warnings pragma has been
added in Perl5.6.0. The -w switch enables warnings unconditionally and
everywhere in your code and the code of modules you include. If you use
warnings though you have more control over the things that perl should
warn about: You can switch off particular groups of warnings in blocks
of code without affecting the rest of your code, for instance. See
'perldoc perllexwarn'.
>> > # Declare the subroutines.
>
>> You don't need to declare the subroutines.
>
> Doesn't use strict force me to predeclare the subs? ...and is it not
> considered a good practice, or am I just reverting back to old comp. sci.
> classes in the pre-Perl days?
Perl does know about forward-declarations of subroutines. They serve a
different purpose though. If you forward-declare them, you can drop the
parens when calling them and make them look more like builtin functions:
@ary = qw(a b c);
test @ary;
sub test { print "@_" }
This gives the warning:
Array found where operator expected at - line 2, at end of line
(Do you need to predeclare test?)
and eventually a fatal error (regardless of strictures):
syntax error at - line 2, near "test @a"
Execution of - aborted due to compilation errors.
If you aadd a declaration to it:
sub test;
@ary = qw(a b c);
test @ary;
sub test { print "@_" }
then it all works as expected. This is the same as putting the function
at the top:
sub test { ... }
@a = qw(a b c);
test @a;
When you always use parens when calling your functions as in 'test(@a)'
you don't have to care about where you defined your functions.
>> > # Top level variables:
>> > my ( %options,
>> > $headline,
>> > $subhead,
>> > @teaser,
>> > @features,
>> > @summary,
>> > @image_links,
>> > @document,
>> > $input );
[...]
>> > sub get_options {
>> > my %options = (
>
>> Aren't you getting a warning here?
>
> Should I be? A list in hash context becomes a hash of key/value pairs
> doesn't it? Well, I mean it does, but why should this give me a warning?
> On the other side of the coin, a hash in list context becomes an array of
> key1 followed by value1, followed by key2, and so on. ..At any rate, I'm
> not getting a warning, but maybe I should be?
Tad was referring to a redefinition warning as in
my %options;
...
my %options;
"my" variable %options masks earlier declaration in same scope at -
line 3.
In fact (and I didn't know that myself) it does not give a warning
because they are not in the same scope. But nonetheless you are masking
the top-level %options variable. Both are lexicals so you can't access
the outer %options any longer from within your subroutine (but you
didn't want to do that anyways, so that's no problem for you).
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: Tue, 22 Jul 2003 06:40:53 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: recompile Perl, with new function names ?
Message-Id: <x7lluroyh7.fsf@mail.sysarch.com>
>>>>> "s" == stu7 <stuseven@hotmail.com> writes:
s> + Is there a way to recomplile Perl with new names for functions ?
s> (...or better, probably, including the regular names with the
s> replacement names... so original functions are still there to make
s> old scripts work :)
hmm, style changed. but no help from me.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 21 Jul 2003 19:22:01 -0700
From: "David Oswald" <spamblock@junkmail.com>
Subject: Re: Using 'my' within nested loops
Message-Id: <vhp83170cs7f75@corp.supernews.com>
"Bob Walton" <bwalton@rochester.rr.com> wrote in message
news:3F1C88B9.5060706@rochester.rr.com...
> David Oswald wrote:
>
> > I am curious about the amount of overhead created with the first example
> > below as compared to the second example below:
> >
> > Example 1:
> > my $this;
> > my $that;
> > foreach $this (@somearray) {
> > foreach $that (@some_other_array) {
> > ........
> > }
> > }
> >
> >
> > Example 2:
> > foreach my $this (@somearray) {
> > foreach my $that (@some_other_array) {
> > .......
> > }
> > }
> >
> Why don't you:
>
> use Benchmark;
>
> and find out?
>
Thanks for the suggestion. I just tried it (and should have thought of that
myself).
Here's the test code I used:
#!/usr/bin/perl -w
use strict;
use warnings;
use Benchmark;
my ($count, $this, $that, $t0, $t1, $td, @array1, @array2);
foreach (1..4000) {
push @array1,$_;
push @array2,$_;
}
$count = 0;
print "Beginning test 1.\n";
$t0 = new Benchmark;
foreach $this (@array1) {
foreach $that (@array2) {
$count++;
}
}
$t1 = new Benchmark;
$td = timediff ($t1, $t0);
print "Test 1 took: ", timestr ( $td ), "\n";
$count = 0;
print "Beginning test 2. \n";
$t0 = new Benchmark;
foreach my $those (@array1) {
foreach my $these (@array2) {
$count++;
}
}
$t1 = new Benchmark;
$td = timediff ($t1, $t0);
print "Test 2 took: ", timestr ( $td ), "\n";
The number of iterations was sufficient to tie up about 30 seconds per test
block on my measly old Windows98 Pentium II/266 notebook (my Perl testbed).
I ran it a couple times. The first time I ran it, the first testcase
(without the "my"'s inside the loops) took 33 seconds and the second
testcase (with the my's in the loop) took 32. The second time I ran it the
results were reversed, 32 and 33. So I guess the answer is that putting my
inside a tight loop doesn't increase overhead and runtime. Of course I
don't know if that's always the case. It could be that my simplified test
interprets and compiles differently than if the loops had more complexity
inside. But that's probably a different discussion.
Thanks all.
Dave
------------------------------
Date: Tue, 22 Jul 2003 10:44:35 +0800
From: Dan Jacobson <jidanni@jidanni.org>
Subject: why doesn't HTML::HeadParser include a parse_file function?
Message-Id: <871xwjuvos.fsf@jidanni.org>
Why does HTML::Parser include a parse_file function, but
HTML::HeadParser doesn't? I see, else it wouldn't be lightweight.
------------------------------
Date: 22 Jul 2003 05:40:49 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: why doesn't HTML::HeadParser include a parse_file function?
Message-Id: <bfiip1$md1$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Dan Jacobson:
> Why does HTML::Parser include a parse_file function, but
> HTML::HeadParser doesn't? I see, else it wouldn't be lightweight.
Actually it does (it's not documented very clearly, though).
HTML::HeadParser is a subclass of HTML::Parser. It inherits parse_file()
from its parent-class. So you can also use it with this module.
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: 21 Jul 2003 23:25:08 -0700
From: ronaldf@eml.cc (Ronald Fischer)
Subject: Re: Why is 'last' not allowed here
Message-Id: <219750c.0307212225.2238600@posting.google.com>
Abigail <abigail@abigail.nl> wrote in message news:<slrnbhcv5t.53v.abigail@alexandra.abigail.nl>...
> Ronald Fischer (ronaldf@eml.cc) wrote on MMMDCVII September MCMXCIII in
> <URL:news:219750c.0307170227.2cff1f13@posting.google.com>:
> %% "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<bf353t$8e6$1@nets3.rz.RWTH-Aachen.DE>...
> %% > That's because the blocks of 'if', 'unless' and 'do' (missed one?)
> %% > aren't treated as a block that is subject to 'last' or 'next'.
> %%
> %% The strange thing is that the manpages explain that 'do' can't be
> %% used, but they tell nothing about if. Just the contrary: They say
> %% that, WRT blocks, 'if' behaves like a loop ('while', 'for').
>
> Which manual page is that?
It is
http://www.perldoc.com/perl5.8.0/pod/perlsyn.html#Basic-BLOCKs-and-Switch-Statements
where it says:
"A BLOCK by itself (labeled or not) is semantically equivalent to a
loop that executes once. Thus you can use any of the loop control
statements in it to leave or restart the block. (Note that this is NOT
true in eval{}, sub{}, or contrary to popular belief do{} blocks,
which do NOT count as loops.)"
Interestingly, http://www.perldoc.com/perl5.8.0/pod/perlsyn.html#Loop-Control
seems to say the contrary, as I found out right now:
"The loop control statements don't work in an if or unless, since they
aren't loops."
These two sentences can be true at the same time only if what goes
after an 'if'
or an 'unless' were NOT a block:
if (CONDITION)
{
# are we in a block here?
}
But I think this *must* be a block, because you can declare
my-variables
inside it.
So I would say that the man pages are in error, because they are
contradicting.
Right?
Ronald
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5254
***************************************