[24536] in Perl-Users-Digest
Perl-Users Digest, Issue: 6714 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 22 00:12:39 2004
Date: Mon, 21 Jun 2004 21:05:07 -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 Mon, 21 Jun 2004 Volume: 10 Number: 6714
Today's topics:
Re: (?{..}) and lexical scoping issues. (Anno Siegel)
Re: Check syntax question... <tadmc@augustmail.com>
Re: DBIx::DBSchema::Table support for composite primary <usenet@morrow.me.uk>
Failed to connect to (da_sotong)
Re: Failed to connect to <invalid-email@rochester.rr.com>
Help! - Need a CGI redirect which passes a querystring (Damon)
Re: Help! - Need a CGI redirect which passes a querystr <matthew.garrish@sympatico.ca>
perl, mysql fetchrow_arrayref without package <joe@invalid.com>
Re: perl, mysql fetchrow_arrayref without package <glex_nospam@qwest.invalid>
Re: perl, mysql fetchrow_arrayref without package ctcgag@hotmail.com
Re: perl, mysql fetchrow_arrayref without package <joe@invalid.com>
Re: perl, mysql fetchrow_arrayref without package <joe@invalid.com>
Question on Perl printing <robinncsu@yahoo.com>
Re: Question on Perl printing <postmaster@castleamber.com>
Re: Question on Perl printing <usenet@morrow.me.uk>
snippet using Image::Magick Sharpen() ? (dan baker)
uninit value puzzler (Walter Roberson)
Re: uninit value puzzler <invalid-email@rochester.rr.com>
Re: uninit value puzzler (Walter Roberson)
Re: Why won't this split file script work? <remorse@partners.org>
Re: Why won't this split file script work? (Jay Tilton)
Re: Why won't this split file script work? <pinyaj@rpi.edu>
Re: Why won't this split file script work? (Anno Siegel)
Re: WMI and boolean values from Win32_Processor (Daniel Berger)
Re: WMI and boolean values from Win32_Processor <Petri_member@newsguy.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Jun 2004 22:04:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: (?{..}) and lexical scoping issues.
Message-Id: <cb7m1k$3tv$1@mamenchi.zrz.TU-Berlin.DE>
Aronaxis, the Sourceror <sourceror@front.ru> wrote in comp.lang.perl.misc:
> On 20 Jun 2004 17:10:56 GMT, Anno Siegel
> <anno4000@lublin.zrz.tu-berlin.de> wrote:
[ counting how many substrings of one string $s are also substrings of
another string $t, lots snipped, including some code by yours truly]
> Thank you, it was real pleasure to read such a code.. it's perfect.
> only one drawback I can see - it generates list of all possible substrings
> before checking it, which can take too much memory on arbitrarily long
> strings.. but I'm in doubt if this function would be useful on long
> strings comparison. so your version is great.
Thanks for your kind words. Programmers suck up compliments about
their code like old ladies suck up compliments about their complexion.
Yes, it generates all substrings ahead of time. All the counting
could be done without moving a single byte of the original strings,
just delimiting substrings by indices. The original Pascal came close
to doing it that way, I'm sure.
But there is another inefficiency. When we detect that a substring of
$s is a substring of $t, we *know* that all substrings of that string
will also be substrings of $t. There is no need to generate them,
we could just add their number to the count. The number of non-empty
substrings of a string of length $l is $l * ( $l + 1) / 2.
This leads to a different algorithm: For each starting position in
$s, find the maximal substring that is also substring of $t. Add
the number of substrings of that string to the match count. There
is no need to count the number of substrings we can use the (unproven)
formula above.
Another observation is that the number of substrings of $s that are
substrings of $t is the same as the number of substrings of $t that
are also substrings of $s. They are both the number of common substrings
of $s and $t. There is no real need for two rounds of counting.
So here is a revised version of ind_compare. Its less pretty, but it
should work for large strings, and be a lot faster when there are
large common substrings. The code is tested, but not debugged. It
may be off in limiting cases.
use constant DEBUG => 1;
sub ind_compare1 {
my ( $s, $t) = @_;
my $match;
my $from = 0;
while ( $from < length $s ) {
my ( $l_match, $l);
for ( 0 .. length( $s) - $from ) {
$l = $_; # last length considered
last unless 1 + index( $t, substr( $s, $from, $_));
$l_match = $_; # last length with match
}
$match += triangle( $l_match);
$from += $l; # this makes it fast (we hope)
}
$match *= 2; # instead of counting again with $s and $t swapped
my $count = triangle( length $s) + triangle( length $t);
print "$match/$count\n" if DEBUG;
$count ? $match/$count : 0;
}
sub triangle { return $_*( $_ + 1)/2 for shift }
Anno
------------------------------
Date: Mon, 21 Jun 2004 18:21:33 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Check syntax question...
Message-Id: <slrncderbt.brm.tadmc@magna.augustmail.com>
Bob <bobx@linuxmail.org> wrote:
> I am going through another persons code. I turned on "strict" and
> "warnings" and I am not sure what to do about this warning:
>
> "Scalar value @_[0] better written as $_[0] at update_patch.pl line
> 939."
>
> Should I change it to reflect what is suggested?
Yes.
> Why did it suggest
> that?
Because sometimes it makes a difference.
> I am just a wee learner of Perl.
Your Question is Asked Frequently:
What is the difference between $array[1] and @array[1]?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 21 Jun 2004 22:15:59 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: DBIx::DBSchema::Table support for composite primary keys
Message-Id: <cb7mmv$ld3$1@wisteria.csv.warwick.ac.uk>
Quoth I & L Fogg <il.fogg@bigpond.net.au>:
>
> => $self->{primary_key} =~ /^(\w*)(,\w*)*$/
> #aah!
> or die "Illegal primary key: ", $self->{primary_key};
> => $2 ? $1.$2 : $1;
This is wrong: $2 will only contain the last of the comma-separated
portions. Try
/^(\w*(?:,\w*)*)$/
or simply
/^([\w,]*)$/
and just using $1.
Ben
--
I must not fear. Fear is the mind-killer. I will face my fear and
I will let it pass through me. When the fear is gone there will be
nothing. Only I will remain.
ben@morrow.me.uk Frank Herbert, 'Dune'
------------------------------
Date: 21 Jun 2004 17:44:24 -0700
From: bobo_shooter85@hotmail.com (da_sotong)
Subject: Failed to connect to
Message-Id: <9cd15a3b.0406211644.1ff01d31@posting.google.com>
Hi all,
I've a perl script that does the sending of email using MIME..however
i keep getting this error when i run the script: Failed to connect to
mail server: Unknown error.
Any one has any idea how i can solve this problem? Thanks in advance =)
------------------------------
Date: Tue, 22 Jun 2004 00:57:38 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Failed to connect to
Message-Id: <40D783ED.9080102@rochester.rr.com>
da_sotong wrote:
...
> I've a perl script that does the sending of email using MIME..however
> i keep getting this error when i run the script: Failed to connect to
> mail server: Unknown error.
>
> Any one has any idea how i can solve this problem? Thanks in advance =)
>
Nope. No idea at all. Maybe I could get an idea if you posted some
code -- like a small standalone portion of your program which
demonstrates your problem and that anyone can copy/paste/execute to
demonstrate said problem. Copy/paste your code, don't retype it.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 21 Jun 2004 19:00:41 -0700
From: damon@tribbledesigns.com (Damon)
Subject: Help! - Need a CGI redirect which passes a querystring value
Message-Id: <fcd2095.0406211800.d1f3058@posting.google.com>
Hi all,
I'm not very familiar with Perl and could use some help.
I need to have the page "myPage.cgi?cnt=60" redirect to
"myPage.aspx?cnt=60". Can anyone give me an easy script for doing this
redirect?
Thanks for any help you can offer.
-Damon
------------------------------
Date: Mon, 21 Jun 2004 22:09:47 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Help! - Need a CGI redirect which passes a querystring value
Message-Id: <ExMBc.8742$MU4.440144@news20.bellglobal.com>
"Damon" <damon@tribbledesigns.com> wrote in message
news:fcd2095.0406211800.d1f3058@posting.google.com...
> Hi all,
>
> I'm not very familiar with Perl and could use some help.
>
> I need to have the page "myPage.cgi?cnt=60" redirect to
> "myPage.aspx?cnt=60". Can anyone give me an easy script for doing this
> redirect?
>
Assuming that is the only variable you're expecting, you could use the
following in myPage.cgi:
use strict;
use warnings;
use CGI;
my $q = new CGI;
my $cnt = $q->param('cnt');
print $q->redirect("http://wherever/myPage.aspx?cnt=$cnt");
Matt
------------------------------
Date: Mon, 21 Jun 2004 22:03:33 GMT
From: Smithy <joe@invalid.com>
Subject: perl, mysql fetchrow_arrayref without package
Message-Id: <VWIBc.12556$M96.4355@fe2.texas.rr.com>
all,
just getting started with this perl/mysql db interface. i am sure
someone else has seen this problem. i have searched for this error
message and the results have been 'the connect failed' or 'the execute
failed'. from what i can tell both are working but the command
'fetchrow_arrayref' command produces the following error.
Can't call method "fetchrow_arrayref" without a package or object
reference at /home/stuff/xyz.pl at line abc
here is the snippet of the perl file
#!/usr/bin/perl
use strict;
use Data::Dumper;
use DBI;
#package main;
..
..
..
$dbh = DBI->connect( $myDB, $myUser, $myPass ) or die $DBI::errstr;
print "$dbh\n" ;
$dbh->{RaiseError}=1;
my $cmd = "show tables;";
my $sth = $dbh->prepare( $cmd );
$sth = $sth->execute;
print "a-$sth\n";
$cmd = "select * from testInfo;";
$sth = $dbh->prepare( $cmd );
print "b-$sth\n";
$sth = $sth->execute or die $DBI::errstr;
print "c-$sth\n";
my $ref = $sth->fetchrow_arrayref ;
#while( @ref ) {
# print "found row: id= @ref('id'), name = @ref('name')\n";
# }
my $rc = $dbh->disconnect;
here is the output..
[76] /home/stuff > testMysql.pl
DBI::db=HASH(0x815e260)
a-8
b-DBI::st=HASH(0x821cf54)
c-1
Can't call method "fetchrow_arrayref" without a package or object
reference at /home/stuff/testMysql.pl line 30.
the 8 value is correct as there are 8 rows in show tables
the select value of 1 is correct, in that there is only one entry in the
table (entered by hand at mysql prompt). the select at the mysql prompt
returns the correct info.
what am i missing?? thanks.
kevin
------------------------------
Date: Mon, 21 Jun 2004 17:18:42 -0500
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: perl, mysql fetchrow_arrayref without package
Message-Id: <69JBc.664$g73.30761@news.uswest.net>
Smithy wrote:
[...]
> my $sth = $dbh->prepare( $cmd );
> $sth = $sth->execute;
> print "a-$sth\n";
> $cmd = "select * from testInfo;";
> $sth = $dbh->prepare( $cmd );
> print "b-$sth\n";
> $sth = $sth->execute or die $DBI::errstr;
You're changing $sth.. don't do that.
> Can't call method "fetchrow_arrayref" without a package or object
> reference at /home/stuff/testMysql.pl line 30.
> what am i missing?? thanks.
------------------------------
Date: 21 Jun 2004 23:32:27 GMT
From: ctcgag@hotmail.com
Subject: Re: perl, mysql fetchrow_arrayref without package
Message-Id: <20040621193227.362$DZ@newsreader.com>
Smithy <joe@invalid.com> wrote:
> all,
>
> just getting started with this perl/mysql db interface. i am sure
> someone else has seen this problem. i have searched for this error
> message and the results have been 'the connect failed' or 'the execute
> failed'. from what i can tell both are working but the command
> 'fetchrow_arrayref' command produces the following error.
>
> $sth = $dbh->prepare( $cmd );
> print "b-$sth\n";
> $sth = $sth->execute or die $DBI::errstr;
> print "c-$sth\n";
> my $ref = $sth->fetchrow_arrayref ;
...
> b-DBI::st=HASH(0x821cf54)
> c-1
As you see here, $sth is now 1, rather than a DBI::st object.
That is because execute does not return a statement handle--so
don't assign the results of an execute to your statement handle.
(Well, if you want to use it again later, anyway. If you don't intend
to use the handle again, you can overwrite it, but it is a poor
practise to do so.)
$sth->execute();
or
print $sth->execute();
or
my $exec_result = $sth->execute();
> the select value of 1 is correct, in that there is only one entry in the
> table (entered by hand at mysql prompt).
No, the value is not correct. Because the execute succeeded, it returns
true. It just so happens that the true value it returns is 1, and it just
so happens that you expected one row. That is luck, rather than
correctness. (As a further (un)luckiness, MySQL's DBD will often have
execute return the number of rows found by the select, but there are
situations where it will not. One should not rely upon it.)
I wish that, upon successfully executing a select, execute would return
the handle itself, but that is not what it does.
BTW, since you turned on RaiseError, you don't need the "or die
$DBI::errstr"
(Also, your commented out while loop has problems.)
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Tue, 22 Jun 2004 02:54:14 GMT
From: smitty <joe@invalid.com>
Subject: Re: perl, mysql fetchrow_arrayref without package
Message-Id: <qbNBc.6679$1L2.2372@fe1.texas.rr.com>
ctcgag@hotmail.com wrote:
> Smithy <joe@invalid.com> wrote:
>
>>all,
>>
>>just getting started with this perl/mysql db interface. i am sure
>>someone else has seen this problem. i have searched for this error
>>message and the results have been 'the connect failed' or 'the execute
>>failed'. from what i can tell both are working but the command
>>'fetchrow_arrayref' command produces the following error.
>>
>>$sth = $dbh->prepare( $cmd );
>>print "b-$sth\n";
>>$sth = $sth->execute or die $DBI::errstr;
>>print "c-$sth\n";
>>my $ref = $sth->fetchrow_arrayref ;
>
>
> ...
>
>
>>b-DBI::st=HASH(0x821cf54)
>>c-1
>
>
> As you see here, $sth is now 1, rather than a DBI::st object.
> That is because execute does not return a statement handle--so
> don't assign the results of an execute to your statement handle.
> (Well, if you want to use it again later, anyway. If you don't intend
> to use the handle again, you can overwrite it, but it is a poor
> practise to do so.)
uugghhh... it seems so obvious now. thanks.
>
> $sth->execute();
> or
> print $sth->execute();
> or
> my $exec_result = $sth->execute();
>
>
>>the select value of 1 is correct, in that there is only one entry in the
>>table (entered by hand at mysql prompt).
>
>
> No, the value is not correct. Because the execute succeeded, it returns
> true. It just so happens that the true value it returns is 1, and it just
> so happens that you expected one row. That is luck, rather than
> correctness. (As a further (un)luckiness, MySQL's DBD will often have
> execute return the number of rows found by the select, but there are
> situations where it will not. One should not rely upon it.)
thanks for the pointers. is the mysql DBD the only one that behaves
this way, or do the others as well?
>
> I wish that, upon successfully executing a select, execute would return
> the handle itself, but that is not what it does.
>
> BTW, since you turned on RaiseError, you don't need the "or die
> $DBI::errstr"
>
> (Also, your commented out while loop has problems.)
first things first, that would get fixed sooner or later..
>
> Xho
>
------------------------------
Date: Tue, 22 Jun 2004 03:36:16 GMT
From: smitty <joe@invalid.com>
Subject: Re: perl, mysql fetchrow_arrayref without package
Message-Id: <QONBc.13755$M96.2340@fe2.texas.rr.com>
J. Gleixner wrote:
> Smithy wrote:
> [...]
>
>> my $sth = $dbh->prepare( $cmd );
>> $sth = $sth->execute;
>> print "a-$sth\n";
>> $cmd = "select * from testInfo;";
>> $sth = $dbh->prepare( $cmd );
>> print "b-$sth\n";
>> $sth = $sth->execute or die $DBI::errstr;
>
>
> You're changing $sth.. don't do that.
>
>> Can't call method "fetchrow_arrayref" without a package or object
>> reference at /home/stuff/testMysql.pl line 30.
>
>
>> what am i missing??
the obvious.. thanks.
thanks.
------------------------------
Date: Mon, 21 Jun 2004 17:45:48 -0400
From: "bear_hua" <robinncsu@yahoo.com>
Subject: Question on Perl printing
Message-Id: <1087854172.437175@sj-nntpcache-5>
Hi, guys. I edited a file in windows and uploaded it into unix. Then I ran
my perl script to read into the file and then printed some results. But the
results seems to be funny.
origianl line:
test1.txt
printed result by perl:
estl.txt
The first character was erased. I noticed the file under unix was changed as
"test1.txt^M" by using vi, which means cartridge return. Did anybody meet
such a problem? Thanks in advance.
-bear
------------------------------
Date: Mon, 21 Jun 2004 16:58:38 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Question on Perl printing
Message-Id: <40d75a0e$0$205$58c7af7e@news.kabelfoon.nl>
bear_hua wrote:
> Hi, guys. I edited a file in windows and uploaded it into unix. Then I ran
> my perl script to read into the file and then printed some results. But the
> results seems to be funny.
>
> origianl line:
> test1.txt
>
> printed result by perl:
> estl.txt
>
> The first character was erased. I noticed the file under unix was changed as
> "test1.txt^M" by using vi, which means cartridge return. Did anybody meet
> such a problem? Thanks in advance.
Upload as ASCII or use fromdos (see man fromdos)
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Mon, 21 Jun 2004 22:23:28 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Question on Perl printing
Message-Id: <cb7n50$ld3$2@wisteria.csv.warwick.ac.uk>
Quoth John Bokma <postmaster@castleamber.com>:
> bear_hua wrote:
>
> > Hi, guys. I edited a file in windows and uploaded it into unix. Then I ran
> > my perl script to read into the file and then printed some results. But the
> > results seems to be funny.
> >
> > origianl line:
> > test1.txt
> >
> > printed result by perl:
> > estl.txt
> >
> > The first character was erased. I noticed the file under unix was changed as
> > "test1.txt^M" by using vi, which means cartridge return. Did anybody meet
> > such a problem? Thanks in advance.
>
> Upload as ASCII or use fromdos (see man fromdos)
or perl -pi -e's/\r$//' <files>.
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
ben@morrow.me.uk
------------------------------
Date: 21 Jun 2004 15:42:43 -0700
From: botfood@yahoo.com (dan baker)
Subject: snippet using Image::Magick Sharpen() ?
Message-Id: <13685ef8.0406211442.30f3bcdc@posting.google.com>
I am doing some Scaling() with a call like this:
$ErrMsg = $image->Scale( geometry=>"${cMaxFullimgX}x${cMaxFullimgY}"
);
and would like to follow up with a little Sharpen, but am having a
hard time guessing what "normal" parameters for the call are. Does
anyone have a little snippet to help explain this? I couldn't find any
example in the Doc
Sharpen
geometry=>geometry,
radius=>double,
sigma=>double
sharpen the image with a gaussian operator of the given radius and
standard deviation (sigma).
TIA,
d
------------------------------
Date: 21 Jun 2004 22:30:34 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: uninit value puzzler
Message-Id: <cb7nia$86d$1@canopus.cc.umanitoba.ca>
I am trying to figure out the logical error in the following code snippit.
Assume, please, that the code is 'use strict' and 'use warnings' clean.
Also assume, please, that $nhit_href is a valid hash reference, and that
it would be relatively common for $nhit_href->{$key} to not already
exist.
my $newcount = 1;
$newcount = $nhit_href->{$key} + 1
if exists $nhit_href->{$key} && defined $nhit_href->{$key};
The problem: from time to time (but not at all often), I get the message:
Use of uninitialized value in addition (+) at /usr/people/roberson/src/CacheUtils.pm line 242.
where line 242 is the second statement.
Have I perhaps missed something in operator precidences? Under what
circumstances might I be trying to increment an uninitialized
$nhit_href->{$key} considering that I -thought- the code is checking for
existance and definedness before attempting the increment?
--
I predict that you will not trust this prediction.
------------------------------
Date: Tue, 22 Jun 2004 01:54:55 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: uninit value puzzler
Message-Id: <40D7915A.4080309@rochester.rr.com>
Walter Roberson wrote:
> I am trying to figure out the logical error in the following code snippit.
>
> Assume, please, that the code is 'use strict' and 'use warnings' clean.
> Also assume, please, that $nhit_href is a valid hash reference, and that
> it would be relatively common for $nhit_href->{$key} to not already
> exist.
>
>
> my $newcount = 1;
> $newcount = $nhit_href->{$key} + 1
> if exists $nhit_href->{$key} && defined $nhit_href->{$key};
>
>
> The problem: from time to time (but not at all often), I get the message:
>
> Use of uninitialized value in addition (+) at /usr/people/roberson/src/CacheUtils.pm line 242.
>
> where line 242 is the second statement.
>
> Have I perhaps missed something in operator precidences? Under what
If you have any doubt about precedence, use parens. Actually, you *do*
have a problem -- your if clause equivalent to:
... if exists($nhit_href->{$key} && defined($nhit_href->{$key}));
So use:
... if exists($nhit_href->{$key}) && defined($nhit_href->{$key});
to resolve the difficulty. Here is a quickie that shows what is going on:
sub a{
print "a got $_[0]\n";
}
sub b{
print "b got $_[0]\n";
}
$c=23;
$d=42;
print "hi " if a($c) && b($d);
print "\n**********\n";
print "xx " if a $c && b $d;
print "\n::::::::::\n";
__END__
You may note in the second case that sub b is called before sub a, and
that sub a's argument is 1, not the desired 23.
> circumstances might I be trying to increment an uninitialized
> $nhit_href->{$key} considering that I -thought- the code is checking for
> existance and definedness before attempting the increment?
>
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 22 Jun 2004 01:59:48 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: uninit value puzzler
Message-Id: <cb83qk$ntr$1@canopus.cc.umanitoba.ca>
In article <40D7915A.4080309@rochester.rr.com>,
Bob Walton <see@sig.invalid> wrote:
:Walter Roberson wrote:
:> $newcount = $nhit_href->{$key} + 1
:> if exists $nhit_href->{$key} && defined $nhit_href->{$key};
:If you have any doubt about precedence, use parens. Actually, you *do*
:have a problem -- your if clause equivalent to:
: ... if exists($nhit_href->{$key} && defined($nhit_href->{$key}));
Thanks, Bob -- I was "too close to the code" to see the problem.
--
Oh, yeah, an African swallow maybe, but not a European swallow.
That's my point.
------------------------------
Date: Mon, 21 Jun 2004 16:43:42 -0400
From: Richard Morse <remorse@partners.org>
Subject: Re: Why won't this split file script work?
Message-Id: <remorse-F4DC14.16434221062004@plato.harvard.edu>
In article
<Pine.SGI.3.96.1040617150701.326419A-100000@vcmr-64.server.rpi.edu>,
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> I'd write this as:
>
> while (<IN>) {
> print OUT if ($. == $start) .. ($. == $stop);
> last if $. == $stop;
> }
According to the docs, you could actually write this as:
while(<IN>) {
print OUT if $start .. $stop;
last if $. == $stop;
}
HTH,
Ricky
------------------------------
Date: Mon, 21 Jun 2004 21:15:04 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Why won't this split file script work?
Message-Id: <40d74e69.67751281@news.erols.com>
Richard Morse <remorse@partners.org> wrote:
: In article
: <Pine.SGI.3.96.1040617150701.326419A-100000@vcmr-64.server.rpi.edu>,
: Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
:
: > I'd write this as:
: >
: > while (<IN>) {
: > print OUT if ($. == $start) .. ($. == $stop);
: > last if $. == $stop;
: > }
:
: According to the docs, you could actually write this as:
:
: while(<IN>) {
: print OUT if $start .. $stop;
: last if $. == $stop;
: }
Not true. perlop says:
If either operand of scalar ``..'' is a constant expression, that
operand is considered true if it is equal (==) to the current
input line number (the $. variable).
Neither $start nor $stop are constant expressions.
------------------------------
Date: Mon, 21 Jun 2004 17:17:32 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Richard Morse <remorse@partners.org>
Subject: Re: Why won't this split file script work?
Message-Id: <Pine.SGI.3.96.1040621171456.22064A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On Mon, 21 Jun 2004, Richard Morse wrote:
> Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
>
>> while (<IN>) {
>> print OUT if ($. == $start) .. ($. == $stop);
>> last if $. == $stop;
>> }
>
>According to the docs, you could actually write this as:
>
> while(<IN>) {
> print OUT if $start .. $stop;
> last if $. == $stop;
> }
Not so. I once (ok, more than once) fell prey to that. The docs state
(although not in the BOLD CAPITAL letters I'd like) that the implicit
comparison to $. only takes place if the argument is a constant
expression:
If either operand of scalar ".." is a constant expression, that operand
is considered true if it is equal ("==") to the current input line num-
ber (the $. variable).
To be pedantic, the comparison is actually "int(EXPR) == int(EXPR)",
but that is only an issue if you use a floating point expression; when
implicitly using $. as described in the previous paragraph, the compar-
ison is "int(EXPR) == int($.)" which is only an issue when $. is set
to a floating point value and you are not reading from a file. Fur-
thermore, "span" .. "spat" or "2.18 .. 3.14" will not do what you want
in scalar context because each of the operands are evaluated using
their integer representation.
--
Jeff Pinyan RPI Acacia Brother #734 RPI Acacia Corp Secretary
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 21 Jun 2004 22:44:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Why won't this split file script work?
Message-Id: <cb7obp$5fk$1@mamenchi.zrz.TU-Berlin.DE>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in comp.lang.perl.misc:
> [posted & mailed]
> On Mon, 21 Jun 2004, Richard Morse wrote:
[...]
> >According to the docs, you could actually write this as:
> >
> > while(<IN>) {
> > print OUT if $start .. $stop;
> > last if $. == $stop;
> > }
>
> Not so. I once (ok, more than once) fell prey to that. The docs state
> (although not in the BOLD CAPITAL letters I'd like) that the implicit
> comparison to $. only takes place if the argument is a constant
> expression:
>
> If either operand of scalar ".." is a constant expression, that operand
Another question is what exactly is a constant expression. Experimentally,
literals and arithmetic expressions of literals are compared to $., as
are constants defined through the "constant" pragma. However, "do{ 0}",
and "do{ 1}" are not. So that's a cop-out if a constant boolean is
needed at either end of scalar "..".
The construct is one of Perl's less well-advised attempts at Doing
What I Mean.
Anno
------------------------------
Date: 21 Jun 2004 16:31:24 -0700
From: djberg96@hotmail.com (Daniel Berger)
Subject: Re: WMI and boolean values from Win32_Processor
Message-Id: <6e613a32.0406211531.6be71dab@posting.google.com>
Petri <Petri_member@newsguy.com> wrote in message news:<cb66h602n66@drn.newsguy.com>...
> In article <6e613a32.0406201520.2e4c618f@posting.google.com>, Daniel Berger
> says...
>
> > So, either they're only defined in XP Pro and later or there's a
> > bug in WMI (or just the WMI documentation).
> > That, or Win32::OLE is broken somehow.
>
> There are whole sections in MSDN that only exist on MSDN... :(
>
> List the names of the properties that really exist:
> ---8<---
> Set objClass = GetObject("winmgmts://./root/cimv2:Win32_Process")
>
> WScript.Echo strClass & "Class Properties:"
> WScript.Echo "------------------------------"
>
> For Each objClassProperty In objClass.Properties_
> WScript.Echo objClassProperty.Name
> Next
> ---8<---
>
> My apologies for the VBScript to all you poor readers of clpm, but I simply
> don't know how to do this enumeration in Perl. :(
>
>
> Petri
Your VB led me to the Perl. They definitely exist as properties. See below.
use strict;
use warnings;
use Sys::Hostname;
use Win32::OLE qw(in with);
my $host = hostname();
my $cs = "winmgmts://$host/root/cimv2:Win32_Processor='cpu0'";
my $wmi = Win32::OLE->GetObject($cs);
foreach my $p(in($wmi->Properties_)){
print $p->{'Name'}, "\n";
}
# Output
AddressWidth
Architecture
Availability
Caption
ConfigManagerErrorCode
ConfigManagerUserConfig
CpuStatus
CreationClassName
CurrentClockSpeed
CurrentVoltage
DataWidth
Description
DeviceID
ErrorCleared
ErrorDescription
ExtClock
Family
InstallDate
L2CacheSize
L2CacheSpeed
LastErrorCode
Level
LoadPercentage
Manufacturer
MaxClockSpeed
Name
OtherFamilyDescription
PNPDeviceID
PowerManagementCapabilities
PowerManagementSupported
ProcessorId
ProcessorType
Revision
Role
SocketDesignation
Status
StatusInfo
Stepping
SystemCreationClassName
SystemName
UniqueId
UpgradeMethod
Version
VoltageCaps
So, it looks like they're simply not defined, at least not yet, though I'm guessing.
Regards,
Dan
------------------------------
Date: 21 Jun 2004 18:11:57 -0700
From: Petri <Petri_member@newsguy.com>
Subject: Re: WMI and boolean values from Win32_Processor
Message-Id: <cb810t026mv@drn.newsguy.com>
In article <6e613a32.0406211531.6be71dab@posting.google.com>, Daniel Berger
says...
>Petri <Petri_member@newsguy.com> wrote in message
>news:<cb66h602n66@drn.newsguy.com>...
>> List the names of the properties that really exist:
> Your VB led me to the Perl. They definitely exist as properties.
> See below.
> # Output
> ConfigManagerErrorCode
> ErrorCleared
Er, these two do NOT appear on either my WinXP or Win2K box using the VBscript
code.
Both boxes have WSH V5.6 and the latest service packs and hotfixes.
But the disturbing thing is, they DO appear when running the Perl code.
I don't even know how that's possible.
> So, it looks like they're simply not defined, at least not yet,
> though I'm guessing.
Who knows what's going on here...
Good job figuring out the Perl translation by the way. :)
I got thrown off course by that underscore after Properties.
Never figured it was part of the name, I just thought it was used as VB's line
concatenation or whatever, since it was the last character on the line.
Petri
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6714
***************************************