[29516] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 760 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 16 14:24:34 2007

Date: Thu, 16 Aug 2007 11:24:25 -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           Thu, 16 Aug 2007     Volume: 11 Number: 760

Today's topics:
        Perl performance difference between Linux distributions (Markus Kuhn)
    Re: Perl performance difference between Linux distribut <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: Perl performance difference between Linux distribut <nospam-abuse@ilyaz.org>
    Re: Perl performance difference between Linux distribut (Alan Curry)
    Re: Perl performance difference between Linux distribut (Markus Kuhn)
    Re: Perl performance difference between Linux distribut (Markus Kuhn)
    Re: Perl performance difference between Linux distribut (Markus Kuhn)
    Re: Perl performance difference between Linux distribut xhoster@gmail.com
    Re: Perl performance difference between Linux distribut xhoster@gmail.com
    Re: Replacing a line <vedpsingh@gmail.com>
    Re: Replacing a line <vedpsingh@gmail.com>
        Search MySQL  groups000@gmail.com
    Re: Search MySQL <jgibson@mail.arc.nasa.gov>
    Re: Search MySQL <rkb@i.frys.com>
    Re: Search MySQL <tzz@lifelogs.com>
    Re: Software error using CGI::Session - Your vendor has xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 15 Aug 2007 19:05:25 GMT
From: n07W33+mgk25@cl.cam.ac.uk (Markus Kuhn)
Subject: Perl performance difference between Linux distributions
Message-Id: <f9vipl$7ju$1@gemini.csx.cam.ac.uk>

--------------------------------------------------------------------------
#!/usr/bin/perl
# This script takes on comparable hardware (stour, mole)
#   50 ms under openSUSE 10.2
# 4200 ms under Fedora 7

use overload q(cmp) => \&cmp;

my %h;
for (my $i=0; $i<5000; $i++) {
    $h{$i} = bless [ undef, undef, { }, undef, { } ] => 'main';
}
--------------------------------------------------------------------------

Any idea, how the choice of Linux distribution on identical hardware
can affect the performance of a Perl script so dramatically
(more than an order of magnitude slower under Fedora 7)?

Fedora 7:  ssh stour time ./stour-test.pl

real    0m4.308s
user    0m4.286s
sys     0m0.019s

SUSE 10.2:  ssh mole time ./stour-test.pl

real    0m0.063s
user    0m0.052s
sys     0m0.012s


(The above script doesn't do anything useful, but is the result of
an attempt to prune away all for this demonstration of this effect
irrelevant parts of a much larger application.)

Any ideas for explanations or independent verifications
of the effect welcome!

Markus

-- 
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain


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

Date: Wed, 15 Aug 2007 14:42:51 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <13c6mac6fmspq18@corp.supernews.com>

On 08/15/07 14:05, Markus Kuhn wrote:
> --------------------------------------------------------------------------
> #!/usr/bin/perl
> # This script takes on comparable hardware (stour, mole)
> #   50 ms under openSUSE 10.2
> # 4200 ms under Fedora 7
> 
> use overload q(cmp) => \&cmp;
> 
> my %h;
> for (my $i=0; $i<5000; $i++) {
>     $h{$i} = bless [ undef, undef, { }, undef, { } ] => 'main';
> }
> --------------------------------------------------------------------------
> 
> Any idea, how the choice of Linux distribution on identical hardware
> can affect the performance of a Perl script so dramatically
> (more than an order of magnitude slower under Fedora 7)?
> 
> Fedora 7:  ssh stour time ./stour-test.pl
> 
> real    0m4.308s
> user    0m4.286s
> sys     0m0.019s
> 
> SUSE 10.2:  ssh mole time ./stour-test.pl
> 
> real    0m0.063s
> user    0m0.052s
> sys     0m0.012s
> 
> 
> (The above script doesn't do anything useful, but is the result of
> an attempt to prune away all for this demonstration of this effect
> irrelevant parts of a much larger application.)
> 
> Any ideas for explanations or independent verifications
> of the effect welcome!
> 
> Markus
> 

How was Perl compiled on those machines?

