[25362] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7607 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 5 14:05:38 2005

Date: Wed, 5 Jan 2005 11:05:21 -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           Wed, 5 Jan 2005     Volume: 10 Number: 7607

Today's topics:
    Re: Can't locate <module> in @INC - but I can see modul (Anno Siegel)
    Re: clp.moderated (was Re: ssl login to ebay) <peter.c.dietrich@freenet.de>
    Re: clp.moderated (was Re: ssl login to ebay) <matternc@comcast.net>
        decoding html entities <merkosh@hadiko.de>
    Re: decoding html entities <1usa@llenroc.ude.invalid>
    Re: FAQ 1.4: What are perl4 and perl5? <uri@stemsystems.com>
    Re: FAQ 4.30: How do I capitalize all the words on one  <georgekinley@hotmail.com>
        Format With Color Output <Some.One@hotmail.com>
        Moving to a new machine <mr@sandman.net>
    Re: Moving to a new machine (Anno Siegel)
    Re: Moving to a new machine <spamtrap@dot-app.org>
        Multiple lines of html store in variable non messy way <andrew.davey@gmail.com>
    Re: Multiple lines of html store in variable non messy  <jgibson@mail.arc.nasa.gov>
    Re: Multiple lines of html store in variable non messy  <spamtrap@dot-app.org>
    Re: Multiple lines of html store in variable non messy  <1usa@llenroc.ude.invalid>
        Need help sorting fixed length records lbeckm3@hotmail.com
    Re: Need help sorting fixed length records <1usa@llenroc.ude.invalid>
    Re: Need help sorting fixed length records lbeckm3@hotmail.com
    Re: Need help sorting fixed length records <uri@stemsystems.com>
    Re: Newbie question: "Get substring of line" <matthew.garrish@sympatico.ca>
    Re: Newbie question: "Get substring of line" <jl_post@hotmail.com>
    Re: Newbie question: "Get substring of line" <uri@stemsystems.com>
    Re: Similair command like 'ls' in perl <phaylon@dunkelheit.at>
    Re: Similair command like 'ls' in perl <mritty@gmail.com>
    Re: Similair command like 'ls' in perl <spamtrap@dot-app.org>
    Re: sort directory help <OEKilla@msn.com>
    Re: sort directory help <jgibson@mail.arc.nasa.gov>
        warnings on sorting hash of hashes <sam.wun@authtec.com>
    Re: warnings on sorting hash of hashes <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: warnings on sorting hash of hashes <thepoet_nospam@arcor.de>
    Re: warnings on sorting hash of hashes <thepoet_nospam@arcor.de>
    Re: warnings on sorting hash of hashes <bernard.el-haginDODGE_THIS@lido-tech.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 5 Jan 2005 18:51:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Can't locate <module> in @INC - but I can see module is there!
Message-Id: <crhcuo$bqa$2@mamenchi.zrz.TU-Berlin.DE>

Ken  <x3v0-usenet@yahoo.com> wrote in comp.lang.perl.misc:
> Justin Wyllie wrote:
> > Hi
> > 
> > I'm running a program sa-learn that comes with SpamAssassin anti-spam s/w.
> > 
> > This script fails on this line:
> > 
> > require Mail::SpamAssassin::CmdLearn;
> > 
> > with a message saying the module can't be found in @INC. The print-out for
> > @INC includes:
> > 
> > 
> > Can't locate Mail/SpamAssassin/CmdLearn.pm in @INC (@INC contains:
> > /usr/local/lib/perl5/site_perl/5.6.1/i386-freebsd
> > /usr/local/lib/perl5/site_perl/5.6.1 /usr/local/lib/perl5/5.6.1/i386-freebsd
> > /usr/local/lib/perl5/5.6.1 /usr/local/lib/perl5/site_perl/5.005/i386-freebsd
> > /usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl)
> > 
> > and the module is installed in
> > usr/local/lib/perl5/site_perl/5.6.1/Mail/SpamAssassin/CmdLearn.pm
> > 
> > Is there any reason other than it not being there that a Perl require call
> > may fail?
> > 
> > Many thanks
> > 
> > Justin Wyllie
> > 
> > 
> 
> Justin,
> 
> Any reason you are using a 'require' instead of 'use'? I think 'use' 
> would probably solve your problem.

I'd expect "use" to report exactly the same error as "require".

