[32150] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 3415 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 15 09:09:40 2011

Date: Wed, 15 Jun 2011 06:09:05 -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           Wed, 15 Jun 2011     Volume: 11 Number: 3415

Today's topics:
        Catastrophic regexp performance with grouping. <alessandro.forghieri@gmail.com>
    Re: How initialize an array to 0's? sln@netherlands.com
    Re: How initialize an array to 0's? sln@netherlands.com
    Re: How initialize an array to 0's? <uri@StemSystems.com>
    Re: How initialize an array to 0's? (David Canzi)
    Re: How initialize an array to 0's? <uri@StemSystems.com>
    Re: How initialize an array to 0's? (David Canzi)
    Re: How initialize an array to 0's? <tzz@lifelogs.com>
    Re: How initialize an array to 0's? sln@netherlands.com
    Re: How initialize an array to 0's? <willem@toad.stack.nl>
    Re: How initialize an array to 0's? <uri@StemSystems.com>
        Regexp help to understand <mikaelpetterson@hotmail.com>
    Re: Scherz am Rande (Alan Curry)
    Re: Scherz am Rande <tzz@lifelogs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 15 Jun 2011 06:07:14 -0700 (PDT)
From: alf <alessandro.forghieri@gmail.com>
Subject: Catastrophic regexp performance with grouping.
Message-Id: <04d3b545-c59e-42f2-b2a8-ea882cb5aab7@glegroupsg2000goo.googlegroups.com>

Greetings.

Consider the follwing code (5.8.8, perl -V follows):
my $strf;
{
local $/=3Dundef;
$strf=3D<$ARGV[0]>;=20
}
$strf =3D~ s/(?:\s*\r?\n?)*\cL/\cL/gx;
# $strf =3D~ s/(\s*\r?\n?)*\cL/\cL/g;                                      =
                                                                           =
             =20

When the second (commented) form of the regexp is used, it becomes about 30=
0 times slower (less than 1 sec vs. 4 minutes on a 36894 lines file). Now I=
 know that grouping (which is not even needed in the above) pays a price, b=
ut this seems pathological...ridiculus even.

Anybody cares to explain? =20

Cheers,
alf

Versione details follow:

 perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=3Dlinux, osvers=3D2.6.18-53.el5, archname=3Di386-linux-thread-mu=
lti
    uname=3D'linux builder10.centos.org 2.6.18-53.el5 #1 smp mon nov 12 02:=
14:55 est 2007 i686 athlon i386 gnulinux '
    config_args=3D'-des -Doptimize=3D-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOUR=
CE=3D2 -fexceptions -fstack-protector --param=3Dssp-buffer-size=3D4 -m32 -m=
arch=3Di386 -mtune=3Dgeneric -fasynchronous-unwind-tables -Dversion=3D5.8.8=
 -Dmyhostname=3Dlocalhost -Dperladmin=3Droot@localhost -Dcc=3Dgcc -Dcf_by=
=3DRed Hat, Inc. -Dinstallprefix=3D/usr -Dprefix=3D/usr -Darchname=3Di386-l=
inux-thread-multi -Dvendorprefix=3D/usr -Dsiteprefix=3D/usr -Duseshrplib -D=
usethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db=
 -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3D3pm -Duseperlio -Dinst=
allusrbinperl=3Dn -Ubincompat5005 -Uversiononly -Dpager=3D/usr/bin/less -is=
r -Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto -Ud_=
endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto -Ud_sets=
ervent_r_proto -Dinc_version_list=3D5.8.7 5.8.6 5.8.5 -Dscriptdir=3D/usr/bi=
n'
    hint=3Drecommended, useposix=3Dtrue, d_sigaction=3Ddefine
    usethreads=3Ddefine use5005threads=3Dundef useithreads=3Ddefine usemult=
iplicity=3Ddefine
    useperlio=3Ddefine d_sfio=3Dundef uselargefiles=3Ddefine usesocks=3Dund=
ef
    use64bitint=3Dundef use64bitall=3Dundef uselongdouble=3Dundef
    usemymalloc=3Dn, bincompat5005=3Dundef
  Compiler:
    cc=3D'gcc', ccflags =3D'-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing=
 -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOUR=
CE -D_FILE_OFFSET_BITS=3D64 -I/usr/include/gdbm',
    optimize=3D'-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=3D2 -fexceptions -=
fstack-protector --param=3Dssp-buffer-size=3D4 -m32 -march=3Di386 -mtune=3D=
generic -fasynchronous-unwind-tables',
    cppflags=3D'-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -Wdec=
laration-after-statement -I/usr/local/include -I/usr/include/gdbm'
    ccversion=3D'', gccversion=3D'4.1.2 20080704 (Red Hat 4.1.2-48)', gccos=