Show us the output of "perl -V"




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

Date: Wed, 15 Aug 2007 21:39:14 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <f9vrq2$115j$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Markus Kuhn
<n07W33+mgk25@cl.cam.ac.uk>], who wrote in article <f9vipl$7ju$1@gemini.csx.cam.ac.uk>:
> --------------------------------------------------------------------------
> #!/usr/bin/perl
> # This script takes on comparable hardware (stour, mole)
> #   50 ms under openSUSE 10.2
> # 4200 ms under Fedora 7
> 
> use overload q(cmp) => \&cmp;
> 
> my %h;
> for (my $i=0; $i<5000; $i++) {
>     $h{$i} = bless [ undef, undef, { }, undef, { } ] => 'main';
> }
> --------------------------------------------------------------------------
> 
> Any idea, how the choice of Linux distribution on identical hardware
> can affect the performance of a Perl script so dramatically
> (more than an order of magnitude slower under Fedora 7)?
> 
> Fedora 7:  ssh stour time ./stour-test.pl
> 
> real    0m4.308s
> user    0m4.286s
> sys     0m0.019s
> 
> SUSE 10.2:  ssh mole time ./stour-test.pl
> 
> real    0m0.063s
> user    0m0.052s
> sys     0m0.012s

Impossible to tell until you redo with 5000 changed to 5, and with an
empty Perl command.  It could be that overload.pm sits on a very slow
drive (networked behind a slow connection).

truss with timestamps...

Hope this helps,
Ilya


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

Date: Wed, 15 Aug 2007 22:58:19 +0000 (UTC)
From: pacman@TheWorld.com (Alan Curry)
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <fa00eb$gva$1@pcls6.std.com>

In article <f9vipl$7ju$1@gemini.csx.cam.ac.uk>,
Markus Kuhn <n07W33+mgk25@cl.cam.ac.uk> wrote:
>Fedora 7:  ssh stour time ./stour-test.pl
>
>real    0m4.308s
>user    0m4.286s
>sys     0m0.019s

This looks like a good case for perl -d:DProf and dprofpp.

-- 
Alan Curry
pacman@world.std.com


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

Date: 16 Aug 2007 15:24:33 GMT
From: n07W33+mgk25@cl.cam.ac.uk (Markus Kuhn)
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <fa1q7h$t6k$1@gemini.csx.cam.ac.uk>

"Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net> writes:
|> On 08/15/07 14:05, Markus Kuhn wrote:
|> > --------------------------------------------------------------------------
|> > #!/usr/bin/perl
|> > # This script takes on comparable hardware (stour, mole)
|> > #   50 ms under openSUSE 10.2
|> > # 4200 ms under Fedora 7
|> > 
|> > use overload q(cmp) => \&cmp;
|> > 
|> > my %h;
|> > for (my $i=0; $i<5000; $i++) {
|> >     $h{$i} = bless [ undef, undef, { }, undef, { } ] => 'main';
|> > }
|> > --------------------------------------------------------------------------
|> > 
|> > Any idea, how the choice of Linux distribution on identical hardware
|> > can affect the performance of a Perl script so dramatically
|> > (more than an order of magnitude slower under Fedora 7)?
|> > 
|> > Fedora 7:  ssh stour time ./stour-test.pl
|> > 
|> > real    0m4.308s
|> > user    0m4.286s
|> > sys     0m0.019s
|> > 
|> > SUSE 10.2:  ssh mole time ./stour-test.pl
|> > 
|> > real    0m0.063s
|> > user    0m0.052s
|> > sys     0m0.012s
|> > 
|> > 
|> > (The above script doesn't do anything useful, but is the result of
|> > an attempt to prune away all for this demonstration of this effect
|> > irrelevant parts of a much larger application.)
|> 
|> How was Perl compiled on those machines?
|> 
|> Show us the output of "perl -V"

On both machines I used the standard Perl binaries that came with the
distributions:

Fedora 7:

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.19-1.2895.fc6xen, archname=i386-linux-thread-multi
    uname='linux xenbuilder1.fedora.redhat.com 2.6.19-1.2895.fc6xen #1 smp wed jan 10 19:09:13 est 2007 i686 athlon i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -Dversion=5.8.8 -Dmyhostname=localhost -Dperladmin=root@localhost -Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr -Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr -Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm -Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n -Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr -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_setservent_r_proto -Dinc_version_list=5.8.7 5.8.6 5.8.5 -Dscriptdir=/usr/bin'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm',
    optimize='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -Wdeclaration-after-statement -I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='4.1.2 20070502 (Red Hat 4.1.2-12)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.6.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.6'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.8/i386-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic -fasynchronous-unwind-tables -L/usr/local/lib'


Characteristics of this binary (from libperl): 
  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 May 16 2007 23:23:14
  @INC:
    /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.7/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.6/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl/5.8.7
    /usr/lib/perl5/site_perl/5.8.6
    /usr/lib/perl5/site_perl/5.8.5
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.7/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.6/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl/5.8.7
    /usr/lib/perl5/vendor_perl/5.8.6
    /usr/lib/perl5/vendor_perl/5.8.5
    /usr/lib/perl5/vendor_perl
    /usr/lib/perl5/5.8.8/i386-linux-thread-multi
    /usr/lib/perl5/5.8.8
    .


SUSE 10.2:

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
  Platform:
    osname=linux, osvers=2.6.18, archname=i586-linux-thread-multi
    uname='linux eisler 2.6.18 #1 smp tue nov 21 12:59:21 utc 2006 i686 athlon i386 gnulinux '
    config_args='-ds -e -Dprefix=/usr -Dvendorprefix=/usr -Dinstallusrbinperl -Dusethreads -Di_db -Di_dbm -Di_ndbm -Di_gdbm -Duseshrplib=true -Doptimize=-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -march=i586 -mtune=i686 -fmessage-length=0 -Wall -D_FORTIFY_SOURCE=2 -g -Wall -pipe',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING -fno-strict-aliasing -pipe -Wdeclaration-after-statement'
    ccversion='', gccversion='4.1.2 20061115 (prerelease) (SUSE Linux)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib /usr/local/lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.5.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.5'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/usr/lib/perl5/5.8.8/i586-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared'


Characteristics of this binary (from libperl): 
  Compile-time options: DEBUGGING MULTIPLICITY PERL_IMPLICIT_CONTEXT
                        PERL_MALLOC_WRAP THREADS_HAVE_PIDS USE_ITHREADS
                        USE_LARGE_FILES USE_PERLIO USE_REENTRANT_API
  Built under linux
  Compiled at Nov 25 2006 11:32:18
  @INC:
    /usr/lib/perl5/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/5.8.8
    /usr/lib/perl5/site_perl/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.8.8
    /usr/lib/perl5/site_perl
    /usr/lib/perl5/vendor_perl/5.8.8/i586-linux-thread-multi
    /usr/lib/perl5/vendor_perl/5.8.8
    /usr/lib/perl5/vendor_perl
    .

-- 
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain


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

Date: 16 Aug 2007 15:38:10 GMT
From: n07W33+mgk25@cl.cam.ac.uk (Markus Kuhn)
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <fa1r12$t6k$2@gemini.csx.cam.ac.uk>

Ilya Zakharevich <nospam-abuse@ilyaz.org> writes:
|> Impossible to tell until you redo with 5000 changed to 5, and with an
|> empty Perl command.  It could be that overload.pm sits on a very slow
|> drive (networked behind a slow connection).

In both cases, all files loaded came from block-buffer cache,
because I have repeated the test runs until the test times
were stable, to elimate I/O latency affecting the runtimes.

The time difference happens entirely within the for loop iterations.
During this time, the only system call that is shown in strace
are 13 consecutive calls to brk to allocate more memory, and the
time difference is entirely in user time, not in system time.

Most minor changes to this program (which -- as I mentioned
-- is already the outcome of a lengthy attempt to strip down with
the help of DProf all irrelevant parts from a huge application
that first exhibited this off problem) cause the dramatic
run-time difference to disappear. Such changes include
for example blessing to another class than "main" or removing
the cmp overload.

