[30542] in Perl-Users-Digest
Perl-Users Digest, Issue: 1785 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 11 09:09:58 2008
Date: Mon, 11 Aug 2008 06:09:10 -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, 11 Aug 2008 Volume: 11 Number: 1785
Today's topics:
Discussion forum sofware in perl <John.Smith@invalid.com>
Re: double slash operator syntax question <hjp-usenet2@hjp.at>
Re: double slash operator syntax question <hjp-usenet2@hjp.at>
Re: double slash operator syntax question <mattj.morrison@gmail.com>
Re: double slash operator syntax question <usenet@larseighner.com>
Re: double slash operator syntax question <hjp-usenet2@hjp.at>
Re: double slash operator syntax question <usenet@larseighner.com>
empty "if" statement - it doesn't look nice, does it? <tch@nospam.wpkg.org>
Re: empty "if" statement - it doesn't look nice, does i <peter@makholm.net>
Re: empty "if" statement - it doesn't look nice, does i <tch@nospam.wpkg.org>
Re: empty "if" statement - it doesn't look nice, does i <peter@makholm.net>
Re: empty "if" statement - it doesn't look nice, does i <tch@nospam.wpkg.org>
Re: empty "if" statement - it doesn't look nice, does i <peter@makholm.net>
Re: empty "if" statement - it doesn't look nice, does i <tch@nospam.wpkg.org>
Re: empty "if" statement - it doesn't look nice, does i <peter@makholm.net>
Re: empty "if" statement - it doesn't look nice, does i <RedGrittyBrick@SpamWeary.foo>
Re: empty "if" statement - it doesn't look nice, does i <RedGrittyBrick@SpamWeary.foo>
Re: empty "if" statement - it doesn't look nice, does i <tch@nospam.wpkg.org>
Re: empty "if" statement - it doesn't look nice, does i <tch@nospam.wpkg.org>
Re: empty "if" statement - it doesn't look nice, does i <RedGrittyBrick@SpamWeary.foo>
Re: empty "if" statement - it doesn't look nice, does i <tch@nospam.wpkg.org>
Re: empty "if" statement - it doesn't look nice, does i <usenet@larseighner.com>
Re: empty "if" statement - it doesn't look nice, does i <usenet@larseighner.com>
Inline C, char* and Visual Studio (was: Re: Need help w <th@example.invalid>
Re: OO Perl <hjp-usenet2@hjp.at>
Re: Trying to understand a constructor with an array. <hjp-usenet2@hjp.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 11 Aug 2008 13:52:10 +0300
From: John <John.Smith@invalid.com>
Subject: Discussion forum sofware in perl
Message-Id: <1b60a4dbm5tl0mldn442cenisrutrlgs4j@4ax.com>
What is your perl generated discussion forum software? Preferable free/gnu.
What I need in addition to features that most forum software has:
- when someone posts something administrator gets a copy via email
- administrator can upload messages as if someone had posted them.
The latter is especially important. I maintain a ask-a-question-and-we-reply
forum. Often members skip the baord ask directly via email. I reply them via
email but I would like to upload the question and my answer to the board so
others can see the question and my answer in hopes someone would benefit from the
answer as well.
I can do perl code myself but my current perl board I have sofware has a message
proprietary system where I've not been able to decipher the message structure.
------------------------------
Date: Mon, 11 Aug 2008 09:47:30 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: double slash operator syntax question
Message-Id: <slrng9vrki.2gj.hjp-usenet2@hrunkner.hjp.at>
On 2008-08-11 02:55, Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth Lars Eighner <usenet@larseighner.com>:
>> What I want to do: if $lb_lang is undefined, I want to set it.
>>
>> What I wrote:
>>
>> $lb_lang // {$lb_lang = 'en'};
>
> $lb_lang //= 'en';
>
>> What perl -w yelled:
>>
>> Useless use of single ref constructor in void context at etc.
>> But it seems to work in spite of the yelling.
>
> Well, sort-of. You are actually constructing an anon hashref out of the
> single-element list ('en') (and I'm slightly surprised -w didn't warn
> about that, as well), and assigning to $lb_lang as a side-effect.
[...]
> since you don't need to build a useless data structure,
>
> $lb_lang // do { $lb_lang = 'en' };
Or just
$lb_lang // ($lb_lang = 'en');
hp
------------------------------
Date: Mon, 11 Aug 2008 09:49:13 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: double slash operator syntax question
Message-Id: <slrng9vrnp.2gj.hjp-usenet2@hrunkner.hjp.at>
On 2008-08-11 03:55, Lars Eighner <usenet@larseighner.com> wrote:
> Michael Carman:
>> Matt wrote:
>>> I don't know about // being some kind of operator other than a pattern
>>> match operator...but you could accomplish that like this
>
>> It's the defined-or operator that was added in Perl 5.10. It's like ||
>> but tests for definedness instead of truth.
>
> It's in 5.8.8 or my perl is lying.
>
I think your perl is lying. My perl 5.8.8 complains:
Search pattern not terminated at ./foo line 6.
hp
------------------------------
Date: Mon, 11 Aug 2008 01:04:33 -0700 (PDT)
From: Matt <mattj.morrison@gmail.com>
Subject: Re: double slash operator syntax question
Message-Id: <01bb6580-8a55-4406-bff9-857fa7d7ff83@f36g2000hsa.googlegroups.com>
On Aug 11, 2:49=A0am, "Peter J. Holzer" <hjp-usen...@hjp.at> wrote:
> On 2008-08-11 03:55, Lars Eighner <use...@larseighner.com> wrote:> Michae=
l Carman:
> >> Matt wrote:
> >>> I don't know about // being some kind of operator other than a patter=
n
> >>> match operator...but you could accomplish that like this
>
> >> It's the defined-or operator that was added in Perl 5.10. It's like ||
> >> but tests for definedness instead of truth.
>
> > It's in 5.8.8 or my perl is lying.
>
> I think your perl is lying. My perl 5.8.8 complains:
>
> =A0 =A0 Search pattern not terminated at ./foo line 6.
>
> =A0 =A0 =A0 =A0 hp
Thanks for catching that "defined" thing Michael.
------------------------------
Date: Mon, 11 Aug 2008 08:33:31 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: double slash operator syntax question
Message-Id: <slrng9vtur.10ov.usenet@debranded.larseighner.com>
In our last episode, <slrng9vrnp.2gj.hjp-usenet2@hrunkner.hjp.at>, the
lovely and talented Peter J. Holzer broadcast on comp.lang.perl.misc:
> On 2008-08-11 03:55, Lars Eighner <usenet@larseighner.com> wrote:
>> Michael Carman:
>>> Matt wrote:
>>>> I don't know about // being some kind of operator other than a pattern
>>>> match operator...but you could accomplish that like this
>>
>>> It's the defined-or operator that was added in Perl 5.10. It's like ||
>>> but tests for definedness instead of truth.
>>
>> It's in 5.8.8 or my perl is lying.
>>
> I think your perl is lying. My perl 5.8.8 complains:
> Search pattern not terminated at ./foo line 6.
Curious. As I said, it works on mine, and perl -V has this
to say for itself:
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=freebsd, osvers=7.0-stable, archname=i386-freebsd-64int
uname='freebsd debranded.6dollardialup.com 7.0-stable freebsd \
7.0-stable #0: mon apr 21 11:15:06 cdt 2008 \
toor@debranded.6dollardialup.com:usrobjusrsrcsysapr08 i386 '
config_args='-sde -Dprefix=/usr/local \
-Darchlib=/usr/local/lib/perl5/5.8.8/mach \
-Dprivlib=/usr/local/lib/perl5/5.8.8 \
-Dman3dir=/usr/local/lib/perl5/5.8.8/perl/man/man3 \
-Dman1dir=/usr/local/man/man1 \
-Dsitearch=/usr/local/lib/perl5/site_perl/5.8.8/mach \
-Dsitelib=/usr/local/lib/perl5/site_perl/5.8.8 \
-Dscriptdir=/usr/local/bin \
-Dsiteman3dir=/usr/local/lib/perl5/5.8.8/man/man3 \
-Dsiteman1dir=/usr/local/man/man1 \
-Ui_malloc -Ui_iconv -Uinstallusrbinperl \
-Dcc=cc -Duseshrplib \
-Dccflags=-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.8/BSDPAN" \
-Doptimize=-O2 -fno-strict-aliasing -pipe -Ud_dosuid -Ui_gdbm \
-Dusethreads=n -Dusemymalloc=y -Duse64bitint'
hint=recommended, useposix=true, d_sigaction=define
usethreads=undef use5005threads=undef useithreads=undef \
usemultiplicity=undef
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=define use64bitall=undef uselongdouble=undef
usemymalloc=y, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.8/BSDPAN" \
-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe \
-Wdeclaration-after-statement -I/usr/local/include',
optimize='-O2 -fno-strict-aliasing -pipe ',
cppflags='-DAPPLLIB_EXP="/usr/local/lib/perl5/5.8.8/BSDPAN" \
-DHAS_FPSETMASK -DHAS_FLOATINGPOINT_H -fno-strict-aliasing -pipe \
-Wdeclaration-after-statement -I/usr/local/include'
ccversion='', gccversion='4.2.1 20070719 [FreeBSD]', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long long', ivsize=8, nvtype='double', \
nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -Wl,-E
--
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
"We have no opinion on your Arab - Arab conflicts, such as your dispute with
Kuwait." -- Bush's Ambassador April Glaspie, giving Saddam Hussein
the greenlight to invade Kuwait.
------------------------------
Date: Mon, 11 Aug 2008 11:01:04 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: double slash operator syntax question
Message-Id: <slrng9vvug.363.hjp-usenet2@hrunkner.hjp.at>
On 2008-08-11 08:33, Lars Eighner <usenet@larseighner.com> wrote:
> In our last episode, <slrng9vrnp.2gj.hjp-usenet2@hrunkner.hjp.at>, the
> lovely and talented Peter J. Holzer broadcast on comp.lang.perl.misc:
>
>> On 2008-08-11 03:55, Lars Eighner <usenet@larseighner.com> wrote:
>>> Michael Carman:
>>>> Matt wrote:
>>>>> I don't know about // being some kind of operator other than a pattern
>>>>> match operator...but you could accomplish that like this
>>>
>>>> It's the defined-or operator that was added in Perl 5.10. It's like ||
>>>> but tests for definedness instead of truth.
>>>
>>> It's in 5.8.8 or my perl is lying.
>>>
>> I think your perl is lying. My perl 5.8.8 complains:
>
>> Search pattern not terminated at ./foo line 6.
>
> Curious. As I said, it works on mine, and perl -V has this
> to say for itself:
>
> Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
> Platform:
Here's my test program:
#!/usr/bin/perl
use warnings;
use strict;
my $lb_lang = $ARGV[0];
$lb_lang // ($lb_lang = 'en');
print "$lb_lang\n"
__END__
hp
------------------------------
Date: Mon, 11 Aug 2008 10:56:08 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: double slash operator syntax question
Message-Id: <slrnga06a9.111r.usenet@debranded.larseighner.com>
In our last episode, <slrng9vvug.363.hjp-usenet2@hrunkner.hjp.at>, the
lovely and talented Peter J. Holzer broadcast on comp.lang.perl.misc:
> On 2008-08-11 08:33, Lars Eighner <usenet@larseighner.com> wrote:
>> In our last episode, <slrng9vrnp.2gj.hjp-usenet2@hrunkner.hjp.at>, the
>> lovely and talented Peter J. Holzer broadcast on comp.lang.perl.misc:
>>
>>> On 2008-08-11 03:55, Lars Eighner <usenet@larseighner.com> wrote:
>>>> Michael Carman:
>>>>> Matt wrote:
>>>>>> I don't know about // being some kind of operator other than a pattern
>>>>>> match operator...but you could accomplish that like this
>>>>
>>>>> It's the defined-or operator that was added in Perl 5.10. It's like ||
>>>>> but tests for definedness instead of truth.
>>>>
>>>> It's in 5.8.8 or my perl is lying.
>>>>
>>> I think your perl is lying. My perl 5.8.8 complains:
>>
>>> Search pattern not terminated at ./foo line 6.
>>
>> Curious. As I said, it works on mine, and perl -V has this
>> to say for itself:
>>
>> Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
>> Platform:
> Here's my test program:
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $lb_lang = $ARGV[0];
> $lb_lang // ($lb_lang = 'en');
> print "$lb_lang\n"
> __END__
runs perfectly (because there is a link to the real location of perl
in freeBSD)
The source my perl was compiled from is perl-5.8.8.tar.bz2 . I don't
even have source for 5.10.x on my machine.
I don't get it.
--
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
Due to a mixup in Urology, orange juice will not be served this morning.
------------------------------
Date: Mon, 11 Aug 2008 11:19:06 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: empty "if" statement - it doesn't look nice, does it?
Message-Id: <g7p06b$v6m$1@online.de>
Although an empty "if" statement is technically OK in Perl, it doesn't
look very nice (and in some languages is even forbidden).
Let's suppose we have a code like:
if ($a == 1 && $b == 2) {
# Essentially an empty "if" statement
} else {
print "We're here only if a is not 1 and b is not 2!\n";
}
What would be a good way to get rid of this empty "if" statement?
Or is it OK to have it?
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Mon, 11 Aug 2008 11:24:01 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <87fxpbnbv2.fsf@hacking.dk>
Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
> What would be a good way to get rid of this empty "if" statement?
Eiter negate the condition or use an "unless" statement instead.
//Makholm
------------------------------
Date: Mon, 11 Aug 2008 11:43:08 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <g7p1jc$156$3@online.de>
Peter Makholm schrieb:
> Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
>
>> What would be a good way to get rid of this empty "if" statement?
>
> Eiter negate the condition or use an "unless" statement instead.
>
> //Makholm
Negating it or using "unless" would yield an unwanted result (but I
didn't explain it very precisely, sorry for that).
We want to print the text only if neither $a nor $b were equal a given
number.
Example 1 - does "nothing" (uses empty "if"):
my $a = 1;
my $b = 2;
if ($a == 1 && $b == 2) {
# Essentially an empty "if" statement
} else {
print "We're here only if a is not 1 and b is not 2!\n";
}
Example 2 - negated, but the result is wrong:
my $a = 0;
my $b = 2;
if ($a != 1 && $b != 2) {
# Essentially an empty "if" statement
} else {
print "We're here only if a is not 1 and b is not 2!\n";
}
Text was printed, although $b was equal 2. Not what we wanted.
Using "next" or "last" in the empty statement would break the things if
this "if" was inside of yet another "if".
"goto" function? Doesn't look much better than an empty "if".
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Mon, 11 Aug 2008 11:46:09 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <878wv3nau6.fsf@hacking.dk>
Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
> Example 2 - negated, but the result is wrong:
Isn't this using the same condition as you original post?
The negated condition would be 2!( $a == 1 && $b == 2)" or by applying
De Morgans Law: "$a != 1 || $b != 2"
> my $a = 0;
> my $b = 2;
>
> if ($a == 1 && $b == 2) {
> # Essentially an empty "if" statement
> } else {
> print "We're here only if a is not 1 and b is not 2!\n";
> }
>
>
> Text was printed, although $b was equal 2. Not what we wanted.
I think you understanding of boolean logic is flawed. The and operator
means that both pćarts should be true, which they clearly are not. So
you code does whats expected.
> Using "next" or "last" in the empty statement would break the things
> if this "if" was inside of yet another "if".
> "goto" function? Doesn't look much better than an empty "if".
Using next or last only makes sens if you're dealing with loop
constructs.
//Makholm
------------------------------
Date: Mon, 11 Aug 2008 12:03:19 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <g7p2p8$rbo$1@online.de>
Peter Makholm schrieb:
> Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
>
>> Example 2 - negated, but the result is wrong:
>
> Isn't this using the same condition as you original post?
Yes, I cancelled the post, and sent a proper condition, too late it seems.
> The negated condition would be 2!( $a == 1 && $b == 2)"
if !( $a == 1 && $b == 2)
?
Doesn't look correct to me?
> or by applying
> De Morgans Law: "$a != 1 || $b != 2"
No, it wouldn't work in a desired way.
>> my $a = 0;
>> my $b = 2;
>>
>> if ($a == 1 && $b == 2) {
>> # Essentially an empty "if" statement
>> } else {
>> print "We're here only if a is not 1 and b is not 2!\n";
>> }
>>
>>
>> Text was printed, although $b was equal 2. Not what we wanted.
>
> I think you understanding of boolean logic is flawed. The and operator
> means that both pćarts should be true, which they clearly are not. So
> you code does whats expected.
I know such does logically what it's supposed to do.
What I meant: negating the "if ($a == 1 && $b == 2)" wouldn't make what
I want.
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Mon, 11 Aug 2008 12:08:56 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <874p5rn9s7.fsf@hacking.dk>
Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
> I know such does logically what it's supposed to do.
> What I meant: negating the "if ($a == 1 && $b == 2)" wouldn't make
> what I want.
so you say that
if (condition) {
# no-op
} else {
do_something();
}
does what you intend to do, but neither
if (!condition) {
do_something();
}
nor
unless (condition) {
do_something();
}
works for you?
//Makholm
------------------------------
Date: Mon, 11 Aug 2008 12:11:34 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <g7p38m$rbo$3@online.de>
Peter Makholm schrieb:
> Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
>
>> I know such does logically what it's supposed to do.
>> What I meant: negating the "if ($a == 1 && $b == 2)" wouldn't make
>> what I want.
>
> so you say that
>
> if (condition) {
> # no-op
> } else {
> do_something();
> }
>
> does what you intend to do, but neither
>
> if (!condition) {
> do_something();
> }
>
> nor
>
> unless (condition) {
> do_something();
> }
>
> works for you?
I'm saying that I have two conditions ;)
I want to do_something() only if none of both conditions is true.
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Mon, 11 Aug 2008 12:17:47 +0200
From: Peter Makholm <peter@makholm.net>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <87tzdrlut0.fsf@hacking.dk>
Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
> I'm saying that I have two conditions ;)
>
> I want to do_something() only if none of both conditions is true.
So you initial code didn't work? That should print something if just
on of the equalities was false.
So what you want is:
if (!cond1 && !cond2) { doit(); }
or
if ($a != 1 && $b != 2) { doit(); }
or
unless (cond1 && cond2) { doit(); }
//Makholm
------------------------------
Date: Mon, 11 Aug 2008 11:22:17 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <48a012dc$0$26088$db0fefd9@news.zen.co.uk>
Tomasz Chmielewski wrote:
> Peter Makholm schrieb:
>> Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
>>
>>> I know such does logically what it's supposed to do.
>>> What I meant: negating the "if ($a == 1 && $b == 2)" wouldn't make
>>> what I want.
>>
>> so you say that
>>
>> if (condition) {
>> # no-op
>> } else {
>> do_something();
>> }
>>
>> does what you intend to do, but neither
>>
>> if (!condition) {
>> do_something();
>> }
>>
>> nor
>>
>> unless (condition) {
>> do_something();
>> }
>>
>> works for you?
>
> I'm saying that I have two conditions ;)
>
> I want to do_something() only if none of both conditions is true.
>
>
Sigh!
$ perl t5.pl
Ugly method
a=1, b=2 :
a=1, b=9 :condition met
a=9, b=2 :condition met
a=9, b=9 :condition met
Less Ugly method
a=1, b=2 :
a=1, b=9 :condition met
a=9, b=2 :condition met
a=9, b=9 :condition met
$ cat t5.pl
#!/usr/bin/perl
use strict;
use warnings;
print "Ugly method\n";
foo(1,2);
foo(1,9);
foo(9,2);
foo(9,9);
print "\nLess Ugly method\n";
bar(1,2);
bar(1,9);
bar(9,2);
bar(9,9);
sub foo {
my($a,$b) = @_;
print "a=$a, b=$b :";
if ($a == 1 && $b == 2) {
# ugly
} else {
print "condition met";
}
print "\n";
}
sub bar {
my($a,$b) = @_;
print "a=$a, b=$b :";
if ($a != 1 || $b != 2) {
print "condition met";
}
print "\n";
}
--
RGB
------------------------------
Date: Mon, 11 Aug 2008 11:38:08 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <48a01693$0$26081$db0fefd9@news.zen.co.uk>
Tomasz Chmielewski wrote:
TC> if ($a == 1 && $b == 2) {
TC> # Essentially an empty "if" statement
TC> } else {
TC> print "We're here only if a is not 1 and b is not 2!\n";
TC> }
... [negation suggested]
TC2> Text was printed, although $b was equal 2. Not what we wanted.
Try your original expression with a=9 and b=2!
Peter Makholm schrieb:
PM> The negated condition would be 2!( $a == 1 && $b == 2)"
PM> or by applying
PM> De Morgans Law: "$a != 1 || $b != 2"
TC> No, it wouldn't work in a desired way.
Probably because your original expression doesn't do what you want
either!
--
RGB
------------------------------
Date: Mon, 11 Aug 2008 12:39:03 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <g7p4s7$taa$2@online.de>
RedGrittyBrick schrieb:
(...)
>> I'm saying that I have two conditions ;)
>>
>> I want to do_something() only if none of both conditions is true.
>>
>>
>
> Sigh!
(...)
> sub bar {
> my($a,$b) = @_;
> print "a=$a, b=$b :";
>
> if ($a != 1 || $b != 2) {
> print "condition met";
> }
>
> print "\n";
>
> }
Ha ha, yeah, am I dumb or blind today? I suppose so.
Thanks, Peter and RGB.
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Mon, 11 Aug 2008 12:43:35 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <g7p54n$eis$1@online.de>
RedGrittyBrick schrieb:
> Tomasz Chmielewski wrote:
>
> TC> if ($a == 1 && $b == 2) {
> TC> # Essentially an empty "if" statement
> TC> } else {
> TC> print "We're here only if a is not 1 and b is not 2!\n";
> TC> }
>
> .... [negation suggested]
>
> TC2> Text was printed, although $b was equal 2. Not what we wanted.
>
> Try your original expression with a=9 and b=2!
It will print the message - the result I want.
> Peter Makholm schrieb:
>
> PM> The negated condition would be 2!( $a == 1 && $b == 2)"
> PM> or by applying
> PM> De Morgans Law: "$a != 1 || $b != 2"
>
> TC> No, it wouldn't work in a desired way.
>
> Probably because your original expression doesn't do what you want
> either!
It does.
It only uses the "empty if" when both "a is 1" and "b is 2".
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Mon, 11 Aug 2008 11:44:13 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <48a01800$0$26079$db0fefd9@news.zen.co.uk>
Tomasz Chmielewski wrote:
> RedGrittyBrick schrieb:
>> Tomasz Chmielewski wrote:
>
> (...)
>
>>> I'm saying that I have two conditions ;)
>>>
>>> I want to do_something() only if none of both conditions is true.
>>>
>>>
>>
>> Sigh!
>
> (...)
>
>> sub bar {
>> my($a,$b) = @_;
>> print "a=$a, b=$b :";
>>
>> if ($a != 1 || $b != 2) {
>> print "condition met";
>> }
>>
>> print "\n";
>>
>> }
>
> Ha ha, yeah, just don't use
Your code doesn't match your comments. Whether your code is wrong or
your comments are wrong - only you can say. If your code is wrong then
correct it before applying negation.
Perhaps when you wrote
if (a == 1 && b == 2)
you actually meant
if (a != 1 && b != 2)
in which case the negation would be
if !(a != 1 && b != 2)
or
if (a == 1 || b == 2)
Either way, if you still don't understand, write a small program (as I
did) that illustrates your question.
--
RGB
------------------------------
Date: Mon, 11 Aug 2008 12:49:09 +0200
From: Tomasz Chmielewski <tch@nospam.wpkg.org>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <g7p5f6$pri$1@online.de>
RedGrittyBrick schrieb:
> Tomasz Chmielewski wrote:
>> RedGrittyBrick schrieb:
>>> Tomasz Chmielewski wrote:
>>
>> (...)
>>
>>>> I'm saying that I have two conditions ;)
>>>>
>>>> I want to do_something() only if none of both conditions is true.
>>>>
>>>>
>>>
>>> Sigh!
>>
>> (...)
>>
>>> sub bar {
>>> my($a,$b) = @_;
>>> print "a=$a, b=$b :";
>>>
>>> if ($a != 1 || $b != 2) {
>>> print "condition met";
>>> }
>>>
>>> print "\n";
>>>
>>> }
>>
>> Ha ha, yeah, just don't use
My grumpy fingers again.
Was to be 'ha ha, yeah, just don't use "else" at all'.
Sorry for not clear comments and thanks for help.
--
Tomasz Chmielewski
http://wpkg.org
------------------------------
Date: Mon, 11 Aug 2008 11:14:36 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <slrnga07cs.111r.usenet@debranded.larseighner.com>
In our last episode, <g7p17c$3vk$1@online.de>, the lovely and talented
Tomasz Chmielewski broadcast on comp.lang.perl.misc:
> Peter Makholm schrieb:
>> Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
>>
>>> What would be a good way to get rid of this empty "if" statement?
>>
>> Eiter negate the condition or use an "unless" statement instead.
> Negating it or using "unless" would yield an unwanted result (but I
> didn't explain it very precisely, sorry for that).
> We want to print the text only if neither $a nor $b were equal a given
> number.
Then why didn't you write that:
if ( $a != 1 && $b != 2 ){print your stuff here, no need for an else}
Or if you must, express this as !( $a == 1 || $b == 2).
That isn't what your orginal amounted to. Else was reached if
either $a or $b were not equal to particular values.
> Example 1 - does "nothing" (uses empty "if"):
> my $a = 1;
> my $b = 2;
> if ($a == 1 && $b == 2) {
> # Essentially an empty "if" statement
> } else {
> print "We're here only if a is not 1 and b is not 2!\n";
> }
No. you get there if either a is not 1 or b is not 2.
Even if you know no logic, running this script should have
told you your conclusion was wrong. This is why people general
ask for actual code from a script that you are trying to run,
not a theoretical example.
> Example 2 - negated, but the result is wrong:
> my $a = 0;
> my $b = 2;
> if ($a == 1 && $b == 2) {
> # Essentially an empty "if" statement
> } else {
> print "We're here only if a is not 1 and b is not 2!\n";
> }
No. You get there any way because $a is not 1.
> Text was printed, although $b was equal 2. Not what we wanted.
> Using "next" or "last" in the empty statement would break the things if
> this "if" was inside of yet another "if".
> "goto" function? Doesn't look much better than an empty "if".
--
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
Cole's Law: Thinly sliced cabbage.
------------------------------
Date: Mon, 11 Aug 2008 11:30:18 +0000 (UTC)
From: Lars Eighner <usenet@larseighner.com>
Subject: Re: empty "if" statement - it doesn't look nice, does it?
Message-Id: <slrnga08ab.111r.usenet@debranded.larseighner.com>
In our last episode, <g7p38m$rbo$3@online.de>, the lovely and talented
Tomasz Chmielewski broadcast on comp.lang.perl.misc:
> Peter Makholm schrieb:
>> Tomasz Chmielewski <tch@nospam.wpkg.org> writes:
>>
>>> I know such does logically what it's supposed to do.
>>> What I meant: negating the "if ($a == 1 && $b == 2)" wouldn't make
>>> what I want.
>>
>> so you say that
>>
>> if (condition) {
>> # no-op
>> } else {
>> do_something();
>> }
>>
>> does what you intend to do, but neither
>>
>> if (!condition) {
>> do_something();
>> }
>>
>> nor
>>
>> unless (condition) {
>> do_something();
>> }
>>
>> works for you?
> I'm saying that I have two conditions ;)
> I want to do_something() only if none of both conditions is true.
So if p is one condition
and q is the other
neither true is: ~p and ~q
this is exactly the same as: ~(p or q)
So
if ( $a != 1 && $b != 2){ this gets done}
and
if ( !( $a == 1 || $b == 2 )){ this gets done}
are exactly the same. And even if you cannot understand the simplest
logic, you can write a short test script to show you that it is so.
--
Lars Eighner <http://larseighner.com/> usenet@larseighner.com
"We have no opinion on your Arab - Arab conflicts, such as your dispute with
Kuwait." -- Bush's Ambassador April Glaspie, giving Saddam Hussein
the greenlight to invade Kuwait.
------------------------------
Date: Mon, 11 Aug 2008 11:16:15 +0200
From: Thomas <th@example.invalid>
Subject: Inline C, char* and Visual Studio (was: Re: Need help with perlxs and C strings)
Message-Id: <g7p010$adf$1@aioe.org>
sisyphus wrote:
> The "-L." will be a problem as Inline's build directory (which is '.')
> is almost certainly not the location that houses the setdata library.
> So you'll need to replace that "-L." with the fully qualified location
> of the setdata library -ie something like "-LC:/library/location".
...
> LIB /OUT:setdata.lib setdata.obj
>
> Faik, it may even work if you rename setdata.a to setdata.obj (but I'm
> a bit doubtful of that).
Creating the right lib/dll file and making it available to the Inline C
compile process really is the key.
I changed a few things and got it to run. Part of the problem was that I
inherited a rather broken Perl installation on the development box, so
reinstalling Perl was an improvement. So perlxs and SWIG might actually
be easier to use than I thought. Anyway, I used Inline C.
Here's what I did for the archives. If somethings looks weird, please
reply. (About the content of the string and the trailing zero character
- my array never gets treated as a C string in my real application, so I
don't care about that. Handle differently if you must.)
Thanks to everyone who helped!
== setdata.h
void __declspec( dllexport ) set_data(char * data);
== setdata.c
#include "setdata.h"
void __declspec( dllexport ) set_data(char * data)
{
data[0] = 'a';
data[1] = 'c';
}
== runme.pl
use Inline C => Config =>
ENABLE => AUTOWRAP;
use Inline C => q{ void set_data(char *); };
my $x="xxxxxxxx";
set_data($x);
print "Data from C function:\n$x";
== Using it
1) Compile with Visual Studio's command line compiler cl and use the
right linking switches to create setdata.lib and setdata.dll:
cl /LD /MT setdata.c
2) Run the vsvars32.bat file which should be part of your Visual Studio
installation to set all directories in a way that makes cl happy. Make
sure that you add the directory where the setdata lib/dll files are
located or move them to whatever directories already are in the LIB
environment variable. You might also succeed with the -L switch sisyphus
mentioned.
3) Run the Perl script:
perl runme.pl
------------------------------
Date: Mon, 11 Aug 2008 10:30:34 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: OO Perl
Message-Id: <slrng9vu5b.2gj.hjp-usenet2@hrunkner.hjp.at>
On 2008-08-10 16:26, Matt <mattj.morrison@gmail.com> wrote:
> Here is the thing. Everything that's done is Perl to "extend the
> language" is done in Modules - which is the way its done, but that
> just doesn't work for me. I don't want to install Moose and any of
> the other Module dependencies it may have. The tooling to make
> installing Modules for Perl just doesn't exist..here is an example.
> I've got a web server - which I rent for a monthly fee. I'm not an
> admin on that server, and I don't have root access. So any Perl
> modules that I install must be to MY directory only...which I know can
> be done, but the thing is that when I develop in my local environment
> I can't just deploy my code to my web server, I have to make sure that
> the Perl modules installed on my local machine are also installed on
> my remote server. I've gotten sick of doing that, so I've decided
> that I'm going to break the mold. I don't want to develop Perl
> modules the way its always been done, I want to do it in a way that
> works for me. I've got my OO Perl stuff in a directory, if I change
> it, I deploy it from my local server to my remote server, no other
> changes needed. On my remote server, I know its there because I
> deployed it there. I didn't have to bring up an SSH session and log
> into the remote server for anything. What I've done with my OO Perl
> "module" is that I've made it completely independent from any and all
> other Perl modules. This way I've got all the code I need without
> having to worry about installing any additional Modules locally or
> remotely.
>
> Hope that makes sense...I'm sure it probably won't to most of you.
Your approach is slightly simpler if you have only one module, one
project and one server.
That advantage vanishes if you have several projects on several
servers using several of your modules. Now you need to keep track of
which modules you need to deploy on which server, exactly as if you used
modules from CPAN. And unlike CPAN, your system for deployment probably
doesn't keep track of dependencies.
hp
------------------------------
Date: Mon, 11 Aug 2008 10:11:23 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: Trying to understand a constructor with an array.
Message-Id: <slrng9vt1b.2gj.hjp-usenet2@hrunkner.hjp.at>
On 2008-08-09 03:32, Michael Carman <mjcarman@mchsi.com> wrote:
> Overt wrote:
>>> my $self = [ @{+shift} ];
>>
>> I would not have discovered it on my own (at least for a long while),
>> because I can't find that construction in any of my documentation.
>
> That's probably because it's not one construct but several written together:
>
> * The [...] creates a reference to an anonymous array. This is what
> gets assigned to $self.
> * The @{...} is an array dereference.
> * The shift() function removes and returns the first element from an
> array. If no array is specified (and you're inside a subroutine) it
> operates on @_.
> * @_ is the array used to pass arguments to subs.
> * The + is the unary sign operator. It forces the "shift" to be
> interpreted as a function call instead of as a bareword. Without it
> the expression would parse as the array @shift instead of as
> @{ shift(@_) }
>
> Personally, I wouldn't write it this way, because I think it's very
> obscure. I would write
>
> my $self = shift;
>
> as Peter suggested.
So I did. But I've been very brief because I wanted to tease the OP into
trying to find out what the subtle difference is. Probably too brief - I
don't think I succeeded.
As a matter of style, I vastly prefer
sub new {
my ($class, $data) = @_;
...
}
over
sub new {
my $class = shift;
my $data = shift;
...
}
especially if the second shift would be hidden in a complex expression
and not be immediately visible to the reader (I sometimes do use shift
(or even pop) to deal with optional arguments).
So that constructor would become:
sub new {
my ($class, $data) = @_;
my $self = $data;
bless $self, $class;
return $self;
}
or, if I wanted to copy the elements of @$data to @$self (and avoid
accidentally blessing $data):
sub new {
my ($class, $data) = @_;
my $self = [ @$data ];
bless $self, $class;
return $self;
}
> You could add a check for C<ref($self) eq 'ARRAY'>
> if you share Leon's concern and want to ensure that the user didn't pass
> in the wrong thing as an argument.
Yup. Since perl cannot check types at compile time it is often a good
idea to add such checks at run time.
hp
------------------------------
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 1785
***************************************