andvers=3D''
    intsize=3D4, longsize=3D4, ptrsize=3D4, doublesize=3D8, byteorder=3D123=
4
    d_longlong=3Ddefine, longlongsize=3D8, d_longdbl=3Ddefine, longdblsize=
=3D12
    ivtype=3D'long', ivsize=3D4, nvtype=3D'double', nvsize=3D8, Off_t=3D'of=
f_t', lseeksize=3D8
    alignbytes=3D4, prototype=3Ddefine
  Linker and Libraries:
    ld=3D'gcc', ldflags =3D' -L/usr/local/lib'
    libpth=3D/usr/local/lib /lib /usr/lib
    libs=3D-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=3D-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=3D/lib/libc-2.5.so, so=3Dso, useshrplib=3Dtrue, libperl=3Dlibperl.=
so
    gnulibc_version=3D'2.5'
  Dynamic Linking:
    dlsrc=3Ddl_dlopen.xs, dlext=3Dso, d_dlsymun=3Dundef, ccdlflags=3D'-Wl,-=
E -Wl,-rpath,/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE'
    cccdlflags=3D'-fPIC', lddlflags=3D'-shared -O2 -g -pipe -Wall -Wp,-D_FO=
RTIFY_SOURCE=3D2 -fexceptions -fstack-protector --param=3Dssp-buffer-size=
=3D4 -m32 -march=3Di386 -mtune=3Dgeneric -fasynchronous-unwind-tables -L/us=
r/local/lib'


Characteristics of this binary (from libperl):=20
  Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
                        PERL_MALLOC_WRAP USE_ITHREADS USE_LARGE_FILES
                        USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at Sep 28 2010 08:49:59
  @INC:
    /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/5.8.8


------------------------------

Date: Tue, 14 Jun 2011 11:54:35 -0700
From: sln@netherlands.com
Subject: Re: How initialize an array to 0's?
Message-Id: <ukafv69per2emhka4husk95nl6732nr7e5@4ax.com>

On Tue, 14 Jun 2011 16:31:46 +0000 (UTC), Willem <willem@toad.stack.nl> wrote:

>Wolf Behrenhoff wrote:
>) On 14.06.2011 17:58, Ralph Malph wrote:
>)> Whoops, in that 1d case this line
>)>> @flagi[1..$jornadas]=split(/\s/,"0 "x$partidos);
>)> should instead read
>)>      @flagi[1..$jornadas]=split(/\s/,"0 "x$jornadas);
>)> So, the number of elements is correct
>)
>) What is this?
>)
>) First you create a string, then you split it again? Further, you assign
>) the value "0", not 0.
>)
>) better use:
>)   @array[1..$n] = (0) x $n;
>)
>) For 2d arrays (= an array of array references), you will need to loop
>) over the first array and run the above command for every array element.
>
>Doesn't:
>  @array = ([(0) x $n]) x $n;
>work ?
>
>
>(Yes, I know it doesn't work, the interesting bit is in why it doesn't.)
>

 'THIS' x 5,  (THAT) x 5,  ([REF]) x 5
It appears only a single thing is constructed and duplicated
only in assingment or when referenced.
This might be a design consideration to save memory.

So, for example 
  @array = ([(0) x 5]) x 3;
does work, but @array elements all have the same reference to [0,0,0,0,0]

Compare that with
  @array = eval "[(0) x 5]," x 3;
where each element has a different reference.

-sln


------------------------------

Date: Tue, 14 Jun 2011 12:03:52 -0700
From: sln@netherlands.com
Subject: Re: How initialize an array to 0's?
Message-Id: <qlbfv61oaqjaeq02m5sup0lkg5ihkl9fju@4ax.com>

On 14 Jun 2011 17:02:37 +0100, gamo@telecable.es wrote:

>
>I have the following correct sentence 
>
>$flagi[1..$jornadas][1..$partidos] = 0;
>
>that doesn't do anything useful.
>
>What is the proper and modern mode to do the thing?
>
>Thanks
>

This probably works

@array[0 .. $jornadas] = eval "[(0) x ($partidos+1)]," x ($jornadas+1);

but, I don't know that it doesen't make a 'temporary' during runtime
that is as large as the variable you intend to assign.
In that case its not very memory efficient and you should choose
to loop through via assignment creating a new reference
[(0) x $partidos] each time (as others have said).

-sln


------------------------------

Date: Tue, 14 Jun 2011 15:04:46 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: How initialize an array to 0's?
Message-Id: <87d3ignsj5.fsf@quad.sysarch.com>