My speculation is that something odd is going wrong with how
Perl has been compiled under Fedora 7, threading libraries or
whatever.

Markus

-- 
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain


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

Date: 16 Aug 2007 15:42:21 GMT
From: n07W33+mgk25@cl.cam.ac.uk (Markus Kuhn)
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <fa1r8t$t6k$3@gemini.csx.cam.ac.uk>

pacman@TheWorld.com (Alan Curry) writes:
|> In article <f9vipl$7ju$1@gemini.csx.cam.ac.uk>,
|> Markus Kuhn <n07W33+mgk25@cl.cam.ac.uk> wrote:
|> >Fedora 7:  ssh stour time ./stour-test.pl
|> >
|> >real    0m4.308s
|> >user    0m4.286s
|> >sys     0m0.019s
|> 
|> This looks like a good case for perl -d:DProf and dprofpp.

The example program is already the result or stripping away
from my larger application that first showed this problem every
irrelevant part. Since there are no longer any user-defined
subroutines involved, the output of dprofpp is no longer
meaningful. I suspect that the combination of the bless and the
overload is triggering this, because removing either fixes the
problem.

Markus

-- 
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain


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

Date: 16 Aug 2007 16:43:22 GMT
From: xhoster@gmail.com
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <20070816124323.901$VC@newsreader.com>

n07W33+mgk25@cl.cam.ac.uk (Markus Kuhn) wrote:
> -------------------------------------------------------------------------
> - #!/usr/bin/perl
> # This script takes on comparable hardware (stour, mole)
> #   50 ms under openSUSE 10.2
> # 4200 ms under Fedora 7
>
> use overload q(cmp) => \&cmp;
>
> my %h;
> for (my $i=0; $i<5000; $i++) {
>     $h{$i} = bless [ undef, undef, { }, undef, { } ] => 'main';
> }
> -------------------------------------------------------------------------


What happens if you change it to:

use overload q(cmp) => sub { warn "calling cmp with @_" };

Since you don't define a sub named cmp, I would expect it to die
if somehow the overload was taking effect, but it would be nice to
see explicit confirmation of that.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 16 Aug 2007 16:50:10 GMT
From: xhoster@gmail.com
Subject: Re: Perl performance difference between Linux distributions
Message-Id: <20070816125012.625$p4@newsreader.com>

n07W33+mgk25@cl.cam.ac.uk (Markus Kuhn) wrote:
> |> >
> |> > (The above script doesn't do anything useful, but is the result of
> |> > an attempt to prune away all for this demonstration of this effect
> |> > irrelevant parts of a much larger application.)
> |>
> |> How was Perl compiled on those machines?
> |>
> |> Show us the output of "perl -V"
>
> On both machines I used the standard Perl binaries that came with the
> distributions:

What if you compile your own perl on each machine from the same source
code?  Maybe the vendor distributions have done something strange to their
code.  At least if you could reproduce the issue with the default
compilation of a standard source-code distribution, it would give others
interested in exploring the issue a good starting point.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Wed, 15 Aug 2007 23:26:35 -0700
From:  Ved <vedpsingh@gmail.com>
Subject: Re: Replacing a line
Message-Id: <1187245595.814703.279710@q4g2000prc.googlegroups.com>