> Otherwise, from looking at the error message, it looks like it may be a 
> path problem.
>
> It says INC contains '/usr/local/lib/perl5/site_perl/5.6.1'. But, it is 
> trying to require 'Mail/SpamAssassin/CmdLearn.pm'. There is a missing / 
> between the library path and the module.
> 
> (It is looking for 
> '/usr/local/lib/perl5/site_perl/5.6.1Mail/SpamAssassin/CmdLearn.pm', 
> which doesn't exist.)

This is just wrong.  It is looking for .../5.6.1/Mail/... .  Please don't
post mere speculation.

Anno


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

Date: Wed, 5 Jan 2005 15:31:58 +0100
From: "Peter Dietrich" <peter.c.dietrich@freenet.de>
Subject: Re: clp.moderated (was Re: ssl login to ebay)
Message-Id: <crgtop$6tq$00$1@news.t-online.com>


"Tad McClellan" <tadmc@augustmail.com> schrieb im Newsbeitrag 
news:slrnctmqgv.4ck.tadmc@magna.augustmail.com...
> Did you receive the registration email? You should have
> gotten one that looks like this:
>
>   http://www.plover.com/clpm/how-to-register
>
> Did you follow the instructions for registering?
>
> Did you get an email rejecting your post?

I didn't know that one has to register in order to able to post messages.
The email address I specified is not one that I check very often, so I had 
no chance of getting to know that email.

Sincerely 




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

Date: Wed, 05 Jan 2005 11:38:19 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: clp.moderated (was Re: ssl login to ebay)
Message-Id: <GaidneSdSNhmikHcRVn-2g@comcast.com>

Peter Dietrich wrote:

> 
> "Tad McClellan" <tadmc@augustmail.com> schrieb im Newsbeitrag
> news:slrnctmqgv.4ck.tadmc@magna.augustmail.com...
>> Did you receive the registration email? You should have
>> gotten one that looks like this:
>>
>>   http://www.plover.com/clpm/how-to-register
>>
>> Did you follow the instructions for registering?
>>
>> Did you get an email rejecting your post?
> 
> I didn't know that one has to register in order to able to post messages.
> The email address I specified is not one that I check very often, so I had
> no chance of getting to know that email.
> 
You need to practice the three major rules of Usenet etiquette:

1) Read the group FAQ before posting.
2) Read the group FAQ before posting.
3) Read the group FAQ before posting.

This applies to *any* newgroup.

-- 
             Christopher Mattern

P.S. Did I mention that you need to read the group FAQ 
before posting?


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

Date: Wed, 05 Jan 2005 16:25:57 +0100
From: Uwe Mayer <merkosh@hadiko.de>
Subject: decoding html entities
Message-Id: <crh0u5$3ug$1@news2.rz.uni-karlsruhe.de>

Hi,

I am parsing HTML contents and am searching for a function which translates
entities like:

&gt;
&#34;

etc. to plain text.

Is there already a function available for this?

Thanks
Uwe 
 


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

Date: 5 Jan 2005 15:43:03 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: decoding html entities
Message-Id: <Xns95D56D0891638asu1cornelledu@132.236.56.8>

Uwe Mayer <merkosh@hadiko.de> wrote in
news:crh0u5$3ug$1@news2.rz.uni-karlsruhe.de: 

> Hi,
> 
> I am parsing HTML contents and am searching for a function which
> translates entities like:
> 
> &gt;
> &#34;
> 
> etc. to plain text.
> 
> Is there already a function available for this?

Surprisingly enough, there is a module called HTML::Entities on CPAN 
which you should have searched before posting here.



-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: Wed, 05 Jan 2005 16:32:46 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 1.4: What are perl4 and perl5?
Message-Id: <x7pt0jq1jm.fsf@mail.sysarch.com>