>>>>> "s" == sln  <sln@netherlands.com> writes:

  s> On 14 Jun 2011 17:02:37 +0100, gamo@telecable.es wrote:
  >> 
  >> I have the following correct sentence 
  >> 
  >> $flagi[1..$jornadas][1..$partidos] = 0;
  >> 
  >> that doesn't do anything useful.
  >> 
  >> What is the proper and modern mode to do the thing?
  >> 
  >> Thanks
  >> 

  s> This probably works

  s> @array[0 .. $jornadas] = eval "[(0) x ($partidos+1)]," x ($jornadas+1);

probably? using eval string?? ewwwww!

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Tue, 14 Jun 2011 19:28:28 +0000 (UTC)
From: dmcanzi@remulak.uwaterloo.ca.uwaterloo.ca (David Canzi)
Subject: Re: How initialize an array to 0's?
Message-Id: <it8cos$b7$1@rumours.uwaterloo.ca>

Ralph Malph  <ralph@happydays.com> wrote:
>Do you really mean to have a 2d array?
>Anyway, use slices. Plus maybe some perl-ish tricks to quickly generate 
>the list of 0s.
>In the 1d case:
>     #be careful, you probably want to start indexing at 0, not 1
>     #leaving it your way for now
>     @flagi[1..$jornadas]=split(/\s/,"0 "x$partidos);
>If you really meant 2d then:
>     @flagi;
>     $flagi[$jornadas]=undef;#the first dimension is grown to have 
>$jornados+1 elements
>     #again, you probably want indices from 0 to $jornados-1.
>     #but maybe you don't for some reason? I'll leave your way here too.
>     map {[]} @flagi;
>     foreach my $row (@flagi){
>         @{$row}=split(/\s/,"0 "x$partidos);
>     }
>This code is untested but should be more  or less correct.
>One more time, be careful with your indices! perl starts indexing at 0, 
>not 1.

------------------
#!/usr/bin/perl

use strict;
use warnings;

my $jornados = 5;
my $partidos = 7;

my $flagi = [ undef, ( [ undef, ( 0 ) x $partidos ] ) x $jornados ];

for my $j ( 1..$jornados ) {
	for my $p ( 1..$partidos ) {
		print ' ', $flagi->[$j][$p];
	}
	print "\n";
}
------------------

This gives the original poster his desired origin 1 indexing.

For origin 0 indexing:
my $flagi = [ ( [ ( 0 ) x $partidos ] ) x $jornados ];

-- 
David Canzi		| Life is too short to point out every mistake. |


------------------------------

Date: Tue, 14 Jun 2011 15:35:28 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: How initialize an array to 0's?
Message-Id: <87hb7smcjj.fsf@quad.sysarch.com>

>>>>> "DC" == David Canzi <dmcanzi@remulak.uwaterloo.ca.uwaterloo.ca> writes:

  DC> For origin 0 indexing:
  DC> my $flagi = [ ( [ ( 0 ) x $partidos ] ) x $jornados ];

as mentioned elsewhere, that assigns the same anon array reference to
each of the lower level entries. if you modify any value in that array,
it will show up in all the copies. you need to use map to create new
array refs for each entry.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Tue, 14 Jun 2011 19:35:28 +0000 (UTC)
From: dmcanzi@remulak.uwaterloo.ca.uwaterloo.ca (David Canzi)
Subject: Re: How initialize an array to 0's?
Message-Id: <it8d60$b7$2@rumours.uwaterloo.ca>

David Canzi <dmcanzi@remulak.uwaterloo.ca.uwaterloo.ca> wrote:
>my $flagi = [ undef, ( [ undef, ( 0 ) x $partidos ] ) x $jornados ];

Now that I've read the rest of the thread I know this doesn't work.

-- 
David Canzi		| Life is too short to point out every mistake. |


------------------------------

Date: Tue, 14 Jun 2011 14:47:55 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: How initialize an array to 0's?
Message-Id: <8739jctct0.fsf@lifelogs.com>

On Tue, 14 Jun 2011 12:03:52 -0700 sln@netherlands.com wrote: 

s> @array[0 .. $jornadas] = eval "[(0) x ($partidos+1)]," x ($jornadas+1);

Using eval() is almost always a bad idea (unless you're writing Tcl, the
ultimate eval() abuser).  It indicates all other options have failed.

map() is the right solution here.  For once :)

Ted


------------------------------

Date: Tue, 14 Jun 2011 15:17:43 -0700
From: sln@netherlands.com
Subject: Re: How initialize an array to 0's?
Message-Id: <denfv61mq1p1lpa9kluumojnavmledfbhv@4ax.com>

On Tue, 14 Jun 2011 14:47:55 -0500, Ted Zlatanov <tzz@lifelogs.com> wrote:

>On Tue, 14 Jun 2011 12:03:52 -0700 sln@netherlands.com wrote: 
>
>s> @array[0 .. $jornadas] = eval "[(0) x ($partidos+1)]," x ($jornadas+1);
>
>Using eval() is almost always a bad idea (unless you're writing Tcl, the
>ultimate eval() abuser).  It indicates all other options have failed.
>
>map() is the right solution here.  For once :)
>

