[31283] in Perl-Users-Digest
Perl-Users Digest, Issue: 2528 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 24 21:09:42 2009
Date: Fri, 24 Jul 2009 18:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 24 Jul 2009 Volume: 11 Number: 2528
Today's topics:
computers and laptops <adnancreativ03@gmail.com>
cpan keeps asking: "Is it OK to try to connect to the I <ignoramus2408@NOSPAM.2408.invalid>
Re: cpan keeps asking: "Is it OK to try to connect to t <smallpond@juno.com>
Re: FAQ 6.23 How can I match strings with multibyte cha <O_TEXT@nospam.fr>
Re: FAQ 6.23 How can I match strings with multibyte cha <hjp-usenet2@hjp.at>
Re: Format a number with any leading arbitrary characte <smallpond@juno.com>
Re: Format a number with any leading arbitrary characte <someone@example.com>
Re: Format a number with any leading arbitrary characte sln@netherlands.com
Re: Format a number with any leading arbitrary characte jidanni@jidanni.org
Re: Format a number with any leading arbitrary characte sln@netherlands.com
Re: Format a number with any leading arbitrary characte <smallpond@juno.com>
Re: Format a number with any leading arbitrary characte sln@netherlands.com
Re: if .. then .. else shorthand problem <ben@morrow.me.uk>
Re: moving a match into a subroutine sln@netherlands.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 24 Jul 2009 04:56:12 -0700 (PDT)
From: Adnan Hafeez <adnancreativ03@gmail.com>
Subject: computers and laptops
Message-Id: <916786b0-9d44-46b3-81a4-2d480e7d2bd7@q40g2000prh.googlegroups.com>
my site have all the latest information about larest models of desktop
and laptops computers and accessorries do visit it.
http://acr-computerandlaptops.blogspot.com/
------------------------------
Date: Fri, 24 Jul 2009 09:03:46 -0500
From: Ignoramus2408 <ignoramus2408@NOSPAM.2408.invalid>
Subject: cpan keeps asking: "Is it OK to try to connect to the Internet?"
Message-Id: <aPSdnQr4D-rfIvTXnZ2dnUVZ_hidnZ2d@giganews.com>
I have perl 5.10.0. Whenever I would invoke cpan to install modules,
it would ask me "Is it OK to try to connect to the Internet?".
I want to disable that question and always assume that the answer is
"yes".
I found some discussions of flag "connect_to_internet_ok", but it does
not seem to be in the list of my options if I enumerate them with "o
conf".
So, how can I disable this annoying question "Is it OK to try to
connect to the Internet?".
thanks
i
------------------------------
Date: Fri, 24 Jul 2009 10:59:18 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: cpan keeps asking: "Is it OK to try to connect to the Internet?"
Message-Id: <h4cil8$tm3$1@news.eternal-september.org>
Ignoramus2408 wrote:
> I have perl 5.10.0. Whenever I would invoke cpan to install modules,
> it would ask me "Is it OK to try to connect to the Internet?".
>
> I want to disable that question and always assume that the answer is
> "yes".
>
> I found some discussions of flag "connect_to_internet_ok", but it does
> not seem to be in the list of my options if I enumerate them with "o
> conf".
>
> So, how can I disable this annoying question "Is it OK to try to
> connect to the Internet?".
>
> thanks
>
> i
vi CPAN.pm
/connect to the Internet
then change:
my $answer = CPAN::Shell::colorable_makemaker_prompt("Is it OK to try to connect to the Internet?", "yes");
to:
# my $answer = CPAN::Shell::colorable_makemaker_prompt("Is it OK to try to connect to the Internet?", "yes");
my $answer = "yes"; # why else would I be running CPAN?
------------------------------
Date: Fri, 24 Jul 2009 15:45:46 +0200
From: O_TEXT <O_TEXT@nospam.fr>
Subject: Re: FAQ 6.23 How can I match strings with multibyte characters?
Message-Id: <h4cdua$1jcf$1@saria.nerim.net>
PerlFAQ Server a =E9crit :
(...)
> These postings aim to=20
> reduce the number of repeated questions as well as allow the community
> to review and update the answers. The latest version of the complete
> perlfaq is at http://faq.perl.org .
>=20
> --------------------------------------------------------------------
>=20
> 6.23: How can I match strings with multibyte characters?
>=20
> Starting from Perl 5.6 Perl has had some level of multibyte charact=
er
> support. Perl 5.8 or later is recommended. Supported multibyte char=
acter
> repertoires include Unicode, and legacy encodings through the Encod=
e
> module. See perluniintro, perlunicode, and Encode.
>=20
(...)
> Let's suppose you have some weird Martian encoding where pairs of A=
SCII
> uppercase letters encode single Martian letters (i.e. the two bytes=
"CV"
> make a single Martian letter, as do the two bytes "SG", "VS", "XX",=
> etc.). Other bytes represent single characters, just like ASCII.
Hello,
As I try to write a piece of code nor for USA --or any other english
speaking country-- nor for mars, so I do not use nor ASCII nor Martian
encoding. As this software should work on Earth it just need to handle
characters humans use, I mean unicode characters.
In practice,
I would like to search for a sequence of unicode characters
(independently of technical details such as the number of bytes a
character is encoded in), from a perl script written in perl language.
Searched sequences take a form such as
=AB=E0 v=E9r=BB with or without tilde/accent, and with a variable number =
of spaces.
For instance, following sequences should match:
-=E0 v=E9r
-=E0 ver
-a ver
-a v=E9r
-=E0 v=E9r
To match those patterns I writed both regular expressions in Perl langage=
:
[\x{00e0}a]\s+(?:v[\x{00e9}e]r
or:
[\N{LATIN SMALL LETTER A WITH GRAVE}a]\s+(?:v[\N{LATIN SMALL LETTER E
WITH ACUTE}e]r
This seems working, however...
however when script is obfuscated with stunnix perl ofuscator original
Perl code is translated to folloing Perl code which does not seam workin=
g:
[\x00e0a]\s+(?:v[\x00e9e]r
[\303\240a]\s+(?:v[\303\251e]r
So, here is my question: is it possible to search for unicode characters
from a Perl script obfuscated by stunnix tool?
------------------------------
Date: Fri, 24 Jul 2009 20:47:55 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: FAQ 6.23 How can I match strings with multibyte characters?
Message-Id: <slrnh6k0es.6ja.hjp-usenet2@hrunkner.hjp.at>
On 2009-07-24 13:45, O_TEXT <O_TEXT@nospam.fr> wrote:
> In practice,
> I would like to search for a sequence of unicode characters
> (independently of technical details such as the number of bytes a
> character is encoded in), from a perl script written in perl language.
> Searched sequences take a form such as
> «ŕ vér» with or without tilde/accent, and with a variable number of spaces.
>
> For instance, following sequences should match:
> -ŕ vér
> -ŕ ver
> -a ver
> -a vér
> -ŕ vér
>
> To match those patterns I writed both regular expressions in Perl langage:
> [\x{00e0}a]\s+(?:v[\x{00e9}e]r
> or:
> [\N{LATIN SMALL LETTER A WITH GRAVE}a]\s+(?:v[\N{LATIN SMALL LETTER E
> WITH ACUTE}e]r
>
> This seems working, however...
> however when script is obfuscated with stunnix perl ofuscator original
> Perl code is translated to folloing Perl code which does not seam working:
> [\x00e0a]\s+(?:v[\x00e9e]r
Looks like the stunnix perl ofuscator doesn't convert the \N notation
correctly. This should read:
[\x{00e0}a]\s+(?:v[\x{00e9}e]r
(plus the missing parenthesis, of course). Report the bug to stunnix.
hp
------------------------------
Date: Fri, 24 Jul 2009 10:40:43 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Format a number with any leading arbitrary character
Message-Id: <h4chid$mpe$1@news.eternal-september.org>
jidanni@jidanni.org wrote:
> $ perldoc -f sprintf
> # Format number with up to 8 leading zeroes
> $result = sprintf("%08d", $number);
> OK, but how do I do
> # Format number with up to 8 leading underscores
> or any arbitrary character?
> OK, I figured it out,
> $ perl -wle '$_ = "00000050"; print; while (s/(^0*)0/$1_/) { }; print;'
> 00000050
> ______50
> Geez.
Use tr for character-to-character mapping.
perl -e '$_ = sprintf "%8d",50; tr/ /_/; print'
______50
------------------------------
Date: Fri, 24 Jul 2009 09:37:27 -0700
From: "John W. Krahn" <someone@example.com>
Subject: Re: Format a number with any leading arbitrary character
Message-Id: <arlam.58290$rg4.18663@newsfe02.iad>
jidanni@jidanni.org wrote:
> $ perldoc -f sprintf
> # Format number with up to 8 leading zeroes
> $result = sprintf("%08d", $number);
> OK, but how do I do
> # Format number with up to 8 leading underscores
> or any arbitrary character?
> OK, I figured it out,
> $ perl -wle '$_ = "00000050"; print; while (s/(^0*)0/$1_/) { }; print;'
> 00000050
> ______50
$ perl -wle '$_ = 50; print; substr $_, 0, 0, "_" x ( 8 - length ); print;'
50
______50
John
--
Those people who think they know everything are a great
annoyance to those of us who do. -- Isaac Asimov
------------------------------
Date: Fri, 24 Jul 2009 11:03:30 -0700
From: sln@netherlands.com
Subject: Re: Format a number with any leading arbitrary character
Message-Id: <m8tj651idsf7nfe6etg976b53hma6o16oj@4ax.com>
On Fri, 24 Jul 2009 04:24:24 +0800, jidanni@jidanni.org wrote:
>$ perldoc -f sprintf
> # Format number with up to 8 leading zeroes
> $result = sprintf("%08d", $number);
>OK, but how do I do
> # Format number with up to 8 leading underscores
>or any arbitrary character?
>OK, I figured it out,
>$ perl -wle '$_ = "00000050"; print; while (s/(^0*)0/$1_/) { }; print;'
>00000050
>______50
>Geez.
I guess you could still use printf without having to do regex.
Following the 8-length strategy:
perl -wle "$_ = 50; print; printf (\"%s%d\", '_' x (8 - length), $_);"
50
______50
Or, it could be generalized:
----------------------
use strict;
use warnings;
my $number = 5000;
my $result = sprintf ("%s%d", '_' x (8 - length $number), $number);
print "$number\n$result\n";
printf ("%s%d \n", fmt('_',13,$number), $number);
printf ("%s%d \n", fmt('_',2,$number), $number);
printf ("%s%d \n", fmt(',',13,$number), $number);
sub fmt {
$_[0] x ($_[1] - length $_[2])
}
__END__
5000
____5000
_________5000
5000
,,,,,,,,,5000
--------------------
-sln
------------------------------
Date: Sat, 25 Jul 2009 02:17:12 +0800
From: jidanni@jidanni.org
Subject: Re: Format a number with any leading arbitrary character
Message-Id: <878wieaqtz.fsf@jidanni.org>
I declare
>>>>> "SC" == Steve C <smallpond@juno.com> writes:
SC> Use tr for character-to-character mapping.
SC> perl -e '$_ = sprintf "%8d",50; tr/ /_/; print'
SC> ______50
the winner, for simplest answer. As far as
> perldoc -f substr
> Hint: B<substr()> returns l-value.
well, "it's probably an even better answer".
------------------------------
Date: Fri, 24 Jul 2009 11:38:58 -0700
From: sln@netherlands.com
Subject: Re: Format a number with any leading arbitrary character
Message-Id: <iuuj65pkepdg4kb73ccaatn7d78he4bngf@4ax.com>
On Fri, 24 Jul 2009 04:24:24 +0800, jidanni@jidanni.org wrote:
>$ perldoc -f sprintf
> # Format number with up to 8 leading zeroes
> $result = sprintf("%08d", $number);
>OK, but how do I do
> # Format number with up to 8 leading underscores
>or any arbitrary character?
>OK, I figured it out,
>$ perl -wle '$_ = "00000050"; print; while (s/(^0*)0/$1_/) { }; print;'
>00000050
>______50
>Geez.
But err, still though, you don't need printf or the regex for what your
problem statement is. Unless you doing some other conversions at the same time.
It really has nothing to do with a 'number' at this point given Perl variable
transparency, it only has to do with formatting of data.
perl -wle "$_ = 50; print; print '_' x (8 - length), $_;"
50
______50
If you were to be using printf for some different formatting then all
bets are off and you will need post printf processing, probably with a regex.
Or, just simply:
$result = sprintf("%s is a char padded integer, %3.2f is a formatted float", '_' x (8 - length $number), $float);
-sln
------------------------------
Date: Fri, 24 Jul 2009 14:43:03 -0400
From: Steve C <smallpond@juno.com>
Subject: Re: Format a number with any leading arbitrary character
Message-Id: <h4cvot$obo$1@news.eternal-september.org>
jidanni@jidanni.org wrote:
> I declare
>>>>>> "SC" == Steve C <smallpond@juno.com> writes:
> SC> Use tr for character-to-character mapping.
> SC> perl -e '$_ = sprintf "%8d",50; tr/ /_/; print'
> SC> ______50
> the winner, for simplest answer. As far as
>> perldoc -f substr
>> Hint: B<substr()> returns l-value.
> well, "it's probably an even better answer".
Yeah. I like substr better, too. Why generate the wrong
value and translate when you can generate the right thing
in one step?
------------------------------
Date: Fri, 24 Jul 2009 11:53:25 -0700
From: sln@netherlands.com
Subject: Re: Format a number with any leading arbitrary character
Message-Id: <740k659ot880j2c1sf87lila27f1reuabk@4ax.com>
On Sat, 25 Jul 2009 02:17:12 +0800, jidanni@jidanni.org wrote:
>I declare
>>>>>> "SC" == Steve C <smallpond@juno.com> writes:
>SC> Use tr for character-to-character mapping.
>SC> perl -e '$_ = sprintf "%8d",50; tr/ /_/; print'
>SC> ______50
>the winner, for simplest answer. As far as
>> perldoc -f substr
>> Hint: B<substr()> returns l-value.
>well, "it's probably an even better answer".
Its not only simple, its unessesary. Why call sprintf and tr///
at all ?
'_' x (8-length) . $_
-sln
------------------------------
Date: Sat, 25 Jul 2009 00:46:42 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: if .. then .. else shorthand problem
Message-Id: <2otpj6-v2t2.ln1@osiris.mauzo.dyndns.org>
Quoth Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>:
> In <2a20.4a65cee6.826b8@zem>, on 07/21/2009
> at 02:21 PM, Justin C <justin.0903@purestblue.com> said:
>
> >if ( (($weight - 30) - (int($weight) - 30)) != 0 ) {
> > ( ($weight - int($weight)) < 0.5 ) ? $half_kilos += 1 : $half_kilos
> >+= 2;
> > print "$half_kilos\n";
> >}
>
> That evaluates both "$half_kilos += 1" and "$half_kilos += 2", then
> selects the appropriate value. What you need to do is to use the ternary
> operator with operands that have no side effects, as in the code suggested
> by J. Gleixner.
Not in Perl you don't:
~% perl -le'
$x = 1;
($x == 1) ? ($x += 1) : ($x += 2);
print $x'
2
~%
You do need to get your precedence correct, however:
~% perl -MO=Deparse,-p -e'($x == 1) ? $x += 1 : $x += 2'
((($x == 1) ? ($x += 1) : $x) += 2);
-e syntax OK
~%
(the ($x == 1) in both cases is to defeat the optimizer).
It is, however, generally considered bad style to use a ?: operator in
void context (that is, when you're ignoring the return value). I've
sometimes wondered how hard it would be to add an 'else' low-precedence
logical operator, so you could write
$x == 1
and $x += 1
else $x += 2;
Ben
------------------------------
Date: Fri, 24 Jul 2009 13:24:02 -0700
From: sln@netherlands.com
Subject: Re: moving a match into a subroutine
Message-Id: <kl5k65pi3cevdvj4hq6jinduo81olim7io@4ax.com>
On 16 Jul 2009 11:15:56 GMT, ram@zedat.fu-berlin.de (Stefan Ram) wrote:
> I want to have the match »something =~ /(.)/g« to be kept in a
> separate subroutine, because then, I can keep this at the
> start of my script. (I like to collect those parts of my
> script that I change often there.)
>
> However, as one can see from the script below, my first attempt
> (exhibit 0) does not work, it only prints empty lines.
>
> When I do not use a subroutine (exhibit 1), the behavior is as
> wanted: it prints lines with »a«, »b«, and »c«.
>
> Can I put the match »something =~ /(.)/g« in a separate
> source code entity that can be moved to the top of my script
> (like a subroutine) and still get the behavior of exhibit 1?
>
>#!/usr/bin/perl
>#perl 5.8.3
>
>use strict;
>use warnings;
>
>my $text = "abc";
>
># exhibit 0
>sub match($){ $_[0] =~ /(.)/g }
>while( match( $text ))
>{ print $1, "\n"; }
>
># exhibit 1
>while( $text =~ /(.)/g )
>{ print $1, "\n"; }
The other posters pointed out your problem.
Probably thier two solutions can be combined into 1.
------------------------------
use strict;
use warnings;
my $text = "abc";
my $val;
sub match($) {
return $_[0] =~ /./g if wantarray;
$_[0] =~ /(.)/g;
$1; # <-- goes out of scope here, just return its value
}
# Scalar context, multiple match() calls
print "$val\n" while ( $val = match( $text ));
print '-' x 20, "\n"; # pos($text) is reset after failed match (unless \G)
# List context, single match() call
print "$_\n" for ( match( $text ));
---------------------------------
-sln
------------------------------
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 2528
***************************************