>>>>> "CM" == Chris Mattern <matternc@comcast.net> writes:

  CM> Uri Guttman wrote:
  >>>>>>> "CM" == Chris Mattern <matternc@comcast.net> writes:
  >> 
  CM> Uri Guttman wrote:
  >> >>>>>>> "AJF" == Alan J Flavell <flavell@ph.gla.ac.uk> writes:
  >> >> 
  AJF> As I recall, both Digital Unix (or whatever it's called today) and
  AJF> Solaris make use of Perl 4 scripts in their maintenance procedures,
  AJF> and come with a version of Perl 4 installed for that reason.  In
  >> >> fact, AJF> a Solaris user brought this up on the group recently, as I
  >> >> dimly AJF> recall.
  >> >> 
  >> >> solaris 9 at least comes with 5.6.1. i don't think solaris ever came
  >> >> with perl4. it does have some perl scripts but not perl4 ones. very
  >> >> few modern unix flavors (i wouldn't call dec unix modern :) come with
  >> >> perl4.
  >> >> 
  >> >> uri
  >> >> 
  CM> Solaris is weird.  9 ships with 5.6.1...and 5.00503.  However, it
  >> doesn't CM> seem to come with any flavor of Perl 4.
  >> 
  >> yeah, i found them in /usr/perl5. but only 5.6.1 is linked from /usr/bin
  >> and in /usr/perl5. i wonder if there are scripts which have
  >> usr/perl5/5.00503/bin/perl5.00503 for a #! line?
  >> 
  >> maybe they kept it in case some older scripts use it. in any case, i
  >> keep perl in /usr/local/bin myself so i never see solaris's perl.
  >> 
  CM> Actually, you can link your perl to /usr/bin if you want.  Solaris's
  CM> perl scripts all go the /usr/perl5 directory, so you won't break 
  CM> them.

i always use /usr/local for my locally installed stuff. much cleaner for
me. i keep /usr as pristine as possible and only load solaris stuff in
there. if i made /usr/local another partition as i have sometimes done,
it makes it much easier to backup and do other stuff.

but for other reasons (like it is so hard to get solaris versions of
many new progs and plugins) i think my solaris desktop days are
numbered.

uri

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


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

Date: Wed, 05 Jan 2005 15:48:58 GMT
From: "George Kinley" <georgekinley@hotmail.com>
Subject: Re: FAQ 4.30: How do I capitalize all the words on one line?
Message-Id: <K%TCd.34079$g4.634543@news2.nokia.com>

Josef Moellers wrote:

> kerb@kerb.eu.org wrote:
> > $text =~ tr/a-a/A-Z/;
> > 
> 
> Nope, this changes all letters to their upper case version.
> "To capitalize" means to change just the first of a series of 
> consecutive letters:
> 
> this sentence looks like this when capitalized
> This Sentence Looks Like This When Capitalized
> 
> this sentence looks like this when uppercased
> THIS SENTENCE LOOKS LIKE THIS WHEN UPPERCASED
> 
> See the difference, it's subtle, but if you look closely enough B-{)

No Offence, but then it should be "Title Case" or "Sentece Case"
and not
4.30: How do I capitalize all the words on one line?
insted
4.31: How do I "Title Case" all the words on one line?





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

Date: Wed, 05 Jan 2005 15:37:14 GMT
From: Muller <Some.One@hotmail.com>
Subject: Format With Color Output
Message-Id: <KQTCd.34078$g4.634686@news2.nokia.com>

Hi,
I am using FORMAT Comand to beautify the conlsole output using "write", 
and I use Win32::Console to add colors, I want only cirtain Variables 
defined in FORMAT to get color effect, 
if I change the color value like 
$Console->Attr($Color);
write;
then complete FORMAT output is changed,


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

Date: Wed, 05 Jan 2005 17:53:04 +0100
From: Sandman <mr@sandman.net>
Subject: Moving to a new machine
Message-Id: <mr-8D56C7.17530405012005@individual.net>

So I've ben using Perl for a couple of years on machine A, now I've bought 
machine B which comes with a newer version of perl. I don't think there is a 
compatibility issue, but I do know that I've downnloaded and installed several 
modules from cpan on machine A, but I can't remember each one specifically.

Is there a easy way to migrate user-installed perl modules to a new 
installation?

Thanks for any help!

-- 
Sandman[.net]


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

Date: 5 Jan 2005 18:36:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Moving to a new machine
Message-Id: <crhc44$bqa$1@mamenchi.zrz.TU-Berlin.DE>

Sandman  <mr@sandman.net> wrote in comp.lang.perl.misc:
> So I've ben using Perl for a couple of years on machine A, now I've bought 
> machine B which comes with a newer version of perl. I don't think there is a 
> compatibility issue, but I do know that I've downnloaded and installed several 
> modules from cpan on machine A, but I can't remember each one specifically.
> 
> Is there a easy way to migrate user-installed perl modules to a new 
> installation?

Basically you use CPAN, or CPANPLUS, to make a bundle of your old
installation, take the bundle to the new machine and install it there.
It's a simple process, see the docs.

Anno


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

Date: Wed, 05 Jan 2005 13:49:24 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Moving to a new machine
Message-Id: <WZudnbTvn8Ipq0HcRVn-sA@adelphia.com>

Sandman wrote:

> So I've ben using Perl for a couple of years on machine A, now I've bought 
> machine B which comes with a newer version of perl. I don't think there is a 
> compatibility issue, but I do know that I've downnloaded and installed several 
> modules from cpan on machine A, but I can't remember each one specifically.
> 
> Is there a easy way to migrate user-installed perl modules to a new 
> installation?

Have a look at CPAN.pm's "autobundle" command.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 5 Jan 2005 08:56:55 -0800
From: "daveyand" <andrew.davey@gmail.com>
Subject: Multiple lines of html store in variable non messy way
Message-Id: <1104944215.598441.77430@z14g2000cwz.googlegroups.com>

Hey guys, cant find on the group what i am trying to do, i blam ethat
on the search terms.

Basically this is the issue:

$Report = "<html><head>	<stlye>		.greenbold{	font-weight:
bold;font-color: green;}.redbold{font-weight: bold;font-color: red;}";
$Report .= "</style></head>";

How can i change it so that i can do something like:

$Report <<EndOfHTML;
<html>
<head>
<stlye>
 .greenbold{
font-weight: bold;
font-color: green;
}
 .redbold{
font-weight: bold;
font-color: red;
}
</style>
</head>
EndOfHTML

you should see that it will be alot more readable.

Maybe i am doing something wrong, but i get errors when trying to do
the above.

Cheers Guys.
Also if this has been discussed can someone point me in the right
direction instead of people repeating thjeir answers to me



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

Date: Wed, 05 Jan 2005 10:24:33 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Multiple lines of html store in variable non messy way
Message-Id: <050120051024330708%jgibson@mail.arc.nasa.gov>

In article <1104944215.598441.77430@z14g2000cwz.googlegroups.com>,
daveyand <andrew.davey@gmail.com> wrote:

> Hey guys, cant find on the group what i am trying to do, i blam ethat
> on the search terms.
> 
> Basically this is the issue:
> 
> $Report = "<html><head>  <stlye>     .greenbold{ font-weight:
> bold;font-color: green;}.redbold{font-weight: bold;font-color: red;}";
> $Report .= "</style></head>";
> 
> How can i change it so that i can do something like:
> 
> $Report <<EndOfHTML;
> <html>
> <head>
> <stlye>
> .greenbold{
> font-weight: bold;
> font-color: green;
> }
> .redbold{
> font-weight: bold;
> font-color: red;
> }
> </style>
> </head>
> EndOfHTML
> 
> you should see that it will be alot more readable.
> 
> Maybe i am doing something wrong, but i get errors when trying to do
> the above.

