[33067] in Perl-Users-Digest
Perl-Users Digest, Issue: 4343 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 6 11:09:22 2015
Date: Tue, 6 Jan 2015 08:09:06 -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 Tue, 6 Jan 2015 Volume: 11 Number: 4343
Today's topics:
Re: fields separation <rweikusat@mobileactivedefense.com>
Re: help,perl script <hjp-usenet3@hjp.at>
Re: help,perl script <gamo@telecable.es>
Re: help,perl script <hjp-usenet3@hjp.at>
Re: help,perl script <gamo@telecable.es>
Re: help,perl script <hjp-usenet3@hjp.at>
Re: help,perl script <gamo@telecable.es>
Re: help,perl script <hjp-usenet3@hjp.at>
Re: help,perl script <gamo@telecable.es>
Re: help,perl script <hjp-usenet3@hjp.at>
Re: help,perl script <news@todbe.com>
Re: help,perl script <gamo@telecable.es>
Re: help,perl script <rweikusat@mobileactivedefense.com>
Re: help,perl script sharma__r@hotmail.com
Re: help,perl script <news@lawshouse.org>
search.cpan.org and metacpan <news@lawshouse.org>
Re: search.cpan.org and metacpan <news@lawshouse.org>
Re: search.cpan.org and metacpan <justin.1410@purestblue.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 04 Jan 2015 22:13:33 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: fields separation
Message-Id: <87a91ytcs2.fsf@doppelsaurus.mobileactivedefense.com>
sammyjeep <cairukai@huawei.com> writes:
> 在 2014年12月31日星期三UTC+8下午11时45分59秒,Rainer Weikusat写道:
>> 蔡汝凯 <cairukai@huawei.com> writes:
>> >> > $buff=~s/<(\s*\n*\s*){1,}\*(\s*\n*\s*){1,}>/<*>/g;
>> >>
>> >> This obviously won't work with separators other than <*>. Further, in a regex
>> >>
>> >> \s*\n*\s*
>> >>
>> >> only the first \s* will ever match anything because \s matches \n,
>> >>
>> >> [rw@doppelsaurus]~#perl -e '$a = " \n "; $a =~ /(\s*)(\n*)(\s*)/;
>> >> printf("|%s|, |%s|, |%s|\n", $1, $2, $3);'
>> >> |
>> >> |, ||, ||
>> > Hi Rainer, i do not think it's the important thing, matching the \n
>> > with \n or with \s. i just need match the whole pattern ant kill them.
>>
>> Assuming you want to match all whitespace and all newlines,
>>
>> \s*\n*\s*
>>
>> is really the same as
>>
>> \s*
>>
>> because \n is a whitespace-character: The first \s* will gobble up all
>> of them because it is a greedy match and the \n*\s* just make the
>> complete regex a little more complicated without affecting what it
>> matches.
>
> Yes, u are right, if we need the $1 to do something,it will not
> work. but in this script is all right.
I don't quite understand what you're trying to argue about: \n is a
whitespace character. \s* matches an arbitrarily long sequence of
whitespace characters starting at the current position and matching as
many characters as possible. Hence, nothing which also matches a
whitespace character will match anything after a \s*. If matching all
whitespace characters is not what's actually intended, \s can't be
used. Something like
\h*\n*
could be used instead (there's also \v for matching 'vertical
whitespace' but - depending on the perl version - this will include
matching so-called 'vertical tabs').
------------------------------
Date: Sun, 4 Jan 2015 13:48:16 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: help,perl script
Message-Id: <slrnmaidkg.usv.hjp-usenet3@hrunkner.hjp.at>
On 2015-01-04 05:59, salmon <salmon@yeah.net> wrote:
> #!/usr/local/bin/perl -w
> use strict;
> use encoding "utf8", STDOUT =>"utf8";
>
> while(<>)
> {
> chomp;
> next if not ((defined $_));
This can never happen because the loop condition already checks whether
$_ is defined.
> my @arr = split /\t/, $_;
> if (@arr +0 == 1)
Better written as if (@arr == 1).
Here you check whether @arr has exactly one element.
> {
> print $_,"\n";
> next;
> }
So here it is guaranteed to have not 1 element but either 0 or 2 or more
elements.
> if( $arr[0] =~ s/(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$)//ig)
But you assume that $arr[0] exists, i.e. @arr has at least one element.
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpat. -- Ralph Babel
------------------------------
Date: Sun, 04 Jan 2015 15:05:14 +0100
From: gamo <gamo@telecable.es>
Subject: Re: help,perl script
Message-Id: <m8bhap$iqq$1@speranza.aioe.org>
El 04/01/15 a las 13:48, Peter J. Holzer escribi:
> On 2015-01-04 05:59, salmon <salmon@yeah.net> wrote:
>> #!/usr/local/bin/perl -w
>> use strict;
>> use encoding "utf8", STDOUT =>"utf8";
>>
>> while(<>)
>> {
>> chomp;
>> next if not ((defined $_));
>
> This can never happen because the loop condition already checks whether
> $_ is defined.
>
>> my @arr = split /\t/, $_;
>> if (@arr +0 == 1)
>
> Better written as if (@arr == 1).
>
> Here you check whether @arr has exactly one element.
>
>> {
>> print $_,"\n";
>> next;
>> }
>
> So here it is guaranteed to have not 1 element but either 0 or 2 or more
> elements.
>
>> if( $arr[0] =~ s/(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$)//ig)
>
> But you assume that $arr[0] exists, i.e. @arr has at least one element.
>
> hp
>
Here is one experiment in which the line happens to begin with a tabulator:
$ perl -E '$a="\t1\t2"; @b = split /\t/,$a; for (@b){ say ; };'
1
2
$
It reads an undefined or empty as a first field.
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Sun, 4 Jan 2015 15:23:34 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: help,perl script
Message-Id: <slrnmaij76.ebm.hjp-usenet3@hrunkner.hjp.at>
On 2015-01-04 14:05, gamo <gamo@telecable.es> wrote:
> El 04/01/15 a las 13:48, Peter J. Holzer escribi:
>> On 2015-01-04 05:59, salmon <salmon@yeah.net> wrote:
>>> my @arr = split /\t/, $_;
[...]
>> So here it is guaranteed to have not 1 element but either 0 or 2 or more
>> elements.
>>
>>> if( $arr[0] =~ s/(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$)//ig)
>>
>> But you assume that $arr[0] exists, i.e. @arr has at least one element.
>
> Here is one experiment in which the line happens to begin with a tabulator:
>
> $ perl -E '$a="\t1\t2"; @b = split /\t/,$a; for (@b){ say ; };'
>
> 1
> 2
> $
>
> It reads an undefined or empty as a first field.
It is empty, not undefined.
here is an experiment which explains better what is happening:
for ("", "1", "1\t2") {
my @a = split(/\t/);
print scalar(@a), ":";
print " <$_>" for @a;
print "\n";
}
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpat. -- Ralph Babel
------------------------------
Date: Sun, 04 Jan 2015 15:43:04 +0100
From: gamo <gamo@telecable.es>
Subject: Re: help,perl script
Message-Id: <m8bjhn$o9h$1@speranza.aioe.org>
El 04/01/15 a las 15:23, Peter J. Holzer escribi:
> On 2015-01-04 14:05, gamo <gamo@telecable.es> wrote:
>> El 04/01/15 a las 13:48, Peter J. Holzer escribi:
>>> On 2015-01-04 05:59, salmon <salmon@yeah.net> wrote:
>>>> my @arr = split /\t/, $_;
> [...]
>>> So here it is guaranteed to have not 1 element but either 0 or 2 or more
>>> elements.
>>>
>>>> if( $arr[0] =~ s/(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$)//ig)
>>>
>>> But you assume that $arr[0] exists, i.e. @arr has at least one element.
>>
>> Here is one experiment in which the line happens to begin with a tabulator:
>>
>> $ perl -E '$a="\t1\t2"; @b = split /\t/,$a; for (@b){ say ; };'
>>
>> 1
>> 2
>> $
>>
>> It reads an undefined or empty as a first field.
>
> It is empty, not undefined.
>
> here is an experiment which explains better what is happening:
>
> for ("", "1", "1\t2") {
> my @a = split(/\t/);
> print scalar(@a), ":";
> print " <$_>" for @a;
> print "\n";
> }
>
> hp
>
>
What I want to mean is that it is...
perl -E '$a=""; if ($a) { say "ok"; } else{ say "not ok"; };'
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Sun, 4 Jan 2015 15:53:03 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: help,perl script
Message-Id: <slrnmaikuf.jgq.hjp-usenet3@hrunkner.hjp.at>
On 2015-01-04 14:43, gamo <gamo@telecable.es> wrote:
> El 04/01/15 a las 15:23, Peter J. Holzer escribi:
>> On 2015-01-04 14:05, gamo <gamo@telecable.es> wrote:
>>> El 04/01/15 a las 13:48, Peter J. Holzer escribi:
>>>> On 2015-01-04 05:59, salmon <salmon@yeah.net> wrote:
>>>>> my @arr = split /\t/, $_;
>>>> But you assume that $arr[0] exists, i.e. @arr has at least one element.
>>>
>>> Here is one experiment in which the line happens to begin with a
>>> tabulator:
>>>
>>> $ perl -E '$a="\t1\t2"; @b = split /\t/,$a; for (@b){ say ; };'
>>>
>>> 1
>>> 2
>>> $
>>>
>>> It reads an undefined or empty as a first field.
>>
>> It is empty, not undefined.
>>
>> here is an experiment which explains better what is happening:
>>
>> for ("", "1", "1\t2") {
>> my @a = split(/\t/);
>> print scalar(@a), ":";
>> print " <$_>" for @a;
>> print "\n";
>> }
>
> What I want to mean is that it is...
>
> perl -E '$a=""; if ($a) { say "ok"; } else{ say "not ok"; };'
This is not what it is happening here. He's getting a warning about an
undefined value. An empty string doesn't produce such a warning.
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpat. -- Ralph Babel
------------------------------
Date: Sun, 04 Jan 2015 16:06:28 +0100
From: gamo <gamo@telecable.es>
Subject: Re: help,perl script
Message-Id: <m8bkti$rpi$1@speranza.aioe.org>
El 04/01/15 a las 15:53, Peter J. Holzer escribi:
> On 2015-01-04 14:43, gamo <gamo@telecable.es> wrote:
>> El 04/01/15 a las 15:23, Peter J. Holzer escribi:
>>> On 2015-01-04 14:05, gamo <gamo@telecable.es> wrote:
>>>> El 04/01/15 a las 13:48, Peter J. Holzer escribi:
>>>>> On 2015-01-04 05:59, salmon <salmon@yeah.net> wrote:
>>>>>> my @arr = split /\t/, $_;
>>>>> But you assume that $arr[0] exists, i.e. @arr has at least one element.
>>>>
>>>> Here is one experiment in which the line happens to begin with a
>>>> tabulator:
>>>>
>>>> $ perl -E '$a="\t1\t2"; @b = split /\t/,$a; for (@b){ say ; };'
>>>>
>>>> 1
>>>> 2
>>>> $
>>>>
>>>> It reads an undefined or empty as a first field.
>>>
>>> It is empty, not undefined.
>>>
>>> here is an experiment which explains better what is happening:
>>>
>>> for ("", "1", "1\t2") {
>>> my @a = split(/\t/);
>>> print scalar(@a), ":";
>>> print " <$_>" for @a;
>>> print "\n";
>>> }
>>
>> What I want to mean is that it is...
>>
>> perl -E '$a=""; if ($a) { say "ok"; } else{ say "not ok"; };'
>
> This is not what it is happening here. He's getting a warning about an
> undefined value. An empty string doesn't produce such a warning.
>
> hp
>
>
But the error do not say explicity "undefined" else it says:
Use of uninitialized value in substitution (s///) at
scripts/rm_no_word\_char.pl line 15, <> line 30
So, 1) it could be a bad idea to use a tab as a separator and
2) if used, there must be check for empty fields
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Sun, 4 Jan 2015 16:20:41 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: help,perl script
Message-Id: <slrnmaimi9.nb7.hjp-usenet3@hrunkner.hjp.at>
On 2015-01-04 15:06, gamo <gamo@telecable.es> wrote:
> El 04/01/15 a las 15:53, Peter J. Holzer escribi:
>> On 2015-01-04 14:43, gamo <gamo@telecable.es> wrote:
>>> perl -E '$a=""; if ($a) { say "ok"; } else{ say "not ok"; };'
>>
>> This is not what it is happening here. He's getting a warning about an
>> undefined value. An empty string doesn't produce such a warning.
>
> But the error do not say explicity "undefined" else it says:
>
> Use of uninitialized value in substitution (s///) at
^^^^^^^^^^^^^^^^^^^
> scripts/rm_no_word\_char.pl line 15, <> line 30
The warning is badly worded, but "uninitialized value" means undef.
So, yes, it does say exactly that, if you know what the warning means,
which you should know if you have been using perl for more than a month
or so.
> So, 1) it could be a bad idea to use a tab as a separator and
> 2) if used, there must be check for empty fields
No. Empty fields are fine. split returns "" for empty fields which do
not trigger a warning. Here he gets an empty array and tries to access
a non-existent element.
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpat. -- Ralph Babel
------------------------------
Date: Sun, 04 Jan 2015 16:48:16 +0100
From: gamo <gamo@telecable.es>
Subject: Re: help,perl script
Message-Id: <m8bnbv$2ad$1@speranza.aioe.org>
El 04/01/15 a las 16:20, Peter J. Holzer escribi:
> On 2015-01-04 15:06, gamo <gamo@telecable.es> wrote:
>> El 04/01/15 a las 15:53, Peter J. Holzer escribi:
>>> On 2015-01-04 14:43, gamo <gamo@telecable.es> wrote:
>>>> perl -E '$a=""; if ($a) { say "ok"; } else{ say "not ok"; };'
>>>
>>> This is not what it is happening here. He's getting a warning about an
>>> undefined value. An empty string doesn't produce such a warning.
>>
>> But the error do not say explicity "undefined" else it says:
>>
>> Use of uninitialized value in substitution (s///) at
> ^^^^^^^^^^^^^^^^^^^
>> scripts/rm_no_word\_char.pl line 15, <> line 30
>
> The warning is badly worded, but "uninitialized value" means undef.
>
> So, yes, it does say exactly that, if you know what the warning means,
> which you should know if you have been using perl for more than a month
> or so.
>
No, I don't remember ever using the if(s///) construction, and I have
years rounding about Perl. Recently there was a post about it, but I
am sceptical about that's the better code to trace.
>
>> So, 1) it could be a bad idea to use a tab as a separator and
>> 2) if used, there must be check for empty fields
>
> No. Empty fields are fine. split returns "" for empty fields which do
> not trigger a warning. Here he gets an empty array and tries to access
> a non-existent element.
>
> hp
>
My bad, here I mean empty and undefined and else not expected.
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Mon, 5 Jan 2015 00:17:06 +0100
From: "Peter J. Holzer" <hjp-usenet3@hjp.at>
Subject: Re: help,perl script
Message-Id: <slrnmajifi.hug.hjp-usenet3@hrunkner.hjp.at>
On 2015-01-04 15:48, gamo <gamo@telecable.es> wrote:
> El 04/01/15 a las 16:20, Peter J. Holzer escribi:
>> On 2015-01-04 15:06, gamo <gamo@telecable.es> wrote:
>>> El 04/01/15 a las 15:53, Peter J. Holzer escribi:
>>>> On 2015-01-04 14:43, gamo <gamo@telecable.es> wrote:
>>>>> perl -E '$a=""; if ($a) { say "ok"; } else{ say "not ok"; };'
>>>>
>>>> This is not what it is happening here. He's getting a warning about an
>>>> undefined value. An empty string doesn't produce such a warning.
>>>
>>> But the error do not say explicity "undefined" else it says:
>>>
>>> Use of uninitialized value in substitution (s///) at
>> ^^^^^^^^^^^^^^^^^^^
>>> scripts/rm_no_word\_char.pl line 15, <> line 30
>>
>> The warning is badly worded, but "uninitialized value" means undef.
>>
>> So, yes, it does say exactly that, if you know what the warning means,
>> which you should know if you have been using perl for more than a month
>> or so.
>>
>
> No, I don't remember ever using the if(s///) construction,
What are you talking about? The warning isn't about using s/// within
if (why should this be special, anyway?), but about the "use of [an]
uninitialized value". This *always* means that you are using the value
undef in a context where a defined value is expected.
> and I have years rounding about Perl.
Yes. At least you have been posting for years in this group. Which makes
it all the more shocking that you wouldn't know what one of the most
common warnings means.
>>> So, 1) it could be a bad idea to use a tab as a separator and
>>> 2) if used, there must be check for empty fields
>>
>> No. Empty fields are fine. split returns "" for empty fields which do
>> not trigger a warning. Here he gets an empty array and tries to access
>> a non-existent element.
>
> My bad, here I mean empty and undefined and else not expected.
Your version of English seems to be incompatible with mine.
hp
--
_ | Peter J. Holzer | Fluch der elektronischen Textverarbeitung:
|_|_) | | Man feilt solange an seinen Text um, bis
| | | hjp@hjp.at | die Satzbestandteile des Satzes nicht mehr
__/ | http://www.hjp.at/ | zusammenpat. -- Ralph Babel
------------------------------
Date: Sun, 04 Jan 2015 17:57:49 -0800
From: "$Bill" <news@todbe.com>
Subject: Re: help,perl script
Message-Id: <54A9EF9D.7030808@todbe.com>
On 1/3/2015 21:59, salmon wrote:
> #!/usr/local/bin/perl -w
> use strict;
> use encoding "utf8", STDOUT =>"utf8";
>
> while(<>)
> {
> chomp;
> next if not ((defined $_));
> my @arr = split /\t/, $_;
> if (@arr +0 == 1)
> {
> print $_,"\n";
> next;
> }
> if( $arr[0] =~ s/(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$)//ig)
> {
>
> print STDERR $_,"\n";
> }
> print $arr[0],"\t",$arr[1],"\n";
> }
That reads like this for me:
#!/usr/local/bin/perl --
use strict;
use warnings;
use encoding "utf8", STDOUT =>"utf8";
while (<>) {
chomp;
my @arr = split /\t/, $_;
if (@arr == 1) { print "$_\n"; next; }
if (defined $arr[0] and
$arr[0] =~ /(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$)/i) {
print STDERR "$_\n";
}
printf "%s\t%s\n", defined $arr[0] ? $arr[0] : '<undef>',
defined $arr[1] ? $arr[1] : '<undef>';
}
__END__
------------------------------
Date: Mon, 05 Jan 2015 11:06:04 +0100
From: gamo <gamo@telecable.es>
Subject: Re: help,perl script
Message-Id: <m8dnmb$521$1@speranza.aioe.org>
El 05/01/15 a las 00:17, Peter J. Holzer escribi:
>> and I have years rounding about Perl.
> Yes. At least you have been posting for years in this group. Which makes
> it all the more shocking that you wouldn't know what one of the most
> common warnings means.
>
>
No, no, for me it's not common, in text context, to obtain undefined
values, because previously you read it as it appears. Numerically, it's
a lot far more easy to happen.
--
http://www.telecable.es/personales/gamo/
The generation of random numbers is too important to be left to chance
------------------------------
Date: Mon, 05 Jan 2015 14:32:03 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: help,perl script
Message-Id: <87d26t70yk.fsf@doppelsaurus.mobileactivedefense.com>
"Peter J. Holzer" <hjp-usenet3@hjp.at> writes:
> On 2015-01-04 15:48, gamo <gamo@telecable.es> wrote:
>> El 04/01/15 a las 16:20, Peter J. Holzer escribió:
>>> On 2015-01-04 15:06, gamo <gamo@telecable.es> wrote:
>>>> El 04/01/15 a las 15:53, Peter J. Holzer escribió:
>>>>> On 2015-01-04 14:43, gamo <gamo@telecable.es> wrote:
>>>>>> perl -E '$a=""; if ($a) { say "ok"; } else{ say "not ok"; };'
>>>>>
>>>>> This is not what it is happening here. He's getting a warning about an
>>>>> undefined value. An empty string doesn't produce such a warning.
>>>>
>>>> But the error do not say explicity "undefined" else it says:
>>>>
>>>> Use of uninitialized value in substitution (s///) at
>>> ^^^^^^^^^^^^^^^^^^^
>>>> scripts/rm_no_word\_char.pl line 15, <> line 30
>>>
>>> The warning is badly worded, but "uninitialized value" means undef.
>>>
>>> So, yes, it does say exactly that, if you know what the warning means,
>>> which you should know if you have been using perl for more than a month
>>> or so.
>>>
>>
>> No, I don't remember ever using the if(s///) construction,
>
> What are you talking about? The warning isn't about using s/// within
> if (why should this be special, anyway?), but about the "use of [an]
> uninitialized value". This *always* means that you are using the value
> undef in a context where a defined value is expected.
Actually, it means (as far as I can tell) that a scalar not marked as
having a value of any particular type (no flags set) is used as operand
in certain expressions (mostly, rvalue expressions). There's no chance
for anything "uninitialized" being involved here and the actual rules
are more than slightly bizarre, eg
[rw@doppelsaurus]~#perl -we 'my $b += 3'
[rw@doppelsaurus]~#perl -we 'my $b; $b = $b + 3'
Use of uninitialized value $b in addition (+) at -e line 1.
[rw@doppelsaurus]~#
OTOH,
[rw@doppelsaurus]~#perl -we 'my $b; $b = $b . 3'
[rw@doppelsaurus]~#
------------------------------
Date: Mon, 5 Jan 2015 11:25:59 -0800 (PST)
From: sharma__r@hotmail.com
Subject: Re: help,perl script
Message-Id: <68e09d7b-a040-4d1b-95f6-58b8bd3e8ae4@googlegroups.com>
On Sunday, 4 January 2015 11:29:50 UTC+5:30, salmon wrote:
> #!/usr/local/bin/perl -w
> use strict;
> use encoding "utf8", STDOUT =>"utf8";
>
> while(<>)
> {
> chomp;
> next if not ((defined $_));
> my @arr = split /\t/, $_;
> if (@arr +0 == 1)
> {
> print $_,"\n";
> next;
> }
> if( $arr[0] =~ s/(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$)//ig)
> {
>
> print STDERR $_,"\n";
> }
> print $arr[0],"\t",$arr[1],"\n";
> }
>
> Use of uninitialized value in substitution (s///) at
> scripts/rm_no_word\_char.pl line 15, <> line 30
>
The uninitialized warning is emitted because $arr[0] does not exist for certain
data points => the line was empty.
Another thing to note is that the check for defined-ness within the while loop
is pointless, since perl does that implicitly in the while(<>) loop and enters
the loop only in case of defined lines.(meaning having a trailing \n)
Actually, while(<>) is equivalent to the following long winded construct
while(defined(local $_ = <ARGV>))
I would rewrite your code as below:
#!/usr/local/bin/perl
use strict;
use warnings;
use encoding "utf8", STDOUT => "utf8";
local $\ = "\n";
while(<>) {
chomp;
next unless /\S/;
my @arr = split;
do{print;next;} if @arr == 1;
print STDERR $_
if $arr[0] =~ s/(?:(^[^0-9a-z\p{Han}]+)|([^0-9a-z\p{Han}]+$))//ig;
print join("\t",@arr[0,1]);
}
-Rakesh
------------------------------
Date: Mon, 05 Jan 2015 20:21:34 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: help,perl script
Message-Id: <3sGdnXGiP8LJbzfJnZ2dnUVZ8mCdnZ2d@giganews.com>
On 05/01/15 19:25, sharma__r@hotmail.com wrote:
> I would rewrite your code as below
Indeed. But is the OP watching? It's nearly two days since debate
started raging here and there's no sign of her/him.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 06 Jan 2015 12:11:30 +0000
From: Henry Law <news@lawshouse.org>
Subject: search.cpan.org and metacpan
Message-Id: <abadnV2nbZhuTTbJnZ2dnUVZ8qudnZ2d@giganews.com>
For some time now (weeks) I've been receiving "The page you are looking
for is temporarily unavailable." from http://search.cpan.org. I use a
local (UK) mirror http://mirror.bytemark.co.uk/CPAN/ but it doesn't seem
to mirror the search function.
https://metacpan.org/ works fine, but it doesn't seem to provide the
same information, specifically all the POD for whatever module you're
looking at.
What I want to be able to do is (1) see in a browser the documentation
for modules that aren't in the standard distribution, both those I've
installed (which don't seem to integrate with the local HTML documents);
(2) search for modules according to their function; and (3) download
the tar file for those modules that I don't want to (or can't) install
from the Ubuntu repos or by the CPAN module.
Could I have some advice on how other people do it? (And does anyone
know what the status of search.cpan.org is going to be in future? I've
searched for that too, without finding anything authoritative).
--
Henry Law Manchester, England
------------------------------
Date: Tue, 06 Jan 2015 12:16:36 +0000
From: Henry Law <news@lawshouse.org>
Subject: Re: search.cpan.org and metacpan
Message-Id: <R7OdnRbvFoO4TzbJnZ2dnUVZ7sadnZ2d@giganews.com>
On 06/01/15 12:11, Henry Law wrote:
> For some time now (weeks) I've been receiving "The page you are looking
> for is temporarily unavailable." from http://search.cpan.org.
Odder still, if I google for a particular module (GD::Graph for
example), and follow the search.cpan.org link from there, I get what I
want, at URL http://search.cpan.org/dist/GDGraph/Graph.pm ... but
http://search.cpan.org/ remains stubbornly unavailable.
There's something I'm not getting here.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 6 Jan 2015 13:21:08 +0000
From: Justin C <justin.1410@purestblue.com>
Subject: Re: search.cpan.org and metacpan
Message-Id: <434tnb-66g.ln1@zem.masonsmusic.co.uk>
On 2015-01-06, Henry Law <news@lawshouse.org> wrote:
> On 06/01/15 12:11, Henry Law wrote:
>> For some time now (weeks) I've been receiving "The page you are looking
>> for is temporarily unavailable." from http://search.cpan.org.
>
> Odder still, if I google for a particular module (GD::Graph for
> example), and follow the search.cpan.org link from there, I get what I
> want, at URL http://search.cpan.org/dist/GDGraph/Graph.pm ... but
> http://search.cpan.org/ remains stubbornly unavailable.
>
> There's something I'm not getting here.
search.cpan.org is provided by a 3rd party, and it's closed source
the perl community don't have any access/control over it. It's an
interface to CPAN, as you found with your googling and finding a
direct link to the CPAN resource.
You just need to find another way in. metacpan is quite useful in
that respect - I'm not sure how it would be showing you different
docs to clicking a result in search.cpan.org, they're both getting
their data from CPAN.
Justin.
--
Justin C, by the sea.
------------------------------
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 4343
***************************************