[17036] in Perl-Users-Digest
Perl-Users Digest, Issue: 4448 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 27 18:10:41 2000
Date: Wed, 27 Sep 2000 15:10:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <970092622-v9-i4448@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 27 Sep 2000 Volume: 9 Number: 4448
Today's topics:
Bizarre problem with array ref in OO module <dbohling@newsfactor.com>
Re: Bizarre problem with array ref in OO module <uri@sysarch.com>
Re: Bizarre problem with array ref in OO module <dbohling@newsfactor.com>
Can't get opendir working in win32 <jluongo@SPAMISBADmediaone.net>
Re: Can't get opendir working in win32 <amonotod@netscape.net>
Re: Candidate for the top ten perl mistakes list <uri@sysarch.com>
Re: Candidate for the top ten perl mistakes list (Logan Shaw)
cgi that grabs html into @ from another cgi page drdementor@my-deja.com
Re: cgi that grabs html into @ from another cgi page <amonotod@netscape.net>
Re: cgi that grabs html into @ from another cgi page drdementor@my-deja.com
Re: cgi that grabs html into @ from another cgi page <blavender@spk.usace.army.mil>
Re: Date Conversion Question <lr@hpl.hp.com>
Re: Date Conversion Question <godzilla@stomp.stomp.tokyo>
Re: foreach two elements at a time? (Abigail)
Re: foreach two elements at a time? (Logan Shaw)
Re: Help with Time::localtime <jim@thebeaches.to>
Re: Help with Unix processes. (Urgent!) (Logan Shaw)
Re: How can I combine regular expressions? <lr@hpl.hp.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Sep 2000 16:10:25 -0400
From: Daniel Bohling <dbohling@newsfactor.com>
Subject: Bizarre problem with array ref in OO module
Message-Id: <970085550.1244321026@isp-east.usenetserver.com>
I'm working on a OO module that provides search functions for our website. It
builds a pair of arrays stored in $self->{'rtime'} and $self->{'rrel'}.
I've included the relevant code at bottom.
I'm getting bizarre problems when i copy these arrays into another and
then joining the subsequent array into a concatenated string.
my @idz = (@{$self->{'rrel'}}, @{$self->{'rtime'}});
print join "\n", @idz; <------works correctly on 34 members
$statement = "
SELECT title,id,body
FROM autostories WHERE id IN ("
. join ",", @idz .
")";
print "$statement\n";<------doesnt work, prints length "...id IN (34)"
And more problems when attempting to subscript them via:
foreach ( @{ $self->{'rtime'} }, @{ $self->{'rrel'} } ) { }
works correctly for the first item, doesn't dereference the second
I can possibly see with the subscript doesn't work (to obfuscated?),
But why the @idz array (a copy that joins correctly once then produces the
length when joined a few lines later)
is just freakin weird.
Help?
sub get_story {
my $self = shift;
my $dbh = $self->{'dbh'};
my $ids = join ",", @{$self->{'rrel'}},@{$self->{'rtime'}} ;
my @idz = (@{$self->{'rrel'}}, @{$self->{'rtime'}});
print join "\n", @idz;
---- ^^^^prints array members correctly
my $statement = "SELECT title,id,body
FROM autostories WHERE id IN ($ids)";
print "$statement\n";
---- ^^^^^prints the joined string correctly
$statement = "
SELECT title,id,body
FROM autostories WHERE id IN ("
. join ",", @idz . ")
";
print "$statement\n";
---- ^^^^print the length of the array "...id IN (34)..."
---- wrong, but worked fine by itself above
my $sth = $dbh->prepare($statement);
$sth->execute;
while (my $ref = $sth->fetchrow_hashref) {
foreach ( @{ $self->{'rtime'} }, @{ $self->{'rrel'} } ) {
---- ^^^^first half of list uses correct values,
---- second half is HASH((0x827.....)
if ($_ = $ref->{id}) {
$_ = $ref;
}
}
}
$sth->finish;
#return $ref;
}
sub final_calcs {
my $self = shift;
my $search = shift;
my $results = $self->{'results'};
my $dbh = $self->{'dbh'};
#######snip
foreach (
sort
{
$results->{$b}{dstamp} <=> $results->{$a}{dstamp}
or
$results->{$b}{no_id} <=> $results->{$a}{no_id}
or
$results->{$b}{count} <=> $results->{$a}{count}
}
(keys %$results)
) {
last if $i == 17;
$i++;
push @{ $self->{'rrel'} }, $_ ;
}
$i = 0;
foreach ( sort { $b <=> $a } ( keys %$results ) ) {
last if $i == 17;
$i++;
push @{ $self->{'rtime'} }, $_ ;
}
$self->get_story;
foreach my $ref ( @{$self->{'rrel'}} ) {
print "$ref->{'id'}\t $ref->{'title'}\n";
}
print "x" x 50 ."\n";
foreach my $ref ( @{$self->{'rtime'}} ) {
print "$ref->{id}\t $ref->{title}\n";
}
}
------------------------------
Date: Wed, 27 Sep 2000 20:17:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Bizarre problem with array ref in OO module
Message-Id: <x7itrh8u93.fsf@home.sysarch.com>
>>>>> "DB" == Daniel Bohling <dbohling@newsfactor.com> writes:
DB> $statement = "
DB> SELECT title,id,body
DB> FROM autostories WHERE id IN ("
DB> . join ",", @idz . ")
^
that . is causing @idz to be evaluated in a scalar context. put parens
around the args to join is one solution. another is to set $" to , in a
local and then interpolate:
{
local( $" ) = ',' ;
$statement = << SQL ;
SELECT title,id,body
FROM autostories WHERE id IN (@idz)
SQL
}
DB> while (my $ref = $sth->fetchrow_hashref) {
DB> foreach ( @{ $self->{'rtime'} }, @{ $self->{'rrel'} } ) {
DB> ---- ^^^^first half of list uses correct values,
DB> ---- second half is HASH((0x827.....)
can't debug that without knowing how you stuffed $self. the deref code
looks ok, so that means you stuffed it differently than you think you did.
try using Data::Dumper to see what is really in the object.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Wed, 27 Sep 2000 17:19:12 -0400
From: Daniel Bohling <dbohling@newsfactor.com>
Subject: Re: Bizarre problem with array ref in OO module
Message-Id: <970090072.374307768@isp-east.usenetserver.com>
On Wed, 27 Sep 2000, Uri Guttman wrote:
>>>>>> "DB" == Daniel Bohling <dbohling@newsfactor.com> writes:
>that . is causing @idz to be evaluated in a scalar context. put parens
>around the args to join is one solution. another is to set $" to , in a
>local and then interpolate:
Aaahhhh that hit the spot.
Many thanks,
See below?
> DB> while (my $ref = $sth->fetchrow_hashref) {
> DB> foreach ( @{ $self->{'rtime'} }, @{ $self->{'rrel'} } ) {
> DB> ---- ^^^^first half of list uses correct values,
> DB> ---- second half is HASH((0x827.....)
>
>can't debug that without knowing how you stuffed $self. the deref code
>looks ok, so that means you stuffed it differently than you think you did.
>try using Data::Dumper to see what is really in the object.
The output from Data::Dumper is what is expected...both items are anonymous
arrays of integers. These are built from the keys of %$results
which which is a my'ed $results = $self->{'results'}.
Help...my eyes are starting to burn!
$VAR1 = [
537121,
537108,
537098,
537034,
536970,
536965,
536962,
536953,
536950,
536922,
536884,
536875,
536865,
536787,
536765,
536752,
536745
];
$VAR2 = [
535223,
536720,
535528,
534242,
536058,
535775,
535668,
537034,
535300,
535530,
534274,
535746,
536884,
536953,
534844,
535926,
536423
];
foreach (
sort
{
$results->{$b}{dstamp} <=> $results->{$a}{dstamp}
or
$results->{$b}{no_id} <=> $results->{$a}{no_id}
or
$results->{$b}{count} <=> $results->{$a}{count}
}
(keys %$results)
) {
last if $i == 17;
$i++;
push (@{ $self->{'rrel'} }, $_ );
---- ^^^^built here and here
}
$i = 0;
foreach ( sort { $b <=> $a } ( keys %$results ) ) {
last if $i == 17;
$i++;
push (@{ $self->{'rtime'} }, $_);
---- ^^^^and here
}
$self->get_story;
------------------------------
Date: Wed, 27 Sep 2000 20:13:06 GMT
From: "James" <jluongo@SPAMISBADmediaone.net>
Subject: Can't get opendir working in win32
Message-Id: <mxsA5.29085$pu4.2977039@typhoon.ne.mediaone.net>
This is the beginning of a script I am writing that will change filenames to
a different format. I am testing now. But I can't even open a directory
with opendir. I try to open a directory and then get all the files and
store them in an array.
The script asks for a directory to be input. I input, for example,
"D:\downloads" and then perl says:
"Bad symbol for filehandle at renamer.pl line 8, <STDIN> line 1."
Here, is my script. What is going on? I am confused
use strict;
print "Which directory?\n";
my ($dir);
$dir = <STDIN>;
chomp ($dir);
opendir (DIR, $dir) || die "Cannot open $dir:$!\n";
my @files = readdir($dir);
print "@files\n";
please respond to me directly, its hard to spot a specific message in the
newsgroup
------------------------------
Date: Wed, 27 Sep 2000 21:09:32 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Can't get opendir working in win32
Message-Id: <8qtnm5$kbu$1@nnrp1.deja.com>
In article <mxsA5.29085$pu4.2977039@typhoon.ne.mediaone.net>,
"James" <jluongo@SPAMISBADmediaone.net> wrote:
> This is the beginning of a script I am writing that will change
filenames to
> a different format. I am testing now. But I can't even open a
directory
> with opendir. I try to open a directory and then get all the files
and
> store them in an array.
>
> The script asks for a directory to be input. I input, for example,
> "D:\downloads" and then perl says:
> "Bad symbol for filehandle at renamer.pl line 8, <STDIN> line 1."
> Here, is my script. What is going on? I am confused
Try using "D:/downloads" as your input. Since perl has already loaded,
it is not necessary to use MS format on your directory statements.
>
> use strict;
>
> print "Which directory?\n";
> my ($dir);
> $dir = <STDIN>;
You could also change this to
$dir = $ARGV[0] || "D:/downloads ";
> chomp ($dir);
> opendir (DIR, $dir) || die "Cannot open $dir:$!\n";
> my @files = readdir($dir);
> print "@files\n";
>
> please respond to me directly, its hard to spot a specific message in
the
> newsgroup
If you don't want a newsgroup answer, don't post a newgroup question...
There are plenty of maillists out there which will put the answer right
in your mailbox. See www.activestate.com for details.
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 18:31:50 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Candidate for the top ten perl mistakes list
Message-Id: <x7og198z56.fsf@home.sysarch.com>
>>>>> "RM" == Ren Maddox <ren.maddox@tivoli.com> writes:
RM> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>> Logan Shaw <logan@cs.utexas.edu> wrote in comp.lang.perl.misc:
>>
>> A significant difference is that splice() isn't an l-value and the
>> corresponding forms are missing. Insignificantly, substr() doesn't
>> have a one-argument form.
RM> Why is that, exactly? It seems that splice() should be an l-value.
because it already allows assignment directly in itself. lvalue splice
would be redundant (not that perl has redundancies!). now lvalue substr
existed before 4 arg substr so that will remain.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 27 Sep 2000 14:50:47 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Candidate for the top ten perl mistakes list
Message-Id: <8qtj2n$d6g$1@provolone.cs.utexas.edu>
In article <8qr8pa$ol7$1@charm.magnus.acs.ohio-state.edu>,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
>Should not a ? b : c become
>
> a :-) b :-( c
>
>?
Now *that* is an excellent idea! It actually might even be clearer
than the standard ? : operator, at least in cases where the first of
the two alternatives is a good one and the other is a bad one.
- Logan
------------------------------
Date: Wed, 27 Sep 2000 20:29:48 GMT
From: drdementor@my-deja.com
Subject: cgi that grabs html into @ from another cgi page
Message-Id: <8qtlbh$i6g$1@nnrp1.deja.com>
Ok here it goes
Page A is a cgi page and dynamic.
Page B is a cgi page and dynamic.
I am writing Page A.(mypage)
I have no control of page B. (the other page)
I want page a to be created on the fly including contents from html
results of the page B cgi.(the other page)
I basicaly dont need to know how to parse or anything, but, I need to
know what function allows you to grab html from another page on the net.
Both these pages are on the same account. So there shoun;t be any
security problems. I need a function that can grab html from another
page on the web and stuff it into an array,
I can figure out the rest.
It would be the same princable of a meta search page or something like
that. Im not making meta search but just trying to clarify my example.
Thanks for your help.
JIm
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 21:03:32 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: cgi that grabs html into @ from another cgi page
Message-Id: <8qtnat$k00$1@nnrp1.deja.com>
In article <8qtlbh$i6g$1@nnrp1.deja.com>,
drdementor@my-deja.com wrote:
> Ok here it goes
>
> Page A is a cgi page and dynamic.
> Page B is a cgi page and dynamic.
>
> I am writing Page A.(mypage)
> I have no control of page B. (the other page)
>
> I want page a to be created on the fly including contents from html
> results of the page B cgi.(the other page)
>
> I basicaly dont need to know how to parse or anything, but, I need to
> know what function allows you to grab html from another page on the
net.
>
> Both these pages are on the same account. So there shoun;t be any
> security problems. I need a function that can grab html from another
> page on the web and stuff it into an array,
>
> I can figure out the rest.
>
> It would be the same princable of a meta search page or something like
> that. Im not making meta search but just trying to clarify my example.
>
> Thanks for your help.
>
> JIm
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Maybe Deja's slogan should be:
Post before you search.
http://www.deja.com/dnquery.xp?ST=QS&DBS=2&groups=comp.lang.perl.misc&QR
Y=lwp&svcclass=dncurrent
Just kidding,
amonotod
--
`\|||/ amonotod@
(@@) netscape.net
ooO_(_)_Ooo________________________________
_____|_____|_____|_____|_____|_____|_____|_____|
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 21:24:45 GMT
From: drdementor@my-deja.com
Subject: Re: cgi that grabs html into @ from another cgi page
Message-Id: <8qtoik$l1s$1@nnrp1.deja.com>
In article <8qtnat$k00$1@nnrp1.deja.com>,
amonotod <amonotod@netscape.net> wrote:
> In article <8qtlbh$i6g$1@nnrp1.deja.com>,
> drdementor@my-deja.com wrote:
> > Ok here it goes
> >
> > Page A is a cgi page and dynamic.
> > Page B is a cgi page and dynamic.
> >
> > I am writing Page A.(mypage)
> > I have no control of page B. (the other page)
> >
> > I want page a to be created on the fly including contents from html
> > results of the page B cgi.(the other page)
> >
> > I basicaly dont need to know how to parse or anything, but, I need
to
> > know what function allows you to grab html from another page on the
> net.
> >
> > Both these pages are on the same account. So there shoun;t be any
> > security problems. I need a function that can grab html from another
> > page on the web and stuff it into an array,
> >
> > I can figure out the rest.
> >
> > It would be the same princable of a meta search page or something
like
> > that. Im not making meta search but just trying to clarify my
example.
> >
> > Thanks for your help.
> >
> > JIm
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
> >
>
> Maybe Deja's slogan should be:
> Post before you search.
>
> http://www.deja.com/dnquery.xp?
ST=QS&DBS=2&groups=comp.lang.perl.misc&QR
> Y=lwp&svcclass=dncurrent
>
> Just kidding,
> amonotod
>
> --
> `\|||/ amonotod@
> (@@) netscape.net
> ooO_(_)_Ooo________________________________
> _____|_____|_____|_____|_____|_____|_____|_____|
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
lol i didnt know what to search for or what its called, I usually try
to search, and you can often find very good stuff when you search their
database.
Jim
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 21:29:54 GMT
From: Brian Lavender <blavender@spk.usace.army.mil>
Subject: Re: cgi that grabs html into @ from another cgi page
Message-Id: <8qtos6$lea$1@nnrp1.deja.com>
LWP
http://www2.linuxjournal.com/lj-issues/issue67/3673.html
When you say cgi in comp.lang.perl.misc, people start to get real
sensitive because PERL didn't start as a CGI language, and while it is
an excellent tool for CGI scripting/programs, it does a whole more.
Try
comp.infosystems.www.authoring.cgi
if your focus specifically CGI.
brian
In article <8qtlbh$i6g$1@nnrp1.deja.com>,
drdementor@my-deja.com wrote:
> Ok here it goes
>
> Page A is a cgi page and dynamic.
> Page B is a cgi page and dynamic.
>
> I am writing Page A.(mypage)
> I have no control of page B. (the other page)
>
> I want page a to be created on the fly including contents from html
> results of the page B cgi.(the other page)
>
> I basicaly dont need to know how to parse or anything, but, I need to
> know what function allows you to grab html from another page on the
net.
>
> Both these pages are on the same account. So there shoun;t be any
> security problems. I need a function that can grab html from another
> page on the web and stuff it into an array,
>
> I can figure out the rest.
>
> It would be the same princable of a meta search page or something like
> that. Im not making meta search but just trying to clarify my example.
>
> Thanks for your help.
>
> JIm
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
--
Brian E. Lavender
US Army Corps of Engineers -- Programmer / Systems Analyst
Sacramento, CA (916) 557-6623
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 27 Sep 2000 14:04:25 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Date Conversion Question
Message-Id: <MPG.143c00b8cf35127898adca@nntp.hpl.hp.com>
In article <39D17BCB.65859E61@stomp.stomp.tokyo> on Tue, 26 Sep 2000
21:47:07 -0700, Godzilla! <godzilla@stomp.stomp.tokyo> says...
> eT wrote:
...
> > I need to convert dates from eg:
>
> > Apr 1 1991 12:00:00:000AM
>
> > to:
>
> > 1991-04-01 12:00:00
I had to copy and mark these lines from your signature by hand. Is this
a stratagem to inhibit comments on your code? Everyone else thinks that
the body of a post should contain the content, while the signature
should contain the signature. You are truly an 'original'.
> if ((index ($line, "12:00:00") == -1) &
> (index ($line, "00:00:00") == -1))
> {
> if (rindex ($am_pm, "PM") > -1)
> { $hour = $hour + 12; }
> else
> { $hour = "0$hour"; }
Why does '11', for example, want to become '011'?
> }
You and Iain Chalmers:
IC> Note 2: if the sybase date hours *aren't* in 24hr format(which the
IC> AM at the end suggests), add the line
IC> $hour+=12 if (substr($frac_sec,-2) eq 'PM');
IC> between the split and the sprintf lines...
have each overlooked a critical step in converting from 12-hour to 24-
hour time notation:
$hour %= 12;
Then add 12 if PM.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 27 Sep 2000 15:00:11 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Date Conversion Question
Message-Id: <39D26DEB.B1AFD72C@stomp.stomp.tokyo>
Larry Rosler wrote:
> Godzilla! wrote:
> > eT wrote:
> > > I need to convert dates from eg:
> > > Apr 1 1991 12:00:00:000AM
> > > to:
> > > 1991-04-01 12:00:00
> I had to copy and mark these lines from your signature by hand. Is this
> a stratagem to inhibit comments on your code? Everyone else thinks that
> the body of a post should contain the content, while the signature
> should contain the signature. You are truly an 'original'.
> > if ((index ($line, "12:00:00") == -1) &
> > (index ($line, "00:00:00") == -1))
> > {
> > if (rindex ($am_pm, "PM") > -1)
> > { $hour = $hour + 12; }
> > else
> > { $hour = "0$hour"; }
> Why does '11', for example, want to become '011'?
> You and Iain Chalmers:
> IC> Note 2: if the sybase date hours *aren't* in 24hr format(which the
> IC> AM at the end suggests), add the line
> IC> $hour+=12 if (substr($frac_sec,-2) eq 'PM');
> IC> between the split and the sprintf lines...
> have each overlooked a critical step in converting from 12-hour to 24-
> hour time notation:
> $hour %= 12;
> Then add 12 if PM.
This isn't the only bug, Mr. Rosler. I have been holding off
on posting until I can 'force' this bug out. I've been playing
around, not seriously, just on and off, trying to find what
conditions will cause this bug to manifest.
Look at my,
(index ($line, "00:00:00") == -1)
This should read,
(index ($line, "0:00:00") == -1)
Leading zero deleted from the hour. I am referencing back to
the original data line, not "$hour" which has double zeroes.
So far, playing around with changing my data base of times
per the original article, this bug hasn't jumped out. This
worries me more. Not being able to manifest this bug, tells
me there is a logic flow problem somewhere, a logic flow bug
which compensates for this erroroneous leading zero. For the
life of me, I cannot "see" my logic flow error. I know something
ain't right but cannot find it, just yet. Either a logic flow
bug in my code or, most likely, a logic flow bug in my brain.
I plan to take a little time out and tear my code apart, setting
it up for step-by-step analysis to find what is wrong with my
logic, in my code or in my mind. This one has me boogered for now.
I'll address this error with 011, while I work on this other problem.
Once I figure out why my code works when it should exhibit a bug,
I'll post what I discover, if I can figure this one!
Thank you Mr. Rosler. It is good to learn of problems like this.
Godzilla!
--
Dr. Kiralynne Schilitubi ¦ Cooling Fan Specialist
UofD: University of Duh! ¦ ENIAC Hard Wiring Pro
BumScrew, South of Egypt ¦ HTML Programming Class
------------------------------
Date: 27 Sep 2000 20:18:31 GMT
From: abigail@foad.org (Abigail)
Subject: Re: foreach two elements at a time?
Message-Id: <slrn8t4le9.lo9.abigail@alexandra.foad.org>
Bart Lateur (bart.lateur@skynet.be) wrote on MMDLXXXIV September MCMXCIII
in <URL:news:dp94tso8rbjcn5llp96s4f27klccqkatuo@4ax.com>:
== Abigail wrote:
==
== >%% In particular $a and $b. These seem to shout "sort sub!" at me.
== >
== >Since the code in question is neither a sub, nor does it involve
== >sort, that would be a pretty strange reaction.
==
== Well... if you have file-scoped lexicals $a and $b, that will pretty
== much mess up any sort subs you may ever want to have in the script.
Yeah, and if you have BEGIN {1/0} in your file, that will mess up things
as well.
I did *NOT* have file-scoped lexicals, so your argument is moot.
Abigail
--
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/ xor !@ _?
exit print :
print and push @_ => shift and goto &{(caller (0)) [3]}}
split // => "KsvQtbuf fbsodpmu\ni flsI " xor & _
------------------------------
Date: 27 Sep 2000 15:24:08 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: foreach two elements at a time?
Message-Id: <8qtl18$da5$1@provolone.cs.utexas.edu>
In article <8qqsmn$bma$1@agate.berkeley.edu>, <keith@softbook.com> wrote:
>What is the perl idiom for traversing an array two elements
>at a time?
>
>In tcl, I can say
> foreach {a b} $list { ... }
The perl idiom would be not to have a list like that at all but instead
to have a list of array references, each of which refers to an array
with two values. So,
@x = (
[ 'a', 'b' ],
[ 'c', 'd' ],
[ 'e', 'f' ]
);
foreach (@x)
{
my ($a, $b) = @$_;
# now do whatever with $a and $b
}
Of course, depending on the problem, an associative array might be a
better data structure.
- Logan
------------------------------
Date: Wed, 27 Sep 2000 18:51:15 GMT
From: "Jim Melanson" <jim@thebeaches.to>
Subject: Re: Help with Time::localtime
Message-Id: <DkrA5.19981$vZ.947215@news20.bellglobal.com>
Johnathan,
Go the simple (if less elegant) route:
$todayval = time; $yesterdayval = $todayval - 86400; $tomorrowval =
$todayval + 86400;
@today = localtime($todayval); @yesterday = localtime($yesterdayval);
@tomorrow = localtime($tomorrowval );
#since we know that:
#($second, $minute, $hour, $DAYOFMONTH, $MONTH, $YEAR, $weekday, $dayofyear,
$isDST) = localtime($offset);
#then (and don't forget to increas the month)
$today[4]++; $prevday[4]++; $nextday[4]++;
%DATE = (
'today' => [$today[5], $today[4], $today[3]],
'yesterday' => [$yesterday[5], $yesterday[4], $yesterday[3]],
'tomorrow' => [$tomorrow[5], $tomorrow[4], $tomorrow[3]]);
You will now access your info this way:
For the year:
$DATE{'today'}[0]
$DATE{'yesterday'}[0]
$DATE{tomorrow}[0]
For the month:
$DATE{'today'}[1]
$DATE{'yesterday'}[1]
$DATE{tomorrow}[1]
For the day of the month:
$DATE{'today'}[2]
$DATE{'yesterday'}[2]
$DATE{tomorrow}[2]
I know, I know. It's clunky, un elegant but it works. Once you get more
experience working with hashes/associateve arrays you can write a formula
that will take this down to just a few lines.
Jim
"Jonathan Wong" <wongjonk@hotmail.com> wrote in message
news:8qptde$1ls$1@horn.hk.diyixian.com...
> Hi all,
>
> I have a small problem with time. I wrote in my script:
>
> use Time::localtime;
> $now = localtime;
>
> I can access the year/month/day values by using $now->mon, etc.....
>
> My problem is that I need them for the day after and the day before
today!!
> $now->mday +1 won't work during month end and month beginning.
>
> How can I achieve that???
>
> Thanks for answering this small stupid problem!!!
>
>
> Jonathan
>
>
>
>
------------------------------
Date: 27 Sep 2000 16:20:20 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Help with Unix processes. (Urgent!)
Message-Id: <8qtoak$dj9$1@provolone.cs.utexas.edu>
In article <39D21621.5CF3F279@ccc.uni-erlangen.de>,
Torsten Schindler <Torsten.Schindler@ccc.uni-erlangen.de> wrote:
>Today I have written the script below to handle my molecule calculation
>jobs on a machine
>with two processors.
>
>My aim is: To start two processes on the machine and if one is finished
>then
>feed the empty processor with a new job.
>(1) How can I rewrite the script as a sub, so that I can call it from
>other routines multiple times with
> different arrays of molecules and functions to handle the molecules.
>(2) It should be possible to do the whole thing in an object orientated
>fashion.
> But, I don't now how to set it up.
> Any good suggestions how I - because want to learn it - can do that?
>(Basic knowlegde about OO stuff is given)
I'm not going to answer #1, since I believe #2 is the better way to go.
Basically, you'll probably want two types of objects. The first type
will be a work unit; the second type will be the work processor. The
work processor object would then be initialized with some work units
and maybe some other parameters (number of concurrent processes to use,
for example), and it would allow you to simply call the method on the
work unit that would cause them to perform and report the work. That
way, the work unit objects themselves can have any implementation you
want, and the work processor doesn't care.
>(3) Is it the right way to use closures???
That depends. It's one way, and it's reasonable, but it's not the only
reasonable way.
>(4) Is the last while loop OK???
I wouldn't do it with signals. That is one way, but signals are
difficult to program and are unreliable. Instead, I'd start by
starting as many processes as I can (within given constraints), then
I'd have a loop that notices when jobs are done with waitpid(). When
one finishes, I'd then remove it from the list of running jobs and
start another job if there is still work left.
Here's an example loop. It uses an array @work_units, which lists the
work units left to be done, a hash %running, which notes which pids are
doing what, a scalar $max_processes, which is an upper bound on the
number of concurrent processes, and a subroutine start_job, which
starts a job and returns the pid of the process started.
# start a bunch of jobs
while ( keys %running < $max_processes and @work_units > 0)
{
$job = shift @work_units; # remove job from array
$pid = start_job ($job);
$running{$pid} = 1; # or, do $running{$pid} = $job
}
# now, as long as we have processes left to harvest or
# work left to do, keep going
while ( keys %running > 0 or @work_units > 0 )
{
$pid = waitpid; # harvest a child
delete $running{$pid}; # update our record of children
if (@work_units > 0)
{
$job = shift @work_units;
$pid = start_job ($job);
$running{$pid} = 1;
}
}
Obviously, this is a bit messy w.r.t. global variables and stuff. If
you make it object oriented, you can easily clean that up, because
all of the state can be stored in the object. You can thus move the
lines before and after the call to start_job into that call itself.
>(5) How to deal with closures in objects???
I'm not sure how that's any different than dealing with closures
anywhere else. Perhaps I don't understand the question.
By the way, a completely different solution to your problem
is to install a batch processing system onto your machine and
to tell it it can use two processors. Then, just submit each
separate command as a job, and the system will take care of
scheduling them for you. Depending on which one you choose,
it might also do things like temporarily suspending the
job(s) when someone wants to use the machine interactively.
One such system is Condor, which you can find at
http://www.cs.wisc.edu/condor/ . A list of other ones is
available at http://hepwww.ph.man.ac.uk/~mcnab/QueShed/ .
Hope that helps.
- Logan
------------------------------
Date: Wed, 27 Sep 2000 13:06:56 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How can I combine regular expressions?
Message-Id: <MPG.143bf3368d1acd3b98adc9@nntp.hpl.hp.com>
In article <st25krjh1r16a1@corp.supernews.com> on Tue, 26 Sep 2000
21:35:23 -0000, Craig Berry <cberry@cinenet.net> says...
...
> my @doubles = qw ( CH TH PS );
> my $dpat = join '|', @doubles;
>
> $line =~ s/\b($dpat)(?=[a-z]|\W)/\u\L$1/g;
Two performance improvements:
$line =~ s/\b($dpat)(?=[a-z\W])/\u\L$1/go;
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 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.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 4448
**************************************