[22161] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4382 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 11 00:06:28 2003

Date: Fri, 10 Jan 2003 21:05:07 -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           Fri, 10 Jan 2003     Volume: 10 Number: 4382

Today's topics:
        How does one determine why perl prog runs so slow???? (Bob Mariotti)
    Re: How does one determine why perl prog runs so slow?? <goldbb2@earthlink.net>
    Re: Is there a maximum length for system() or backtick  <goldbb2@earthlink.net>
    Re: muli-spaced fields and split() <Jodyman@hotmail.com>
    Re: Newbie ? Who uses Perl? <will@com.yahoo>
    Re: newline "\n" not working <mthunter@students.uiuc.edu>
    Re: newline "\n" not working <bobx@linuxmail.org>
    Re: newline "\n" not working <goldbb2@earthlink.net>
    Re: parsing xml with perl --- very urgent .. help pleas (Tad McClellan)
    Re: parsing xml with perl --- very urgent .. help pleas <uri@stemsystems.com>
    Re: Pick First Occurance of duplicate data - Thanks <eholz.one@verizon.net>
    Re: Pick First Occurance of duplicate data - Thanks (Tad McClellan)
        Pick First Occurance of duplicate data <eholz.one@verizon.net>
    Re: Pick First Occurance of duplicate data <glex@qwest.net>
    Re: Pick First Occurance of duplicate data <bongie@gmx.net>
    Re: Pick First Occurance of duplicate data <jurgenex@hotmail.com>
    Re: recording environment variables prior to download <Jodyman@hotmail.com>
    Re: Red Hat 8 breaking one-liner signature script <goldbb2@earthlink.net>
    Re: Relocation error (was: Re: "Can't locate loadable o <goldbb2@earthlink.net>
    Re: stucked <mats.svensson2@telia.com>
    Re: undef of large Hashes/Arrays took a very long time <goldbb2@earthlink.net>
    Re: Unix Vars declared in system() call -> %ENV <goldbb2@earthlink.net>
    Re: What is a simple way to read and write zip files? <goldbb2@earthlink.net>
    Re: What is a simple way to read and write zip files? <bart.lateur@pandora.be>
    Re: What is a simple way to read and write zip files? <bart.lateur@pandora.be>
    Re: word lenght (Tad McClellan)
    Re: word lenght (Tad McClellan)
    Re: word lenght <Jodyman@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 11 Jan 2003 04:28:32 GMT
From: R.Mariotti@FinancialDataCorp.com (Bob Mariotti)
Subject: How does one determine why perl prog runs so slow????
Message-Id: <3e1f9aaf.7348417@news.cshore.com>

Honestly!  I HAVE searched this group, other perl sites, perlfaqs, etc
and I cannot find anything that actually covers this topic.  It IS
perl so I'm posting in the perl group.

I have a perl program that has been in production for a couple of
years.  It was originally developed under perl 5.005 running under the
IBM AIX version 4.2.1 OS.  Performance was blazingly fast.

Some months ago we upgraded our servers OS to IBM AIX version 5.1
which comes with perl 5.6 but I could NOT get DBI/DBD installed to
link to MySQL.

Finally I downloaded the source for Perl 5.8 and compiled it cleanly
using gcc which I obtained from the Bull Freeware site.

Upon completion the perl program(s) along with MySQL functioned fine.
Great news! I though.

Here's the scope of the application:

We builld a database (MySQL type MyIsam) about 30 MB in size.

We then have a large sequential file (3 million records) which our
program reads.  It does a pattern match on each line and upon the
detection of certain lines it randomly accesses the MySQL database to
obtain some info.

It them conditionally outputs a small sequential file.

On the prior OS this process would run to completion in less than one
hour.  

Now - on the new OS version with Perl 5.8 the same program using the
same data files and database took over FORTY EIGHT HOURS to complete.

I ruled our a MySQL issue because if I comment out the MySQL access
the run time is still incredibly slow.

So, here's my question for the perl guru's that I could not find in
the faqs or other resources:

How does one go about determining what may be the cause of this
unacceptable performance?   I researched the module Benchmark but that
only measures time.   Where should one start?  Is this an issue that
others have experienced (I'm sure) and what was done to overcome it?

BTW - the performance on our non-perl applications still rockets along
so I don't think its the system/OS itself.

I will be eagerly awaiting any and all suggestions.

Bob


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

Date: Sat, 11 Jan 2003 00:13:02 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How does one determine why perl prog runs so slow????
Message-Id: <3E1FA7DE.EEC4AFC1@earthlink.net>

Bob Mariotti wrote:
[snip]
> So, here's my question for the perl guru's that I could not find in
> the faqs or other resources:
> 
> How does one go about determining what may be the cause of this
> unacceptable performance?   I researched the module Benchmark but that
> only measures time.   Where should one start?  Is this an issue that
> others have experienced (I'm sure) and what was done to overcome it?

You need to run a profiler.  The Devel::DProf module is the preferred
way, though you might also want to try Devel::SmallProf,
Devel::Profiler, or Devel::AutoProfiler.

To use Devel::DProff, you would do:

   perl -d:DProff myperlprog.pl args ...

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 10 Jan 2003 22:14:32 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Is there a maximum length for system() or backtick commands?
Message-Id: <3E1F8C18.5ED2E83D@earthlink.net>

Hal Vaughan wrote:
> 
> Benjamin Goldberg wrote:
> 
> > Hal Vaughan wrote:
> >>
> >> I've been testing Bash for maximum command line lengths (and trying
> >> to find a limit in the man page) and can't find any.
> >
> > The limit is not due to the shell, but due to the underlying syscall
> > -- I would suggest you do 'man exec' from your commandline, and
> > scroll down to where it mentions ARG_MAX.
> 
> It never occured to me that the limit would be on the number of args,
> NOT on the line length.  Thanks for pointing that out.

Actually, it is on the total number of bytes of all the args put
together.  My point was that it's not a *shell* limit, but a limit on
the underlying system call.  (You can adjust this limit by recompiling
your unix/linux kernel).

> man exec gives me the short bash command help -- the one that lists
> bash built-ins.  Doing 'man bash|grep ARG_MAX' yeilds nothing.

Err, try 'man 2 exec', or 'man -2 exec', or 'man -s 2 exec' (depending
on the syntax of your system's man command) and perhaps that will give
the appropriate man page.

> > [snip]
> >> Is there a maximum length I can make $command without problems?  I
> >> can easily see sending 400 (or even 500) files to the printer this
> >> way. I'd rather do it in one command (for various reasons), then
> >> breaking it down by limiting each command to only a certain number
> >> of files.
> >
> > How about:
> >    open( FILENAMES_TO_PRINTER, "| xargs lp");
> >    foreach my $file (@files) {
> >       print FILENAMES_TO_PRINTER $file, "\n";
> >    }
> >    close FILENAMES_TO_PRINTER;
> > [untested]
> >
> > This does have the effect of breaking it down, and limiting each
> > command to only a certain number of files, but the 'xargs' program
> > knows what ARG_MAX is, and puts on each commandline the *maximum*
> > number of files.
> 
> That might be a BIG help.  Does it start sending out commands WHILE
> the loop is still running,

Every time it accumulates ARG_MAX bytes of arguments, it sends out one
command.

> or will it wait until I close the file handle?

The remaining arguments (the last few, which don't quite make ARG_MAX
bytes) get sent when you close the filehandle.

> One of my concerns is that I very likely might be printing
> OpenOffice.org files, instead of postscript, and OOo can take time
> (10 seconds on my 500 Mhz on Linux) to load for a command like
> "oowriter -p file1 file2...." and the purpose of sending multiple
> commands is to eliminate the pause between printout sheets.  I figure
> if one line can hold 15 args, that pause will be "hidden" by the time
> it takes to print out the pages.  (I still am not sure if I'll be
> using lp or oowriter.)

After googling, I see that there exists an OpenOffice.org API of some
sort (I only found a brief mention of this, so I'm not entirely sure
what this is)... perhaps you can use this to start one instance of the
oowriter process, and then connect to it, and send multiple filenames to
it through the API?

This, however, is getting beyond the realm of perl, and hence doesn't
belong on clp.misc -- if you decide to try this route, email the ooo
developers.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Sat, 11 Jan 2003 03:24:51 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: muli-spaced fields and split()
Message-Id: <78MT9.3812$Dq.386364@newsread2.prod.itd.earthlink.net>

"bad_knee" <bl8n8r@yahoo.com> wrote in message
> Hello,
>
> I was in the middle of parsing a logfile when I realized some
> fields have 2 spaces instead of one.  This of couse screws up
> my field order when i split(/ /, $_) with a 1-space delimiter.
>
> Thu Jan  9 16:00:18 2003 1098 foo.bar.org 3333 bar.txt
> Fri Jan 10 07:16:13 2003 9 foo.bar.org 7662600 foo.txt
>
> note the double spaces between "Jan" and "9".  Someone must
> have a favourite way of getting rid of the extra spaces.  Please
> share.

Show us your code thus far.  What do you want to extract from
your logs?

You can always use:
$day = substr($_,0,2); $mo = substr($_,4,3);
$date = substr($_,8,2); $time = substr($_,11,8);

etc, etc, etc.

Jody




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

Date: Sat, 11 Jan 2003 01:40:00 GMT
From: w i l l <will@com.yahoo>
Subject: Re: Newbie ? Who uses Perl?
Message-Id: <fgtu1vkhp2mtrvbcomhaisabhvlm15k365@4ax.com>

On Fri, 10 Jan 2003 11:49:34 -0500, "jmg" <jmg@jmg.com> wrote:

>I'm looking to get back into programming after a long absence and I would like to know were to
>concentrate my efforts.
>So, where is Perl being used?

anywhere people want to get things done, quickly.

>What companies or industries are using it?

The ones with smarts.

>From what I've read it's a fairly new language, so is this going to be the next hot language that's
>going to sweep all the others off to the side?

perl is anything but new.

>
>Thanks for the help.

that's what this group is for.

-Will



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

Date: Fri, 10 Jan 2003 23:14:49 GMT
From: Mike Hunter <mthunter@students.uiuc.edu>
Subject: Re: newline "\n" not working
Message-Id: <slrnb1ul4r.kod.mthunter@ux8.cso.uiuc.edu>

On 10 Jan 2003 14:49:34 -0800, bazzz777 wrote:
>  I'm trying to write lines to a javascript file using the perl CGI module on Linux.
>  
>  The lines are written to the .js file with:
>  
>  open(file1,">>/tmp/$projectname");
>  print file1 "$duedate\n";
>  print file1 "$email\n";
>  print file1 "$description\n";
>  close(file1);
>  
>  The .js looks okay in Linux but cannot be
>  read by any web browser.
>  
>  AND...
>  
>  In MS Windows all the data appears as one long line.
>  I can make the javascript web browser readable if I edit in newlines
>  using a Windows text editor. 
>  
>  I also tried my CGI with "\r" instead of "\t" but

I assume you meant "\n", not "\t", right?

Did you try "\r\n"?


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

Date: Sat, 11 Jan 2003 01:00:16 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: newline "\n" not working
Message-Id: <A0KT9.5516$Fj2.3212452@news2.news.adelphia.net>

"bazzz777" <bazzz777@yahoo.com> wrote in message
news:6c9ad26f.0301101449.26b2c270@posting.google.com...
> I'm trying to write lines to a javascript file using the perl CGI module
on Linux.
>
> The lines are written to the .js file with:
>
> open(file1,">>/tmp/$projectname");
> print file1 "$duedate\n";
> print file1 "$email\n";
> print file1 "$description\n";
> close(file1);
>
> The .js looks okay in Linux but cannot be
> read by any web browser.
>
> AND...
>
> In MS Windows all the data appears as one long line.
> I can make the javascript web browser readable if I edit in newlines
> using a Windows text editor.
>

I ran this:

use strict;
use warnings;

my $duedate = "20030109";
my $email = 'bob@bob.com';   #-> bogus e-mail
my $description = "test me script";

open(file1,">>test.txt");
print file1 "$duedate\n";
print file1 "$email\n";
print file1 "$description\n";
close(file1);

and got this in the text file:

20030109
bob@bob.com
test me script

Newlines worked fine for me. I am on Windows XP home and I am using the
ActiveState 5.8 dsitro. Maybe your installation is broken or something.

Try:  perl -cw myscript.pl

Where the myscript.pl is the name of yours. It should tell you of any
problems.

Bob




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

Date: Fri, 10 Jan 2003 22:22:54 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: newline "\n" not working
Message-Id: <3E1F8E0E.166B422E@earthlink.net>

bazzz777 wrote:
> 
> I'm trying to write lines to a javascript file using the perl CGI
> module on Linux.
> 
> The lines are written to the .js file with:
> 
> open(file1,">>/tmp/$projectname");
> print file1 "$duedate\n";
> print file1 "$email\n";
> print file1 "$description\n";
> close(file1);
> 
> The .js looks okay in Linux but cannot be
> read by any web browser.

What are the permissions on the created file?  Who is the file owner? 
Is it in a location that it *would* be readable, if it had the right
permissions and owner?

> AND...
> 
> In MS Windows all the data appears as one long line.

I doubt that -- if you run that perl script on MS Windows, each line of
data in the resultant file will appear on it's own line.

If you run the perl script on linux, and then transfer the resulting
file to windows, and use binary mode instead of text mode for the
transfer, THEN the lines might appear all on one long line.  But not
otherwise.

> I can make the javascript web browser readable if I edit in newlines
> using a Windows text editor.
>
> I also tried my CGI with "\r" instead of "\t" but
> the results are the same.

Tried what instead of what?
There are no "\t" characters in the orignal script.

> Thanks for any help or suggestions.

Either run the cgi script on windows in the first place, or if you
insist on running on linux and transferring it to windows, remember to
transfer it in *text* mode, not binary mode.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 10 Jan 2003 16:28:12 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: parsing xml with perl --- very urgent .. help please
Message-Id: <slrnb1ui7s.tga.tadmc@magna.augustmail.com>

Harald H.-J. Bongartz <bongie@gmx.net> wrote:
> Tad McClellan wrote:


>> Did smoke come out of the computer's vents?
> 
> Had that some weeks ago, but I was not using Perl at that moment. ;-)


Many of my EE labs in college, regardless of whether they were
supposed to be an "LED flasher" or a "serial bus interface",
instead ended up as "voltage to smoke converters"...


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 10 Jan 2003 23:41:30 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: parsing xml with perl --- very urgent .. help please
Message-Id: <x7adi8indh.fsf@mail.sysarch.com>

>>>>> "TM" == Tad McClellan <tadmc@augustmail.com> writes:

  TM> Harald H.-J. Bongartz <bongie@gmx.net> wrote:
  >> Tad McClellan wrote:

  >>> Did smoke come out of the computer's vents?
  >> 
  >> Had that some weeks ago, but I was not using Perl at that moment. ;-)

  TM> Many of my EE labs in college, regardless of whether they were
  TM> supposed to be an "LED flasher" or a "serial bus interface",
  TM> instead ended up as "voltage to smoke converters"...

perl content: none, as this was way before perl was created.

i used to put a small 1/4 watt plastic encased transistor into a
transistor tester (which could sweep voltage and current and show that
on a scope). just turn up the numbers really high and you had a neat
lighter as long as you didn't inhale the fume from the burning
transistor.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

Date: Sat, 11 Jan 2003 01:27:05 GMT
From: "Eric W. Holzapfel" <eholz.one@verizon.net>
Subject: Re: Pick First Occurance of duplicate data - Thanks
Message-Id: <3E1F72F4.5050804@verizon.net>


--------------070706000009050802020407
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Thanks for the info.  Who would have thought to use perldoc!! (not me)!
Thanks again,

eric

Jürgen Exner wrote:

>Eric W. Holzapfel wrote:
>  
>
>>I have a Perl script that reads an Apache log file.  I get the ip
>>address from the access_log file.
>>There can be multiple entries with the same IP.  I would like to pick
>>the first occurrance (or just one) in a series of ip addresses that
>>are the same.  There can be, for example, 200 lines in the file, and
>>the same IP address can be on subsequent lines.  Lines 1 thru 33 can
>>be
>>4.44.56.55, etc.  I would like to pick just on IP for multiple
>>occurances.
>>    
>>
>
>Which part of the FAQ "perldoc -q duplicate" is unclear and needs
>improvement?
>
>jue
>
>
>  
>


--------------070706000009050802020407
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
  <title></title>
</head>
<body>
Thanks for the info. &nbsp;Who would have thought to use perldoc!! (not me)!<br>
Thanks again,<br>
<br>
eric<br>
<br>
J&uuml;rgen Exner wrote:<br>
<blockquote type="cite"
 cite="midAcKT9.1531$CC5.1305@nwrddc03.gnilink.net">
  <pre wrap="">Eric W. Holzapfel wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">I have a Perl script that reads an Apache log file.  I get the ip
address from the access_log file.
There can be multiple entries with the same IP.  I would like to pick
the first occurrance (or just one) in a series of ip addresses that
are the same.  There can be, for example, 200 lines in the file, and
the same IP address can be on subsequent lines.  Lines 1 thru 33 can
be
4.44.56.55, etc.  I would like to pick just on IP for multiple
occurances.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Which part of the FAQ "perldoc -q duplicate" is unclear and needs
improvement?

jue


  </pre>
</blockquote>
<br>
</body>
</html>

--------------070706000009050802020407--



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

Date: Fri, 10 Jan 2003 22:01:58 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Pick First Occurance of duplicate data - Thanks
Message-Id: <slrnb1v5pm.u9o.tadmc@magna.augustmail.com>

Eric W. Holzapfel <eholz.one@verizon.net> wrote:

> Who would have thought to use perldoc!! (not me)!


You should have lurked then.

      http://mail.augustmail.com/~tadmc/clpmisc.shtml


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 11 Jan 2003 00:34:53 GMT
From: "Eric W. Holzapfel" <eholz.one@verizon.net>
Subject: Pick First Occurance of duplicate data
Message-Id: <3E1F66A7.1030205@verizon.net>

Hello Perlies,

I have a Perl script that reads an Apache log file.  I get the ip 
address from the access_log file.
There can be multiple entries with the same IP.  I would like to pick 
the first occurrance (or just one) in a series of ip addresses that are 
the same.  There can be, for example, 200 lines in the file, and the 
same IP address can be on subsequent lines.  Lines 1 thru 33 can be 
4.44.56.55, etc.  I would like to pick just on IP for multiple occurances.  

How can I do this in Perl?

Thanks

Eric W. Holzapfel



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

Date: Fri, 10 Jan 2003 18:56:57 -0600
From: Jeff D Gleixner <glex@qwest.net>
Subject: Re: Pick First Occurance of duplicate data
Message-Id: <dYJT9.2597$337.149737@news.uswest.net>

 >I would like to pick just on IP for multiple occurances.
> How can I do this in Perl?

Use a hash.  Each key would be the IP.

-- 
Jeff Gleixner
Performance Evaluations quote of the moment:
	"If you give him a penny for his thoughts, you'd get change."



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

Date: Sat, 11 Jan 2003 02:05:43 +0100
From: "Harald H.-J. Bongartz" <bongie@gmx.net>
Subject: Re: Pick First Occurance of duplicate data
Message-Id: <1739735.MeANvVfTL5@nyoga.dubu.de>

Eric W. Holzapfel wrote:
> I have a Perl script that reads an Apache log file.  I get the ip
> address from the access_log file.
> There can be multiple entries with the same IP.  I would like to pick
> the first occurrance (or just one) in a series of ip addresses that
> are
> the same.  There can be, for example, 200 lines in the file, and the
> same IP address can be on subsequent lines.  Lines 1 thru 33 can be
> 4.44.56.55, etc.  I would like to pick just on IP for multiple
> occurances.

I'm not sure what you want exactly.  Do you mean only one single entry
for every IP in the whole file or one entry for every sequence of lines
with the same IP?  For the first problem, I would use a hash:

        #!/usr/bin/perl
        use strict;
        use warnings;
        my %iphash;
        while (<>) {
                my ($ip) = split ' ', $_, 2;
                $iphash{$ip} = $_;
        }
        print $iphash{$_} for (sort keys %iphash);

If you just want to ignore consecutive lines with the same IP, I would
choose a more "traditional" way:

        #!/usr/bin/perl
        use strict;
        use warnings;
        my $lastIP;
        while (<>) {
                my ($ip) = split ' ', $_, 2;
                next if $ip eq $lastIP;
                print;
                $lastIP = $ip;
        }

(untested)

Both codes assume that the first entry of each line in the log file is
the IP, followed by whitespace (at least that's what my Apache logs
look like).
If two (or more) clients access the site almost simultaneously, the last
method will not reduce the log very much, because you will likely have
an alternation of these two (or more) IPs on consecutive lines.

Ciao,
        Harald
-- 
Harald H.-J. Bongartz <bongie@gmx.net>
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> What's the opposite of 'omniscient'?
I don't know.                   [from alt.usage.english]


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

Date: Sat, 11 Jan 2003 01:13:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Pick First Occurance of duplicate data
Message-Id: <AcKT9.1531$CC5.1305@nwrddc03.gnilink.net>

Eric W. Holzapfel wrote:
> I have a Perl script that reads an Apache log file.  I get the ip
> address from the access_log file.
> There can be multiple entries with the same IP.  I would like to pick
> the first occurrance (or just one) in a series of ip addresses that
> are the same.  There can be, for example, 200 lines in the file, and
> the same IP address can be on subsequent lines.  Lines 1 thru 33 can
> be
> 4.44.56.55, etc.  I would like to pick just on IP for multiple
> occurances.

Which part of the FAQ "perldoc -q duplicate" is unclear and needs
improvement?

jue




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

Date: Sat, 11 Jan 2003 02:38:05 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: recording environment variables prior to download
Message-Id: <hsLT9.3761$Dq.381541@newsread2.prod.itd.earthlink.net>

"Chris" <chris_12003@yahoo.com> wrote in message
> I'm trying to give my users a single url address to download a
> specific file.  Since this is a password protected folder I'd like to
> record the remote_user and some other environment variables.
> Something like:
>
> http://www.mysite.com/getfile.pl?file1.exe

Do you mean:

http://www.mysite.com/cgi-bin/getfile.pl?file=file1.exe

Jodyman




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

Date: Fri, 10 Jan 2003 22:39:44 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Red Hat 8 breaking one-liner signature script
Message-Id: <3E1F9200.D2A59384@earthlink.net>

Emmy wrote:
> 
> Hello,
> 
> I used in mutt this one-liner for random signature,
> 
> set signature="perl -an0777F'\n\s*\n' -e 'print \$F[rand(@F)],
> \"\ngee\n\"' ~/pers_doc/massime|"
> 
> All on one line, of course. The ~/pers_doc/massime text file contains
> assorted quotes, often spanning more than one line. The quote
> separator is an empty line (\n\s*\n above)
> 
> Now, used with Mutt 1.4, Perl 5.8 inside RH 8.0, it only prints one
> word of a random sentence (see below, I added the "gee" string just to
> see where it would be printed). From an xterm the one liner works
> perfectly, i.e. prints whole multi-line signatures as before (removing
> the backslashes before $F and the \n double quotes, of course). From
> Mutt (launched as "xterm -e mutt" from the WM menu) it doesn't work.

WAG: It's possible that Mutt isn't running the command through bash, and
as a result, the -F'\n\s*\n' part is being misinterpreted.  See what
happens if you run this through Mutt:

   perl -le 'print q <<' -e'\n\s*\n' -e '>>;'
(Note the lack of a space between the second -e and it's argument)

If everything is working right, you should get:
<
\n\s*\n
>

Otherwise... there's your error.

[snip]
> What should I fix, and where should I look? It is known that Perl 5.8
> and the Unicode system-wide settings don't really like each other yet,

Oh, actually, the problem is that perl 5.8 *does* like the unicode
system-wide settings.

The problems that people have there occur because they think "unix means
you don't have to binmode() your binary files", and they get bitten by
the fact this is untrue on redhat8 with perl5.8.

The historical "binary mode == text mode on unix" behavior has induced a
certain laziness in unix programmers with respect to binmode, causing
them to leave it out when they should have it in.

> but this is probably also due to the environment in which mutt
> launches that script, right? Either way, any suggestion is
> appreciated.

Hmm, try this (both from within Mutt, and from the xterm):
   echo $LANG
Or:
   perl -le 'print $ENV{LANG}'

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 10 Jan 2003 22:50:56 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Relocation error (was: Re: "Can't locate loadable object" - but it's there)
Message-Id: <3E1F94A0.ED759E6B@earthlink.net>

Ernest Mueller wrote:
[snip]
> Now I have another problem.  perl sees the shared library, but can't
> load it, giving the error:
> 
> Can't load
> '/usr/local/lib/perl5/site_perl/sun4-solaris/auto/
>    XML/Parser/Expat/Expat.so'
> for module XML::Parser::Expat: ld.so.1: /usr/local/bin/perl: fatal:
> relocation error: file
> /usr/local/lib/perl5/site_perl/sun4-solaris/auto/
>    XML/Parser/Expat/Expat.so:
> symbol Perl_stack_sp: referenced symbol not found at
> /usr/local/lib/perl5/5.6.1/sun4-solaris/DynaLoader.pm line 206.
[snip]
> Any ideas?

This indicates that the Expat.so which you are using was not compiled
with the version of perl you have on your machine.

The proper fix is to reinstall the XML-Parser-2.31.tar.gz distribution.

You should probably do this with:
   perl -MCPAN -e "install('XML-Parser')"

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 10 Jan 2003 23:45:11 GMT
From: "Mats" <mats.svensson2@telia.com>
Subject: Re: stucked
Message-Id: <20030111.004525.1504569917.9654@telia.com>

Hi Mr Allaire

"> I've dealt with parent/child relationships in databases via tree
> representations (see Joe Celko's book "SQL for Smarties").  That's a
> nice data driven approach."

I looked it up at amazon and it looked very great, Joe Celko seemed to be
a very productive man. 

"If you are thinking in Perl, look at perldoc
> perldsc "More Elaborate Records."  "

OK. 

"If you represent a message like :
> 
> my $msg = {
> 	TEXT => $body,
> 	ID => $unique_id,
> 	DATE => $post_date,
> 	AUTHOR => $authors{$some_id},
> 	RECORD => $filename,
> 	PARENT => $msg_ref,
> 	CHILDREN => [ @msg_refs ],
> 	PRINT => \&print_code,
> 	PURGE => \&del_code,
> 	...
> }"

That was a very good idea, I'm to strict and coventional when working
with hashes so your idea here was helpful also with other problems I
have. I will use it.

"> Of course there is more than one way to so it -- I am just tossing out
> an idea.  I'd opt for the database driven approach myself."

Yes, there is more than one way, but I will use your idea to build up the
chunk of messages

" Take a look at
> 
>
http://searchdatabase.techtarget.com/tip/1,289483,sid13_gci537290,00.html"

That was also a great tip! Thanx!

/Regards from Mats.


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

Date: Fri, 10 Jan 2003 23:15:25 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: undef of large Hashes/Arrays took a very long time
Message-Id: <3E1F9A5D.B4CF629E@earthlink.net>

Jan Schubert wrote:
> 
> Pls, may someone point me to some documentation about memory
> consumption of very large Arrays and/or Hashes!? It seems that
> undef/unfree of huge Arrays (2-3GB) takes very long

It generally shouldn't.  If it does, there's a bug in your malloc.

Type this from the commandline:
   perl -V:usemymalloc

Whichever it is, consider recompiling perl to have the opposite value,
and see if this has any effect.

> and would even apply when exiting a perl-program.

Not necessarily.  Under normal circumstances, many of the things in
perl's memory are freed simply by exiting -- that is, the operating
system magically cleans up all memory used by a program.  This happens
nearly instantaneously, no matter what kind of wierd malloc bugs the
program might have.

> Is there any way to speed this up? If i do a kill to the proggy it
> exits immediatly and the memory is freed, so how can i do this
> in perl?

You can do this with:
   kill "TERM" => $$;
However, it will have the rather harmful effect that no destructors will
be called, which may cause problems if your program has open network
connections, especially if whatever they're connected to expects to get
some special message before the connection is closed.

> Also i'm interessted in geeting some information about access-times to
> such huge arrays and hashes. Which one is faster?

Generally, to access one element of an array is faster than accessing
one element of a hash.

The two data structures have entirely different purposes, though -- what
is it you're using them for?

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 10 Jan 2003 21:04:44 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Unix Vars declared in system() call -> %ENV
Message-Id: <3E1F7BBC.FF092654@earthlink.net>

Sam Holden wrote:
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> > Christopher Hamel wrote:
[snip]
> >> Is there any way to launch this program within Perl and have the
> >> variable declarations within the program update %ENV?
> >
> > Sure:
> >    open SHELL_SCRIPT, "-|", '. my_unix_script >/dev/null; env'
> >       or die "Couldn't start shell script: $!";
[snip reading from SHELL_SCRIPT and inserting into %ENV]
> Of course that will get it wrong if the script did something really
> aweful like:
> 
> foo='howdy
> bar=baz'
> export foo
> 
> But of course that's just silly :)

If one wants to deal with really bizzarre things like that, you'd have
to write a sub-program which outputs it's environment in an unambiguous
way.

   open SHELL_SCRIPT, "-|", q[
      . my_unix_script >/dev/null
      perl -e 'print 0+keys(%ENV), "\\n";' \\
           -e 'print pack("N/a*", $_) for %ENV;"
   ]  or die "Couldn't start shell script: $!";
   chomp(my $count = <SHELL_SCIPT>);
   my @add_to_env = unpack "N/a*" x (2*$count),
      do { local $/; <SHELL_SCRIPT> };
   close SHELL_SCRIPT;
   while( my ($key, $val) = splice @add_to_env, 0, 2 ) {
      $ENV{$key} = $val;
   }
   __END__
[untested]

Interestingly, this is about the same number of lines as the previous
version, even taking into account the subprogram.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Fri, 10 Jan 2003 20:46:07 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: What is a simple way to read and write zip files?
Message-Id: <3E1F775F.421B2BA3@earthlink.net>

Hal Vaughan wrote:
> Benjamin Goldberg wrote:
[snip]
> > Look into Archive::ZIP, on CPAN.
>
> Thanks.
> 
> I've looked at it. (And downloaded it and been exerpimenting w/ it.)
> It's VERY poorly documented.  There are examples, but they leave a lot
> of holes for someone who doesn't know whatever C or C++ library this
> is accessing.

It's using the 'zlib' C library (which is used for compression and
decompression), and it's own XS library for handling all other aspects
of the zip file format.

No aspect of the Archive::Zip module appears designed to reflect zlib,
though -- that stuff is all hidden behind the scenes.

The documentation of A::Z seems very clear to me, though -- I don't see
what you're having problems with.

> It is also strongly OO, and it uses other IO modules which, to many,
> might be easy to understand, but to someone still trying to learn OO
> and IO, it is very hard to follow.

Although it *uses* a number of other IO modules, you shouldn't have to
use any of those yourself to use A::Z, especially if your goal is to
simply uncompress members of the zipfile into strings.

   use Archive::Zip qw( :ERROR_CODES :CONSTANTS );
   my $zipfile = Archive::Zip->new();
   $zipfile->read( 'someZip.zip' ) == AZ_OK
      or die 'read error';
   foreach my $member ( $zipfile->members ) {
      print "File ", $member->fileName(), " contains:\n";
      print $zipfile->contents( $member ), "\n";
   }
   # [untested]

> I was hoping to find something with straightforward where I could do
> something like using a simple read or write function.

The simpler a module is, the less functionality it has.

Archive::Zip offers a lot of functionality, and as a result, looks very
complex.

However, you don't need to *use* all of that functionality -- you can,
if you want, use it in as simple a manner as I've shown above.

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Sat, 11 Jan 2003 02:23:26 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: What is a simple way to read and write zip files?
Message-Id: <udvu1vg4mfm5gne4n3rtqufbn4nenivm93@4ax.com>

Hal Vaughan wrote:

> Maybe a module that simple uncompresses a zip 
>compressed string (and compresses it as well)?

	Archive::Zip

which relies on Compress::Zlib for the actual compression/decompression.

Careful: you can't just open a ZIP file, add new data, and save the data
over the old data with writeToFileNamed. That is because the module uses
the file as backup for holding the member data.

For that, there is a special method, overwrite (and overwriteAs), which
both appear to be rather underdocumented.

-- 
	Bart.


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

Date: Sat, 11 Jan 2003 02:27:30 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: What is a simple way to read and write zip files?
Message-Id: <420v1vss1rhsjkp58k02jsh0rh92bee2ku@4ax.com>

Hal Vaughan wrote:

>I've looked at it. (And downloaded it and been exerpimenting w/ it.) It's 
>VERY poorly documented.  There are examples, but they leave a lot of holes 
>for someone who doesn't know whatever C or C++ library this is accessing.  
>It is also strongly OO, and it uses other IO modules which, to many, might 
>be easy to understand, but to someone still trying to learn OO and IO, it 
>is very hard to follow.
>
>I was hoping to find something with straightforward where I could do 
>something like using a simple read or write function.

All you need is the recipe.

I've been involved in threads about this module here, or in
comp.lang.perl.modules, with working sample code. There is also a recent
thread on PerlMonks (which is where I learned about overwrite()), again
with working code. 

	<http://perlmonks.org/index.pl?node_id=224370>

-- 
	Bart.


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

Date: Fri, 10 Jan 2003 16:36:25 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: word lenght
Message-Id: <slrnb1uin9.tga.tadmc@magna.augustmail.com>

R.Noory <rnoory@videotron.ca> wrote:

> So please help me with these expressions. 
> 
> 1. 6 letters and more. 

   m/[a-zA-Z]{6,}/

> 2. more or equal to six letters

   m/[a-zA-Z]{6,}/

How is requirement #2 different from #1 ?


> 3. equal to 6 letters

   m/[a-zA-Z]{6}/

> 4. less than 6 letters

   m/[a-zA-Z]{0,5}/

> 5. less or equal to 6 letters

   m/[a-zA-Z]{0,6}/


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 10 Jan 2003 16:48:20 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: word lenght
Message-Id: <slrnb1ujdk.tga.tadmc@magna.augustmail.com>

R.Noory <rnoory@videotron.ca> wrote:

> Applying this pattern ['\S(\w{5})'] gives me words with six letters and more. 


No it doesn't.

Please post actual Perl code if you expect others to understand it.

What operator does that stuff appear in?


Your code fragment appears to match *one* character, because
that is all that a character class _can_ match.

If it is indeed a character class, then it matches the same
characters as    ['(){}\S\w5]

Perhaps the context for the code fragment is   m['\S(\w{5})']
in which case it _still_ does not match 6 letters. It matches
strings of length 8:

   1 single quote
   1 non-whitespace character
   5 word characters (which can include chars that are NOT letters)
   1 single quote


> ['\S(\w{1,5})']doesn't seem to work. 


That would depend on what it is that you were expecting it to do.

You did not tell us what it is that you were expecting it to do.

What were you expecting it to do?


> So please help me with these expressions. 


They appear to be similiar to the ones you asked about
several weeks ago. Are you still working on that same problem?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 11 Jan 2003 02:43:46 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: word lenght
Message-Id: <CxLT9.3767$Dq.382446@newsread2.prod.itd.earthlink.net>

"R.Noory" <rnoory@videotron.ca> wrote in message

> Applying this pattern ['\S(\w{5})'] gives me words with six letters and
more.
> ['\S(\w{1,5})']doesn't seem to work. So please help me with these
expressions.
>
> 1. 6 letters and more.
> 2. more or equal to six letters
> 3. equal to 6 letters
> 4. less than 6 letters
> 5. less or equal to 6 letters
>

Looks like homework to me.  :-)

Jody




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

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.  

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 V10 Issue 4382
***************************************


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