What errors? When? I can see two errors in the above, but don't know
about which you are asking.

1. You need an equal sign in your assignment statement.
2. stlye != style

Please post a complete program using cut-and-paste and not retyping.
Always have 'use strict' and 'use warnings' in any program posted to
this newsgroup.

Thanks.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: Wed, 05 Jan 2005 13:59:01 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Multiple lines of html store in variable non messy way
Message-Id: <16adnfB_4d9opUHcRVn-uQ@adelphia.com>

daveyand wrote:

> How can i change it so that i can do something like:
> 
> $Report <<EndOfHTML;

The only thing missing above is the '=' in your assignment:

my $Report = <<EndOfHTML;

More importantly though, it's not a very good idea to embed HTML within 
your Perl code in the first place. Most of us who have been working with 
these things for a while have gravitated towards a "template-based" 
approach, where skeleton output is loaded from an external template, 
which has placeholders for inserting dynamically-generated content.

My own preferred solution is the venerable Text::Template, although 
there are dozens of modules on CPAN to choose from.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 5 Jan 2005 19:02:20 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Multiple lines of html store in variable non messy way
Message-Id: <Xns95D58ED205EE5asu1cornelledu@132.236.56.8>

"daveyand" <andrew.davey@gmail.com> wrote in news:1104944215.598441.77430
@z14g2000cwz.googlegroups.com:

> Hey guys, cant find on the group what i am trying to do, i blam ethat
> on the search terms.

I blame it on (bad) laziness.

 ...

> Cheers Guys.
> Also if this has been discussed can someone point me in the right
> direction instead of people repeating thjeir answers to me

It is discussed in the FAQ:

perldoc -q "HERE documents"


-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: 5 Jan 2005 08:02:34 -0800
From: lbeckm3@hotmail.com
Subject: Need help sorting fixed length records
Message-Id: <1104940954.773508.318790@c13g2000cwb.googlegroups.com>

I have a rather large file >350 meg that I need to sort on positions
88-89 (State).  I've looked at Unix sort command and File::sort in perl
but haven't been able to figure out how to do this.  All of those sorts
are based on fields and field delimiters which I don't have as the
fields are defined by positions, not spaces or :'s etc.!!  Is there a
way to do this?  Thanks in advance!!

-Lyle



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

Date: 5 Jan 2005 16:22:11 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Need help sorting fixed length records
Message-Id: <Xns95D573AB4955Dasu1cornelledu@132.236.56.8>

lbeckm3@hotmail.com wrote in news:1104940954.773508.318790
@c13g2000cwb.googlegroups.com:

> I have a rather large file >350 meg that I need to sort on positions
> 88-89 (State).  I've looked at Unix sort command and File::sort in perl
> but haven't been able to figure out how to do this.  All of those sorts
> are based on fields and field delimiters which I don't have as the
> fields are defined by positions, not spaces or :'s etc.!!  Is there a
> way to do this?  

There are many ways. All would involve the use of the substr function:

perldoc -f substr

Make an attempt to solve your problem and post code if you run into 
difficulties.

If this is not a one-off job, I would be inclined to write something that 
converts the data file to a SQLite database (http://www.sqlite.org/) and 
issue queries against that.

Sinan

-- 
A. Sinan Unur
1usa@llenroc.ude.invalid 
(remove '.invalid' and reverse each component for email address)



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

Date: 5 Jan 2005 08:30:53 -0800
From: lbeckm3@hotmail.com
Subject: Re: Need help sorting fixed length records
Message-Id: <1104942653.037492.112440@c13g2000cwb.googlegroups.com>

I think I found a command that appears to do what I need;

sort -o sortfile +0.87 orig

of course that takes it from 88 - end of line, but I think that will
work for my purposes.  I do know how to use the substr function but I
don't know if the system would handle loading the entire file to memory
at one time (thinking I'd load the file into an array and sort from
there).  This job is one of those year-end deals, so not often, but...
Thanks for the swift reply!

-Lyle



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

Date: Wed, 05 Jan 2005 16:45:33 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need help sorting fixed length records
Message-Id: <x7k6qrq0yb.fsf@mail.sysarch.com>

>>>>> "l" == lbeckm3  <lbeckm3@hotmail.com> writes:

  l> I have a rather large file >350 meg that I need to sort on positions
  l> 88-89 (State).  I've looked at Unix sort command and File::sort in perl
  l> but haven't been able to figure out how to do this.  All of those sorts
  l> are based on fields and field delimiters which I don't have as the
  l> fields are defined by positions, not spaces or :'s etc.!!  Is there a
  l> way to do this?  Thanks in advance!!

<untested>

use Sort::Maker ;

my $sorter = make_sorter( 'GRT', string => 'substr( $_, 88, 2 )' ) ;

my @sorted = $sorter->( @unsorted ) ;


also unix sort can sort by column positions. rtfm more thoroughly. it
should be faster than any perl sort.

uri

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


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

Date: Wed, 5 Jan 2005 09:16:29 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Newbie question: "Get substring of line"
Message-Id: <_ESCd.12091$7n1.726920@news20.bellglobal.com>


<jl_post@hotmail.com> wrote in message 
news:1104933267.285083.279430@z14g2000cwz.googlegroups.com...
>
> And I've wondered:  just how much IS the performance penalty,
> anyway?  I decided to perform a Benchmark test:
>
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> use Benchmark;
> my $count = 1e7;
> my $bad = q!$string = $'  if "abc=xyz" =~ m/=/!;
> my $good = q!$string = $1  if "abc=xyz" =~ m/=(.*)$/!;
> timethese($count, {bad => $bad, good => $good})
> __END__
>
>
> The results surprised me.  I got the following output:
>
>> Benchmark: timing 10000000 iterations of bad, good...
>> bad: 18 wallclock secs (16.42 usr + -0.03 sys = 16.39 CPU)
>>      @ 610090.90/s
>> good: 22 wallclock secs (20.73 usr +  0.00 sys = 20.73 CPU)
>>       @ 482299.60/s
>
>

That's not a useful benchmark. You'd need to benchmark the two in different 
scripts in order to avoid the time penalty on the grouping regex incurred 
because you've used $` in the first. It's also not the most optimal way to 
group a pattern. Please recheck perlre:

<quote>
WARNING: Once Perl sees that you need one of $&, $`, or $' anywhere in the 
program, it has to provide them for every pattern match. This may 
substantially slow your program. Perl uses the same mechanism to produce $1, 
$2, etc, so you also pay a price for each pattern that contains capturing 
parentheses. (To avoid this cost while retaining the grouping behaviour, use 
the extended regular expression (?: ... ) instead.)
</quote>

Matt 




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

Date: 5 Jan 2005 07:34:49 -0800
From: "jl_post@hotmail.com" <jl_post@hotmail.com>
Subject: Re: Newbie question: "Get substring of line"
Message-Id: <1104939289.842837.134310@f14g2000cwb.googlegroups.com>

> <jl_post@hotmail.com> wrote in message
> news:1104933267.285083.279430@z14g2000cwz.googlegroups.com...
> >
> > And I've wondered:  just how much IS the performance penalty,
> > anyway?  I decided to perform a Benchmark test:
> >
> >
> > #!/usr/bin/perl
> > use strict;
> > use warnings;
> > use Benchmark;
> > my $count = 1e7;
> > my $bad = q!$string = $'  if "abc=xyz" =~ m/=/!;
> > my $good = q!$string = $1  if "abc=xyz" =~ m/=(.*)$/!;
> > timethese($count, {bad => $bad, good => $good})
> > __END__
> >
> >
> > The results surprised me.  I got the following output:
> >
> >> Benchmark: timing 10000000 iterations of bad, good...
> >> bad: 18 wallclock secs (16.42 usr + -0.03 sys = 16.39 CPU)
> >>      @ 610090.90/s
> >> good: 22 wallclock secs (20.73 usr +  0.00 sys = 20.73 CPU)
> >>       @ 482299.60/s
> >
> >
>

Matt Garrish replied:
> That's not a useful benchmark. You'd need to benchmark
> the two in different scripts in order to avoid the time
> penalty on the grouping regex incurred because you've
> used $` in the first.


That thought did occur to me before I posted that code.  For
curiosity's sake, I ran separate copies of the script, each one only
running one test line.  These are my results:

The "bad" code:
> 33 wallclock secs (31.89 usr +  0.01 sys = 31.90 CPU)
>    @ 31343

The "good" code:
> 45 wallclock secs (43.69 usr +  0.00 sys = 43.69 CPU)
>    @ 22890

(If you are wondering why the results are so much different than the
ones in the previous post, it's because I ran this code on a different
computer.)

As you can see, the "bad" code still is faster than the "good" code.
Besides, those code snippets are eval'ed (according to "perldoc
Benchmark"), so I don't think the "good" code suffers the penalty the
"bad" code introduces (but I could be wrong about that).  Either way,
as a one-liner, the above code that uses $' is more efficient than the
above code that does not.
 
   -- Jean-Luc



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

Date: Wed, 05 Jan 2005 16:30:09 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Newbie question: "Get substring of line"
Message-Id: <x7sm5fq1nz.fsf@mail.sysarch.com>

>>>>> "jpc" == jl post@hotmail com <jl_post@hotmail.com> writes:

  >> > my $bad = q!$string = $'  if "abc=xyz" =~ m/=/!;
  >> > my $good = q!$string = $1  if "abc=xyz" =~ m/=(.*)$/!;
  >> > timethese($count, {bad => $bad, good => $good})
  >> > __END__
  >> >
  >> >
  >> > The results surprised me.  I got the following output:
  >> >
  >> >> Benchmark: timing 10000000 iterations of bad, good...
  >> >> bad: 18 wallclock secs (16.42 usr + -0.03 sys = 16.39 CPU)
  >> >>      @ 610090.90/s
  >> >> good: 22 wallclock secs (20.73 usr +  0.00 sys = 20.73 CPU)
  >> >>       @ 482299.60/s


  jpc> That thought did occur to me before I posted that code.  For
  jpc> curiosity's sake, I ran separate copies of the script, each one only
  jpc> running one test line.  These are my results:

  jpc> The "bad" code:
  >> 33 wallclock secs (31.89 usr +  0.01 sys = 31.90 CPU)
  >> @ 31343

  jpc> The "good" code:
  >> 45 wallclock secs (43.69 usr +  0.00 sys = 43.69 CPU)
  >> @ 22890

  jpc> (If you are wondering why the results are so much different than the
  jpc> ones in the previous post, it's because I ran this code on a different
  jpc> computer.)

  jpc> As you can see, the "bad" code still is faster than the "good" code.
  jpc> Besides, those code snippets are eval'ed (according to "perldoc
  jpc> Benchmark"), so I don't think the "good" code suffers the penalty the
  jpc> "bad" code introduces (but I could be wrong about that).  Either way,
  jpc> as a one-liner, the above code that uses $' is more efficient than the
  jpc> above code that does not.

you still don't get the issue. that benchmark is totally useless to
illustrate the problem. $' causes ALL OTHER regexes to copy their entire
string in case some code somewhere references $' or friends. the actual
regex that uses $' might be faster which proves a single use of $' may
be faster than $1. the penalty lies elsewhere. please learn to properly
analyze a problem and how to properly isolate it in a benchmark.

do you think that caveat would be there if it was not true? or that
avoiding $' would stay in the docs and perl culture for so long? or that
avoiding use English would be encouraged as it uses $'? or that
English.pm would have been modified to allow it to not export aliases
for $'? of course you know all of that!!

when you have calmed down from your snit after you read this, try to
actually isolate the issue in a proper benchmark. spend some deep time
in thought in how to do it. post your benchmark for review. then talk
about $' with some confidence. until then, please don't refer newbies to
use $' as it is still bad for speed and i still think it is not good
code. it is a special case variable that doesn't extend well to multiple
grabs. it doesn't do anything special in list context as explicit grabs
do. it is another special variable to explain (actually 3). they can be
trivially emulated with explicit grabs. perl6 has dropped them. do you
need any more reasons why they are bad?

uri

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


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

Date: Wed, 05 Jan 2005 14:59:40 +0100
From: Robert Sedlacek <phaylon@dunkelheit.at>
Subject: Re: Similair command like 'ls' in perl
Message-Id: <pan.2005.01.05.13.59.39.907117@dunkelheit.at>

Petterson Mikael wrote:

> Any hints?

Hints? Many. Perl has a very good documentation, just take a look at 
'perldoc perlfunc'[0]. Sorry, I'm not a friend of giving answers in
'out of the box'-style.

g,
Robert

[0] Should work in google as well as in your cli.

-- 
http://www.dunkelheit.at/

Ordinary morality is only for ordinary people.
                       -- Aleister Crowley



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

Date: Wed, 05 Jan 2005 14:31:26 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Similair command like 'ls' in perl
Message-Id: <2TSCd.22193$fe5.17692@trndny06>

"Glenn Jackman" <xx087@freenet.carleton.ca> wrote in message
news:slrnctnr99.es7.xx087@smeagol.ncf.ca...
>     opendir my $d, $directory;
>     my @dirs = map {$_->[0]}
>                sort {$a->[1] <=> $b->[1]}
>                map {[$_, -M]}
>                grep {-d}
>                readdir $d;

Please see the warning in perldoc -f readdir to learn why this won't
work.

Paul Lalli




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

Date: Wed, 05 Jan 2005 13:36:25 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Similair command like 'ls' in perl
Message-Id: <55ydnT_aCIo0rkHcRVn-3w@adelphia.com>

Petterson Mikael wrote:

> When I do 'ls' in a shell I get a whole bunch of information including a 
> timestamp. Is it possible to get the same information in perl.

Have a look at:

perldoc -f opendir
perldoc -f readdir
perldoc -f stat

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: 5 Jan 2005 09:08:40 -0800
From: "Jake Wiley" <OEKilla@msn.com>
Subject: Re: sort directory help
Message-Id: <1104944920.267947.200310@f14g2000cwb.googlegroups.com>

Thanks for the info Nathan

I tried your sample Jim Gibson and It looks like it's trying to work
but only after several of these messages:
Use of uninitialized value in numeric comparison (<=>) at  blah blah
blah line 14
which was this line :

map{ $_->[0] }

After that the ouput was Aug 5 2004 Nov 7 2004 etc in chronological
order. Thats what I needed.. :-)

