[21730] in Perl-Users-Digest
Perl-Users Digest, Issue: 3934 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 8 14:06:52 2002
Date: Tue, 8 Oct 2002 11:05:12 -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, 8 Oct 2002 Volume: 10 Number: 3934
Today's topics:
ANNOUNCE: CGI::Echo V 1.01 <ron@savage.net.au>
Re: Anyone who uses Perl on VAX <jozefn@newbolt.sonic.net>
Can Perl/mod_perl know who logged in to Apache .htacces (Hardy Merrill)
Re: Can Perl/mod_perl know who logged in to Apache .hta <perl-dvd@ldschat.com>
Re: Can Perl/mod_perl know who logged in to Apache .hta <danb@mail.dnttm.ro>
Re: complex so-called 3 dimensional array problem <goldbb2@earthlink.net>
extract emails with corresponding URLs from whoisreport (Nat)
Fork question? (paul)
Re: Fork question? <jhalpin@nortelnetworks.com_.nospam>
Re: Fork question? ctcgag@hotmail.com
Re: Fork question? news@roaima.freeserve.co.uk
Re: Fork question? <goldbb2@earthlink.net>
Re: Help me understand *foo = \... (Tad McClellan)
Re: Help me understand *foo = \... <goldbb2@earthlink.net>
Re: help with perl map??? <perl-dvd@ldschat.com>
Re: help with perl map??? <alecler@sympatico.ca>
I only need one row from mysql <bernie@nospam.bernieberg.com>
Re: I only need one row from mysql <jeff@vpservices.com>
Re: I only need one row from mysql news@roaima.freeserve.co.uk
Re: I only need one row from mysql <goldbb2@earthlink.net>
Re: I only need one row from mysql (Tad McClellan)
Re: I only need one row from mysql <jeff@vpservices.com>
Intialising the COM port from Perl under W2K <invalid@pinnock.com>
Re: ithreads, perl 5.8 and shared objects <goldbb2@earthlink.net>
Re: mod_perl startup.pl and require (trwww)
Re: On Windows: if ($pid = open(CHILD, "|-")) { <goldbb2@earthlink.net>
On Windows: ioctl.ph <rhedin@aquifer.geology.uiuc.edu>
shell/perl question: how processes get invoked? <jayasena@cs.uiuc.edu>
Re: synonymous subroutines <Tassilo.Parseval@post.rwth-aachen.de>
Re: synonymous subroutines <mjcarman@mchsi.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 7 Oct 2002 08:24:55 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: ANNOUNCE: CGI::Echo V 1.01
Message-Id: <3da2ff1d@post.usenet.com>
**** Post for FREE via your newsreader at post.usenet.com ****
V 1.01 corrects a bug in test.pl. test.pl was copied from Module::MakeDist and used that module instead of using CGI::Echo.
See the earlier announcement for details.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
*** Usenet.com - The #1 Usenet Newsgroup Service on The Planet! ***
http://www.usenet.com
Unlimited Download - 19 Seperate Servers - 90,000 groups - Uncensored
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
------------------------------
Date: Tue, 08 Oct 2002 15:40:05 GMT
From: Joseph Norris <jozefn@newbolt.sonic.net>
Subject: Re: Anyone who uses Perl on VAX
Message-Id: <Pine.LNX.4.40.0210080839450.30573-100000@newbolt.sonic.net>
Jim,
You are a wealth of information - thanks again.
#Joseph Norris (Perl - what else is there?/Linux/CGI/Mysql)
print @c=map chr $_+100,(6,17,15,16,-68,-3,10,11,16,4,1,14,-68,12,1,14,8,
-68,4,-3,-1,7,1,14,-68,-26,11,15,1,12,4,-68,-22,11,14,14,5,15,-90);
On Tue, 8 Oct 2002, Jim Agnew wrote:
> Joseph Norris wrote:
> >
> > Tom,
> >
> > You are right - I should have said openvms. I did not know that this was
> > going to be the OS when I orginally sent the email. The manager just
> > said "Vax box".
> >
> > BTW. I understand that you can get a hobbist version of OpenVms but
> > I don't know where. Any Ideas?
> >
> > Thanks.
> >
> > #Joseph Norris (Perl - what else is there?/Linux/CGI/Mysql)
> > print @c=map chr $_+100,(6,17,15,16,-68,-3,10,11,16,4,1,14,-68,12,1,14,8,
> > -68,4,-3,-1,7,1,14,-68,-26,11,15,1,12,4,-68,-22,11,14,14,5,15,-90);
> >
> > On Tue, 8 Oct 2002, Tom Beer wrote:
> >
> > > Jim Agnew wrote in message <3DA1DC51.382DBAF7@vcu.edu>...
> > > >jozefn wrote:
> > > >> I now have a project on a VAX. Have not seen the box yet - don't know
> > > about the OS - as you can see - very green.
> > > >>
> > > >Welcome to one of the finest os's around. Definitely not a desktop
> > > >except for the very hard-core..
> > >
> > > Technically, VAX refers to the hardware (and I think VAXs are now obsolete -
> > > replaced by Alphas). The OS is most likely to be VMS.
> > >
> > > Tom.
> > >
> > >
> > >
>
>
> ok the hobbyist is avail from http://www.montagar.com/
>
> but you do need to be a (free) member of encompass, the old DECUS users
> group..
>
> the VMS FAQ, opensource links, etc is at:
>
> http://www.openvms.compaq.com/
>
> enjoy..
>
------------------------------
Date: 8 Oct 2002 09:11:30 -0700
From: hmerrill123@yahoo.com (Hardy Merrill)
Subject: Can Perl/mod_perl know who logged in to Apache .htaccess?
Message-Id: <a357877c.0210080811.7b392712@posting.google.com>
Is there any way(module?) that Perl/mod_perl can know who logged in to
an Apache webserver that is using .htaccess authentication?
TIA.
------------------------------
Date: Tue, 8 Oct 2002 11:26:53 -0600
From: "David" <perl-dvd@ldschat.com>
Subject: Re: Can Perl/mod_perl know who logged in to Apache .htaccess?
Message-Id: <UsEo9.6351$G5.5948@fe01>
> Is there any way(module?) that Perl/mod_perl can know who logged in
to
> an Apache webserver that is using .htaccess authentication?
$ENV{'REMOTE_USER'}
for a list of environment variables try:
foreach my $key(%ENV){
print qq^\$ENV{'$key'} = "$ENV{$key}"\n^;
}
Regards,
David
------------------------------
Date: Tue, 8 Oct 2002 20:18:43 +0200
From: "Dan Borlovan" <danb@mail.dnttm.ro>
Subject: Re: Can Perl/mod_perl know who logged in to Apache .htaccess?
Message-Id: <anv41d$fmp$1@nebula.dnttm.ro>
> Is there any way(module?) that Perl/mod_perl can know who logged in to
> an Apache webserver that is using .htaccess authentication?
I think the username is passed in the enviroment to cgi scripts - check
$ENV{'REMOTE_USER'}
You may also find interesting $ENV{'REMOTE_ADDR'} and
$ENV{'HTTP_X_FORWARDED_FOR'}
Danb
------------------------------
Date: Tue, 08 Oct 2002 12:07:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: complex so-called 3 dimensional array problem
Message-Id: <3DA302D0.FD91EBB4@earthlink.net>
hugo wrote:
[snip]
> $dbh = DBI->connect($connectstring,$username,$password) or die "Can't
> connect to database";
You should have RaiseError set, since I don't see you checking for
errors anywhere else. Also, you should say *why* you can't connect to
the database.
my $dbh = DBI->connect(
$connectstring, $username, $password,
{ RaiseError => 1 },
) or die "Can't connect to [$connectstring]: $DBI::errstr";
> $sth = $dbh ->prepare ("SELECT user, task, add_time, FROM
> tasks WHERE project=\"$current_project\" AND month=\"$current_month\"
> AND year=\"$year\" ORDER BY task, ddate, s_time_order, end_time_order
> ASC");
> $sth->execute();
This would be better written as:
my $sth = $dbh->prepare(q[
SELECT user, task, add_time
FROM tasks
WHERE project=? AND month=? AND year=?
ORDER BY task, ddate, s_time_order, end_time_order ASC
]);
$sth->execute( $current_project, $current_month, $year );
It's both clearer, due to whitespace, and less prone to errors, due to
placeholders instead of quoted, interpolated, strings.
> while ($ref = $sth ->fetchrow_hashref()) {
> $Task_ID[$count] = $ref->{'task_ID'};
> $U[$count] = $ref->{'user'};
> $Ta[$count] = $ref->{'task'};
> $A_time[$count] = $ref->{'add_time'};
> $Time_total = $Time_total + $A_time[$count];
> $count++;
Why keep four seperate arrays? Why not one array?
push @data, {%$ref};
$Time_total += $ref->{add_time};
Note that there's no need for $count.
> }
> $sth->finish();
This is only needed if you read part of the results of a select
statement, and want to discard the rest of it. Since you never use
'last' to perform an early departure from your while loop, all of your
records have been read by the time this line is reached, so no ->finish
is needed.
>
> 2. Calculated the time (total number of hours as long as the task is
> the same):
>
> $ta_time = 0;
> @ta = @Ta;
> my ( $previous, $sum, $counting);
> while ( @ta ) {
> my ( $ch, $time ) = ( shift @ta, shift @A_time);
> if ( defined $previous and $previous ne $ch ) {
> $ta_time[$counting] = $sum;
> $counting++;
> $sum = 0;
> }
> $sum += $time;
> $previous = $ch;
>
> }
> $ta_time[$counting] = $sum;
Ugh. How about:
my %time_per_task;
foreach my $row (@data) {
my ($task, $time) = @{$row}{"task", "add_time"};
no warnings 'undefined';
$time_per_task{$task} += $time;
}
my @ta_time = @time_per_task{ sort keys %time_per_task };
It would have been better storing the stuff into time_per_task inside of
the original ->fetchrow loop, though.
> Now I want to do all this inside a double nested loop where @P is a
> list of projects and @U is a list of users for which I want to get
> data (which are tasks descriptions), WITHIN each project.
>
> 1. Get data from database:
>
> for ($p = 0; $p < @P; $p++) {
> for ($u = 0; $u < @U; $u++) {
> $count=0;
> $dbh = DBI->connect($connectstring,$username,$password) or die "Can't
> connect to database";
Why are you creating a new database connection here?
What's wrong with using the one you already have?
> $sth = $dbh ->prepare ("SELECT task, add_time FROM tasks WHERE
> month=\"$current_month\" AND year=\"$year\" AND project=\"$P[$p]\" AND
> user=\"$U[$u]\" ORDER BY project, user, task, ddate, s_time_order,
> end_time_order ASC");
> $sth->execute();
Bleh. Outside of this loop, put a prepare statement of the form:
$sth = $dbh->prepare(q[
SELECT task, add_time
FROM tasks
WHERE month=? AND year=? AND project=? AND user=?
ORDER BY
project, user, task, ddate,
s_time_order, end_time_order ASC
]);
Then, inside the loop, where your original prepare/execute was, put:
$sth->execute(
$current_month, $year,
$data[$p]{project}, $data[$u]{user},
);
[snip]
Most of the rest of the stuff looks pretty confused.
I would suggest that you re-figure out what you want to do, and describe
it plain simple english, and show some sample data, and show how your
program outputs that data, and show how you want your program to output
that data instead.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 8 Oct 2002 10:06:19 -0700
From: wynethlia@cox.net (Nat)
Subject: extract emails with corresponding URLs from whoisreport.com list
Message-Id: <6b32ea12.0210080906.6ef6e753@posting.google.com>
I need to find a script or application that can run through the long
lists of URLs that come up at whoisreport.com, extract the admin
emails from the WHOIS info pages and parse these out along with the
corresponding URL into a CSV file for use in an Access database.
Anyone heard of such a beast or know where I can get one created?
------------------------------
Date: 8 Oct 2002 08:41:35 -0700
From: paulthomson@hotmail.com (paul)
Subject: Fork question?
Message-Id: <464e478f.0210080741.3109956@posting.google.com>
Hi,
I have an application that sends messages(stored in mySQL) to a server
using IO::Socket. There might be times when I need to speed up the
process. For example, if there 1000 messages - rather than sending
them one at a time I would like the application to 'split' 10 times
and each child to send 100 each and (in theory) speed things up
greatly.
I have taken a quick look at fork and before I go mad and build the
application I wondered what alternatives I have. Am I even barking up
the wrong tree with fork?
Thanks in advance for any help.
Regards,
Paul
------------------------------
Date: 08 Oct 2002 10:58:45 -0500
From: Joe Halpin <jhalpin@nortelnetworks.com_.nospam>
Subject: Re: Fork question?
Message-Id: <yxs7k7ksncqy.fsf@nortelnetworks.com_.nospam>
paulthomson@hotmail.com (paul) writes:
> I have an application that sends messages(stored in mySQL) to a
> server using IO::Socket. There might be times when I need to speed
> up the process. For example, if there 1000 messages - rather than
> sending them one at a time I would like the application to 'split'
> 10 times and each child to send 100 each and (in theory) speed
> things up greatly.
>
> I have taken a quick look at fork and before I go mad and build the
> application I wondered what alternatives I have. Am I even barking
> up the wrong tree with fork?
You probably will wind up with interleaved messages doing it that
way. Each child process is going to be writing into the same TCP send
queue. Child process scheduling, when the send queue fills up and who
gets to it first after that, aren't things you can control from an
application.
If you had a different connection for each child, and the receiving
application could put them in order, that might work.
I'd consider compression instead though personally. The zlib library
works very nicely, and has a perl module to access it with on
CPAN. There are a few other modules that provide
compression/decompression as well there.
Joe
------------------------------
Date: 08 Oct 2002 16:38:11 GMT
From: ctcgag@hotmail.com
Subject: Re: Fork question?
Message-Id: <20021008123811.504$zl@newsreader.com>
paulthomson@hotmail.com (paul) wrote:
> Hi,
>
> I have an application that sends messages(stored in mySQL) to a server
> using IO::Socket. There might be times when I need to speed up the
> process. For example, if there 1000 messages - rather than sending
> them one at a time I would like the application to 'split' 10 times
> and each child to send 100 each and (in theory) speed things up
> greatly.
Where's the bottleneck? Getting the messages out of mySQL, doing
something with them in perl, the wire over which the socket goes, or the
server on the receiving end? If the servers are already doing the best
they can, they may actually get slower with paralellization, as they have
to take time out to deal with your increased harassment.
Do you expect any answer back from the sockets?
(Does it matter what order the messages are served?)
> I have taken a quick look at fork and before I go mad and build the
> application I wondered what alternatives I have.
Parallel:ForkManager, perhaps.
> Am I even barking up
> the wrong tree with fork?
Don't know, maybe.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Tue, 8 Oct 2002 17:34:53 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Fork question?
Message-Id: <df1vna.7qr.ln@moldev.cmagroup.co.uk>
paul <paulthomson@hotmail.com> wrote:
> I have an application that sends messages(stored in mySQL) to a server
> using IO::Socket. There might be times when I need to speed up the
> process. For example, if there 1000 messages - rather than sending
> them one at a time I would like the application to 'split' 10 times
> and each child to send 100 each and (in theory) speed things up
> greatly.
The overhead of extracting the data from the database will (generally)
greatly swap the overhead of sending the data across a network.
First get your application to work, and then determine the slow points
by profiling the code.
Remember, there are two important points about optimisation:
1. A slow working program is infinitely more useful than a fast
non-working one
2. Avoid doing any optimisation for as long as possible
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Tue, 08 Oct 2002 13:32:43 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Fork question?
Message-Id: <3DA316BB.9186B537@earthlink.net>
paul wrote:
>
> Hi,
>
> I have an application that sends messages(stored in mySQL) to a server
> using IO::Socket. There might be times when I need to speed up the
> process. For example, if there 1000 messages - rather than sending
> them one at a time I would like the application to 'split' 10 times
> and each child to send 100 each and (in theory) speed things up
> greatly.
The write() or print() of the messages takes little time, since the
computer doing the sending has outgoing tcp buffers. It's constructing
the messages which takes time, and the actual transfer between computers
which takes time (which shows up as time spent recieving the message).
> I have taken a quick look at fork and before I go mad and build the
> application I wondered what alternatives I have. Am I even barking up
> the wrong tree with fork?
Premature optomization is the root of all evil.
Fork *might* indeed be the way to go, but first see how long it takes
when you construct and send the messages serially.
If you do decide to use fork... consider the following example piece of
code... it lets message construction happen in seperate processes, but
it avoids the problem of getting messages unintentionally interleaved
from two or more processes writing to the socket at once:
my $socket = ...; # to send messages to the server.
$| = 1, select $_ for select $socket;
pipe( TOKEN_R, TOKEN_W ) or die;
for( 1 .. 20 ) {
fork and next;
while( more_messages_to_send() ) {
# creating a message may take a while to do...
# This is why it's done in it's own process.
my $message = construct_message();
# get the token ... exit if the socket was closed
# on the remote end.
getc(TOKEN_R) or write(TOKEN_W, "0"), exit;
# write to the socket. Usually takes little time to do.
my $wrote_ok = eval {
local $SIG{PIPE} = sub { die };
print $socket $message;
};
# put the token back.
write(TOKEN_W, "0"), last unless $wrote_ok;
write(TOKEN_W, "1");
}
exit;
}
# put the token in.
write(TOKEN_W, "1");
# wait for the children to finish.
wait or die $! for 1..20;
# take the token back out.
getc(TOKEN_R) or die "Got SIGPIPE while writing to socket\n";
# clean up socket.
print $socket "No more messages";
close $socket;
__END__
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 8 Oct 2002 09:41:28 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help me understand *foo = \...
Message-Id: <slrnaq5rko.2s2.tadmc@magna.augustmail.com>
Da Witch <heather710101@yahoo.com> wrote:
>
> Thanks! Your post and the ones by Steve and Ilya have gone a long way
> in dissipating the fog. Some of it still lingers, though:
>
> In <ansrag$t602@onews.collins.rockwell.com> Michael Carman <mjcarman@mchsi.com> writes:
>
>>our() can't be used to declare a typeglob. You
>>don't declare typeglobs at all
Because they are "internal types", rather than "variables"[1]?
>> (well, sometimes via local(), but that's
>>a different creature altogether.)
> I'm surprised that local typeglobs are that much different from --um--
> non-local typeglobs (???)
>
> What confuses me about typeglobs is that in some contexts they behave
> like regular Perl variable-like things: one can assign to them, one
> can make references pointing to them, one can declare them local.
^^^^^^^^^^^^^^^^^^
local() does not declare (create) variables [2]:
A C<local> just gives temporary values to global
(meaning package) variables. It does I<not> create
a local variable.
Dynamic scoping can easily make people's head hurt (and so
can manipulating the Symbol Table, as with typeglobs).
When teaching Perl I throw this out there in an attempt
to remove (some of) the pain:
local() is not really about a _variable_.
It is about the _value_ of a variable.
> But then it turns out that one can't declare them my
Not being able to do symbol table stuff with my()'d variables
should not be surprising, since they are _not in_ the
symbol table. :-)
> or our (!?!?!),
> which produces in me a mild sense of cognitive/syntatic chaos.
our() works on variables, but not on "internal types"?
Errr, but "perldoc -f local" says "modifies the listed variables"
and it works on typeglobs, so maybe "variable" and "internal type"
are _not_ distinct. Now I'm starting to get confused too...
[1] "Typeglobs and Filehandles" in perldata.pod
[2] "Temporary Values via local()" in perlsub.pod
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 08 Oct 2002 12:39:15 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help me understand *foo = \...
Message-Id: <3DA30A33.B5819ED9@earthlink.net>
Da Witch wrote:
>
> I've read all the relevant parts in the Camel book (I think), but I'm
> still very confused by Perl expressions such as:
>
> *xyz = [1, 2, 3];
>
> Is *xyz a global variable?
Yes, insofar as any perl variable is global. It refers, as others have
said, to a special kind of object, a typeglob, in the current package
(someone said that it refers to a typeglob in the main:: package, but
that's false).
The *xyz typeglob holds the $xyz global, the @xyz global, the %xyz
global, the &xyz subroutine, the xyz format specifyer (for write), and
the xyz filehandle.
When you assign an arrayref to a typeglob, it replaces the appropriate
slot of the typeglob with that arrayref. In other words, suppose you
did:
my $x = \@xyz; my $y = [1, 2, 3];
print $x, $y, \@xyz, "\n";
*xyz = $x;
print $x, $y, \@xyz, "\n";
You'll get something like:
ARRAY(0xdeadbeef)ARRAY(0x12345678)ARRAY(0xdeadbeef)
ARRAY(0xdeadbeef)ARRAY(0x12345678)ARRAY(0x12345678)
Note that the contents of the original @xyz aren't changed -- instead,
@xyz refers to a different array.
(Sortof like switching the numbers on the houses on a street ... they're
the same houses, in the same locations, with the same contents, but
someone looking for house 432 will find a different house).
> How does the effect of above line differ from that of
>
> our @xyz = (1, 2, 3);
Look at it as two parts:
our @xyz;
This line creates a new lexical variable, @xyz, which happens to be an
alias to the global variable @xyz.
This has no "real" effect on much of anything, *except* that it keeps
'use strict' from being unhappy with your use of @xyz here or later in
this scope.
(I can't think of a house/house number analogy, sorry)
@xyz = (1, 2, 3);
Then, it assigns a list to that array.
The global @xyz still is the same array it always was, but it's contents
have changed.
(Instead of switching the house numbers, the people have left and moved
elsewhere, and someone else has moved in. The house is the same, in the
same place as it was, with the same number, but it has different
contents.)
> ? Why does
>
> our *xyz;
>
> produce an error? Is it because "our" is redundant in this case?
Because our actually a funny way of declaring a funny lexical variable.
And you can't have a lexical typeglob.
> On p. 249, the Camel book says:
>
> ...typeglob references can't be passed back out of the scope of a
> localized typeglob.
>
> I can't quite understand this. I thought it meant that the following
> code would result in an error:
>
> use strict;
> my $f = &foo();
> sub foo {
> local *f;
> return \*f;
> }
>
> ...but it doesn't. (Not that I would have any idea of what I could do
> with a variable holding \*f).
Because it does not do what you might expect it to do. Consider:
sub foo {
local *f;
warn \@f, \*f;
return \*f;
}
warn \@f, \*f;
my $foo = foo();
warn \@{*$foo}, $foo;
Which produces:
ARRAY(0x17757f8)GLOB(0x17757e0) at - line 6.
ARRAY(0x177f228)GLOB(0x17757e0) at - line 3.
ARRAY(0x17757f8)GLOB(0x17757e0) at - line 8.
To make it do something closer to what you would expect it to do, you'd
need something like:
sub foo {
local *f;
my $glob = *f;
warn \@f, \$glob;
\$glob;
}
Or:
sub foo {
return \do {
local *f;
warn \@f, \*f;
*f;
};
}
Neither of which is especially pretty.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 8 Oct 2002 09:13:49 -0600
From: "David" <perl-dvd@ldschat.com>
Subject: Re: help with perl map???
Message-Id: <gwCo9.6294$G5.1252@fe01>
> Can someone please tell me what this is doing?
>
> map {$_ = ['re', $_]} @args;
>
> What else is needed?
Mike, you need to set an array equal to the statement like this:
@args = map {$_ = ['re', $_]} @args;
map does not work on the array provided it, it only uses it as a
source.
Regards,
David
------------------------------
Date: Tue, 08 Oct 2002 11:55:14 -0400
From: Andre <alecler@sympatico.ca>
Subject: Re: help with perl map???
Message-Id: <alecler-F105A2.11551408102002@news1.qc.sympatico.ca>
In article <gwCo9.6294$G5.1252@fe01>, "David" <perl-dvd@ldschat.com>
wrote:
> > Can someone please tell me what this is doing?
> >
> > map {$_ = ['re', $_]} @args;
> >
> > What else is needed?
>
> Mike, you need to set an array equal to the statement like this:
>
> @args = map {$_ = ['re', $_]} @args;
No. You should write:
@args = map ['re', $_], @args;
But a foreach loop is the proper way:
$_ = ['re', $_] for @args;
Andre
------------------------------
Date: Tue, 08 Oct 2002 10:23:53 -0500
From: bernie <bernie@nospam.bernieberg.com>
Subject: I only need one row from mysql
Message-Id: <3da306a8@news.splitrock.net>
Howdy,
With the way I have my database and select statement setup I know I
will only how one row returned, how would I get it without doing a loop?
this is sorta what I have right now:
<snip>
$qry = "SELECT * FROM table WHERE uname=$uname";
$sth = $DB->prepare($qry); #assume I have the db connection aready setup
$sth->execute;
# now, how would I get the data about of it?, do I still need to do some
sort of fetchrow() or something?
#I wan't to do something like this, my sytax is probably wrong
if ("$password" = $sth[5]) {
print "password is good;
}else{
print "password is bad";
}
</snip>
thanks for any pointers you have give!
--
bernie
www.bernieberg.com
------------------------------
Date: Tue, 08 Oct 2002 08:50:10 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: I only need one row from mysql
Message-Id: <3DA2FEB2.4080009@vpservices.com>
bernie wrote:
> Howdy,
> With the way I have my database and select statement setup I know I
> will only how one row returned, how would I get it without doing a loop?
> this is sorta what I have right now:
>
> $qry = "SELECT * FROM table WHERE uname=$uname";
> $sth = $DB->prepare($qry); #assume I have the db connection aready setup
> $sth->execute;
Instead of those last two lines just do this:
my $row_arrayref = $DB->selectrow_arrayref($qry);
You don't need a statement handle ($sth) for a single row query, you can
just do it from the database handle as shown above and in the DBI docs.
--
Jeff
------------------------------
Date: Tue, 8 Oct 2002 17:30:19 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: I only need one row from mysql
Message-Id: <r61vna.7qr.ln@moldev.cmagroup.co.uk>
bernie <bernie@nospam.bernieberg.com> wrote:
> With the way I have my database and select statement setup I know I
> will only how one row returned, how would I get it without doing a loop?
Uh, don't use a loop?
> $qry = "SELECT * FROM table WHERE uname=$uname";
Generally, I'd recommend avoiding "*" in a query. If you know what you
want, ask for it explicitly. If you don't know what you want then how
will your program cope when the schema gets changed?
> $sth = $DB->prepare($qry); #assume I have the db connection aready setup
> $sth->execute;
> # now, how would I get the data about of it?, do I still need to do some
> sort of fetchrow() or something?
How about just calling fetchrow?
my @sth = $sth->fetchrow_array; # Personally I'd prefer @row
> if ("$password" = $sth[5]) {
Two points: (1) the = is an assignment, and so will fail in this context. I presume you really mean eq; (2) don't quote variables needlessly.
if ($password eq $sth[5]) {
> print "password is good;
> }else{
> print "password is bad";
> }
Chris
--
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}
------------------------------
Date: Tue, 08 Oct 2002 12:51:26 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: I only need one row from mysql
Message-Id: <3DA30D0E.B6D49622@earthlink.net>
bernie wrote:
>
> Howdy,
> With the way I have my database and select statement setup I
> know I will only how one row returned, how would I get it without
> doing a loop?
Err, don't use a loop?
> this is sorta what I have right now:
>
> <snip>
>
> $qry = "SELECT * FROM table WHERE uname=$uname";
> $sth = $DB->prepare($qry); #assume I have the db connection aready setup
> $sth->execute;
$sth = $DB->prepare(q[
SELECT * FROM table WHERE uname=? LIMIT 1
]);
$sth->execute($uname);
> # now, how would I get the data about of it?, do I still need to do
> # some sort of fetchrow() or something?
> #I wan't to do something like this, my sytax is probably wrong
>
> if ("$password" = $sth[5]) {
> print "password is good;
> }else{
> print "password is bad";
> }
my ($pass_from_db) = ($sth->fetchrow_array)[5]
or die "No password in database!\n";
if( $password eq $pass_from_db ) {
# good
} else {
# bad
}
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 8 Oct 2002 11:54:21 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: I only need one row from mysql
Message-Id: <slrnaq63dt.36c.tadmc@magna.augustmail.com>
bernie <bernie@nospam.bernieberg.com> wrote:
> With the way I have my database and select statement setup I know I
> will only how one row returned, how would I get it without doing a loop?
perldoc DBI
""selectrow_array""
@row_ary = $dbh->selectrow_array($statement);
@row_ary = $dbh->selectrow_array($statement, \%attr);
@row_ary = $dbh->selectrow_array($statement, \%attr, @bind_values);
This utility method combines the prepare, execute, and
fetchrow_array entries elsewhere in this document into
a single call.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 08 Oct 2002 10:31:10 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: I only need one row from mysql
Message-Id: <3DA3165E.60508@vpservices.com>
news@roaima.freeserve.co.uk wrote:
> bernie <bernie@nospam.bernieberg.com> wrote:
>
>>$qry = "SELECT * FROM table WHERE uname=$uname";
>>
>
> Generally, I'd recommend avoiding "*" in a query.
This is good advice in this case because the OP uses column order to
find column values. But I think saying it should be avoided in general
is going too far. For example, if I simply want to dump out the
resultset to an HTML table, I want it to reflect the current schema, not
some version of the schema that is hard-coded into the query itself.
> If you know what you
> want, ask for it explicitly. If you don't know what you want then how
> will your program cope when the schema gets changed?
By using fetchrow_hashref() and friends to refer to the columns by name
rather than by order. If the schema changes to rename the columns, this
would break, but so would a hard-coded query.
--
Jeff
------------------------------
Date: Tue, 8 Oct 2002 18:58:38 +0100
From: "Graeme" <invalid@pinnock.com>
Subject: Intialising the COM port from Perl under W2K
Message-Id: <53Fo9.672$B66.81858@newsfep2-gui>
ActivePerl 5.6.1.628
W2000 SP3
I'm trying to capture caller ID information from my modem to keep a
log of incoming calls but I'm having problem talking to the modem on
either of my COMM ports. When I first run the following code after a
boot it doesn't error it just doesn't get anything from the modem. If
I go into TERMINAL and access the same COMM port I get normal
responses to AT etc. After going into terminal the perl code runs fine
until the next boot. I'm trying to initialise the COMM port using MODE
from within the code but it doesn't seem to work?
If anyone has any ideas, I'd appreciate any help.
TIA
#!c:\perl\perl.exe -w
$modem = `mode com2 baud=9600 parity=n data=8 stop=1` ;
print $modem ;
print "Opening modem for output\n" ;
open(PORT, ">COM2") or die "Cannot write to COM2"; ;
print "Enabling caller ID on modem\n" ;
print PORT "AT%CCID=1\r" ;
print "Closing modem for output\n" ;
close(PORT) ;
print "Opening modem for input\n" ;
open (PORT, "<COM2") or die "Cannot read from COM2";
while (<PORT>) {
print $_ ;
if ( $_ =~ m/^DATE/ ) {
$date = substr($_,7) ;
chomp($date) ;
}
if ( $_ =~ m/^TIME/ ) {
$time = substr($_,7) ;
chomp($time) ;
}
if ( $_ =~ m/^TYPE/ ) {
$type = substr($_,7) ;
chomp($type) ;
}
if ( $_ =~ m/^CALR/ ) {
$calr = substr($_,7) ;
chomp($calr) ;
if ( ($calr ne "P") and ($calr ne "O")) {
logcall () ;
}
}
if ( $_ =~ m/^NAME/ ) {
$calr = substr($_,7) ;
chomp($calr) ;
if ( $calr ne "RINGBACK" ) {
logcall () ;
}
}
}
exit ;
sub logcall {
$logrec = $type . " " . $date . " " . $time . " " . $calr . "\n" ;
print $logrec ;
open(APP, ">>calllog.txt") ;
print APP $logrec ;
$calr = "" ;
close(APP) ;
}
*** end of code ***
*** output ***
C:\Inetpub\wwwroot>commport.pl
Status for device COM2:
-----------------------
Baud: 9600
Parity: None
Data Bits: 8
Stop Bits: 1
Timeout: ON
XON/XOFF: OFF
CTS handshaking: ON
DSR handshaking: OFF
DSR sensitivity: OFF
DTR circuit: ON
RTS circuit: HANDSHAKE
Opening modem for output
Enabling Caller ID on modem
Closing modem for output
Opening modem for input
*** end of output ***
(at this point it either logs calls OK or does nothing at all
depending on whether I have accessed the modem from TERMINAL)
--
Graeme
------------------------------
Date: Tue, 08 Oct 2002 11:43:11 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <3DA2FD0F.E8A96F55@earthlink.net>
Ilya Zakharevich wrote:
> Rocco Caputo wrote:
> > I must disagree with you here. A properly designed events library
> > will integrate itself with other event loops without the need for
> > strange select() hacks. As Uri mentioned, POE includes such a
> > library.
>
> Oh, get real! There is *absolutely* no way to marry several event
> loops which use different IPC mechanisms - unless your OS supports
> waiting on both kinds of events. Try to wait on a semaphore *or* on
> file-being-readable (without using the threads). Even using the
> threads this requires ugly hacks. (I did it for Tk event loop on OS/2
> - which can wait on GUI events together with select(). Ugly...)
Rocco wasn't talking about different IPC *mechanisms*, but different
libraries event loops.
Isn't it nice that POE can piggyback it's event loop onto other system's
event loops? Because of that, POE doesn't have to have a select loop
*and* wait for Tk events -- instead POE simply tells Tk to wait for
events on the filehandles which POE is watching, and tell Tk about the
timeouts it wants, and then it calls Tk's event loop mechanism.
> > POE's library presents an abstract interface to events. It supports
> > a number of concrete event loops through the use of bridge classes
> > [1].
> > These bridges replace POE's default select() code entirely with
> > other event loops, making select() hacks moot.
>
> Now suppose two modules - which do not know about each other - try to
> subclass select(). How would they do it?
That's not how you would do it. Let's suppose you have written an app
which uses POE and X11::Protocol for a GUI. You've set up a callback
with POE so that when the filehandle which sends you X events does so,
it sends the data into your X11::Protocol object.
Now, you want to add another GUI, with Tk.
You load up Tk, then tell POE to use it's Tk bridge instead of it's
default select loop, and viola! You've got an X gui and Tk gui, and
they're completely oblivious to each other -- but they work fine anyway.
Now suppose you have a third gui, call it Fubar, which has a bridge
class to let it use POE instead of it's own select loop. Does it need
to know about Tk being there? No!
Now suppose you have a fourth gui, call it Quux, which has a bridge
class to let it use Fubar instead of it's own select loop. Does it need
to know about either of Tk or POE being there? No.
In other words, you don't have A and B subclass C, you have A subclass B
which subclasses C; this way, C doesn't need to know what B is a
subclass of, as long as it provides an interface known to it.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 8 Oct 2002 09:02:52 -0700
From: toddrw69@excite.com (trwww)
Subject: Re: mod_perl startup.pl and require
Message-Id: <d81ecffa.0210080802.7b82be0c@posting.google.com>
"Tan Nguyen" <nospam@nospam.com> wrote in message news:<3da27581$1_4@nopics.sjc>...
> "Ken" <angel@xev.net> wrote in message
> news:fafcc419.0210071654.2adc908@posting.google.com...
> > I am currently using mod_perl. I use a startup.pl script to preload
> > all my needed modules. Most of them I load with use(). However, there
> > are some modules that I need to create when Apache is started. The
> > files don't exist until Apache is started. (Just bare with me.) I
> > create the modules in startup.pl. Therefore, I can't use the use()
> > statement. If I try, the modules are loaded before they exist.
Are you saying that you pragmatically manipulate text strings and
eval() the packages into life in startup.pl, or simply that the
package definitions are located in the file named startup.pl? If you
mean the latter, you don't need to use or require anything. Just have
httpd.conf load your startup script, then in your handlers, say:
SomePackage::Defined::In::StartupPl::functionName();
where functionName is a function defined logically after the
statement:
package SomePackage::Defined::In::StartupPl;
in the file startup.pl.
> > Ok, here is my question:
> > Will loading modules with require() preload them into memory like the use
> statement does?
> Yes and No.
> Say, we have a module "Foo" with an exported function "bar". When you
> "require Foo", you load Foo into memory but you don't import "bar". When you
> "use Foo", you load Foo into memory and import "bar" into your current
> namespace at compile time.
>
> use Foo;
> is equivalent to
> BEGIN { require Foo; import Foo }
> so you can call bar like this:
> bar "Good day, mate";
In a mod_perl process, the only way this works is if you call bar()
from inside startup.pl, because the function is only exported to the
current namespace, not all modules that are loaded into the mod_perl
process.
> require Foo;
> and you try
> bar "Good day, mate";
> you'll hear errors screaming at you.
If you try to call bar() in a mod_perl handler or anywhere other than
startup.pl, this is what you get period.
I tried: use Apache::Constants; in startup.pl and tried to return( OK
) in a handler. Wrong. so I just did:
use Apache::Constants (); # dont export anything
in startup.pl and return( Apache::OK ) from the handler.
> Of course, you can get around like this:
> Foo::bar "Good day, mate";
This is bascially what you have to do period in mod_perl handlers,
unless you feel like use()ing all the modules that export functions in
each of your handlers. Thats expensive in terms of memory for large
projects.
This discussion should be on the mod_perl mailing list,
send mail to modperl-subscribe@perl.apache.org to subscribe.
Todd W.
------------------------------
Date: Tue, 08 Oct 2002 12:45:53 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: On Windows: if ($pid = open(CHILD, "|-")) {
Message-Id: <3DA30BC1.15DB729D@earthlink.net>
Rick Hedin wrote:
>
> Hello all.
>
> The line mentioned in the subject line doesn't work on Windows. I got
> it out of The Perl Cookbook, so it probably works on Unix.
>
> Is there some equivalent expression that works on Windows? I would
> like to do some "create a child process and communicate with it using
> pipes" stuff on Windows. Best of all is if somebody has some code
> that already does that on Windows that they're willing to share.
The problem is, open(CHILD, "|-") uses forking to create the child
process. Windows doesn't really have true forking -- although it has a
fork function, this is really an emulation using threads. Sadly, perl
hasn't incorporated it's fork emulation into open(FH, "|-") ... so you
have to do the two steps seperately yourself:
pipe( FROM_PARENT, TO_CHILD );
if( $pid = fork ) {
# parent.
close FROM_PARENT;
print TO_CHILD "stuff";
close TO_CHILD;
waitpid $pid, 0 or die horribly;
$? and die horribly;
} else {
# child.
close TO_CHILD;
open STDIN, "<&FROM_PARENT" or die horribly;
close FROM_PARENT;
while( <STDIN> ) {
# stuff with $_.
}
exit;
}
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 8 Oct 2002 11:33:42 -0500
From: "Rick Hedin" <rhedin@aquifer.geology.uiuc.edu>
Subject: On Windows: ioctl.ph
Message-Id: <rKDo9.34468$m7.319148@vixen.cso.uiuc.edu>
Hi. Has someone made an ioctl.ph for Windows? Is it available?
I need F_GETFL defined, and so forth.
Regards,
Rick
------------------------------
Date: Tue, 08 Oct 2002 11:48:29 -0500
From: "V. Sanath D. Jayasena" <jayasena@cs.uiuc.edu>
Subject: shell/perl question: how processes get invoked?
Message-Id: <3DA30C5D.FF482F32@cs.uiuc.edu>
Hi,
I am using a Sun Ultra5, with SunOS 5.8 (Solaris 8). My default
shell is tcsh, but I use "#!/usr/bin/sh" in shell scripts.
I appreciate expert views on this. I want to run a program
(an executable, say, "xyz") repeatedly (a different input file
each time) for experiments. I tried using a Perl script to do
the looping but due to some reason, a single "xyz" session
cannot seem to handle it after a few iterations. So I wrote
a Perl script "run-xyz.pl" to invoke a single "xyz" sesssion with
1 input file given as argument, and use a shell script "run-xyz.sh"
to call "run-xyz.pl" in a loop with a different input file each time.
(I prefer Perl; that is why I use both in this case)
I run the executable shell script at Unix prompt as: "> run-xyz.sh".
BUT, the shell script invokes the perl script within the loop
and DOES NOT wait until it is over; it simply goes around
and start the next loop and repeats the same. So I have many
"xyz" processes running concurrently. I don't want that because
each input file causes "xyz" to be really CPU- and memory-intensive.
I want one "xyz" process to run at a time (i.e., sequentially).
My assumption was: a shell script would do things sequentially.
The two scripts are given below. Any ideas/hints?
Thanks.
Sanath Jayasena
--------------------------------------------------
#!/usr/bin/sh
#
# run-xyz.sh
#
FILELIST=`ls *.dat`
for infile in $FILELIST
do
perl run-xyz.pl $infile
done
--------------------------------------------------
#!/local/all/perl
#
# run-xyz.pl
#
$INFILE = $ARGV[0];
open(XYZ,"|xyz") || die "Can't start xyz\n" ;
printf XYZ "read_dat $INFILE; ";
# process data here by giving more commands to XYZ
# each command terminated by ";"
printf XYZ "write_dat $INFILE.result ; " ;
printf XYZ "quit; ";
------------------------------
Date: 8 Oct 2002 15:36:37 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: synonymous subroutines
Message-Id: <anuu25$ihf$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Johannes Fürnkranz:
> I want to have two subroutines in a package that do exactly the same
> thing. It's just that there are two names for the thing.
>
> So, my first thought was to define a and simply set the type glob of b
> to a, like this:
>
> *b = *a;
>
> That works, but it has the effect that it will also treat $b and $a as
> synonymous which makes me feel a bit uncomfortable.
>
> So what I really want is to only set the &-entry in the type glob table.
> So I tried:
>
> &b = &a;
>
> This also works, but gives a warning:
>
> $ perl -e 'sub a { print "a"; }; &b = &a; b();'
> Can't modify non-lvalue subroutine call at -e line 1.
> a
>
> What would be the correct way of doing that?
*b = \&a;
This only sets the CODE-slot and leaves the other slots untouched.
This is a general pattern. To only set the scalar slot:
*b = \$scalar;
And so forth for the other slots.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Tue, 08 Oct 2002 10:38:40 -0500
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: synonymous subroutines
Message-Id: <anuu54$t3q1@onews.collins.rockwell.com>
On 10/8/02 10:01 AM, Johannes Fürnkranz wrote:
>
> I want to have two subroutines in a package that do exactly the same
> thing. It's just that there are two names for the thing.
>
> So, my first thought was to define a and simply set the type glob of b
> to a, like this:
>
> *b = *a;
>
> That works, but it has the effect that it will also treat $b and $a as
> synonymous which makes me feel a bit uncomfortable.
Well, if you're subroutines are actually named 'a' and 'b' then it
should, since $a and $b are special vars, but otherwise it probably
doesn't matter.
> So what I really want is to only set the &-entry in the type glob table.
> [...]
> What would be the correct way of doing that?
*b = \&a;
-mjc
------------------------------
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 3934
***************************************