On Aug 6, 7:35 pm, Ved <vedpsi...@gmail.com> wrote:
> Hi all,
> I have to replace commented line in a list of  " .cpp" file .
> Line  looks like this:
> //#define BBPRxChanRouteFileLoadInput 1
>
> i.e. The line format :
> //#define (FileName)FileLoadInput 1
>  is to be replaced with
> #define (FileName)FileLoadInput 1
>
> I have written a code using Tie::File which is mentioned below.
> I want to do two things:
>
> 1) Remove trailing .cpp in $dir ?
>
> 2) What to do in this to get (/ //#define $dirFileLoadInput 1 /)   in
> the for loop ?
>
> For above example file name in my.rxfiles is:
> BBPRxChanRoute.cpp
>
> Thanks in advance
> Ved
> #######################################################
>
> #!/usr/local/bin/perl
> use strict;
> use warnings;
> use Tie::File;
>
> my $dir_list = 'my.rxfiles'; #contains list of .cpp files
>     open my $fh,'<',$dir_list or die "Cannot read $dir_list: $!\n";
>     while (my $dir = <$fh>) {
>      chop $dir;
>      my $file = "$dir";
>       chomp $file;
>      if (-e $dir) {
>        process_one_file($dir);
>      } else {
>        warn "File $dir does not exist; skipping\n";
>      }
>    }
>
>    #Using core module Tie::File to process a file in this subroutine
>    sub process_one_file {
>      my $dir = shift;
>      print "Processing $dir\n";
>       tie my @array, 'Tie::File', $dir  or die "tie error $dir: $!
> \n" ;
>       for (@array) {
>           if (/\//#define $dirFileLoadInput 1/)  #what to do here ??
>            {
>             $_ = #define $dirFileLoadinput 1 ;
>             last;
>            }
>         }
>    }

##################################################
Hi All,
Thanks for the replies.
I am posting the code for the completeness of the thread.
My task is being accomplished with this code, though I am still not
sure if it is perfect code.

#!/usr/local/bin/perl
use strict;
use warnings;
use Tie::File;

my $cpp_file_list = 'my.rxfiles';
    open my $fh,'<',$cpp_file_list or die "Cannot read $cpp_file_list:
$!\n";
    while (my $cpp_file = <$fh>) {
         chomp $cpp_file;
     my  $module_name = "$cpp_file";
     $module_name =~ s/\.cpp$//;#removing trainling .cpp
      print "this is name $module_name\n";
      print "this is CPP $cpp_file\n";
     if (-e $cpp_file) {
       process_one_file($cpp_file,$module_name);
     } else {
       warn "File $cpp_file does not exist; skipping\n";
     }
   }

   #Using core module Tie::File to process a file in this subroutine
   sub process_one_file {
	   my($cpp_file,$module_name)=@_;
      $cpp_file = shift;
     print "Processing $cpp_file\n";
      tie my @array, 'Tie::File', $cpp_file  or die "tie error
$cpp_file: $!\n" ;

 for (@array) #Each line should come one by one
  {
  #if ( s{^//(#define ${module_name}FileLoadInput 1)}{$1} ) {
  if ( s{//(#define ${module_name}FileLoadInput 1)}{$1} ) {
      print "true $module_name \n"
     # print " $array  \n"
         }
 else
        { print "false $module_name \n"}

         }

 }



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

Date: Wed, 15 Aug 2007 23:31:45 -0700
From:  Ved <vedpsingh@gmail.com>
Subject: Re: Replacing a line
Message-Id: <1187245905.514906.110650@e9g2000prf.googlegroups.com>

Hi All,
Thanks for the replies.
I am posting the code for the completeness of the thread.
My task is being accomplished with this code, though I am still not
sure if it is perfect code.

#!/usr/local/bin/perl
use strict;
use warnings;
use Tie::File;

my $cpp_file_list = 'my.rxfiles';
    open my $fh,'<',$cpp_file_list or die "Cannot read $cpp_file_list:
$!\n";
    while (my $cpp_file = <$fh>) {
         chomp $cpp_file;
     my  $module_name = "$cpp_file";
     $module_name =~ s/\.cpp$//;#removing trainling .cpp
      print "this is name $module_name\n";
      print "this is CPP $cpp_file\n";
     if (-e $cpp_file) {
       process_one_file($cpp_file,$module_name);
     } else {
       warn "File $cpp_file does not exist; skipping\n";
     }
   }

   #Using core module Tie::File to process a file in this subroutine
   sub process_one_file {
	   my($cpp_file,$module_name)=@_;
      $cpp_file = shift;
     print "Processing $cpp_file\n";
      tie my @array, 'Tie::File', $cpp_file  or die "tie error
$cpp_file: $!\n" ;

 for (@array) #Each line should come one by one
  {
  #if ( s{^//(#define ${module_name}FileLoadInput 1)}{$1} ) {
  if ( s{//(#define ${module_name}FileLoadInput 1)}{$1} ) {
      print "true $module_name \n"
     # print " $array  \n"
         }
 else
        { print "false $module_name \n"}

         }

 }




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

Date: Wed, 15 Aug 2007 18:30:17 -0000
From:  groups000@gmail.com
Subject: Search MySQL
Message-Id: <1187202617.542554.275980@50g2000hsm.googlegroups.com>

I am looking for some advice on the best way to split up a search
field on a web for so I can use the data to search a table in MySQL.
Right now the data comes into the script as one string. For example, I
have a product in my table that has a Manufacturer of SONY, a Product
ID of 12345 and a Description of Color LCD. If my user searches for
any of those 3 things individually the product will come up but if the
search for SONY Color it will not since it looks for the entire
string. Below is the current code I am using. I have tried using MATCH
and Fulltext indexing but that doesn't work right either.

Thanks in advance for any help.

#!/usr/bin/perl -w

use strict;
use CGI;
use DBI;
use CGI::Carp qw(fatalsToBrowser);

#Create new CGI object
my $cgi = new CGI;

#Connect to DB
my $dbh = DBI->connect("DBI:mysql:XXXXX:XXXXX","XXXXX","XXXXX") or die
$DBI::errstr;

#Print html header
print $cgi->header("text/html");

#pull in keyword from form
my $keyword = $cgi->param("keyword");

#prepare statement
my $sth = $dbh->prepare("SELECT *
FROM `productTable`
WHERE `mfg` like '%$keyword%'
OR `productID` like '%$keyword%'
OR `desc` like '%$keyword%'") or die;

#execute statement
$sth->execute() or die;

#print results
while (my $rec = $sth->fetchrow_hashref) {
       print qq(
<table>
<tr>
    <td align="left">$rec->{mfg}</td>
    <td align="left">$rec->{productID}</td>
    <td align="left">$rec->{desc}</td>
</tr>
</table>
            );
}



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

Date: Wed, 15 Aug 2007 12:17:31 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Search MySQL
Message-Id: <150820071217315346%jgibson@mail.arc.nasa.gov>

In article <1187202617.542554.275980@50g2000hsm.googlegroups.com>,
<groups000@gmail.com> wrote:

> I am looking for some advice on the best way to split up a search
> field on a web for so I can use the data to search a table in MySQL.
> Right now the data comes into the script as one string. For example, I
> have a product in my table that has a Manufacturer of SONY, a Product
> ID of 12345 and a Description of Color LCD. If my user searches for
> any of those 3 things individually the product will come up but if the
> search for SONY Color it will not since it looks for the entire
> string. Below is the current code I am using. I have tried using MATCH
> and Fulltext indexing but that doesn't work right either.
> 
> Thanks in advance for any help.

You can split on whitespace:

  @words = split " ", $string;

You can find all words (contiguous substrings of 1-9, a-z, A-Z, _):

  @words = $string =~ m{ \w+ }gx;

You can find all 5-digit or longer numbers:

  @numbers = $string =~ m{ \d{5,} }gx;

What you do with these is then up to you.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Wed, 15 Aug 2007 16:47:05 -0700
From:  Ron Bergin <rkb@i.frys.com>
Subject: Re: Search MySQL
Message-Id: <1187221625.455239.105410@g12g2000prg.googlegroups.com>

On Aug 15, 11:30 am, groups...@gmail.com wrote:
> I am looking for some advice on the best way to split up a search
> field on a web for so I can use the data to search a table in MySQL.
> Right now the data comes into the script as one string. For example, I
> have a product in my table that has a Manufacturer of SONY, a Product
> ID of 12345 and a Description of Color LCD. If my user searches for
> any of those 3 things individually the product will come up but if the
> search for SONY Color it will not since it looks for the entire
> string. Below is the current code I am using. I have tried using MATCH
> and Fulltext indexing but that doesn't work right either.
>
> Thanks in advance for any help.
>
> #!/usr/bin/perl -w
>
> use strict;
> use CGI;
> use DBI;
> use CGI::Carp qw(fatalsToBrowser);
>
> #Create new CGI object
> my $cgi = new CGI;
>
> #Connect to DB
> my $dbh = DBI->connect("DBI:mysql:XXXXX:XXXXX","XXXXX","XXXXX") or die
> $DBI::errstr;
>
> #Print html header
> print $cgi->header("text/html");
>
> #pull in keyword from form
> my $keyword = $cgi->param("keyword");
>
> #prepare statement
> my $sth = $dbh->prepare("SELECT *
> FROM `productTable`
> WHERE `mfg` like '%$keyword%'
> OR `productID` like '%$keyword%'
> OR `desc` like '%$keyword%'") or die;
>
> #execute statement
> $sth->execute() or die;
>
> #print results
> while (my $rec = $sth->fetchrow_hashref) {
>        print qq(
> <table>
> <tr>
>     <td align="left">$rec->{mfg}</td>
>     <td align="left">$rec->{productID}</td>
>     <td align="left">$rec->{desc}</td>
> </tr>
> </table>
>             );
>
> }

It would be much better to have 3 or more form fields (brand,
part_number, description, etc) instead of lumping them into 1 var.



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

Date: Thu, 16 Aug 2007 11:59:45 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Search MySQL
Message-Id: <m2hcmzjtz2.fsf@lifelogs.com>

On Wed, 15 Aug 2007 18:30:17 -0000 groups000@gmail.com wrote: 

g> #pull in keyword from form
g> my $keyword = $cgi->param("keyword");

At least do s/\W//g to remove all non-word characters, after splitting.
Generally you should treat all external input as dangerous in a CGI
environment; see "perldoc -q cgi":

"How do I make sure users can't enter values into a form that cause my
 CGI script to do bad things?

 See the security references listed in the CGI Meta FAQ

 http://www.perl.org/CGI_MetaFAQ.html"

Here's an implementation of what you're trying to do.  I would use
placeholders and a ORM mapper like Rose::DB::Object to achieve this, but
I hope it at least shows you how to use a few Perl techniques.

Ted

#!/usr/bin/perl

use warnings;
use strict;

my $keyword = "hello there;;; you";
my @keywords;
foreach (split ' ', $keyword)
{
 s/\W+//g;
 push @keywords, $_;
}
print "@keywords\n"; # 'hello', 'there', 'you'

my $st = "SELECT * FROM `productTable` WHERE %s";
my @column_clauses;
foreach my $column (qw/mfg productID desc/)
{
 push @column_clauses, join(' OR ', map { sprintf '`%s` LIKE \'%%%s%%\'', $column, $_ } @keywords);
}

$st = sprintf $st, join(' OR ', @column_clauses);

print "$st\n"; # SELECT * FROM `productTable` WHERE `mfg` LIKE '%hello%' OR `mfg` LIKE '%there%' OR `mfg` LIKE '%you%' OR `productID` LIKE '%hello%' OR `productID` LIKE '%there%' OR `productID` LIKE '%you%' OR `desc` LIKE '%hello%' OR `desc` LIKE '%there%' OR `desc` LIKE '%you%'


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

Date: 15 Aug 2007 19:34:29 GMT
From: xhoster@gmail.com
Subject: Re: Software error using CGI::Session - Your vendor has not defined Fcntl macro O_NOFOLLOW
Message-Id: <20070815153431.272$iF@newsreader.com>

wmwilson01@gmail.com wrote:
> On Aug 15, 10:15 am, xhos...@gmail.com wrote:
>
> > I don't know why the eval isn't doing what it is supposed to be
> > doing.  Perhaps Fcntl is somehow bypassing it.  What version of Fcntl
> > do you have?
> >
>
> I'll give that a try.  Fcntl version is 1.03.

I don't seen any diff between 1.03 and what I have that would
seem relevant.

Hmmm.  Are you monkeying around with $SIG{__DIE__}?  I ask because
the only way I've been able to reproduce your error is if I put something
like:
BEGIN {$SIG{__DIE__} = sub {warn $_[0]; exit};}

before the "my $s=new CGI::Session"


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

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


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