Here is my modified piece.
opendir(DIRHANDLE, "E:\\Backup") or die "couldn't open E:\\Backup :
$!";
my @dates = readdir(DIRHANDLE);
my @sorted =
map{ $_->[0] }
sort { $a->[1] <=> $b->[1] }
map { [$_, parsedate($_)] } @dates;
print @sorted;

Why the error message about "Use of uninitialized value in numeric
comparison (<=>)"



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

Date: Wed, 05 Jan 2005 10:52:43 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: sort directory help
Message-Id: <050120051052432086%jgibson@mail.arc.nasa.gov>

In article <1104944920.267947.200310@f14g2000cwb.googlegroups.com>,
Jake Wiley <OEKilla@msn.com> wrote:

> Thanks for the info Nathan
> 
> I tried your sample Jim Gibson and It looks like it's trying to work
> but only after several of these messages:
> Use of uninitialized value in numeric comparison (<=>) at  blah blah
> blah line 14
> which was this line :
> 
> map{ $_->[0] }
> 
> After that the ouput was Aug 5 2004 Nov 7 2004 etc in chronological
> order. Thats what I needed.. :-)
> 
> Here is my modified piece.
> opendir(DIRHANDLE, "E:\\Backup") or die "couldn't open E:\\Backup :
> $!";
> my @dates = readdir(DIRHANDLE);
> my @sorted =
> map{ $_->[0] }
> sort { $a->[1] <=> $b->[1] }
> map { [$_, parsedate($_)] } @dates;
> print @sorted;
> 
> Why the error message about "Use of uninitialized value in numeric
> comparison (<=>)"
> 