Definetly agree. 'eval' should have been named evil()

-sln


------------------------------

Date: Wed, 15 Jun 2011 07:53:19 +0000 (UTC)
From: Willem <willem@toad.stack.nl>
Subject: Re: How initialize an array to 0's?
Message-Id: <slrnivgp7f.194a.willem@toad.stack.nl>

sln@netherlands.com wrote:
) On Tue, 14 Jun 2011 14:47:55 -0500, Ted Zlatanov <tzz@lifelogs.com> wrote:
)
)>On Tue, 14 Jun 2011 12:03:52 -0700 sln@netherlands.com wrote: 
)>
)>s> @array[0 .. $jornadas] = eval "[(0) x ($partidos+1)]," x ($jornadas+1);
)>
)>Using eval() is almost always a bad idea (unless you're writing Tcl, the
)>ultimate eval() abuser).  It indicates all other options have failed.
)>
)>map() is the right solution here.  For once :)
)>
)
) Definetly agree. 'eval' should have been named evil()

And the block-version of 'eval' ?  I use that all the time.


SaSW, Willem
-- 
Disclaimer: I am in no way responsible for any of the statements
            made in the above text. For all I know I might be
            drugged or something..
            No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT


------------------------------

Date: Wed, 15 Jun 2011 04:37:23 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: How initialize an array to 0's?
Message-Id: <87k4cnfq2k.fsf@quad.sysarch.com>

>>>>> "W" == Willem  <willem@toad.stack.nl> writes:

  W> ) Definetly agree. 'eval' should have been named evil()

  W> And the block-version of 'eval' ?  I use that all the time.

they are totally different functions with unfortunately the same
name. eval string compiles perl code at run time and then runs it. it
will catch die and fatal errors. it is best used for code generation and
not for simple short cuts which are almost always better done in other
ways. eval block's code is compiled at compile time and all the eval
does is catch die and fatal errors. both eval's will return the value of
their expressions.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Wed, 15 Jun 2011 00:29:05 -0700 (PDT)
From: mike <mikaelpetterson@hotmail.com>
Subject: Regexp help to understand
Message-Id: <b0c13494-1e22-47a8-b552-f538e24a484c@y30g2000yqb.googlegroups.com>

Hi,

I am trying to use regexp and grouping to extract numbers.

I have the following string:

X-ADF_BASE_Z32B_APP_NO4.20.1_SE

And I am trying to the following regexp:

match types like  4.1, 4.11, 4.1.1, 4.11.1
	my ($firstpos, $secondpos, $thirdpos) = /(\d)\.(\d+)\.*(\d*)/;




		#Occurrs first time.
		if ( scalar(@highest) == 0 ) {

			print $firstpos;
			print $secondpos;
			print $thirdpos;

The print becomes:

42014
20
1

Can anyone be nice to help me and explain what I am doing wrong.

I was expecting:

4
20
1

br,

//mike


------------------------------

Date: Tue, 14 Jun 2011 18:35:19 +0000 (UTC)
From: pacman@kosh.dhis.org (Alan Curry)
Subject: Re: Scherz am Rande
Message-Id: <it89l6$oii$1@speranza.aioe.org>

In article <8739jd8jrx.fsf@sapphire.mobileactivedefense.com>,
Rainer Weikusat  <rweikusat@mssgmbh.com> wrote:
>in a suitable way, either. Because of this, his very non-abysmal code
>has now written 47,731,957 'uninitialized value of $something'
>messages to said Apache log file, consuming a total of 10,882,826,240
>bytes of disk space (11G), completely filling up the SSD partition his

The root of this problem is the "I run a server and never look at the
logs" style of administration. Log files aren't just for post-disaster
grepping and blaming. A sysadmin who wants to avoid problems should
proactively tail -f /var/log/* once in a while.

I like to keep the tail -f running on an otherwise unused virtual
console or a window of my GNU screen session, so I flip past it
occasionally without even intending to.

-- 
Alan Curry


------------------------------

Date: Tue, 14 Jun 2011 14:49:57 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Scherz am Rande
Message-Id: <87y614ry56.fsf@lifelogs.com>

On Tue, 14 Jun 2011 18:35:19 +0000 (UTC) pacman@kosh.dhis.org (Alan Curry) wrote: 

AC> I like to keep the tail -f running on an otherwise unused virtual
AC> console or a window of my GNU screen session, so I flip past it
AC> occasionally without even intending to.

GNU tail with -F is slightly better, since it follows by name and
keeps retrying.  I do this too on servers I manage, very handy.

Ted


------------------------------

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 3415
***************************************


home help back first fref pref prev next nref lref last post