[19971] in Perl-Users-Digest
Perl-Users Digest, Issue: 2166 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 20 18:06:29 2001
Date: Tue, 20 Nov 2001 15:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006297509-v10-i2166@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 20 Nov 2001 Volume: 10 Number: 2166
Today's topics:
Re: Can I avoid 2 passes? <uri@stemsystems.com>
Re: Can I avoid 2 passes? <nilram@boisdarc.tamu-commerce.edu>
Re: Can I avoid 2 passes? <nilram@boisdarc.tamu-commerce.edu>
Re: Can I avoid 2 passes? <godzilla@stomp.stomp.tokyo>
Re: Can I avoid 2 passes? <bart.lateur@skynet.be>
Re: Can I avoid 2 passes? <bart.lateur@skynet.be>
Do Not Redirect CGI Questions To CIWAC <godzilla@stomp.stomp.tokyo>
Re: elsif problems <no@email.com>
Re: elsif problems <Tassilo.Parseval@post.rwth-aachen.de>
Re: fork() help needed (Logan Shaw)
help w/ error: 'package does not return true' <brice@webprojkt.com>
How would I do parameter/variable passing from Makefile (bac3)
Re: Just wondering ... why is there no "since" informat (Logan Shaw)
Re: Just wondering ... why is there no "since" informat <mgjv@tradingpost.com.au>
Re: LWP documentation gap: URL-encoded parameters? (Tad McClellan)
multiple arrays as arguments <sidarous@isr6132.urh.uiuc.edu>
Re: multiple arrays as arguments <Laocoon@eudoramail.com>
Re: multiple arrays as arguments <steven.nospam.spencer@team.ozemail.com.au>
Re: multiple arrays as arguments (Tad McClellan)
Newbie question: When do you destroy objects? <Lavon.Missell@sas.com>
Re: Newbie question: When do you destroy objects? <uri@stemsystems.com>
Re: OT: New Perl Journal <emarkert@netscape.net>
Re: OT: New Perl Journal <uri@stemsystems.com>
result pages (10 by 10) <perl@cableone.net>
result pages (10 by 10) <perl@cableone.net>
Re: result pages (10 by 10) <Laocoon@eudoramail.com>
Re: result pages (10 by 10) <Laocoon@eudoramail.com>
Re: result pages (10 by 10) (John J. Trammell)
Re: Special chars <Laocoon@eudoramail.com>
Re: Traversing directories (BUCK NAKED1)
Re: using sendmail from perl <no@email.com>
Re: using sendmail from perl <kragen@canonical.org>
Re: using sendmail from perl <zkent@adelphia.net>
Re: using sendmail from perl <nilram@boisdarc.tamu-commerce.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 Nov 2001 20:08:17 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Can I avoid 2 passes?
Message-Id: <x7bshxdx1t.fsf@home.sysarch.com>
>>>>> "EC" == E Chang <echang@netstorm.net> writes:
EC> split takes an optional third argument that limits the number of
EC> fields.
EC> my ($user, $rest) = split (/:/, $_, 2);
EC> $users{$user} = $rest;
even simpler:
%users = map split (/:/, $_, 2), <PW> ;
that will leave a newline on the values but that can be removed with:
chomp values %users ;
<only recent perl's can do lvalue values>
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 20 Nov 2001 15:55:52 -0600
From: Dale Henderson <nilram@boisdarc.tamu-commerce.edu>
Subject: Re: Can I avoid 2 passes?
Message-Id: <873d392jkn.fsf@camel.tamu-commerce.edu>
>>>>> "DM" == Drew Myers <bh_ent@hotmail.com> writes:
DM> Effectively, I'd like to combine the split and join statements
DM> above, but I'm not sure exactly how to do that, or if it's
DM> even a viable solution.
You can always use the regex approach
if(/^([^:]+);(.*)/){
$users{$1}=$2;
}else{
die "Bad file format"
}
Even has th advantage of checking your data file.
--
Dale Henderson
"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..." -- G. H. Hardy
------------------------------
Date: 20 Nov 2001 15:57:39 -0600
From: Dale Henderson <nilram@boisdarc.tamu-commerce.edu>
Subject: Re: Can I avoid 2 passes?
Message-Id: <87y9l114x8.fsf@camel.tamu-commerce.edu>
>>>>> "Godzilla" == Godzilla! <godzilla@stomp.stomp.tokyo> writes:
Godzilla> You will discover my test script below my signature to
Godzilla> be relatively quick and efficient for your
Godzilla> task. However, a simple associative array would be more
Godzilla> efficient. A hash should be a second choice to an array
Godzilla> method for most programming circumstances. What you do
Godzilla> later in your program would be a deciding factor on
Godzilla> which, an array or a hash, would be best to use.
So what's the difference between a hash and and associative array?
--
Dale Henderson
"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..." -- G. H. Hardy
------------------------------
Date: Tue, 20 Nov 2001 14:26:02 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Can I avoid 2 passes?
Message-Id: <3BFAD87A.D6D5173D@stomp.stomp.tokyo>
Dale Henderson wrote:
> > Godzilla wrote:
> Godzilla> You will discover my test script below my signature to
> Godzilla> be relatively quick and efficient for your
> Godzilla> task. However, a simple associative array would be more
> Godzilla> efficient. A hash should be a second choice to an array
> Godzilla> method for most programming circumstances. What you do
> Godzilla> later in your program would be a deciding factor on
> Godzilla> which, an array or a hash, would be best to use.
> So what's the difference between a hash and and associative array?
Format, creation and access methodologies along with efficiency.
An array is most often superior for all criteria.
My suggestion is you research and read about arrays and hashes.
It is clear you have a bit of Perl learning yet to accomplish;
differences between arrays and hashes, are readily apparent.
Godzilla!
------------------------------
Date: Tue, 20 Nov 2001 22:32:39 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Can I avoid 2 passes?
Message-Id: <4ollvt0fvht2ivih60ll0rga56ot2bfdsu@4ax.com>
Uri Guttman wrote:
> chomp values %users ;
>
><only recent perl's can do lvalue values>
For older perls, you can use a hash slice:
chomp @users{keys %users};
--
Bart.
------------------------------
Date: Tue, 20 Nov 2001 22:48:13 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Can I avoid 2 passes?
Message-Id: <dcnlvtsr9750tgjrdeo5gfuq9sq09fq6ud@4ax.com>
Godzilla! wrote:
>> So what's the difference between a hash and and associative array?
>
>Format, creation and access methodologies along with efficiency.
You stupid person. A "hash" is simply another shorter name for an
"associative array". Technically, they're the same thing.
So what's the difference between a car and an automobile?
--
Bart.
------------------------------
Date: Tue, 20 Nov 2001 13:41:35 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Do Not Redirect CGI Questions To CIWAC
Message-Id: <3BFACE0F.C0B7ECEA@stomp.stomp.tokyo>
I will state again what I have recently stated.
Do not redirect people with cgi questions to
the comp.infosystems.www.authoring.cgi group.
Reasons for this are very apparent.
Anyone care to present an argument, a rational
argument having an auto-bot moderated newsgroup
is both a logical idea and a good idea?
I certainly have acted in a responsible manner
by investing a lot of time and effort into
trying to restore the cgi group. Have you?
Godzilla!
------------------------------
Date: Tue, 20 Nov 2001 19:08:13 -0000
From: "Brian Wakem" <no@email.com>
Subject: Re: elsif problems
Message-Id: <CSxK7.1192$6W6.393902@news2-win.server.ntlworld.com>
"Matt" <linuxnb@yahoo.com> wrote in message
news:429a5a3b.0111201051.2aaf3df@posting.google.com...
> OK, I just don't get it. What am I missing here. I'm a total newbie to
> PERL. I have a script with some nested if-elsif-else statements. The
> script fails when I use elsif, but works fine if I change them all to
> if's. Here are the two almost identicle scripts(actually this file is
> called from another script using 'require'). Thanks in advance for any
> help.
<snip>
| if ( $h > 0 && $h < 12 )
| {
| $ampm="AM";
| $h=~s/0//;
| }
| elsif ( $h > 12 )
| {
| $ampm="PM";
| $h-=12;
| }
| elsif ( $h == 12 )
| {
| $ampm="PM";
| }
| else ( $h == 0 )
<snip>
You can't put an argument in an else statement. It must be either:-
else {
# do stuff
}
or just use another elsif
elsif ($h == 0) {
}
--
Brian Wakem
------------------------------
Date: Tue, 20 Nov 2001 20:14:14 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: elsif problems
Message-Id: <9tea26$da6$00$1@news.t-online.com>
On 20 Nov 2001 10:51:59 -0800, Matt wrote:
[errors with nested if, elsif, else]
> elsif ( $h == 12 )
> {
> $ampm="PM";
> }
> else ( $h == 0 )
else does not take a contition. Either remove the expression inside the
brackets or make it a elsif depending on what you want to achieve.
[...]
Tassilo
--
"If you want to travel around the world and be invited to speak at a lot
of different places, just write a Unix operating system."
(By Linus Torvalds)
------------------------------
Date: 20 Nov 2001 15:12:26 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: fork() help needed
Message-Id: <9tegvq$66a$1@starbuck.cs.utexas.edu>
In article <slrn9vko6f.qt.jee@rltrekary.radiolinja.fi>, Jere Eerola <at> wrote:
>What I would really
>like to do is write perl program which checks if there is
>already five processes running and if not starts another one.
>
>I already wrote program that starts 5 processes but can't get any
>further. Any advise or point to documentation or examples is very
>much appreciated.
The easiest way to do approach this problem is to start 5 processes and
then use wait() to ask the system to inform you when one of them
exits. Here's an example.
sub do_something
{
print STDERR "I am process number $$ and I am about to"
. " do something.\n";
# do whatever you want here
print STDERR "And now process number $$ is done.\n";
}
sub start_a_child
{
$pid = fork;
die "Can't fork ($!)\n" unless defined $pid;
if (not $pid)
{
# i am the child process
do_something;
exit;
}
# i am the parent, so just return
}
# start 5 processes
for (1 .. 5)
{
start_a_child;
}
# start new processes as existing ones finish
while (1)
{
$pid = wait; # wait on a child process to exit
print STDERR "Process number $pid just finished.\n";
start_a_child;
}
This example never terminates, but hopefully you get the basic idea.
Probably you'll ultimately want to have some way of exiting when there
are no more child processes that need to be started and all the
already-started child processes have finished.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: Tue, 20 Nov 2001 22:29:54 GMT
From: Brice Ruth <brice@webprojkt.com>
Subject: help w/ error: 'package does not return true'
Message-Id: <B820357E.627D%brice@webprojkt.com>
I'm trying to create a simple package (class) that will hold some variables
for me. Unfortunately, when I try to 'use' this package, Perl keeps giving
me an error about the package not returning true. I have the line '1;' at
the end of the package file ... I've read through the applicable section in
the camel book and followed its directions - no go.
Here's my package code:
package PDFglobals;
use Text::PDF::API;
use strict;
use Class::Struct;
struct (
font_encoding => '$',
font_name => '$',
xres => '$',
yres => '$',
pageX => '$',
pageY => '$',
font_size => '$',
data_cols => '$',
data_col_sizes => '@',
bounding_rect => '@',
pdf => 'Text::PDF::API',
);
1;
The file is called 'PDFglobals.pm' and to use it, I have the line:
use PDFglobals;
in my calling script. Both files reside in the same directory. The error I
get is:
File "PDFout-row.pl"; Line 13: PDFglobals.pm did not return a true value
I'm running perl 5.6.0 on darwin 1.4.1 (Mac OS X v10.1.1).
Any help would be sincerely appreciated. Feel free to respond offline to
brice@webprojkt.com
TIA,
Brice Ruth
------------------------------
Date: 20 Nov 2001 11:20:36 -0800
From: bac3ui@yahoo.com (bac3)
Subject: How would I do parameter/variable passing from Makefile to perl?
Message-Id: <9d02b656.0111201120.62361550@posting.google.com>
Hello everyone,
How would I do parameter passing from Makefile to perl?
I could do it in make with special characters like $^, $@
but I've been having problem getting the same mechanism work in perl.
Thank you for your help,
my example in GNUmake:
========================================================
Makefile
...
include allprocesses.mak
...
DOSOMETHING: file1 file2 file3
...
==========================================================
allprocesses.mk
...
shared:
$(patsubst %, $(doing1)/%, $(DOSOMETHING))
...
$(doing1)/%: %
cp $^ /destination;
echo $@ ;
#this works for make
#
@perl -e ' \
($$file1, $$file2, $$file3)=split(/ /, $$DOSOMETHING);
#or
($$file1, $$file2, $$file3)=split(/ /, $_);
\
#these wouldn't work in perl. )-:
------------------------------
Date: 20 Nov 2001 14:59:31 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Just wondering ... why is there no "since" information in the man pages?
Message-Id: <9teg7j$640$1@starbuck.cs.utexas.edu>
In article <slrn9vkgf7.mfo.mgjv@martien.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>I keep various older (and development) installations of Perl around,
>just so I have access to the documentation, and so I can test certain
>snippets and constructions now and again.
That's a good idea.
>I can spare the 15 MB per Perl version in /opt/. If you need to write code
>which is backward compatible, I don't think decent historical
>information in the documentation can beat a test against a running perl.
It can't beat it for ultimate accuracy, but it certainly can beat it
for convenience.
If your desire is to write something which works with many different
versions of Perl, then you should test it with several versions. But
you don't necessarily want to do that at every step of the way while
you're writing the code.
>While I can see how it could be useful to have some of this history in
>the documentation, I am afraid it would make the documentation also
>quite messy. Many features/functions/syntactical sugar crept in in
>various versions and subversions of Perl. And when do you clean it out?
>
>Or do you think that all history since Perl 1 should appear in te
>documentation? Or since perl3? 4? 5.004? 5.6.0?
You don't need to have a full history. All that you need to do is have
a single version number for each currently-supported feature. The
version number indicates at what release the feature became like it
currently is.
We can assume that if you're reading a release's documentation, you
want to use features that are supported in that release. Usually all
you want to know is how recent the user's release will have to be to
successfully run your code if you use a certain feature.
If you want to know more than that, you can search the full history
somewhere else, but most of the time, that information is enough.
- Logan
--
"In order to be prepared to hope in what does not deceive,
we must first lose hope in everything that deceives."
Georges Bernanos
------------------------------
Date: Tue, 20 Nov 2001 22:56:03 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Just wondering ... why is there no "since" information in the man pages?
Message-Id: <slrn9vlns2.hmq.mgjv@verbruggen.comdyn.com.au>
On 20 Nov 2001 14:59:31 -0600,
Logan Shaw <logan@cs.utexas.edu> wrote:
> In article <slrn9vkgf7.mfo.mgjv@martien.heliotrope.home>,
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>>I keep various older (and development) installations of Perl around,
>>just so I have access to the documentation, and so I can test certain
>>snippets and constructions now and again.
>
> That's a good idea.
I think so too :)
>>I can spare the 15 MB per Perl version in /opt/. If you need to write code
>>which is backward compatible, I don't think decent historical
>>information in the documentation can beat a test against a running perl.
>
> It can't beat it for ultimate accuracy, but it certainly can beat it
> for convenience.
I am not too certain about that. I fear that too many historical notes
in the documentation could make it harder to parse/follow.
> If your desire is to write something which works with many different
> versions of Perl, then you should test it with several versions. But
> you don't necessarily want to do that at every step of the way while
> you're writing the code.
Nope. And I guess that I also rely on my own historical knowledge of
Perl. I generally know when I'm writing code that certain
constructions, keywords and syntax is only available in version x.y
and above.
>>While I can see how it could be useful to have some of this history in
>>the documentation, I am afraid it would make the documentation also
>>quite messy. Many features/functions/syntactical sugar crept in in
>>various versions and subversions of Perl. And when do you clean it out?
>>
>>Or do you think that all history since Perl 1 should appear in te
>>documentation? Or since perl3? 4? 5.004? 5.6.0?
>
> You don't need to have a full history. All that you need to do is have
> a single version number for each currently-supported feature. The
> version number indicates at what release the feature became like it
> currently is.
Yes, but the documentation, as it is (also see my other post on this)
is not very well suited for these interjections. perlfunc, perlvar and
maybe parts of perlre could be most easily documented historically,
but perlsyn, perldata and perlop would be very hard to do.
Besides that, features don't only get added, they get changed and
deprecated. delete didn't use to work on slices. flock didn't always
automatically flush a file handle on an unlock. keys %hash wasn't
always an lvalue. The various formats for pack weren't always there.
The way use works has changed. Implicit split to @_ wasn't always
deprecated. The statement modifiers haven't all come into existence in
the same version of Perl. substr didn't always have a fourth argument.
splice didn't always take a negative length. eof didn't always work as
expected with <>.
And that list is by no means complete. To document all these changes
accurately in the documentation itself would in my view create a bit
of a mess, unless the documentation got reshuffled significantly.
And of course, none of this takes into account that certian versions
of perl were supposed to have certain behaviour/features, but they
were buggy.
As I said in another post: I think perl is just too organic to
decently incorporate all this, historically, in the documentation
itself.
> We can assume that if you're reading a release's documentation, you
> want to use features that are supported in that release. Usually all
> you want to know is how recent the user's release will have to be to
> successfully run your code if you use a certain feature.
>
> If you want to know more than that, you can search the full history
> somewhere else, but most of the time, that information is enough.
True. I guess I'm just biased towards keeping this sort of information
out of the documentation, mainly because I don't need it in the
documentation. There aren't many times that I need to check the
documentation to find out when a feature became available.
Martien
--
|
Martien Verbruggen | Failure is not an option. It comes
Trading Post Australia Pty Ltd | bundled with your Microsoft product.
|
------------------------------
Date: Tue, 20 Nov 2001 22:04:21 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: LWP documentation gap: URL-encoded parameters?
Message-Id: <slrn9vlhqj.lfv.tadmc@tadmc26.august.net>
kj <kj345@lycos.com> wrote:
>In the LWP doc it says:
>
> The library supports ftp ASCII transfer mode by specifying the
> "type=a" parameter in the URL.
>
>...but nowhere it says the exact syntax of this URL-encoding of
>parameters.
>I just want to confirm
>that my inability to find the answer to such a simple question doesn't
>just reflect great ignorance on my part.
Confirmation is lacking :-)
The format for URL encoding will be the same regardless of what
programming language you choose to use, so the answer is not
related to programming languages.
You have been looking in the wrong places, _that_ is why you
haven't found the answer.
Try looking at newsgroups/web sites about the web and CGI stuff.
Once you know what you need to do, you can ask here if you can't
figure out how to get that done using Perl.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 20 Nov 2001 16:24:42 -0600
From: Mark Sidarous <sidarous@isr6132.urh.uiuc.edu>
Subject: multiple arrays as arguments
Message-Id: <Pine.LNX.4.33.0111201613450.2746-100000@isr6132.urh.uiuc.edu>
Hi. I have a problem. Right now I'm passing in 2 arrays to a function as
arguments. Now Perl just lumps them into @_. So what I'm currently doing
is passing (@1, @2, $#1) in to the function. It pops the last value
($#1), then takes the first $#1 values and puts them in an array. All the
rest go into @2. The function then fiddles around with @1 and @2, then
passes them back (@1, @2, $#1).
So this all WORKS, but it seems to be a very inefficient, slow way of
doing things. Is there a better way to pass these arrays in and return
them?
Also, I've considered the possibility of just having all the functions in
my program directly modify the arrays instead of passing them in as
arguments and returning the arrays after modification. Is this a better
way of doing things? I want to keep things modular, and it seems to me
that the argument thing works better in that respect and seems like
there's less potential to screw things up, although its probably slower.
These arrays arent very big right now (max 400 or so integers), but I want
this to be scalable as this may be used for arrays with thousands/millions
of entries sometime in the future (hopefully on a faster machine than mine!).
--
------------------------------
Date: Tue, 20 Nov 2001 23:41:32 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: multiple arrays as arguments
Message-Id: <Xns915FF10901473Laocooneudoramailcom@62.153.159.134>
One word : References
perldoc perlref
example
sub my_sub {
my($array1,$array2) = @_;
# Do processing here..
}
my_sub(\@ar1,\@ar2);
------------------------------
Date: Wed, 21 Nov 2001 09:55:21 +1100
From: "Steve Spencer" <steven.nospam.spencer@team.ozemail.com.au>
Subject: Re: multiple arrays as arguments
Message-Id: <tbBK7.2441$li3.72541@ozemail.com.au>
I've found the best way to get arround this problem is to pass in array
references..
&subroutine(\@array1, \@array2)
when you access the arguements within the sub routine you use this format.
($arrayref1, $arrayref2) = @_;
@routinearray1 = @{$arrayref1};
@routinearray2 = @{$arrayref2};
hope this helps..
Steve
"Mark Sidarous" <sidarous@isr6132.urh.uiuc.edu> wrote in message
news:Pine.LNX.4.33.0111201613450.2746-100000@isr6132.urh.uiuc.edu...
> Hi. I have a problem. Right now I'm passing in 2 arrays to a function as
> arguments. Now Perl just lumps them into @_. So what I'm currently doing
> is passing (@1, @2, $#1) in to the function. It pops the last value
> ($#1), then takes the first $#1 values and puts them in an array. All the
> rest go into @2. The function then fiddles around with @1 and @2, then
> passes them back (@1, @2, $#1).
>
> So this all WORKS, but it seems to be a very inefficient, slow way of
> doing things. Is there a better way to pass these arrays in and return
> them?
>
> Also, I've considered the possibility of just having all the functions in
> my program directly modify the arrays instead of passing them in as
> arguments and returning the arrays after modification. Is this a better
> way of doing things? I want to keep things modular, and it seems to me
> that the argument thing works better in that respect and seems like
> there's less potential to screw things up, although its probably slower.
> These arrays arent very big right now (max 400 or so integers), but I want
> this to be scalable as this may be used for arrays with thousands/millions
> of entries sometime in the future (hopefully on a faster machine than
mine!).
>
> --
>
>
>
>
------------------------------
Date: Tue, 20 Nov 2001 22:59:04 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: multiple arrays as arguments
Message-Id: <slrn9vlleu.lmu.tadmc@tadmc26.august.net>
Mark Sidarous <sidarous@isr6132.urh.uiuc.edu> wrote:
>Right now I'm passing in 2 arrays to a function as
>arguments. Now Perl just lumps them into @_.
>So this all WORKS, but it seems to be a very inefficient, slow way of
>doing things. Is there a better way to pass these arrays in and return
>them?
Pass references to arrays instead of lists.
>Also, I've considered the possibility of just having all the functions in
>my program directly modify the arrays instead of passing them in as
>arguments and returning the arrays after modification. Is this a better
>way of doing things?
Yes, passing arguments in undoubtably better than working on
global array variables.
>I want to keep things modular, and it seems to me
>that the argument thing works better in that respect and seems like
>there's less potential to screw things up, although its probably slower.
Passing 2 scalars (references) will be a *whole lot* faster than
passing all of the scalars from both arrays.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 20 Nov 2001 14:02:07 -0500
From: "LaVon Missell" <Lavon.Missell@sas.com>
Subject: Newbie question: When do you destroy objects?
Message-Id: <9te9bf$rrt$1@license1.unx.sas.com>
I took this code from a newsgroup posting. This code prints the title of a
web page.
Ultimately, I want to process all the htm files in a directory tree. Getting
the title and other information from each file. If I put the code
surrounded by ## in a loop, there will lots and
lots of objects and performance may suffer. Do I need to call a destructor
at the bottom of the loop when the "new" is at the top of a loop? Can I
reuse object ie. move the "new" outside the loop and just give it a new file
name and everything in this object "re-initializes"?
Thanks in advance for your help.
require HTML::HeadParser;
$file='u:\perl\p_his.htm';
#*****************************;
my $p = HTML::HeadParser -> new;
$p -> parse_file($file);
my $t = $p -> header ('Title');
print $t, "\n";
$t = undef;
#*******************************;
------------------------------
Date: Tue, 20 Nov 2001 20:14:15 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Newbie question: When do you destroy objects?
Message-Id: <x78zd1dwrw.fsf@home.sysarch.com>
>>>>> "LM" == LaVon Missell <Lavon.Missell@sas.com> writes:
LM> I took this code from a newsgroup posting. This code prints the
LM> title of a web page. Ultimately, I want to process all the htm
LM> files in a directory tree. Getting the title and other information
LM> from each file. If I put the code surrounded by ## in a loop,
LM> there will lots and lots of objects and performance may suffer.
LM> Do I need to call a destructor at the bottom of the loop when the
LM> "new" is at the top of a loop? Can I reuse object ie. move the
LM> "new" outside the loop and just give it a new file name and
LM> everything in this object "re-initializes"?
LM> my $p = HTML::HeadParser -> new;
LM> $p -> parse_file($file);
LM> my $t = $p -> header ('Title');
LM> print $t, "\n";
LM> $t = undef;
perl uses reference counting to detect object destruction. in a loop
like that, each object will get down to a zero count when the $p or $t
variables are next assigned. then the previous object will be destroyed
and collected (assuming no data loops or external references remain).
and the $t = undef should not be needed if $p and $t are properly
scoped. when the scope exits, the last values they have will also be
destroyed.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 20 Nov 2001 21:19:49 GMT
From: Erich Markert <emarkert@netscape.net>
Subject: Re: OT: New Perl Journal
Message-Id: <3BFAC8C4.4020508@netscape.net>
> complain to the publisher. it's not Readable Publications, which
> is what you are seeing. complain to the new publisher.
>
>
>>Is this what we are to continue to expect from TPJ?
It's a pity that the hard working folks who pour their hearts into
creating excellent content are having a difficult time finding a
publisher who is willing to give TPJ the proper forum it deserves.
I know the ongoing problems that TPJ had with Earthwatch and was
ecstatic to hear that TPJ was pairing up with CMP - Sys Admin is a great
mag - but I HOPE that CMP realizes that anything less than the quarterly
dedicated mag is useless...
------------------------------
Date: Tue, 20 Nov 2001 21:42:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: OT: New Perl Journal
Message-Id: <x7zo5hce44.fsf@home.sysarch.com>
>>>>> "EM" == Erich Markert <emarkert@netscape.net> writes:
>> complain to the publisher. it's not Readable Publications, which
>> is what you are seeing. complain to the new publisher.
>>
>>
>>> Is this what we are to continue to expect from TPJ?
EM> It's a pity that the hard working folks who pour their hearts into
EM> creating excellent content are having a difficult time finding a
EM> publisher who is willing to give TPJ the proper forum it deserves.
EM> I know the ongoing problems that TPJ had with Earthwatch and was
EM> ecstatic to hear that TPJ was pairing up with CMP - Sys Admin is a great
EM> mag - but I HOPE that CMP realizes that anything less than the quarterly
EM> dedicated mag is useless...
this has been covered elsewhere. the problem is very simple. due to
earthweb's stupidty and the economy in general, tpj lost massive amounts
of ad revenue. that is what supports the content. so cmp merged tpj into
sysadmin to lower publishing costs and hopefully raise ad revenue. it
has somewhat backfired as tpj content has shrunk so much and now ads in
tpj cost so much more because of the larger circulation of
sysadmin. even though the two have some overlapping readership, that may
not be enough to make this work. most tpj readers are not sysadmins and
don't need nor want the sysadmin mag. and not all sysadmin readers are
perl hackers. getting tpj back to a separate publication will require
more perl specific ads and larger circulation. those are not likely to
happen soon. so we are stuck the smaller mergerd version which while not
great is better then the defunct one that earthweb left behind.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 20 Nov 2001 16:33:04 -0600
From: "Jason Gray" <perl@cableone.net>
Subject: result pages (10 by 10)
Message-Id: <tvlmighe8v42d9@corp.supernews.com>
I'm currently trying to figure out how to display 10 results at a time then
if there is more, a link will show and you'll be able to view the next 10
results. Like if a file has 29 lines, I want to be able to view 3 pages. Any
help would be good.
Regards,
Jason Gray
"Just Another Perl Programmer"
------------------------------
Date: Tue, 20 Nov 2001 16:48:24 -0600
From: "Jason Gray" <perl@cableone.net>
Subject: result pages (10 by 10)
Message-Id: <tvlnfa2pr9jhf9@corp.supernews.com>
I'm currently trying to figure out how to display 10 results at a time then
if there is more, a link will show and you'll be able to view the next 10
results. Like if a file has 29 lines, I want to be able to view 3 pages. Any
help would be good.
Regards,
Jason Gray
"Just Another Perl Programmer"
------------------------------
Date: Tue, 20 Nov 2001 23:50:34 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: result pages (10 by 10)
Message-Id: <Xns915FF2916D465Laocooneudoramailcom@62.153.159.134>
"Jason Gray" <perl@cableone.net> wrote in
news:tvlmighe8v42d9@corp.supernews.com:
> I'm currently trying to figure out how to display 10 results at a time
> then if there is more, a link will show and you'll be able to view the
> next 10 results. Like if a file has 29 lines, I want to be able to view
> 3 pages. Any help would be good.
Thats confusing.. You want to show 10 at a time or 3 or first 10 then 3?
Anyway.. example :
my $i = 1;
while (<RESULTS>) {
print and next unless $i++ % 11; # or $i++ <= 11; my $i = 1 etc..
#stuff...
}
------------------------------
Date: Tue, 20 Nov 2001 23:50:56 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: result pages (10 by 10)
Message-Id: <Xns915FF2A10BA34Laocooneudoramailcom@62.153.159.134>
Why's everyone posting their stuff two times
------------------------------
Date: Tue, 20 Nov 2001 16:50:51 -0600
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: result pages (10 by 10)
Message-Id: <slrn9vlnmh.la8.trammell@haqq.el-swifto.com>
On Tue, 20 Nov 2001 16:33:04 -0600, Jason Gray <perl@cableone.net> wrote:
> I'm currently trying to figure out how to display 10 results at a time then
> if there is more, a link will show and you'll be able to view the next 10
> results. Like if a file has 29 lines, I want to be able to view 3 pages. Any
> help would be good.
>
http://search.cpan.org/doc/TIMB/DBI_Talk5_2001/sld059.htm
--
Only a very small fraction of our DNA does anything; the rest is all
comments and ifdefs.
------------------------------
Date: Tue, 20 Nov 2001 23:41:18 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Special chars
Message-Id: <Xns915FF0FF3943CLaocooneudoramailcom@62.153.159.134>
I dunno.. maybe Unicode?
------------------------------
Date: Tue, 20 Nov 2001 13:15:02 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Traversing directories
Message-Id: <14154-3BFAABB6-299@storefull-241.iap.bryant.webtv.net>
bart.lateur@skynet.be (Bart=A0Lateur)
> Hmm... I think it's time for a new
> slogan, in the realm of "stop feeding the > trolls". It is: "stop
slamming the
> newbies". Come out of your ivory tower. > [ SNIP ]
Thanks, Bart. That really needed to be said. The problem with arrogant
people is that they can't accept the fact that they have a problem; and
realization and acceptance is always a mandated prerequisite to any
hopeful cure.
Regards,
--Dennis
---------------------------------------
"I don't understand... whas yo plan?... that you can't be... good to me.
Be Good to ME!" --Tina Turner
------------------------------
Date: Tue, 20 Nov 2001 19:12:40 -0000
From: "Brian Wakem" <no@email.com>
Subject: Re: using sendmail from perl
Message-Id: <RWxK7.1195$6W6.399766@news2-win.server.ntlworld.com>
"Zachary Kent" <zkent@adelphia.net> wrote in message
news:n1wK7.4246$XJ5.1146978@news1.news.adelphia.net...
> Flame-throwers Ready! I can take it! (at least a little)
>
> Hello, I am using Perl 5.005_03 and Sendmail 8.11.1 on a server I don't
own
> or have root access (your basic leased web account). I am calling
Sendmail
> via Perl in a CGI environment with the following commands:
>
> open (MAIL, "|/usr/sbin/sendmail -t") or error("Can't open sendmail");
> print MAIL ("To: $regEmail\n");
> print MAIL ("From: $config{'helpEmail'}\n");
> print MAIL ("Subject: Enrollment Confirmation (re: Biological Warfare
> broadcast)\n\n");
> print MAIL ("$ebody_w");
> close MAIL;
<snip>
if ($regEmail !~ /^[\w-.]+\@[\w-.]+$/) {
print "You have not entered a valid email address";
}
else {
open (MAIL, "|/usr/sbin/sendmail -t") or error("Can't open sendmail");
print MAIL ("To: $regEmail\n");
print MAIL ("From: $config{'helpEmail'}\n");
print MAIL ("Subject: Enrollment Confirmation (re: Biological Warfare
broadcast)\n\n");
print MAIL ("$ebody_w");
close MAIL;
}
--
Brian Wakem
------------------------------
Date: 20 Nov 2001 16:43:23 -0500
From: Kragen Sitaker <kragen@canonical.org>
Subject: Re: using sendmail from perl
Message-Id: <83d72dm83o.fsf@panacea.canonical.org>
"Zachary Kent" <zkent@adelphia.net> writes:
> The problem arises when someone has put an invalid character (comma, space,
> or >) in their address. Instead of a graceful warning or something I get a
> fatal error that kills my script and leaves the user in Limbo.
Is the fatal error 'Broken pipe'? On the one machine where I have
sendmail (8.8.8+Sun), it doesn't check the addresses for validity
until after the email is finished, but if your version checks the
address for validity and exits if they're ill-formed, that would
explain your symptoms.
You'd need to establish a signal handler for SIGPIPE if that's the
problem --- $SIG{PIPE} = sub { die "Broken pipe" }; --- and then use
eval{} to trap the die. (Signal handlers in Perl are kinda dodgy
though.)
Hope this helps.
------------------------------
Date: Tue, 20 Nov 2001 22:07:41 GMT
From: "Zachary Kent" <zkent@adelphia.net>
Subject: Re: using sendmail from perl
Message-Id: <NuAK7.39$cs3.34618@news1.news.adelphia.net>
<nobull@mail.com> wrote in message news:u9elmts3h8.fsf@wcl-l.bham.ac.uk...
> "Zachary Kent" <zkent@adelphia.net> writes:
>
> > open (MAIL, "|/usr/sbin/sendmail -t") or error("Can't open sendmail");
> > print MAIL ("To: $regEmail\n");
>
> > The problem arises when someone has put an invalid character (comma,
space,
> > or >) in their address. Instead of a graceful warning or something I
get a
> > fatal error that kills my script and leaves the user in Limbo.
>
> This seems highly improbable.
I agree. However, its happening.
> sendmail is being run in a separate process and being fed stuff down a
> pipe. It is almost impossible for sendmail to harm your script except
> by a deliberate malicious act.
al-Qa'ida? bin Laden?
> Perhaps you should present us with the raw data from which you arrived
> at the conclusion that an error in sendmail killed your script so that
> we could provide an alternative interpretation.
I used the code above. The email address either comes from a database or
from a form. In the beginning I was not screening user's email addresses
(lazy). When any of the scripts attempt to send them an email and they
contained invalid characters, the user sees a 550 script error. This never
happended until we moved our sites onto a VPS (virtual private server) which
I DON"T RECOMMEND!
Anyway, any email address with a space, comma, <, etc causes a 550 error
using the code above.
Brian Wakem says to use a regexp but I have heard that they are not always
100% accurate. I have never tried trapping it in an eval. Does that work?
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
No bull here!
Zach
------------------------------
Date: 20 Nov 2001 16:24:18 -0600
From: Dale Henderson <nilram@boisdarc.tamu-commerce.edu>
Subject: Re: using sendmail from perl
Message-Id: <87u1vp13ot.fsf@camel.tamu-commerce.edu>
>>>>> "ZK" == Zachary Kent <zkent@adelphia.net> writes:
ZK> The problem arises when someone has put an invalid character
ZK> (comma, space, or >) in their address. Instead of a graceful
ZK> warning or something I get a fatal error that kills my script
ZK> and leaves the user in Limbo.
ZK> Is there some way to do this so that Sendmail dies gracefully
ZK> on a bad email? (remember I don't have root access and most
ZK> likely can't configure sendmail other than what it is).
Testing the validity of an email address is much more difficult
that simply scanning for invalid characters (I think all three of
the above are valid under certain circumstances). Fortunately
there are at least two modules at CPAN to do this for you the one
I'm most familiar with is Email::Valid another has RFC in the title.
For more information about email addresses you can see "Mastering
Regular Expressions" (Appendix B has an email checking regex
thats nearly a page (6,598 bytes) long.)
Also perlfaq9 contains:
How do I check a valid mail address?
As a previous poster pointed out Sendmail dying shouldn't kill
your script. Perhaps its locking?
--
Dale Henderson
"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..." -- G. H. Hardy
------------------------------
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 2166
***************************************