[13045] in Perl-Users-Digest
Perl-Users Digest, Issue: 455 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 10 23:07:21 1999
Date: Tue, 10 Aug 1999 20:05:09 -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, 10 Aug 1999 Volume: 9 Number: 455
Today's topics:
Anon Subs and Parameters bpruett@my-deja.com
Re: Anon Subs and Parameters <mpersico@erols.com>
Re: Creating variables on the fly with CGI.pm? <makarand_kulkarni@my-deja.com>
Re: Custer's Last Code <fkrul@acc.com>
Re: exists problem <uri@sysarch.com>
Re: Flocking, whassat? <flexit@flexit.eurobell.co.uk>
Re: http://www.perl.com gone? <elaine@chaos.wustl.edu>
Re: http://www.perl.com gone? (Martien Verbruggen)
Re: HTTP_REFERER and Frames <flavell@mail.cern.ch>
Improving speed of a sub <dhill@sunbeach.net>
Re: Improving speed of a sub (brian d foy)
Re: Improving speed of a sub <dhill@sunbeach.net>
IO::Socket dilemma <brundlefly76@hotmail.com>
Need help using OO Perl <berube@odyssee.net>
Newbie alert !! (Thanks, followup, and a question) <cajun@rattler.cajuninc.com>
Newbie help with typeglobs zzspectrez@my-deja.com
Re: NEWSFLASH: Supremes rule anti-advert-ware illegal (Ronald J Kimball)
Re: Perl version question <randy@theory.uwinnipeg.ca>
Re: Problems with the system function <bwalton@rochester.rr.com>
Re: reference to object method <dchristensen@california.com>
Re: reference to object method (Damian Conway)
shopping cart recommendations PETER@yaleads.ycc.yale.edu
Should I use fork to "parallel process"? <revjack@radix.net>
Re: Should I use fork to "parallel process"? <mpersico@erols.com>
Strange File Behavior <jstraumann@worldnet.att.net>
Re: suggestions for CRAP (Rachael Ludwick)
Re: system command syntax question <bwalton@rochester.rr.com>
Time:: Hires <abhargav@rational.com>
Re: Time:: Hires (Graham Ashton)
Re: Time:: Hires <randy@theoryx5.uwinnipeg.ca>
Re: turn $6 into $6000 <mpersico@erols.com>
Re: using alarm under win32 <bwalton@rochester.rr.com>
Re: Why use Perl when we've got Python?! <mpersico@erols.com>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Aug 1999 01:28:04 GMT
From: bpruett@my-deja.com
Subject: Anon Subs and Parameters
Message-Id: <7oqjiq$a0r$1@nnrp1.deja.com>
I have a problem with anon subroutines and parameters.
Can I pass a param to a code reference of an anon sub? For example.
# Get a reference to the sub
$theref = sub { $this->sub_in_this_package };
# Set a parameter
$para = 'Bob';
# Now call the code ref
$result = &$theref($para);
# and Print it
print "$result\n";
When I do something like this the sub does run, but the parameter never
gets to it. Have I missed something or is that just not possible?
Thanks in advance.
Bob
===================================
http://pyropepper.com
Fiery Food & Fun
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 10 Aug 1999 22:54:00 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Anon Subs and Parameters
Message-Id: <37B0E5C8.B5D729FE@erols.com>
Try
$theref->($para);
bpruett@my-deja.com wrote:
>
> I have a problem with anon subroutines and parameters.
>
> Can I pass a param to a code reference of an anon sub? For example.
>
> # Get a reference to the sub
> $theref = sub { $this->sub_in_this_package };
>
> # Set a parameter
> $para = 'Bob';
>
> # Now call the code ref
> $result = &$theref($para);
>
> # and Print it
> print "$result\n";
>
> When I do something like this the sub does run, but the parameter never
> gets to it. Have I missed something or is that just not possible?
>
> Thanks in advance.
>
> Bob
>
> ===================================
> http://pyropepper.com
> Fiery Food & Fun
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
--
Matthew O. Persico
You'll have to pry my Emacs from my cold dead oversized
control-pressing left pinky finger. -- Randal L. Schwartz
------------------------------
Date: Wed, 11 Aug 1999 02:08:38 GMT
From: Makarand Kulkarni <makarand_kulkarni@my-deja.com>
Subject: Re: Creating variables on the fly with CGI.pm?
Message-Id: <7oqluu$bnu$1@nnrp1.deja.com>
[In article <7omgen$t6r$1@news.servint.com>,
<vlad@doom.net> wrote:
> I did this, which is a lot smaller obviously:
> my @fields = param ();
> for (@fields) {
> ${$_} = param ($_);
> }
..{rest of the code snipped...}
]
-
If you are using CGI.pm then the params
are already cached by the CGI module in
a hash for quick access. Storing them
in your hash is not going to make access
to these any faster than a regular call
to param() provided by CGI.
If you have a lot of params that are related
to each other then name them as var1, var2 etc.
(as you are already doing). However,you can try
using 'indexing' to the param name to retrieve
the value.
For example.
foreach (1..10) {
my $var = $CGIObject->param ('var'.$_);
# use the value of $var ..
#..
}
Or if I had a matrix of text elements (10 x 10) was submitted from
a form then something like this would be sufficient ( if the
names of the text fields were as shown below..
var01 var02 var03..,var09
var11 var12 var13..,var19
var21 var22 var23..
..
var91 var92 var93.., var99
foreach $a ( 0..9)
{
foreach $b ( 0..9)
{
$value = $CGIObject->param ('var'.$a.$b );
# use this value..
# got hold of the cell value..
}
}
Hope this helps.
--
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 10 Aug 1999 18:09:57 -0700
From: Frank Krul <fkrul@acc.com>
To: sholden@cs.usyd.edu.au
Subject: Re: Custer's Last Code
Message-Id: <37B0CD65.651543D1@acc.com>
> Read up on taint checking in the perl documentation and it all should be
> explained. Look in the 'perldoc perlsec'
>
> And do you really have executables in /www. Good values for PATH are
> /bin:/usr/bin, even better is nothing at all. If you run external programs
> then use the full path names (use some config variables to aid in porting
> the script of course).
I used absolute paths for the execs. This is the new error:
Insecure dependency in exec while running setuid at /dev/fd/3 line 123.
Content-type: text/html
I'll read the documentation, thank you for the pointer. I sort of got thrown into
perl with one Orielly book that does not cover this sort of thing, and a unix box
without perl manpages.
------------------------------
Date: 10 Aug 1999 23:03:27 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: exists problem
Message-Id: <x7zozz9fy8.fsf@home.sysarch.com>
>>>>> "GL" == Gene LeFave <gene@tekdata.com> writes:
GL> The exact error log is:
GL> . Premature end of script headers
GL> . Syntax error in file ... at line 68,
GL> . next 2 tokens " exists $in"
GL> . Execution of ... aborted due to compilation errors.
>> It's certainly not the perl version that is the problem, except
>> you have a buggy build (*very* unlikely).
>>
>> Anno
well, that is definitely a sign you have a flea bitten camel carcass
running on that machine. exists didn't exist in perl4 hence the syntax
error.
so make sure what version of perl is on that machine with perl -v. and
remove the perl4 and get a proper install of perl5.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: Wed, 11 Aug 1999 03:04:03 +0100
From: "Troy Knight" <flexit@flexit.eurobell.co.uk>
Subject: Re: Flocking, whassat?
Message-Id: <7oqli6$vuq$1@slrn.eurobell.net>
Hi, yeah actually I did check perlfaq5 and it directed me to perlfunc page.
On this page it says that you can use "one of LOCK_SH, LOCK_EX, or LOCK_UN,
possibly combined with LOCK_NB" with the flock function. Only thing is, it
doesn't explain what these do, well okay it says LOCK_EX makes an exclusive
ect. but I dont know what this means and which one to use in what
situation...this is what I need to understand...
Troy
------------------------------
Date: Tue, 10 Aug 1999 22:01:10 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: http://www.perl.com gone?
Message-Id: <37B0D906.86796278@chaos.wustl.edu>
Martien Verbruggen wrote:
> The links are there in lynx as well. Maybe you should try again.
C'mon darling, many of the links were broken when Tom recently redid the
design of perl.com. Perhaps the user isn't terribly industrious, but the
site did change quite a bit.
e.
------------------------------
Date: Wed, 11 Aug 1999 02:34:26 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: http://www.perl.com gone?
Message-Id: <Si5s3.148$O21.7666@nsw.nnrp.telstra.net>
In article <37B0D906.86796278@chaos.wustl.edu>,
Elaine -HFB- Ashton <elaine@chaos.wustl.edu> writes:
> Martien Verbruggen wrote:
>> The links are there in lynx as well. Maybe you should try again.
>
> C'mon darling, many of the links were broken when Tom recently redid the
> design of perl.com. Perhaps the user isn't terribly industrious, but the
> site did change quite a bit.
'Many of the links' suggests that there were more than two links, but
the poster said:
>>> When I go there, I find only two links, one to Perl and one to XML
Was it that broken? If so, I obviously didn't access it when that was
going on, and it wasn't going on when I replied. That's why I
suggested the poster try again :)
Martien
--
Martien Verbruggen | My friend has a baby. I'm writing down
Interactive Media Division | all the noises the baby makes so later
Commercial Dynamics Pty. Ltd. | I can ask him what he meant - Steven
NSW, Australia | Wright
------------------------------
Date: Wed, 11 Aug 1999 02:48:48 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HTTP_REFERER and Frames
Message-Id: <Pine.HPP.3.95a.990811024347.3118A-100000@hpplus03.cern.ch>
On Tue, 10 Aug 1999, TVsezSO wrote:
> i am haveing a small prob with the environment variable HTTP_REFERER if
> i call the cgi script from a frame page it returns the menu frame url
> instead of the main frame.
You're definitely in the wrong place here: the principle of your
question would be the same whatever language you coded it in.
On comp.infosystems.www.authoring.cgi I feel sure you'd find a recent
thread where a questioner was reminded that the HTTP referer was
documented to be useful only for informational purposes and should not
be relied on. I can only repeat that you should not rely on it.
Perhaps if you would reveal to that CGI group (after consulting its FAQ
and automoderation procedure) what it is that you are really trying to
achieve, rather than merely presenting a non-solution to some unstated
problem, you may get some useful suggestions.
good luck
------------------------------
Date: Tue, 10 Aug 1999 21:58:14 -0400
From: Duncan Hill <dhill@sunbeach.net>
Subject: Improving speed of a sub
Message-Id: <Pine.LNX.4.10.9908102153170.19395-100000@bajan.pct.edu>
I have this subroutine:
sub show_copyright
{
my ($foo) = @_;
open (COPYRIGHT, "<./cpnotice.htm")
or croak "Cannot open cpnotice.htm: $!";
print "Content-type: text/html\n\n";
while (<COPYRIGHT>)
{
s/referrer/$foo/;
print;
}
close COPYRIGHT;
}
Is there any way to make it faster? I'm very wary of the s//, as it
has to be done on every line, but its the only way I can think of
changing a single placeholder in the included file on the fly.
Also, should I be doing
while ($line = <COPYRIGHT>)
instead, or is it safe to use just the file handle?
(The croak is from using CGI::Carp, which doesn't appear to be too
big.)
--
Duncan Hill Sapere aude
One net to rule them all, One net to find them,
One net to bring them all, and using Unix bind them.
------------------------------
Date: Tue, 10 Aug 1999 22:29:25 -0400
From: brian@pm.org (brian d foy)
Subject: Re: Improving speed of a sub
Message-Id: <brian-ya02408000R1008992229250001@news.panix.com>
In article <Pine.LNX.4.10.9908102153170.19395-100000@bajan.pct.edu>, Duncan Hill <dhill@sunbeach.net> posted:
> I have this subroutine:
> sub show_copyright
> {
> my ($foo) = @_;
>
> open (COPYRIGHT, "<./cpnotice.htm")
> or croak "Cannot open cpnotice.htm: $!";
>
> print "Content-type: text/html\n\n";
> while (<COPYRIGHT>)
> {
> s/referrer/$foo/;
> print;
> }
>
> close COPYRIGHT;
> }
>
> Is there any way to make it faster? I'm very wary of the s//, as it
> has to be done on every line, but its the only way I can think of
> changing a single placeholder in the included file on the fly.
>
> Also, should I be doing
> while ($line = <COPYRIGHT>)
> instead, or is it safe to use just the file handle?
while( <FILE> )
is the same as
while( defined( $_ = <FILE> ) )
with less typing.
you might want to do this:
open( FILE, ... ) .... ;
local $/ = undef;
my $data = <FILE>;
$data =~ s/this/that/g;
print $data;
--
brian d foy
CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: Tue, 10 Aug 1999 22:33:56 -0400
From: Duncan Hill <dhill@sunbeach.net>
Subject: Re: Improving speed of a sub
Message-Id: <Pine.LNX.4.10.9908102231260.19529-100000@bajan.pct.edu>
On Tue, 10 Aug 1999, brian d foy wrote:
> In article <Pine.LNX.4.10.9908102153170.19395-100000@bajan.pct.edu>,
> Duncan Hill <dhill@sunbeach.net> posted:
> > while (<COPYRIGHT>)
> > {
> > s/referrer/$foo/;
> > print;
> > }
> local $/ = undef;
> my $data = <FILE>;
> $data =~ s/this/that/g;
> print $data;
Urm.. ok, I may be a twit here, but wouldn't that try and read the
entire file into a scalar? Granted, memory isn't too much of an issue
if one person hits it, but if several hundred people hit the same part
at once, memory is gonna hurt.
--
Duncan Hill Sapere aude
One net to rule them all, One net to find them,
One net to bring them all, and using Unix bind them.
------------------------------
Date: Wed, 11 Aug 1999 02:23:35 GMT
From: Brundle <brundlefly76@hotmail.com>
Subject: IO::Socket dilemma
Message-Id: <7oqmqu$ce4$1@nnrp1.deja.com>
This is not a problem with IO::Socket, but a fundemental lack of
knowledge on my part.
Say I initiate a TCP connection to a server, and we are speaking a
protocol that goes back and forth of the same connection:
local: 'hi'
remote: 'how are you'
local: 'fine thanks'
This works fine with 'print $socket 'hi' and $response=<$socket>.
But say the server doesnt always respond - sometimes I say something
and they dont say anything back. Then I am blocked when I read on
<$socket>.
How do I test $socket to see if there is data on the pipe before trying
to read it?
Any help much appreciated
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 10 Aug 1999 21:43:46 -0400
From: "Benjamin Bérubé" <berube@odyssee.net>
Subject: Need help using OO Perl
Message-Id: <7oqkcv$mr1$1@news.quebectel.com>
Hello,
I'm not new to Perl, but I'm new to OO Perl. I'm trying to write a simple
sample class consisting of a counter and an array. Here's a look at my
class :
##############################################
package MyClass;
sub new
{
my($myref) = {};
$myref->{'counter'} = 0; # initialize counter element
$myref->{'array'} = []; # create anonymous array
bless($myref);
return ($myref);
}
sub add
{
my($object) = shift;
# this will write "titi" in the array at the position of the counter, then
increment the counter
local($counter) = $object->{'counter'}++;
${$object->{'array'}}[$counter] = "titi".$counter;
}
sub print
{
my($object) = shift;
print "Printing ---<BR>";
foreach $line (@{$object->{'array'}}) {
print "texte: $line <BR>";
}
}
1;
############################################
This works fine using this program :
######
#!/usr/local/bin/perl
print ("Content-type: text/html\n\n");
use MyClass;
$a = new MyClass;
$a->add();
$a->add();
$a->add();
$a->print();
######
This will print this :
>>>>>
Printing ---
texte: titi0
texte: titi1
texte: titi2
<<<<<
Cool. My questions are as follow.
(1) What means using ${} as in the following line ?
${$object->{'array'}}[$counter] = "titi".$counter;
I think it's some sort of getting the scalar at the position pointed in the
array.
(2) How can I use some sort of variable that would be a pointer to
$object->{'counter'} (for example) so that I could do :
$pointer = 4; # assuming that $pointer points to the counter of the
current object
This way, if I would do :
print $object->{'counter'};
I would get "4".
(3) Same question as before, but a pointer to the $object->{'array'} so that
I could do :
print @array;
or
$array[$pos] = "blabla";
For both question two and three, I read something about using the * like in
*pointer, but i'm not getting how it works.
Any help will be appreciated. Also, let me know if the way i'm doing my
class is "the way to do it".
Thanks !
Ben
berube@odyssee.net
------------------------------
Date: Tue, 10 Aug 1999 18:18:47 -0700
From: Cajun <cajun@rattler.cajuninc.com>
Subject: Newbie alert !! (Thanks, followup, and a question)
Message-Id: <37B0CF76.3F13F7E0@rattler.cajuninc.com>
I'd like to thank Sam Holden, Vlad, John Borwick, and Tad McClellan
for their responses to my original question (below). Vlad, thank you
very much for breaking down the one-line of code in order to make it
easier for me to understand / learn.
I have one more question regarding this. When I used Sam's code:
perl -lni -e 'print $_,"|||||"' database.file
I ended up with ^M at the end of each line. I used the dos2unix utility
to remove them ( I could have probably used Perl too if I knew more
about it). The question is though, why did I get them in the first
place ?
Again, thanks to all for the help! I am trying to learn Perl and have
searched the www quite a bit to find resources. I do have the Learning
Perl book.
Mike
>Current database example:
>
>|Mary|601 Elm Street|Nowhere, CA|99999|555-111-2222|
>|Joe|432 Pine Street|Downtown, CA|88888|555-222-3333|
>
>The database definition has been expanded to include five more blank
>fields at the end of each record. Making the new database example look
>like this:
>
>|Mary|601 Elm Street|Nowhere, CA|99999|555-111-2222||||||
>|Joe|432 Pine Street|Downtown, CA|88888|555-222-3333||||||
>
[snip]
------------------------------
Date: Wed, 11 Aug 1999 01:37:46 GMT
From: zzspectrez@my-deja.com
Subject: Newbie help with typeglobs
Message-Id: <7oqk59$aeg$1@nnrp1.deja.com>
Im trying to pass hash to subroutine so that I can modify
it but it isnt working... Im looking in Programming perl and it
shows...
sub blah {
local (*someary) = @_;
<snip>
&blah (*myary);
Im trying this in a cgi-script and Im getting the following errors in
my apache error log.
Variable "%frm_data" is not imported at /usr/lib/cgi-bin/grade.pl line
32.
Global symbol "frm_data" requires explicit package name at
/usr/lib/cgi-bin/grade.pl line 32.
Variable "%frm_data" is not imported at /usr/lib/cgi-bin/grade.pl line
33.
a snippet of my code is::
sub parse_html {
local (*frm_data) = @_;
blah.....
if (defined($frm_data{$key})) {
$frm_data{$key} = join ("\0", $frm_data{$key},$val);
}else{
$frm_data{$key} = $val;
}
blah...
}
blah...
&parse_html (*quiz_data);
blah...
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
------------------------------
Date: Tue, 10 Aug 1999 22:51:55 -0400
From: rjk@linguist.dartmouth.edu (Ronald J Kimball)
Subject: Re: NEWSFLASH: Supremes rule anti-advert-ware illegal
Message-Id: <1dwc97h.19r66q3shftk6N@p144.tc19a.metro.ma.tiac.com>
I R A Darth Aggie <fl_aggie@thepentagon.com> wrote:
> On 30 Jul 1999 18:20:26 GMT, John Callender <jbc@shell2.la.best.com>, in
> <37a1ecea$0$13652@nntp1.ba.best.com> wrote:
>
> + But yeah, from a certain perspective it does suck.
>
> Thus why G*d uses a killfile whilst reading Usenet...
The existence of killfiles do not justify off-topic postings.
--
_ / ' _ / - aka -
( /)//)//)(//)/( Ronald J Kimball rjk@linguist.dartmouth.edu
/ http://www.tiac.net/users/chipmunk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 10 Aug 1999 20:20:55 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: Perl version question
Message-Id: <7oqjjb$qif$1@canopus.cc.umanitoba.ca>
Tim Lowe <timlowe@removeme.u.washington.edu> wrote in
message news:MPG.12194a9ababee7929896bd@news.uswest.net...
> My university has switched web servers and thus I had to move everything
> over to a new server. I had a messageboard that ran perfectly under the
> following version of perl: 5.004_04 for osfalpha-dec_osf
> But now I get "premature end of script headers" errors under this
> version: 5.004_04 for aix
>
> My university provided the unix program to copy the website over from one
> server to the other. I've double checked all file permissions and
> directory references, but I guess I could have missed something. I'm just
> wondering if my script errors are due to the fact that the perl was
> compiled for different platforms or if they are due to the unix web
> tranfer utility. Thanks to anyone who can point me in the right
> direction.
>
Hi,
Since they're the same perl version, and assuming there
was no corruption of the files during the transfer, it's probably
not the different platform in principle. A few things to consider:
- does a simple "hello world" type of script work, using the
same paths and permissions?
- are you running under 'use strict' with warnings turned on?
- if you do something like
open (FILE, 'filename')
do you also include
or die "Cannot open filename: $!"
- if you use the CGI module, can the script be run from the
command line?
- if your script uses any modules, does the new server have them?
- if you make any explicit references to programs or files in
your script, do these exist on the server?
best regards,
Randy Kobes
--
Physics Department Phone: (204) 786-9399
University of Winnipeg Fax: (204) 774-4134
Winnipeg, MB R3B 2E9 http://theory.uwinnipeg.ca/
Canada randy@theory.uwinnipeg.ca
> --
> "Every man is given the key to the gates of heaven.
> The same key opens the gates of hell." -Buddhist saying
> ----------
> Timothy Lowe
> University of Washington
> Physics Dept - PEG
> timlowe@removeme.u.washington.edu
> ----------
> Remove the "removeme." from my email to send a reply.
------------------------------
Date: Tue, 10 Aug 1999 22:05:08 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Problems with the system function
Message-Id: <37B0DA54.7881008B@rochester.rr.com>
>
...
>
> preferably, I'd like to be able to do something
> like:
>
> $table = system(...);
Ray, if you want to pick up the standard output of a command in a Perl
variable, use the backtick or qx operator (see perlop), as in:
$table=`...`;
The system function returns the error code, not the standard output.
...
------------------------------
Date: Tue, 10 Aug 1999 18:26:32 -0700
From: "David Christensen" <dchristensen@california.com>
Subject: Re: reference to object method
Message-Id: <37b0cefe@news5.newsfeeds.com>
Damian:
Approach #1 doesn't seem to work:
1 #!/fsf/bin/perl -w
2 use Bar;
3
4 my $bar = new Bar();
5
6 $bar->FooOnYou("Howdy ");
7
8 my $ref = \&Bar::FooOnYou;
9
10 my @args = ("Doody, ");
11 &$ref($bar, @args);
12
13 @args = ("cowboy Bob!\n");
14 $bar->$ref(@args);
~/code/perl/foo$ ./foo
Can't locate object method "CODE(0xd09f8)" via package "Bar" at
./foo.pl line 14.
Howdy Doody,
Approach #2 looks good:
1 #!/fsf/bin/perl -w
2 use Bar;
3
4 my $bar = new Bar();
5
6 $bar->FooOnYou("Howdy ");
7
8 my $ref = \&Bar::FooOnYou;
9
10 my @args = ("Doody, ");
11 &$ref($bar, @args);
12
13 my $closure = sub { $bar->FooOnYou(@_) };
14
15 &$closure("cowboy Bob!\n");
~/code/perl/foo$ ./foo
Howdy Doody, cowboy Bob!
Thanks :-)
--
David Christensen
dchristensen@california.com
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: 11 Aug 1999 03:04:50 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: reference to object method
Message-Id: <7oqp8i$ioe$1@towncrier.cc.monash.edu.au>
"David Christensen" <dchristensen@california.com> writes:
>> my $ref = \&Bar::FooOnYou;
>> $var->$ref("Howdy\n");
>OK interesting symetry with Martien's approach:
>I'm wondering if this is TIMTOWDI, or if there's a gotcha in
>there...
No gotchas. In fact the $bar->$ref syntax is the preferred one -
it makes it clearer you're doing a method call.
Note that you can also use symbolic references and write:
my $ref = "Bar::FooOnYou";
$var->$ref("Howdy\n");
But you didn't hear that from me ;-)
Damian
------------------------------
Date: Tue, 10 Aug 99 21:06:03 EDT
From: PETER@yaleads.ycc.yale.edu
Subject: shopping cart recommendations
Message-Id: <18396128BBS86.PETER@yaleads.ycc.yale.edu>
Any recommendations for a quality, free, implemenation of shopping cart code?
------------------------------
Date: 11 Aug 1999 02:29:30 GMT
From: revjack <revjack@radix.net>
Subject: Should I use fork to "parallel process"?
Message-Id: <7oqn6a$ecd$1@news1.Radix.Net>
Keywords: Hexapodia as the key insight
I have a clumsy little script I use to perform a 'whois' query on a name
given at the command line. It serially queries internic, APNIC, RIPE,
ARIN, etc., saving me a little typing when I want to check out a name.
I'm guessing it would run faster if it performed the queries at (roughly)
the same time, instead of serially.
Forking each query into its own process seems like a logical approach.
Generally speaking, is this a stupid idea?
------------------------------
Date: Tue, 10 Aug 1999 22:58:42 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Should I use fork to "parallel process"?
Message-Id: <37B0E6E2.816B73E7@erols.com>
revjack wrote:
>
> I have a clumsy little script I use to perform a 'whois' query on a name
> given at the command line. It serially queries internic, APNIC, RIPE,
> ARIN, etc., saving me a little typing when I want to check out a name.
>
> I'm guessing it would run faster if it performed the queries at (roughly)
> the same time, instead of serially.
>
> Forking each query into its own process seems like a logical approach.
>
> Generally speaking, is this a stupid idea?
Only if you have a perl version compiled with threads.
:-)
I just began my own adventures forking children, reaping dead children (who
was the sick puppy who coined this nomenclature?), etc. Just be sure of two
things:
1) Remember that all data structures are COPIED. That means if you have an
open file, all kids and the parent will be writing to the same file. The
interleaving may not be what you want. Be sure you understand the
consequences of all the shared variables.
2) Make sure the main prog does not exit until all the children are reaped.
Otherwise your process table will fill up and your sysadmin will be looking
to fork and reap you. See the Perl Cookbook for great code snippets.
--
Matthew O. Persico
You'll have to pry my Emacs from my cold dead oversized
control-pressing left pinky finger. -- Randal L. Schwartz
------------------------------
Date: Tue, 10 Aug 1999 22:41:27 -0400
From: "John J. Straumann" <jstraumann@worldnet.att.net>
Subject: Strange File Behavior
Message-Id: <37B0E2D7.8732DD5C@worldnet.att.net>
Hey All:
I am writing data out to a file via a CGI. each time the CGi runs, i
want the contents of the file overwritten with the new data from the
CGI. The file is a simple sequential file of numbers, like this:
0
4
5
etc.
Now, the program works fine when the file DNE. Using
if ( open( theFile, ">$dataFile" ) ) # Create File
the file is created and the data written out with this line:
for ( $i=1; $i<=50; $i++ )
{
print theFile ( "$theArray[ $i ]\n" ); # Write to file
}
This code gives me the file as shown above, one number per line.
However, if the program runs again, and the file is opened using the
same command, the contents are not wiped out and replaced, but the
program adds a newline on each line, leaving this:
1
2
4
6
etc.
I even tried reading the file into an array, deleting the file,
processing, and then re-creating the file and writing the new data out,
but no dice.
Any ideas?
TIA.
John.
------------------------------
Date: Wed, 11 Aug 1999 01:58:57 GMT
From: raludwicREMOVETHIS@u.arizona.edu (Rachael Ludwick)
Subject: Re: suggestions for CRAP
Message-Id: <37b0d5bb.18921232@news.arizona.edu>
>If you folks are serious I would be willing to host the site (e-mail,
>web, and dns) and anything else that might be needed. Hosted on a
>linux machine that I own that sits on my isp's T1. I however am not a
>very good webpage designer unless you consider fuschia and sky blue nice
>"matching" colors :).
Most of you probably (all right, probably all of you) don't know me (I
lurk in most newsgroups), but I can volunteer for this. I actually am
pretty good at perl ... at least I'd know when something is very, very
wrong ... AND IM-arrogant-O I make fairly decent web pages. My
current homepage is http://www.u.arizona.edu/~raludwic. Mine doesn't
have any scripts right now, but I have/do written/write scripts (using
the CGI module. really! I don't try to "roll my own"!)
I myself have seen some really awful things...when I first started out
with perl I downloaded some scripts from "Matt's Script Archive" (is
that the name or is it Mike?) that I was unable to adapt to my use
because I couldn't understand them! Even with comments!!! I had
thought there should have been an install script that asked you
questions to customize the script because the script was so
obtuse...once I learned perl I realized it wasn't perl that was obtuse
but the script.
--
Rachael Ludwick
raludwic@REMOVEu.arizona.edu
http://www.u.arizona.edu/~raludwic
------------------------------
Date: Tue, 10 Aug 1999 22:30:22 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: system command syntax question
Message-Id: <37B0E03D.36FA7454@rochester.rr.com>
...
> I want to do this command using the system command in perl on an NT system:
>
> copy "my file name with spaces" file2
>
> but if I do:
>
> $tmp = "my file name with spaces";
> $file1 = "\"" . $tmp . "\"";
>
> system("copy $file1 $file2");
>
> perl complains because $file1 has double-quotes in its name. How do I
> make system view the double-quotes in $file1 as part of the string
> name?
...
Tom, what error message exactly do you get? When I try it, it works fine:
$tmp="my file.txt";
$file1="\"".$tmp."\"";
$file2="myfile.txt";
system("copy $file1 $file2");
copying "my file.txt" to "myfile.txt". Any chance you forgot to define
variable $file2?
------------------------------
Date: Tue, 10 Aug 1999 18:56:17 -0700
From: "Ashish Bhargava" <abhargav@rational.com>
Subject: Time:: Hires
Message-Id: <7oql79$a12$1@usenet.rational.com>
OS: WinNT
Perl Version : 5.001
Build #: 110 (Aug 13, 1996)
I have inherited a perl program which is used for doing some time
measurements. Currently its using the time() function to get the time. This
is in seconds. I need sub second reading. One way is to use HiRes module. I
am having problems installing this module. If someone has done it please let
me know what steps.
Is it pssoible to use C functions to do the time? If yes, how?
Any help is appreciated.
Thanks,
Ashish
------------------------------
Date: 11 Aug 1999 02:18:51 GMT
From: billynospam@mirror.bt.co.uk (Graham Ashton)
Subject: Re: Time:: Hires
Message-Id: <slrn7r1ncc.53j.billynospam@wing.mirror.bt.co.uk>
In article <7oql79$a12$1@usenet.rational.com>, Ashish Bhargava wrote:
>One way is to use HiRes module. I am having problems installing this
>module.
afraid I've not tried it (well not on NT anyway).
try reading the docs for select() instead. it might do enough for you to
be able to avoid Time::Hires altogether.
--
Graham
P.S. <billynospam@mirror.bt.co.uk> is a fully working address...
------------------------------
Date: 11 Aug 1999 02:30:14 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: Time:: Hires
Message-Id: <7oqn7m$ru5$1@canopus.cc.umanitoba.ca>
In comp.lang.perl.misc Ashish Bhargava <abhargav@rational.com> wrote:
> OS: WinNT
> Perl Version : 5.001
> Build #: 110 (Aug 13, 1996)
> I have inherited a perl program which is used for doing some time
> measurements. Currently its using the time() function to get the time. This
> is in seconds. I need sub second reading. One way is to use HiRes module. I
> am having problems installing this module. If someone has done it please let
> me know what steps.
Hi,
What sort of problems are you having? Using perl5.00503 and
VC++ 6 on Win 98, the (latest) Time-HiRes package built without
problems for me.
It looks like you're using a fairly old version of ActiveState's
perl. If possible, upgrade to the latest build, and you can use the
Perl Package Manager (ppm) to automatically install this module.
See http://www.activestate.com/.
best regards,
Randy Kobes
--
Physics Department Phone: (204) 786-9399
University of Winnipeg Fax: (204) 774-4134
Winnipeg, Manitoba R3B 2E9 e-mail: randy@theoryx5.uwinnipeg.ca
Canada http://theory.uwinnipeg.ca/
------------------------------
Date: Tue, 10 Aug 1999 22:52:33 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: turn $6 into $6000
Message-Id: <37B0E571.AC227A25@erols.com>
$x='$6';
$x += '000';
print $x;
--
Matthew O. Persico
You'll have to pry my Emacs from my cold dead oversized
control-pressing left pinky finger. -- Randal L. Schwartz
------------------------------
Date: Tue, 10 Aug 1999 21:58:42 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: using alarm under win32
Message-Id: <37B0D8D2.92FD0CAD@rochester.rr.com>
...
> I can't get alarm() to work under win32. Is there any way to do
> something similar to alarm() under win32. Here's a simple example of
...
Brian, from the ActiveState FAQ:
There are several functions that are unimplemented in the Perl for Win32
system. Primary
among these are alarm() and fork(), which are used in a few Perl modules.
Because they're
missing in Perl for Win32, you can't use those modules. Here is a
complete list of
unimplemented functions: ...
------------------------------
Date: Tue, 10 Aug 1999 22:51:17 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: Why use Perl when we've got Python?!
Message-Id: <37B0E525.B8ED0EAC@erols.com>
Mitchell Morris wrote:
>
[snip]
> All that said, I really wish that nested structures in Perl were as simple to
> read and write as Python's. I can write $hash{$key}->[0] as well as the next
> guy, but damnit I don't really want to be managing the references myself.
>
Then don't. If you omit the ->, it still works.
Try it.
--
Matthew O. Persico
You'll have to pry my Emacs from my cold dead oversized
control-pressing left pinky finger. -- Randal L. Schwartz
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. Due to their sizes, neither the Meta-FAQ nor
the FAQ are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq" from
almanac@ruby.oce.orst.edu.
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 V9 Issue 455
*************************************