Sounds like parsedate() is having trouble converting your file dates
into a numerical form. Print out the file names and inspect. Look for
file names that aren't valid dates (untested):

my @files = readdir(DIRHANDLE);
print "@files\n";
my @dates = map { parsedate($_) } @files;
print join("\n",@dates),"\n";

 ... etc.


----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---


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

Date: Wed, 05 Jan 2005 22:53:20 +0800
From: sam <sam.wun@authtec.com>
Subject: warnings on sorting hash of hashes
Message-Id: <crh0j4$7bv$1@news.hgc.com.hk>

Hi,

I got the following warnings when doing sorting a hash with hashes:

Use of uninitialized value in numeric comparison (<=>) at hash-hash.pl 
line 22.
Use of uninitialized value in numeric comparison (<=>) at hash-hash.pl 
line 22.
Use of uninitialized value in numeric comparison (<=>) at hash-hash.pl 
line 22.
Use of uninitialized value in numeric comparison (<=>) at hash-hash.pl 
line 22.
Use of uninitialized value in numeric comparison (<=>) at hash-hash.pl 
line 22.
Use of uninitialized value in numeric comparison (<=>) at hash-hash.pl 
line 22.


#!/bin/usr/perl -w

#use warnings;

my %products = (
     1 => {
         name      => "Floor Wax",
         wholesale => "50.00",
         retail    => "75.00",
     },
     2 => {
         name      => "Paper Towel",
         wholesale => "20.00",
         retail    => "40.00",
     },
     3 => {
         name      => "Hand Soap",
         wholesale => "30.00",
         retail    => "65.00",
    },
);

