[31409] in Perl-Users-Digest
Perl-Users Digest, Issue: 2661 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 1 14:09:41 2009
Date: Sun, 1 Nov 2009 11:09:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 1 Nov 2009 Volume: 11 Number: 2661
Today's topics:
Re: FAQ 7.27 How can I comment out a large block of Per <cartercc@gmail.com>
Re: FAQ 7.27 How can I comment out a large block of Per <jurgenex@hotmail.com>
Re: FAQ 7.27 How can I comment out a large block of Per <nospam-abuse@ilyaz.org>
Re: FAQ 7.27 How can I comment out a large block of Per <spamtrap@shermpendley.com>
Re: FAQ 7.27 How can I comment out a large block of Per <cartercc@gmail.com>
Re: FAQ 7.27 How can I comment out a large block of Per <hjp-usenet2@hjp.at>
Re: FAQ 7.27 How can I comment out a large block of Per <spamtrap@shermpendley.com>
Re: FAQ 7.27 How can I comment out a large block of Per <hjp-usenet2@hjp.at>
Re: FAQ 7.27 How can I comment out a large block of Per <jurgenex@hotmail.com>
Net::LDAP::LDIF->current_lines() seems unworkable in th <wangpenghui@gmail.com>
unintialised warning <john1949@yahoo.com>
Re: unintialised warning sln@netherlands.com
Re: unintialised warning <rvtol+usenet@xs4all.nl>
Re: unintialised warning <someone@example.com>
Re: unintialised warning sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 31 Oct 2009 12:46:29 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <f3a46be6-c1c7-471b-a4a3-437e38453d2d@15g2000yqy.googlegroups.com>
On Oct 31, 11:00=A0am, PerlFAQ Server <br...@theperlreview.com> wrote:
> 7.27: How can I comment out a large block of Perl code?
This doesn't necessarily need to be a Perl issue. While it's true that
Perl doesn't have multi-line comments like C or Java, you might be
able to do the same thing with your editor using single line comments.
The big advantage comes when you are testing a large block -- you
don't have to keep moving the start of your multi-line comment and you
can see exactly what code is running and what isn't.
For example, in vi, to comment lines 231 through 317, do
:231,317 s/^/#/
which will replace the beginning of the line with #.
To remove the comments from lines 245 through 277, do
:245,277 s/#//
which will replace # with nothing (therefore removing it).
This is so useful that I find myself doing it while writing Java,
instead of using the multi-line Java comments.
CC
------------------------------
Date: Sat, 31 Oct 2009 12:56:29 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <9h5pe5l504em0sfpb5e31fjhca3bpvuisr@4ax.com>
ccc31807 <cartercc@gmail.com> wrote:
>On Oct 31, 11:00 am, PerlFAQ Server <br...@theperlreview.com> wrote:
>> 7.27: How can I comment out a large block of Perl code?
>
>This doesn't necessarily need to be a Perl issue. While it's true that
>Perl doesn't have multi-line comments like C or Java, you might be
>able to do the same thing with your editor using single line comments.
Sure. In Emacs you simply do M-x comment-region.
But that is an Emacs solution, not a Perl solution, and FAQ is about
Perl.
jue
------------------------------
Date: Sat, 31 Oct 2009 21:05:47 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <slrnhep9lb.b27.nospam-abuse@powdermilk.math.berkeley.edu>
On 2009-10-31, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Sure. In Emacs you simply do M-x comment-region.
>
> But that is an Emacs solution, not a Perl solution, and FAQ is about
> Perl.
FAQ is about "Perl questions", not "Perl solutions".
Hope this helps,
Ilya
------------------------------
Date: Sat, 31 Oct 2009 19:49:41 -0400
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <m2skczw2cq.fsf@shermpendley.com>
Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
> On 2009-10-31, Jürgen Exner <jurgenex@hotmail.com> wrote:
>> Sure. In Emacs you simply do M-x comment-region.
>>
>> But that is an Emacs solution, not a Perl solution, and FAQ is about
>> Perl.
>
> FAQ is about "Perl questions", not "Perl solutions".
IMHO, I think the answer to this one should be restricted to what needs
to be written in a Perl script to create a block comment. How to use
various editors to write it is really a question about those editors; for
instance, the Emacs command given above is the same no matter what
language you happen to be editing, so it has nothing whatsoever to do
with Perl.
sherm--
------------------------------
Date: Sat, 31 Oct 2009 19:46:34 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <4a91f8af-2b40-45d0-b867-6f3a9b3e7f4c@j19g2000yqk.googlegroups.com>
On Oct 31, 6:49=A0pm, Sherm Pendley <spamt...@shermpendley.com> wrote:
> IMHO, I think the answer to this one should be restricted to what needs
> to be written in a Perl script to create a block comment. How to use
> various editors to write it is really a question about those editors; for
> instance, the Emacs command given above is the same no matter what
> language you happen to be editing, so it has nothing whatsoever to do
> with Perl.
IMO this is an artificial distinction. The need to comment out blocks
is real, as is the absence of a direct method of doing so in Perl.
Sherm is correct in that using an editor to make block comments 'has
nothing whatsoever to do with Perl.' On the other hand, a non-Perl
solution to a real problem is better to a non-solution to a real
problem.
Even if Perl somehow got block comments, most would probably continue
to use what works for them -- using their editors to comment out
blocks. Besides, at this point, the lack of multi-line comments in
Perl perhaps can be seen as intentional, in the sense that if they
were really perceived as needed they would have been added by now.
CC.
------------------------------
Date: Sun, 1 Nov 2009 14:42:24 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <slrnher420.svq.hjp-usenet2@hrunkner.hjp.at>
On 2009-10-31 23:49, Sherm Pendley <spamtrap@shermpendley.com> wrote:
> Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
>> On 2009-10-31, Jürgen Exner <jurgenex@hotmail.com> wrote:
>>> Sure. In Emacs you simply do M-x comment-region.
>>>
>>> But that is an Emacs solution, not a Perl solution, and FAQ is about
>>> Perl.
>>
>> FAQ is about "Perl questions", not "Perl solutions".
>
> IMHO, I think the answer to this one should be restricted to what needs
> to be written in a Perl script to create a block comment. How to use
> various editors to write it is really a question about those editors; for
> instance, the Emacs command given above is the same no matter what
> language you happen to be editing, so it has nothing whatsoever to do
> with Perl.
While I agree that the specific ways to do this in various editors are
out of scope for a Perl FAQ, the answer should mention that good editors
make it easy to add and remove comments in a range of lines.
Personally, I don't think I've ever used the =pod/=cut method to
"comment out a large block of Perl code", but always added "#"-marks to
the beginning of each line of the block. This also has the advantage
that it can be nested, unlike =pod/=cut. One interesting variation of
this technique is to add a short tag to each comment, like this "#t1 ".
Then you can remove all comments with this tag with a global search and
replace.
hp
------------------------------
Date: Sun, 01 Nov 2009 09:19:07 -0500
From: Sherm Pendley <spamtrap@shermpendley.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <m2iqdu5nvo.fsf@shermpendley.com>
"Peter J. Holzer" <hjp-usenet2@hjp.at> writes:
> While I agree that the specific ways to do this in various editors are
> out of scope for a Perl FAQ, the answer should mention that good editors
> make it easy to add and remove comments in a range of lines.
How about this as an intro then:
Many programming-oriented text editors provide an easy, language agnostic
way to comment and uncomment a range of lines. Details about specific
editors are beyond the scope of this FAQ, so check the docs, FAQ, or
support forum for the editor you're using.
But don't worry! If you're using an editor such as Notepad that lacks
such a function, you're not entirely out of luck. The rest of this FAQ
is for you, so keep reading.
> Personally, I don't think I've ever used the =pod/=cut method to
> "comment out a large block of Perl code", but always added "#"-marks to
> the beginning of each line of the block.
Neither have I - but I've never spent much time using an editor that
didn't have a "(un)comment selected block" function either. :-)
sherm--
------------------------------
Date: Sun, 1 Nov 2009 16:50:19 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <slrnherbhs.p0.hjp-usenet2@hrunkner.hjp.at>
On 2009-11-01 14:19, Sherm Pendley <spamtrap@shermpendley.com> wrote:
> "Peter J. Holzer" <hjp-usenet2@hjp.at> writes:
>> While I agree that the specific ways to do this in various editors are
>> out of scope for a Perl FAQ, the answer should mention that good editors
>> make it easy to add and remove comments in a range of lines.
>
> How about this as an intro then:
>
> Many programming-oriented text editors provide an easy, language agnostic
> way to comment and uncomment a range of lines. Details about specific
> editors are beyond the scope of this FAQ, so check the docs, FAQ, or
> support forum for the editor you're using.
>
> But don't worry! If you're using an editor such as Notepad that lacks
> such a function, you're not entirely out of luck. The rest of this FAQ
> is for you, so keep reading.
Nice.
>> Personally, I don't think I've ever used the =pod/=cut method to
>> "comment out a large block of Perl code", but always added "#"-marks to
>> the beginning of each line of the block.
>
> Neither have I - but I've never spent much time using an editor that
> didn't have a "(un)comment selected block" function either. :-)
Vim doesn't even have such a function. But marking a block and typing
:s/^/# /
is easy and and fast enough that I haven't even bothered to bind that to
a key (which would be simple enough).
hp
------------------------------
Date: Sun, 01 Nov 2009 08:42:26 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: FAQ 7.27 How can I comment out a large block of Perl code?
Message-Id: <cfere5t6o1vjopch3bmsn2hfod2onitl7u@4ax.com>
Sherm Pendley <spamtrap@shermpendley.com> wrote:
>"Peter J. Holzer" <hjp-usenet2@hjp.at> writes:
>
>> While I agree that the specific ways to do this in various editors are
>> out of scope for a Perl FAQ, the answer should mention that good editors
>> make it easy to add and remove comments in a range of lines.
>
>How about this as an intro then:
>
>Many programming-oriented text editors provide an easy, language agnostic
>way to comment and uncomment a range of lines. Details about specific
>editors are beyond the scope of this FAQ, so check the docs, FAQ, or
>support forum for the editor you're using.
Nice.
Expect in Emacs the Perl mode or c-perl mode is language-aware. I would
remove those 3 word "language agnostic way".
jue
------------------------------
Date: Sun, 1 Nov 2009 01:26:02 -0800 (PST)
From: Wang Penghui <wangpenghui@gmail.com>
Subject: Net::LDAP::LDIF->current_lines() seems unworkable in the new version.
Message-Id: <8bba2980-efaa-4b9e-adc5-7dc3d00e91c5@g1g2000pra.googlegroups.com>
#!/usr/bin/perl -w
use Net::LDAP::LDIF;
Hi,
I have a perl script to convert ldif file, put the base64 encoded text
to one line.
Recently it seems unworkable with the follow error:
Use of uninitialized value in print at ./readldif.pl line 14, <GEN0>
line 46735.
Use of uninitialized value in print at ./readldif.pl line 14, <GEN0>
line 46804.
Use of uninitialized value in print at ./readldif.pl line 14, <GEN0>
line 46893.
The OS is debian 5.0.4. And the libnet-ldap-perl is 0.36-1.
I have searched the web for a while but no result, could someone pick
me up?
Here are the script:
$ldif = Net::LDAP::LDIF->new( "source.ldif", "r", onerror =>
'undef' );
while( not $ldif->eof ( ) ) {
$entry = $ldif->read_entry ( );
if ( $ldif->error ( ) ) {
print "Error msg: ", $ldif->error ( ), "\n";
print "Error lines:\n", $ldif->error_lines ( ), "\n";
} else {
if ($entry->dn =~ m/contact/) {
print $ldif->current_lines();
}
print "\n\n";
}
}
$ldif->done ( );
Thanks very much.
Penghui Wang.
------------------------------
Date: Sun, 1 Nov 2009 15:32:17 -0000
From: "John" <john1949@yahoo.com>
Subject: unintialised warning
Message-Id: <hck9lq$frj$1@news.albasani.net>
Hi
The following can cause a warning if undefined
my $value=$PAR{$name};
What the best solution?
my $value=$PAR{$name }or $value='';
or
my $value=''; if (defined $PAR{$name}) {$value=$PAR{$name}}
or
is there a cleaner solution?
Regards
John
------------------------------
Date: Sun, 01 Nov 2009 07:45:49 -0800
From: sln@netherlands.com
Subject: Re: unintialised warning
Message-Id: <n7bre5tndd5qt56r99rv4phjijo2k37l90@4ax.com>
On Sun, 1 Nov 2009 15:32:17 -0000, "John" <john1949@yahoo.com> wrote:
>Hi
>
>The following can cause a warning if undefined
>
>my $value=$PAR{$name};
^^^^^
only if undefined
-sln
------------------------------
Date: Sun, 01 Nov 2009 17:17:38 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: unintialised warning
Message-Id: <4aedb4a2$0$83233$e4fe514c@news.xs4all.nl>
John wrote:
> The following can cause a warning if undefined
>
> my $value=$PAR{$name};
my $value = defined($name) ? $PAR{$name} : undef;
This means that $value itself can still be undef.
Or did you mean 'name' in stead of $name?
--
Ruud
------------------------------
Date: Sun, 01 Nov 2009 09:16:53 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: unintialised warning
Message-Id: <aojHm.8535$zy1.1137@newsfe14.iad>
Andrew DeFaria wrote:
> On 11/01/2009 08:32 AM, John wrote:
>>
>> The following can cause a warning if undefined
>>
>> my $value=$PAR{$name};
>>
>> What the best solution?
>>
>> my $value=$PAR{$name }or $value='';
>> or
>> my $value=''; if (defined $PAR{$name}) {$value=$PAR{$name}}
>> or
>> is there a cleaner solution?
>
> my $value ||= $PAR{$name}
That is exactly the same as saying:
my $value = $PAR{$name}
Because my() creates a variable that starts out undefined and an
undefined variable is false so the || test will always fail.
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
------------------------------
Date: Sun, 01 Nov 2009 10:43:48 -0800
From: sln@netherlands.com
Subject: Re: unintialised warning
Message-Id: <a7kre5lsu6v2spd28vqj0d1a968dq0jklb@4ax.com>
On Sun, 1 Nov 2009 15:32:17 -0000, "John" <john1949@yahoo.com> wrote:
>Hi
>
>The following can cause a warning if undefined
>
>my $value=$PAR{$name};
>
>What the best solution?
>
>my $value=$PAR{$name }or $value='';
>or
>my $value=''; if (defined $PAR{$name}) {$value=$PAR{$name}}
>or
>is there a cleaner solution?
>
>Regards
>John
>
>
The only uninitialized warning would be if $name were undefined
when you try to use it, ie: $PAR{$name}. It is always legitimate
to assing undef to a scalar variable.
Don't be confused between logical's 'or' and ||. They both do the
same logical test form, but 'or' is used for control flow.
So, my $value2 = 0 or 1; is functionally equivalent to
(my $value2 = 0) or 1; which assigns 0 to $value2 because
^^^^^^^^^^^^^^^
this expression is evaluated and the result of the assignment is always
*TRUE*, and because of that is always meaningless, a non-conditional.
You have to be carefull with || as well. Perl interprets 'undef' logically
equal to 0. So $value = undef || 1; and $value = 0 || 1; both assign
1 to $value.
Some examples follow below ..
-sln
---------
# 'or' can be used like '||' when used for control flow.
use strict;
use warnings;
my $value;
$value = undef || 1;
print $value,"\n";
$value = 0 || 1;
print $value,"\n\n";
# The ||, // and && operators return the last value evaluated
# (unlike C's || and &&, which return 0 or 1).
# --------------------
# For Perl 5.10 :
# $a // $b is exactly equivalent to defined($a) ? $a : $b
$value = defined(0) ? 0 : 3;
print $value,"\n";
$value = defined(undef) ? 0 : 3;
print $value,"\n";
$value = 0 // 3;
print $value,"\n";
$value = undef // 3;
print $value,"\n";
$value = undef;
my $value2 = 0 or 1;
print $value2,"\n";
__END__
Found = in conditional, should be == at gg.pl line 34.
1
1
0
3
0
3
0
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 2661
***************************************