[31274] in Perl-Users-Digest
Perl-Users Digest, Issue: 2519 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 15 21:09:44 2009
Date: Wed, 15 Jul 2009 18:09:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 15 Jul 2009 Volume: 11 Number: 2519
Today's topics:
Re: cpan fails to work after machine relocation sln@netherlands.com
Re: getting return value of external application on win sln@netherlands.com
Re: removing paragraphs from text files sln@netherlands.com
Why doesn't this 'next if' work? <maxmoor@remove_hotmail.com>
Re: Why doesn't this 'next if' work? <uri@stemsystems.com>
Re: Why doesn't this 'next if' work? <tadmc@seesig.invalid>
Re: Why doesn't this 'next if' work? <maxmoor@remove_hotmail.com>
Re: Why doesn't this 'next if' work? sln@netherlands.com
Re: Why doesn't this 'next if' work? (Doug Miller)
Re: Why doesn't this 'next if' work? sln@netherlands.com
Re: Why doesn't this 'next if' work? sln@netherlands.com
Re: Why doesn't this 'next if' work? sln@netherlands.com
Re: Why doesn't this 'next if' work? <jurgenex@hotmail.com>
Re: Why doesn't this 'next if' work? sln@netherlands.com
Re: Why doesn't this 'next if' work? <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 15 Jul 2009 11:52:16 -0700
From: sln@netherlands.com
Subject: Re: cpan fails to work after machine relocation
Message-Id: <o89s55lvojfn24oaicq18gttp56df0oeba@4ax.com>
On Mon, 13 Jul 2009 15:37:27 +0200, Josef Moellers <josef.moellers@ts.fujitsu.com> wrote:
>j.keßler wrote:
>> -----BEGIN xxx SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> Josef Moellers wrote:
>>> j.keßler wrote:
>>>
>>>> Hello,
>>>>
>>>> did you tried what comes with the error message ?(below)
>>>>> You have not configured a urllist and do not allow connections to the
>>>>> internet to get a list of mirrors. If you wish to get a list of CPAN
>>>>> mirrors to pick from, use this command
>>> I noticed this only after I posted the message. Cancelling was probably
>>> too late. Thing was ... it did work at home!
>>>
>>> Josef
>> but it sounds like you have to configure CPAN again.
>
>Being a person who goes for pragmatic solutions ... I just used my swiss
>army knife (vi ;-) to edit the /etc/perl/CPAN/config.pm to insert the
>URL from the old config.
>
>It now works.
>
>Josef
Aren't you supposed to be able to do that without modifying a .pm file?
-sln
------------------------------
Date: Wed, 15 Jul 2009 11:44:46 -0700
From: sln@netherlands.com
Subject: Re: getting return value of external application on win32
Message-Id: <go8s55t47o5cfpmspks9joudekh5e5p34b@4ax.com>
On Wed, 15 Jul 2009 17:16:54 +0100, Ben Morrow <ben@morrow.me.uk> wrote:
>
>Quoth alfonsobaldaserra <alfonso.baldaserra@gmail.com>:
>>
>> i am calling an external command in perl on win32 as follows
>>
>> my $app = 'c:\program files\foo\flarp.exe status quux';
>> my $spam = qx/ $app 2>&1 /;
> ^^^^
>This means that the command will be run through cmd.exe, which exits
>successfully (despite the command having failed).
>
>> now i need to get the status of executed command
>>
>> if ( $? == 0 ) { print "yay"; }
>
>$? contains the exit value of the cmd.exe process (since that's the only
>thing cmd.exe knows about). Apparently this is always 0.
>
>I would recommend using Win32::Process instead. It's a little awkward,
>but should let you do the redirection without involving cmd. You will
>have to create the pipe and read from it by hand, of course.
>
>Ben
Why wouldn't system work?
Docs:
if ($? == -1) {
print "failed to execute: $!\n";
}
elsif ($? & 127) {
printf "child died with signal %d, %s coredump\n",
($? & 127), ($? & 128) ? 'with' : 'without';
}
else {
-->>> printf "child exited with value %d\n", $? >> 8;
}
Or does Perl/system spawn processes on everything except Windowz?
-sln
------------------------------
Date: Wed, 15 Jul 2009 11:35:18 -0700
From: sln@netherlands.com
Subject: Re: removing paragraphs from text files
Message-Id: <o58s55lue6rl5nqm55orvf9j9g5ar48bet@4ax.com>
On Tue, 14 Jul 2009 16:04:44 +0300, Eric Pozharski <whynot@pozharski.name> wrote:
>On 2009-07-13, Peter J. Holzer <hjp-usenet2@hjp.at> wrote:
>*SKIP*
>*skipping alfonsobaldaserra since he skipped Tad anyway*
>
>> s/define service\{.*PING.*\}\s+//sg
>>
>> OTOH would match anything from the first "define service{" to the last
>> "}" in the file (provided there's a PING somewhere between them) so it
>> would probably remove a lot more than you want. The /[^}]*/ in Tad's
>> regex is there to keep the match within a single brace-delimited block
>> (and it's a bit simple-minded: It won't work if you have a } inside a
>> comment, for example, but you probably don't, so that doesn't matter).
>
>Then stricter
>
> qr/\}\n+/
>
>and stricter
>
> qr/\}(?:\h*\n)+/ # needs 5.10
^^^^
510 is great, a lot of new stuff in the engine.
New nesting, etc.
When you can write a regex without the need for the
# needs 5.10
maybe it might be usefull.
Btw, I don't think anybody skipped Tad, who never skips
anybody.
-sln
------------------------------
Date: 15 Jul 2009 19:24:27 GMT
From: Max Moor <maxmoor@remove_hotmail.com>
Subject: Why doesn't this 'next if' work?
Message-Id: <Xns9C497E3BC4794maxmoorhotmailcom@74.209.136.95>
Hi All,
I'm fairly new to perl, and have already fixed this problem, but I
want to understand why it didn't work before.
This is the original, non-working code:
@o_list = ();
foreach my $o ( @{$stuff->{thingys}} ) {
# Exclude if no match
$match = 'n';
foreach $thingy (@test_thingys) {
if ($o->{thingy} == $thingy) {
$match = 'y';
last;
}
}
next if ($match != 'y');
push @o_list, $o;
}
Basically, its running through a list of "thingys", checking to see if
the item matches any of a list of test "thingys." Before checking the list,
I set $match to 'n'. If I find a match, I set it to 'y' and dump out of the
loop. At least, that was the intent. What really happened was that "next
if" line never ran, and all items got pushed onto "o_list." I did some
checking, and found that $match equaled 'n'. The line simply wasn't ever
running.
The working snippet...
@o_list = ();
foreach my $o ( @{$stuff->{thingys}} ) {
# Exclude if no match
$match = 0;
foreach $thingy (@test_thingys) {
if ($o->{thingy} == $thingy) {
$match = 1;
last;
}
}
next if (!match);
push @o_list, $o;
}
The only change was the "flag" values. Instead of 'y' and 'n', it's
now 0 and 1.
Can anyone tell me what about the 'n' and 'y' messed up the logic?
Thanks for your help,
Max
------------------------------
Date: Wed, 15 Jul 2009 15:34:16 -0400
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <87d481pwp3.fsf@quad.sysarch.com>
>>>>> "MM" == Max Moor <maxmoor@remove_hotmail.com> writes:
MM> next if ($match != 'y');
that does a numeric comparison. 'n' is 0 and so is 'y' so that will
never be true. use eq for string compares. if you had enabled warnings
perl would have told you this. also you aren't using strict which helps
too. ask perl for all the help it can give you.
now the bigger picture is you shouldn't be using boolean flags like that
in general. proper use of next/last will eliminate the need for them. i
don't have the time to review the logic but others may do so.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 15 Jul 2009 15:17:31 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <slrnh5se1e.of9.tadmc@tadmc30.sbcglobal.net>
Max Moor <maxmoor@remove_hotmail.com> wrote:
> next if ($match != 'y');
You should always enable warnings when developing Perl code!
use warnings;
Have you seen the Posting Guidelines that are posted here frequently?
> @o_list = ();
You should always enable strict in all Perl programs.
use strict;
Now you need to declare the variable. You do not need to ensure
it is empty, Perl will do that for you.
my @o_list;
> foreach my $o ( @{$stuff->{thingys}} ) {
>
> # Exclude if no match
> $match = 0;
> foreach $thingy (@test_thingys) {
>
> if ($o->{thingy} == $thingy) {
Are your thingies numbers or are they strings?
If they are strings, then you are once again using the wrong operator.
> $match = 1;
> last;
> }
> }
> next if (!match);
^^
^^ where's the dollar sign?
This is clearly NOT a "working snippet".
You should copy/paste rather than attempt to retype code.
Have you seen the Posting Guidelines that are posted here frequently?
> Can anyone tell me what about the 'n' and 'y' messed up the logic?
perl can tell you, but you have to ask it to tell you (by enabling warnings):
Argument "y" isn't numeric in numeric ne (!=) at ...
== is for comparing numbers. eq if for comparing strings.
next if ($match ne 'y');
or, probably better:
next unless $match eq 'y';
Your original code was the equivalent of
next if 0 != 0;
because perl converted your strings into numbers since it could
see that you were using a numeric operator.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: 15 Jul 2009 20:19:14 GMT
From: Max Moor <maxmoor@remove_hotmail.com>
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <Xns9C49878524685maxmoorhotmailcom@74.209.136.99>
Uri Guttman <uri@stemsystems.com> wrote in
news:87d481pwp3.fsf@quad.sysarch.com:
>>>>>> "MM" == Max Moor <maxmoor@remove_hotmail.com> writes:
>
> MM> next if ($match != 'y');
>
> that does a numeric comparison. 'n' is 0 and so is 'y' so that will
> never be true. use eq for string compares. if you had enabled warnings
> perl would have told you this. also you aren't using strict which helps
> too. ask perl for all the help it can give you.
>
> now the bigger picture is you shouldn't be using boolean flags like that
> in general. proper use of next/last will eliminate the need for them. i
> don't have the time to review the logic but others may do so.
>
> uri
>
Hi uri,
Thanks for the answer. Makes sense.
I also agree with you about flags, but there's still alot of ugly in
this code. It's really just an eval block inside a larger perl script that
we users on a particular site are allowed access to. We can use it to
price check items we have for sale.
I'm a C programmer from way back, but haven't done perl before. I
started with the code as generated by an auto-writer they provide.
Hopefully I'll get to know my way around perl well enough that some things
like bad logic will get cleaned up.
I'll see what I can do to add warnings and strict-ness. I'm not sure
how that might affect the larger script I don't have say over.
Anyway, thanks again for the knowledge. I appreciate the help.
- Max
------------------------------
Date: Wed, 15 Jul 2009 13:48:51 -0700
From: sln@netherlands.com
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <g1gs551ng44agkbd3hvo2hsjgqrajdples@4ax.com>
On 15 Jul 2009 19:24:27 GMT, Max Moor <maxmoor@remove_hotmail.com> wrote:
>Hi All,
>
> I'm fairly new to perl, and have already fixed this problem, but I
>want to understand why it didn't work before.
>
> This is the original, non-working code:
>
>@o_list = ();
>foreach my $o ( @{$stuff->{thingys}} ) {
>
> # Exclude if no match
> $match = 'n';
> foreach $thingy (@test_thingys) {
>
> if ($o->{thingy} == $thingy) {
if .. == .. or .. eq ..
> $match = 'y';
> last;
> }
> }
> next if ($match != 'y');
if .. != .. or .. ne ..
>
> push @o_list, $o;
>}
Take your pick. Not both.
-sln
------------------------------
Date: Wed, 15 Jul 2009 21:50:44 GMT
From: spambait@milmac.com (Doug Miller)
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <Nis7m.11904$lv5.791@flpi149.ffdc.sbc.com>
In article <g1gs551ng44agkbd3hvo2hsjgqrajdples@4ax.com>, sln@netherlands.com wrote:
>On 15 Jul 2009 19:24:27 GMT, Max Moor <maxmoor@remove_hotmail.com> wrote:
>
>>Hi All,
>>
>> I'm fairly new to perl, and have already fixed this problem, but I
>>want to understand why it didn't work before.
>>
>> This is the original, non-working code:
>>
>>@o_list = ();
>>foreach my $o ( @{$stuff->{thingys}} ) {
>>
>> # Exclude if no match
>> $match = 'n';
>> foreach $thingy (@test_thingys) {
>>
>> if ($o->{thingy} == $thingy) {
>
>if .. == .. or .. eq ..
depending on the type of the two operands.
>> $match = 'y';
>> last;
>> }
>> }
>> next if ($match != 'y');
>
>if .. != .. or .. ne ..
Wrong. ne is necessary for string comparisons.
>>
>> push @o_list, $o;
>>}
>
>Take your pick. Not both.
Nonsense. $match, being assigned values of either 'n' or 'y', clearly requires
the string inequality operator ne. He can't "take [his] pick" there.
Likewise, he can't pick and choose in the other comparison either. If the
operands are numeric, he *must* use ==; if they are strings, he *must* use eq.
------------------------------
Date: Wed, 15 Jul 2009 14:59:39 -0700
From: sln@netherlands.com
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <s7ks55tu25t9bsb4jtf8a2m0dou5d7703m@4ax.com>
On Wed, 15 Jul 2009 21:50:44 GMT, spambait@milmac.com (Doug Miller) wrote:
>In article <g1gs551ng44agkbd3hvo2hsjgqrajdples@4ax.com>, sln@netherlands.com wrote:
>>On 15 Jul 2009 19:24:27 GMT, Max Moor <maxmoor@remove_hotmail.com> wrote:
>>
>>>Hi All,
>>>
>>> I'm fairly new to perl, and have already fixed this problem, but I
>>>want to understand why it didn't work before.
>>>
>>> This is the original, non-working code:
>>>
>>>@o_list = ();
>>>foreach my $o ( @{$stuff->{thingys}} ) {
>>>
>>> # Exclude if no match
>>> $match = 'n';
>>> foreach $thingy (@test_thingys) {
>>>
>>> if ($o->{thingy} == $thingy) {
>>
>>if .. == .. or .. eq ..
>
>depending on the type of the two operands.
>
>>> $match = 'y';
>>> last;
>>> }
>>> }
>>> next if ($match != 'y');
>>
>>if .. != .. or .. ne ..
>
>Wrong. ne is necessary for string comparisons.
>>>
>>> push @o_list, $o;
>>>}
>>
>>Take your pick. Not both.
>
>Nonsense. $match, being assigned values of either 'n' or 'y', clearly requires
>the string inequality operator ne. He can't "take [his] pick" there.
>
>Likewise, he can't pick and choose in the other comparison either. If the
>operands are numeric, he *must* use ==; if they are strings, he *must* use eq.
^^^^^^^^^^^^^^^^^^^^^^^^^
Nonsense, 2 == ... and 2 eq ...
-sln
------------------------------
Date: Wed, 15 Jul 2009 15:05:03 -0700
From: sln@netherlands.com
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <ehks55p430hg7ad0tdjchoii5tbf2tcfvc@4ax.com>
On Wed, 15 Jul 2009 14:59:39 -0700, sln@netherlands.com wrote:
>On Wed, 15 Jul 2009 21:50:44 GMT, spambait@milmac.com (Doug Miller) wrote:
>
>>In article <g1gs551ng44agkbd3hvo2hsjgqrajdples@4ax.com>, sln@netherlands.com wrote:
>>>On 15 Jul 2009 19:24:27 GMT, Max Moor <maxmoor@remove_hotmail.com> wrote:
>>>
>>>>Hi All,
>>>>
>>>> I'm fairly new to perl, and have already fixed this problem, but I
>>>>want to understand why it didn't work before.
>>>>
>>>> This is the original, non-working code:
>>>>
>>>>@o_list = ();
>>>>foreach my $o ( @{$stuff->{thingys}} ) {
>>>>
>>>> # Exclude if no match
>>>> $match = 'n';
>>>> foreach $thingy (@test_thingys) {
>>>>
>>>> if ($o->{thingy} == $thingy) {
>>>
>>>if .. == .. or .. eq ..
>>
>>depending on the type of the two operands.
>>
>>>> $match = 'y';
>>>> last;
>>>> }
>>>> }
>>>> next if ($match != 'y');
>>>
>>>if .. != .. or .. ne ..
>>
>>Wrong. ne is necessary for string comparisons.
>>>>
>>>> push @o_list, $o;
>>>>}
>>>
>>>Take your pick. Not both.
>>
>>Nonsense. $match, being assigned values of either 'n' or 'y', clearly requires
>>the string inequality operator ne. He can't "take [his] pick" there.
>>
>>Likewise, he can't pick and choose in the other comparison either. If the
>>operands are numeric, he *must* use ==; if they are strings, he *must* use eq.
> ^^^^^^^^^^^^^^^^^^^^^^^^^
>Nonsense, 2 == ... and 2 eq ...
>
>-sln
There should actually be a 2 e= ... operator, no need for conversion (if necessary).
-sln
------------------------------
Date: Wed, 15 Jul 2009 15:10:40 -0700
From: sln@netherlands.com
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <1tks55pibkkp8aali1frtqi8j82t817b3t@4ax.com>
On Wed, 15 Jul 2009 21:50:44 GMT, spambait@milmac.com (Doug Miller) wrote:
>In article <g1gs551ng44agkbd3hvo2hsjgqrajdples@4ax.com>, sln@netherlands.com wrote:
>>On 15 Jul 2009 19:24:27 GMT, Max Moor <maxmoor@remove_hotmail.com> wrote:
>>
>>>Hi All,
>>>
>>> I'm fairly new to perl, and have already fixed this problem, but I
>>>want to understand why it didn't work before.
>>>
>>> This is the original, non-working code:
>>>
>>>@o_list = ();
>>>foreach my $o ( @{$stuff->{thingys}} ) {
>>>
>>> # Exclude if no match
>>> $match = 'n';
>>> foreach $thingy (@test_thingys) {
>>>
>>> if ($o->{thingy} == $thingy) {
>>
>>if .. == .. or .. eq ..
>
>depending on the type of the two operands.
>
>>> $match = 'y';
>>> last;
>>> }
>>> }
>>> next if ($match != 'y');
>>
>>if .. != .. or .. ne ..
>
>Wrong. ne is necessary for string comparisons.
>>>
>>> push @o_list, $o;
>>>}
>>
>>Take your pick. Not both.
>
>Nonsense. $match, being assigned values of either 'n' or 'y', clearly requires
>the string inequality operator ne. He can't "take [his] pick" there.
>
>Likewise, he can't pick and choose in the other comparison either. If the
>operands are numeric, he *must* use ==; if they are strings, he *must* use eq.
But, match != 'y' is valid, isin't it? Isin't that valid???
-sln
------------------------------
Date: Wed, 15 Jul 2009 16:11:33 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <i7os55p81d2rehgopcjfgs292pupdddioe@4ax.com>
spambait@milmac.com (Doug Miller) wrote:
>Likewise, he can't pick and choose in the other comparison either. If the
>operands are numeric, he *must* use ==; if they are strings, he *must* use eq.
Actually you can mix and match. But you better know exactly what you are
doing.
There is nothing stopping you from comparing the string values of two
numbers and actually of the top my head I can't think of a scenario,
where you would get an unexpected surprise.
And you can also compare the numerical values of two strings. However in
this case you really better know what those numerical values are going
to be because most of the time it's probably not what you would expect.
jue
------------------------------
Date: Wed, 15 Jul 2009 16:49:09 -0700
From: sln@netherlands.com
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <6nqs55d2ulqvqb5kekn28p9e14c11t0cgk@4ax.com>
On Wed, 15 Jul 2009 16:11:33 -0700, Jürgen Exner <jurgenex@hotmail.com> wrote:
>spambait@milmac.com (Doug Miller) wrote:
>>Likewise, he can't pick and choose in the other comparison either. If the
>>operands are numeric, he *must* use ==; if they are strings, he *must* use eq.
>
>Actually you can mix and match. But you better know exactly what you are
>doing.
>
>There is nothing stopping you from comparing the string values of two
>numbers and actually of the top my head I can't think of a scenario,
>where you would get an unexpected surprise.
>
>And you can also compare the numerical values of two strings. However in
>this case you really better know what those numerical values are going
>to be because most of the time it's probably not what you would expect.
>
>jue
Very well said.
-sln
------------------------------
Date: Thu, 16 Jul 2009 01:03:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Why doesn't this 'next if' work?
Message-Id: <2b72j6-unt2.ln1@osiris.mauzo.dyndns.org>
Quoth Jürgen Exner <jurgenex@hotmail.com>:
>
> There is nothing stopping you from comparing the string values of two
> numbers and actually of the top my head I can't think of a scenario,
> where you would get an unexpected surprise.
-1 lt -2
Ben
------------------------------
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 V11 Issue 2519
***************************************