foreach my $key (sort {$products{retail}{$a} <=> $products{retail}{$b}} 
keys %products) {
     print "\n<br>K|$key| N|$products{$key}{name}| 
W|$products{$key}{wholesale}| R|$products{$key}{retail}|";
}
print "\n";

What is wrong with line 22 on the line of "foreach...."?

Thanks
Sam.


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

Date: Wed, 5 Jan 2005 16:06:11 +0100
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: warnings on sorting hash of hashes
Message-Id: <Xns95D5A3CF1C77Eelhber1lidotechnet@62.89.127.66>

sam <sam.wun@authtec.com> wrote:

[snipped warnings]

> #!/bin/usr/perl -w
> 
> #use warnings;


Better to remove the "-w" and uncomment that.
Also add


use strict;

 
> my %products = (
>      1 => {
>          name      => "Floor Wax",
>          wholesale => "50.00",
>          retail    => "75.00",
>      },
>      2 => {
>          name      => "Paper Towel",
>          wholesale => "20.00",
>          retail    => "40.00",
>      },
>      3 => {
>          name      => "Hand Soap",
>          wholesale => "30.00",
>          retail    => "65.00",
>     },
> );
> 
> foreach my $key (sort {$products{retail}{$a} <=>
> $products{retail}{$b}} keys %products) {


Change $products{retail}{$a} and $product{retail}{$b} to
$products{$a}{retail} and $products{$b}{retail} respectively. Also, 
since %product's keys are 1, 2, 3 you should perhaps consider using 
an array of hashes instead of a hash of hashes.


-- 
Cheers,
Bernard


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

Date: Wed, 05 Jan 2005 16:14:26 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: warnings on sorting hash of hashes
Message-Id: <41dc0453$0$23121$9b4e6d93@newsread2.arcor-online.net>

sam wrote:
> Hi,
> 
> I got the following warnings when doing sorting a hash with hashes:
> 
> Use of uninitialized value in numeric comparison (<=>) at hash-hash.pl 
> line 22.
[...]
> 
> foreach my $key (sort {$products{retail}{$a} <=> $products{retail}{$b}} 
> keys %products) {
>     print "\n<br>K|$key| N|$products{$key}{name}| 
> W|$products{$key}{wholesale}| R|$products{$key}{retail}|";
> }
> print "\n";
> 
> What is wrong with line 22 on the line of "foreach...."?

There is no key "retail" in the %products hash, and
you have to dereference your sub-keys.
You probably meant to write
foreach my $key (sort {
	$products{$a}->{retail} <=> $products{$b}->{retail}
	} keys %products )
{
	...

HTH
-Chris


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

Date: Wed, 05 Jan 2005 16:27:23 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: warnings on sorting hash of hashes
Message-Id: <41dc075b$0$29422$9b4e6d93@newsread4.arcor-online.net>

Christian Winter wrote:
 > and you have to dereference your sub-keys.

Of course not "you have to", but rather should do it
for readablity.

-Chris


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

Date: Wed, 5 Jan 2005 16:33:46 +0100
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: warnings on sorting hash of hashes
Message-Id: <Xns95D5A87C0384Belhber1lidotechnet@62.89.127.66>

Christian Winter <thepoet_nospam@arcor.de> wrote:

> Christian Winter wrote:
> > and you have to dereference your sub-keys.
> 
> Of course not "you have to", but rather should do it
> for readablity.


Adding "->" is done for readability. The dereferencing is done whether 
you use "->" or not.


-- 
Cheers,
Bernard


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

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


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