[30060] in Perl-Users-Digest
Perl-Users Digest, Issue: 1303 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 25 00:09:46 2008
Date: Sun, 24 Feb 2008 21:09:09 -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, 24 Feb 2008 Volume: 11 Number: 1303
Today's topics:
Re: checking for duplicates in a string <john1949@yahoo.com>
Re: CPAN and man page installation <vincent+news@vinc17.org>
Re: Get an arbitrary hash key, quickly. <socyl@987jk.com.invalid>
hash <newsgroups@free.fr.invalid>
Re: hash <tadmc@seesig.invalid>
How to get an account at cpan.org? <alodiaf@yahoo.de>
Re: How to get an account at cpan.org? <ben@morrow.me.uk>
Is DBI prepare() statement enough for SQL injection? <howachen@gmail.com>
Re: Long line in perl script <mailursubbu@gmail.com>
Re: PL/Perl: when to set @INC? <tadmc@seesig.invalid>
Re: PL/Perl: when to set @INC? <socyl@987jk.com.invalid>
pregunrta kind.loud.912801@gmail.com
Re: pregunrta <yankeeinexile@gmail.com>
Re: setting %ENV in a module <pgodfrin@gmail.com>
Re: Storing references in a hash - why does Perl compla <ro.naldfi.scher@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 24 Feb 2008 11:31:41 -0000
From: "John" <john1949@yahoo.com>
Subject: Re: checking for duplicates in a string
Message-Id: <jZOdnR8X4d0HyFzanZ2dneKdnZydnZ2d@eclipse.net.uk>
"Ben Morrow" <ben@morrow.me.uk> wrote in message
news:62p695-mc2.ln1@osiris.mauzo.dyndns.org...
>
> Quoth Gunnar Hjalmarsson <noreply@gunnar.cc>:
>> John wrote:
>> > Consider a string $packed consisting of "AAXYGHDRJKYYXYZZGH"
>> > This represent items of two chars eg AA XY GH etc.
>> > I need to remove duplicates.
>> > I can do it by 'unpacking' and repacking using two loops such as
>> >
>> > for (my $j=0; $j<$total; $j=$j+2) {
>> > my $part1=substr($packed,$j,2);
>
> Hmm... even if you *did* want to unpack, this is a bad way to do it.
> Gunnar's /../g is much better, and unpack '(A2)*' better again.
>
>> > etc etc.
>> >
>> > But is there a better, dare I say, elegant, way?
>>
>> my $packed = 'AAXYGHDRJKYYXYZZGH';
>> my %seen;
>> print join(' ', map $seen{$_}++ ? () : $_, $packed =~ /../g), "\n";
>
> That still unpacks and repacks.
>
> s/(..)/$seen{$1}++ ? '' : $1/ge;
>
> Ben
>
Many thanks. It is taken me most of the morning to work out why it works,
but it does.
Thanks again
John
------------------------------
Date: Sun, 24 Feb 2008 16:20:15 +0000 (UTC)
From: Vincent Lefevre <vincent+news@vinc17.org>
Subject: Re: CPAN and man page installation
Message-Id: <20080224161434$4af3@prunille.vinc17.org>
In article <fs1795-663.ln1@osiris.mauzo.dyndns.org>,
Ben Morrow <ben@morrow.me.uk> wrote:
> export PERL_MM_OPT="INSTALLMAN1DIR=$HOME/man/man1
> INSTALLMAN3DIR=$HOME/man/man3"
I've added
$ENV{'PERL_MM_OPT'} = 'INSTALLMAN1DIR=~/man/man1 INSTALLMAN3DIR=~/man/man3';
to my .cpan/CPAN/MyConfig.pm file, but I still get the same error.
It seems that this environment variable isn't taken into account.
FYI, I already have the following:
cpan> o conf
CPAN::Config options and /home/vlefevre/.cpan/CPAN/MyConfig.pm:
commit Commit changes to disk
defaults Reload defaults from disk
init Interactive setting of all options
build_cache 10
build_dir /home/vlefevre/.cpan/build
bzip2 /bin/bzip2
cache_metadata 1
cpan_home /home/vlefevre/.cpan
curl /usr/bin/curl
dontload_hash
ftp /usr/bin/ftp
ftp_passive 1
ftp_proxy
getcwd cwd
gpg /usr/bin/gpg
gzip /bin/gzip
histfile /home/vlefevre/.cpan/histfile
histsize 100
http_proxy
inactivity_timeout 0
index_expire 1
inhibit_startup_message 0
installman1dir /home/vlefevre/man/man1
installman3dir /home/vlefevre/man/man3
keep_source_where /home/vlefevre/.cpan/sources
lynx /usr/bin/lynx
make /usr/bin/make
make_arg -j2
make_install_arg UNINST=1
make_install_make_command /usr/bin/make
makepl_arg LIB=~/lib/site_perl INSTALLMAN1DIR=~/man/man1 INSTALLMAN3DIR=~/man/man3
mbuild_arg
mbuild_install_arg --uninst 1
mbuild_install_build_command ./Build
mbuildpl_arg
ncftpget /usr/bin/ncftpget
no_proxy
pager less -is
prefer_installer EUMM
prerequisites_policy ask
scan_cache atstart
shell /usr/bin/zsh
show_upload_date 1
tar /bin/tar
term_is_latin 1
unzip /usr/bin/unzip
urllist
http://cpan.cict.fr/
http://cpan.mirrors.easynet.fr/
ftp://ftp.pasteur.fr/pub/computing/CPAN/
ftp://ftp.u-strasbg.fr/CPAN
wget /usr/bin/wget
--
Vincent Lefèvre <vincent@vinc17.org> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
------------------------------
Date: Sun, 24 Feb 2008 20:37:40 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: Get an arbitrary hash key, quickly.
Message-Id: <fpskik$7n1$1@reader2.panix.com>
In <20080223210702.865$Dq@newsreader.com> xhoster@gmail.com writes:
>I'm not keen on using "scalar %hash", as it is more esoteric than
>"scalar keys %hash". And using the next to cause they "each" to reboot
>when it delivers an undefined value is more subtle than I care for.
Still, using foreach in the inner loop is unnecessary use of memory.
What's wrong with
while ( keys %hash ) {
while ( my $to_do = each %hash ) {
delete $hash{ $to_do };
# etc.
}
}
?
Or perhaps this expresses the intentions more clearly:
{
while ( my $to_do = each %hash ) {
delete $hash{ $to_do };
# etc.
}
redo if keys %hash;
}
kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Sun, 24 Feb 2008 15:43:54 +0100
From: Newsgroups <newsgroups@free.fr.invalid>
Subject: hash
Message-Id: <1203864234.5612.12.camel@localhost>
Hi everybody,
I can't make sense of my little perl script ; I've no idea where the
probleme is... could you give me a way to understand...
I've this short code :
use strict;
use Data::Dumper;
use Lingua::Identify qw/:language_identification/;
my %probabilities;
my %languages = langof_file("test.txt");
print Dumper(%languages);
it print the text in the console :
$VAR1 = 'pt';
$VAR2 = '0.0299573389196567';
$VAR3 = 'tr';
$VAR4 = '0.0152319153730931';
$VAR5 = 'da';
$VAR6 = '0.0359140188331814';
.../...
But, I want an output like this one :
$VAR1 = {
'pt' => '0.0299573389196567',
'tr' => '0.0152319153730931',
'es' => '0.0403864688211945',
'da' => '0.0359140188331814',
};
What's wrong ?
------------------------------
Date: Sun, 24 Feb 2008 08:40:48 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: hash
Message-Id: <slrnfs30fg.kbu.tadmc@tadmc30.sbcglobal.net>
Newsgroups <newsgroups@free.fr.invalid> wrote:
> Hi everybody,
>
> I can't make sense of my little perl script ; I've no idea where the
> probleme is... could you give me a way to understand...
>
> I've this short code :
> use strict;
> use Data::Dumper;
> use Lingua::Identify qw/:language_identification/;
>
> my %probabilities;
> my %languages = langof_file("test.txt");
>
> print Dumper(%languages);
>
> it print the text in the console :
> $VAR1 = 'pt';
> $VAR2 = '0.0299573389196567';
> $VAR3 = 'tr';
> $VAR4 = '0.0152319153730931';
> $VAR5 = 'da';
> $VAR6 = '0.0359140188331814';
> .../...
>
>
> But, I want an output like this one :
>
> $VAR1 = {
> 'pt' => '0.0299573389196567',
> 'tr' => '0.0152319153730931',
> 'es' => '0.0403864688211945',
> 'da' => '0.0359140188331814',
> };
>
> What's wrong ?
Pass Dumper() a reference rather than a list of keys and values:
print Dumper \%languages;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 24 Feb 2008 22:15:53 +0100
From: "Alos Diaf" <alodiaf@yahoo.de>
Subject: How to get an account at cpan.org?
Message-Id: <op.t61r0txvxx9xny@hope>
hi,
wanna publish a module,
have to register at pause,
want to use a myname@cpan.org, who can i get such?
thx.
------------------------------
Date: Mon, 25 Feb 2008 00:34:42 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to get an account at cpan.org?
Message-Id: <22f995-a16.ln1@osiris.mauzo.dyndns.org>
Quoth "Alos Diaf" <alodiaf@yahoo.de>:
>
> wanna publish a module,
> have to register at pause,
> want to use a myname@cpan.org, who can i get such?
See http://pause.perl.org/pause/query?ACTION=request_id .
You need a (non-cpan) email address, but this can be completely private
(not published anywhere).
Ben
------------------------------
Date: Sun, 24 Feb 2008 19:00:54 -0800 (PST)
From: howa <howachen@gmail.com>
Subject: Is DBI prepare() statement enough for SQL injection?
Message-Id: <c103cf1e-5a86-419c-b61c-d5f54317778a@s12g2000prg.googlegroups.com>
I have just found a simple cases, which is not, e.g.
#--------------------------------------------------
use strict;
use DBI;
use Data::Dumper;
my $dbh = DBI-
>connect("DBI:mysql:database=information_schema;host=localhost","root","",
{ RaiseError => 1, AutoCommit => 1 });
my $input = "%a"; # User hack by using wildcard
my $sth = $dbh->prepare("SELECT * FROM `CHARACTER_SETS` WHERE
`CHARACTER_SET_NAME` LIKE ? ") ;
$sth->execute( $input . "%") ; # Originally you let the user search by
prefix
while ( my $data = $sth->fetchrow_hashref() ) {
print Dumper $data;
}
#--------------------------------------------------
So we should not 100% believe in prepare() which make you100% SQL
injection free.
Any other cases want to share?
Howard
------------------------------
Date: Sun, 24 Feb 2008 20:39:35 -0800 (PST)
From: Subra <mailursubbu@gmail.com>
Subject: Re: Long line in perl script
Message-Id: <bf60433c-c926-436c-83e8-f89128289bfa@d21g2000prf.googlegroups.com>
On Feb 23, 7:16 pm, "Petr Vileta" <sto...@practisoft.cz> wrote:
> John W. Krahn wrote:
> > Petr Vileta wrote:
>
> >> Subra wrote:
>
> >>> Is there any special character like in C (\) which I should put at
> >>> the end of the broken line ????
>
> >> You can wrap line at any space in your long line. Example:
>
> >> if ($settings->{$service_name}->{'pin_home_dir'} ||
> >> $settings->{$service_type}->{'pin_home_dir'}) {
>
> > It doesn't even have to be at a space:
>
> > $ perl -MData::Dumper -le'$w->{x}->{y}->{z} = "hello"; print Dumper
> > $w' $VAR1 = {
> > 'x' => {
> > 'y' => {
> > 'z' => 'hello'
> > }
> > }
> > };
>
> > $ perl -MData::Dumper -le'
> > $w
> > ->
> > {x}
> > ->
> > {y}
> > ->
> > {z}
> > =
> > "hello";
> > print Dumper $w'
> > $VAR1 = {
> > 'x' => {
> > 'y' => {
> > 'z' => 'hello'
> > }
> > }
> > };
>
> Yes, of course, but wrapping line at space (or tab) is better readable for
> human and for perl novice too ;-)
> --
> Petr Vileta, Czech republic
> (My server rejects all messages from Yahoo and Hotmail. Send me your
> mail from another non-spammer site please.)
>
> Please reply to <petr AT practisoft DOT cz>
Thanks one and all for making it clear....
------------------------------
Date: Sat, 23 Feb 2008 21:50:39 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: PL/Perl: when to set @INC?
Message-Id: <slrnfs1qcf.hno.tadmc@tadmc30.sbcglobal.net>
kj <socyl@987jk.com.invalid> wrote:
> I'd like these procedures to be able to load
> Perl modules that reside outside the paths in the default @INC, so
> I'd like to modify @INC appropriately as soon as possible after
> the PostgreSQL server is started.
>
> Does anyone know how to do this?
perldoc -q INC
How do I add a directory to my include path (@INC) at runtime?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Sun, 24 Feb 2008 17:08:53 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Re: PL/Perl: when to set @INC?
Message-Id: <fps8b4$kuk$1@reader2.panix.com>
In <slrnfs1qcf.hno.tadmc@tadmc30.sbcglobal.net> Tad J McClellan <tadmc@seesig.invalid> writes:
>kj <socyl@987jk.com.invalid> wrote:
>> I'd like these procedures to be able to load
>> Perl modules that reside outside the paths in the default @INC, so
>> I'd like to modify @INC appropriately as soon as possible after
>> the PostgreSQL server is started.
>>
>> Does anyone know how to do this?
> perldoc -q INC
> How do I add a directory to my include path (@INC) at runtime?
Not what I was trying to find out, but maybe this is not the right
forum for my question... My apologies.
kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Sun, 24 Feb 2008 10:03:39 -0800 (PST)
From: kind.loud.912801@gmail.com
Subject: pregunrta
Message-Id: <b6b4cc4c-60f5-4347-abc2-6331ee79c1f3@k2g2000hse.googlegroups.com>
como puedo utilizar el mause en turbo pascal y buscar los espacios en
blanco ejemplo: al realizar un juego de numeros que tienen que caer en
la matriz que ocupa 50 espacios luego eliminarlos cuando tienen 3 =F3
mas numeros iguales(1,1,1,1) y en los lugares basillos caigan los que
estan sobre de ellos.
gracias si me dan alguna idea se los agradecere bastante
------------------------------
Date: 24 Feb 2008 17:08:10 -0600
From: Lawrence Statton <yankeeinexile@gmail.com>
Subject: Re: pregunrta
Message-Id: <877igut0kl.fsf@hummer.cluon.com>
kind.loud.912801@gmail.com writes:
> gracias si me dan alguna idea se los agradecere bastante
Y que de pregunta tiene de ver con Perl? Mejor busca en un grupo de
usuarios de Turbo Pascal.
--
Lawrence Statton - lawrenabae@abaluon.abaom s/aba/c/g
Computer software consists of only two components: ones and
zeros, in roughly equal proportions. All that is required is to
place them into the correct order.
------------------------------
Date: Sun, 24 Feb 2008 19:45:12 -0800 (PST)
From: pgodfrin <pgodfrin@gmail.com>
Subject: Re: setting %ENV in a module
Message-Id: <b55664f2-4f93-4239-bdc8-d67be05291ba@i29g2000prf.googlegroups.com>
...snip...
> I would capture these into variables rather than using $N. Here you also
> need to substitute for $vars in the replacement. This is a rather crude
> version; it doesn't honour proper shell quoting, though it does allow \$
> for a literal $. If you need real shell interpolation, it's probably
> easiest to feed it to /bin/sh with 'exec /usr/bin/env' stuck on the end,
> and parse the output.
>
> if (my ($var, $value) = /^ export \s+ (\w+) = (.+)/x) {
> for ($value) {
> s/ (?<! \\ ) \$ (\w+) /$ENV{$1}/gx;
> s/ \\ (.) /$1/gx;
> }
>
> Ben
Hi Ben,
You da MAN! I still don't understand the "zero-width negative look-
behind assertion" you're using, nor anything about how that regular
expression works, but you've solved this problem (wow!):
Here are the results:
package Mymod;
use strict;
use warnings;
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK);
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(setrun);
sub setrun
{
my($evf)=@_ ;
my($RVARS,$e,$v);
open $RVARS,"<","$evf" or die "Can't open input: $evf\n";
foreach (<$RVARS>)
{
if (($e,$v) = /^export\s+(\w+)=(.+)/)
{
for ($v)
{
s/(?<!\\)\$(\w+)/$ENV{$1}/g;
s/\\(.)/$1/g;
}
$ENV{$e}=$v;
}
} # end foreach
close $RVARS;
return 1;
} # end setenv
1;
#!/usr/bin/perl
use warnings;
no warnings 'once';
use Env;
#Env::import;
#use MymodSimp2 ;
use Mymod;
setrun("etfile");
print "TMPTEST: $ENV{TMPTEST}\n";
print "TMPTOO: $ENV{TMPTOO}\n";
print "Now with scalar vars...\n";
Env::import;
print "TMPTEST: $TMPTEST\n";
print "TMPTOO: $TMPTOO\n";
exit;
[pgodfrin:~/perl/et]> envtest
TMPTEST: /tmp
TMPTOO: /tmp
Now with scalar vars...
TMPTEST: /tmp
TMPTOO: /tmp
I'll try to figure out the RE but ... wow!
thanks,
pg
------------------------------
Date: Sun, 24 Feb 2008 04:34:45 -0800 (PST)
From: Ronny <ro.naldfi.scher@gmail.com>
Subject: Re: Storing references in a hash - why does Perl complain here?
Message-Id: <54c2f5a4-fced-4aca-821a-def1f2d47832@e60g2000hsh.googlegroups.com>
On Feb 23, 2:45 pm, Jeremy Nixon <~$!~( )@( )u.defocus.net> wrote:
> Ronny <ro.naldfi.sc...@gmail.com> wrote:
> > my %uts={};
> > $uts{X}={};
>
> > Perl 5.8.6 complains:
>
> > "Reference found where even-sized list expected"
>
> > Now I don't question the *content* of this sentence (actually, {} *is*
> > a reference), but I wonder
> > why Perl insists in having something like
>
> > $uts{X}=();
>
> > instead.
>
> It's not complaining about that, it's complaining about the line before it,
> which should be
>
> my %uts = ();
>
> Or simply
>
> my %uts;
Of course, you are right!!!! Thank you for pointing this out!
Ronald
------------------------------
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 1303
***************************************