[25148] in Perl-Users-Digest
Perl-Users Digest, Issue: 7397 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 12 14:05:38 2004
Date: Fri, 12 Nov 2004 11:05:08 -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, 12 Nov 2004 Volume: 10 Number: 7397
Today's topics:
Re: Best way to pass module creator reference <andres@exlibris-usa.com>
Extract domain name <blislecp@hotmail.com>
Re: Extract domain name <mritty@gmail.com>
Re: Extract domain name <and11@rol.ru>
Re: Extract domain name <a@ry.ca>
Re: Extract domain name <and11@rol.ru>
FAQ 3.18: Is it safe to return a reference to local or <comdog@panix.com>
Re: FAQ 9.16: How do I decode a CGI form? <do-not-use@invalid.net>
Re: FAQ 9.16: How do I decode a CGI form? (Anno Siegel)
Fun problem: Overlapping words <usenet_05_08_2004@stuartmoore.org.uk>
Re: Fun problem: Overlapping words <jurgenex@hotmail.com>
Re: how greedy is nongreedy in regexp ? <usenet@morrow.me.uk>
Re: human nature of perl (new operators etc) <wyzelli@yahoo.com>
Re: human nature of perl (new operators etc) <usenet@morrow.me.uk>
little indent script <ioneabu@yahoo.com>
Re: little indent script <jurgenex@hotmail.com>
Re: little indent script <a@ry.ca>
Re: Looking to improve program (Tom Ewall)
Re: Looking to improve program <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 12 Nov 2004 07:55:18 -0500
From: Andres Monroy-Hernandez <andres@exlibris-usa.com>
Subject: Re: Best way to pass module creator reference
Message-Id: <JPydnX8_HvcqLwncRVn-ig@comcast.com>
Drago wrote:
> I have a module which I would like to be able to create instances of a
> class it knows nothing about. Is there a neat way short of an anonymous
> subroutine, like this example:
>
> use Foo;
> use Bar;
> # this works, but seems overly verbose
> Bar->new(sub { Foo->new(@_) } );
>
> I note that
>
> $c = \&Foo;
> print ref($c); # says CODE
>
> but within my module, one cannot then say
>
> $c->new(...);
>
> So I am not sure what \&Foo is giving me (i.e. a code reference to
> what?). So is there a better way than the way I did it in the first
> example?
I am not sure how clean this is, but you could pass a string with the
name of the class that you want to instantiate.
use strict;
use warnings;
my $foo = Foo->new('Bar');
print ref($foo), ",", ref($foo->{object}), "\n";
package Foo;
sub new {
my ($class, $param) = @_;
my $this;
eval ( "\$this->{object} = $param->new('test');");
return bless($this, $class);
}
package Bar;
sub new {
my $class = shift;
my $this = { value => shift };
return bless($this, $class);
}
--
Andrs Monroy-Hernndez
------------------------------
Date: Fri, 12 Nov 2004 08:02:57 -0800
From: "Shabam" <blislecp@hotmail.com>
Subject: Extract domain name
Message-Id: <3u-dnd1_9JRvQAncRVn-ig@adelphia.com>
How do you fetch just the domain name part of a variable in a script? The
variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
"http://sub.domain.com/blahblah/whatever/page.htm".
What I need is to extract just the "domain.com".
------------------------------
Date: Fri, 12 Nov 2004 16:23:55 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Extract domain name
Message-Id: <vs5ld.5$2V4.4@trndny06>
[removed non-existant groups, removed off topic AOL group, set followups
to c.l.p.m.]
"Shabam" <blislecp@hotmail.com> wrote in message
news:3u-dnd1_9JRvQAncRVn-ig@adelphia.com...
> How do you fetch just the domain name part of a variable in a script?
The
> variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
> "http://sub.domain.com/blahblah/whatever/page.htm".
>
> What I need is to extract just the "domain.com".
Try using the Regexp::Common module from CPAN. I seem to recall it has
a method for parsing URIs
Paul Lalli
------------------------------
Date: Fri, 12 Nov 2004 20:09:29 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: Extract domain name
Message-Id: <cn2qt0$n1j$1@news.rol.ru>
Look for URI module. IMHO, its a good and simple thing for parsing URLs
use URI;
($domain = URI->new("http://www.domain.com/blahblah/whatever/page.htm")->authority) =~ s/^www\.//i
Regards,
Andrew
Shabam wrote on 12 Ноябрь 2004 16:02:
> How do you fetch just the domain name part of a variable in a script? The
> variable can be "http://www.domain.com/blahblah/whatever/page.htm" or
> "http://sub.domain.com/blahblah/whatever/page.htm".
>
> What I need is to extract just the "domain.com".
--
Andrew
------------------------------
Date: Fri, 12 Nov 2004 11:38:38 -0600
From: Ryan Thompson <a@ry.ca>
Subject: Re: Extract domain name
Message-Id: <20041112112906.V20279@coyote>
[ Cross-post trimmed ]
Shabam wrote to :
> How do you fetch just the domain name part of a variable in a script?
> The variable can be "http://www.domain.com/blahblah/whatever/page.htm"
> or "http://sub.domain.com/blahblah/whatever/page.htm".
>
> What I need is to extract just the "domain.com".
This is definitely a non-trivial problem. Fortunately, it's been
partially solved already. I'm involved in the SpamAssassin and SURBL
projects, where this really became obvious when spammers started
obfuscating URIs, and using domains from many different TLDs where it
takes a lot of research to determine where to chop the hostname to get
the actual registrar domain.
There's much more to it than using a library or regexp.
See get_uri_list() in SpamAssassin 3's PerMsgStatus.pm for one
"industrial strength" solution to this problem, which still has room for
improvement.
- Ryan
--
Ryan Thompson <ryan@sasknow.com>
SaskNow Technologies - http://www.sasknow.com
901-1st Avenue North - Saskatoon, SK - S7K 1Y4
Tel: 306-664-3600 Fax: 306-244-7037 Saskatoon
Toll-Free: 877-727-5669 (877-SASKNOW) North America
------------------------------
Date: Fri, 12 Nov 2004 20:40:45 +0000
From: Andrew Tkachenko <and11@rol.ru>
Subject: Re: Extract domain name
Message-Id: <cn2snj$n1j$2@news.rol.ru>
Sorry, did'nt pay attention to sub-domains in your example.
So, IMHO, it depends on your task - if it allows to guess possible
TLD values, then just split domain name into parts and leave just matched
TLD and SLD.
Regards,
Andrew
Ryan Thompson wrote on 12 Ноябрь 2004 17:38:
> [ Cross-post trimmed ]
>
> Shabam wrote to :
>
>> How do you fetch just the domain name part of a variable in a script?
>> The variable can be "http://www.domain.com/blahblah/whatever/page.htm"
>> or "http://sub.domain.com/blahblah/whatever/page.htm".
>>
>> What I need is to extract just the "domain.com".
>
> This is definitely a non-trivial problem. Fortunately, it's been
> partially solved already. I'm involved in the SpamAssassin and SURBL
> projects, where this really became obvious when spammers started
> obfuscating URIs, and using domains from many different TLDs where it
> takes a lot of research to determine where to chop the hostname to get
> the actual registrar domain.
>
> There's much more to it than using a library or regexp.
>
> See get_uri_list() in SpamAssassin 3's PerMsgStatus.pm for one
> "industrial strength" solution to this problem, which still has room for
> improvement.
>
> - Ryan
>
--
Andrew
------------------------------
Date: Fri, 12 Nov 2004 17:03:04 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 3.18: Is it safe to return a reference to local or lexical data?
Message-Id: <cn2qc8$frm$1@reader1.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
3.18: Is it safe to return a reference to local or lexical data?
Yes. Perl's garbage collection system takes care of this so everything
works out right.
sub makeone {
my @a = ( 1 .. 10 );
return \@a;
}
for ( 1 .. 10 ) {
push @many, makeone();
}
print $many[4][5], "\n";
print "@many\n";
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: 12 Nov 2004 13:41:54 +0100
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <yzdvfcbck8d.fsf@invalid.net>
Sam Holden <sholden@flexal.cs.usyd.edu.au> writes:
> On 12 Nov 2004 10:04:03 +0100, Arndt Jonasson <do-not-use@invalid.net> wrote:
> >
> >
> > This phrase "cargo cult" is something I hadn't seen before I started
> > reading this news group. I think it's a very good expression (I think
> > I know what it means in real life, but I'll refrain from trying to
> > explain it), but where did it originate in the context of programming?
> > It can certainly be applied to other languages than Perl.
>
> It's a term that isn't restricted to perl, I've heard it used with
> other languages. Perl suffers from it greatly due to Perl's
> popularity in early (and later) CGI programming. Hence lots of bad
> code was written by those not exactly "skilled in the art" and
> since it was for the web, it was published on the web and then
> copied by others even less skilled in the art...
>
> http://www.catb.org/~esr/jargon/html/C/cargo-cult-programming.html
Thanks. Now I have to reread that book - I didn't remember the
reference there.
A personal example of cargo cult programming was the way everyone,
including me, inserted a certain piece of incomprehensible TECO code
in their emacs.init, just because it did "good things". It did do good
things, and eventually I traced the code back to its source (since it
had mutated a little on the way) and learned what it actually
did. Later, I found that my own substantially grown emacs.init had
been copied into those of quite a lot of people.
------------------------------
Date: 12 Nov 2004 13:05:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <cn2ce3$raq$1@mamenchi.zrz.TU-Berlin.DE>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> >>>>> "BM" == Brian McCauley <nobull@mail.com> writes:
>
> BM> I concur with Gunnar about this rant adversely affecting
> BM> credibility. (Personal winge: I don't like the use of the word
> BM> 'unprofessional'. A professional is, by definition, someone getting
> BM> paid to work on something. The implication of using 'unprofessional'
> BM> in this way that work for which people is paid is necessaritly of a
> BM> higher quality than work that is given freely is anathma to me).
>
> i disagree with your definition of professional. in my high school drama
> class our teacher said that there were professional (paid) productions
> that were amateurish and amatuer productions that were professional. i
> know many open source coders who i would call professional even without
> getting paid and we have all seen paid cow-orkers that shouldn't be in
> the coding profession.
Amateurs do it because they like to, professionals because they need
to eat.
The defining characteristic of an amateur isn't the quality of the
work, though it would be silly to deny there's a correlation. An
amateur has a different perspective and hence different priorities.
A professional must optimize the productivity of her work, or she'll
be out of a job. That means spending on anything only the exact
amount of effort that is needed to get it done. It is amateurish,
for instance, to polish some interior interface till it shines if
a rough version does the job.
The amateur wants to optimize, if anything, the satisfaction she gets
from her work. If that means spending a week (or a month) on something
few people will ever notice, that's fine, and the few who do notice
may enjoy themselves tremendously. The world may have to wait a week
or a month longer for the finished product.
If it ever gets finished... There's another difference. An amateur
can afford to leave unfinished work around, perhaps indefinitely.
If that happens to a professional, it's a failure.
The style of a professional will tend to stick to tried-and-proven
constructs and avoid any risk of current failure and future misunder-
standing. It will be deliberately predictable and schematic. An
amateur may find that boring and use some rare idioms or daring
inventions just to spice things up. Thus, an amateur may develop
a personal, characteristic style of programming.
A professional is trained to take up *any* house style without a hitch,
just like a studio musician is expected to play by ear a credible
rendition of any musical style. The amateur blues player may play a
more authentic blues, but will suck at tango (or not). But I digress...
Similarly, the professional is expected to have a broad knowledge
of the field, something that grows on a good education (haha) plus
a lifetime of experience, at a rate of 8+ hours a day, in different
work environments. Few amateurs get that amount of experience
and diversification. On the other hand, If you need an expert in
some obscure field of knowledge no professional can afford to learn,
you may have to look for an amateur.
I believe that the open software environment is a place where both
types of programmers can work together and where their different
take on things can merge into each other's culture. That is a
good thing.
Anno
------------------------------
Date: Fri, 12 Nov 2004 17:12:22 +0000
From: Stuart Moore <usenet_05_08_2004@stuartmoore.org.uk>
Subject: Fun problem: Overlapping words
Message-Id: <cn2qtn$lkb$1@gemini.csx.cam.ac.uk>
A bit of a poser for anyone bored:
I was chatting with some friends, and we were trying to work out
suitable strings of letters which could have spaces and punctuation in
different places to produce different sentences
e.g.
Therestopenlarge
parses to
There stop enlarge
or
The rest open large
Anyone have an idea of a good perl program to work these out? My
thoughts so far involved grabbing words from /usr/share/dict/words (or
whatever the equivalent is on your system) and loading them into a hash
so it's quick to see if foo is a word; choosing one at random (e.g.
there); trying to find a subword (e.g. the), then looking for a word
starting with the difference (e.g. re.*) until you end up with a
suitable string. Then repeat.
My hope is to find some that make sense, but I'm not optimistic.
Hope that some of you are interested by the challenge.
------------------------------
Date: Fri, 12 Nov 2004 17:27:07 GMT
From: "Jrgen Exner" <jurgenex@hotmail.com>
Subject: Re: Fun problem: Overlapping words
Message-Id: <Ln6ld.15$d96.4@trnddc01>
Stuart Moore wrote:
> A bit of a poser for anyone bored:
>
> I was chatting with some friends, and we were trying to work out
> suitable strings of letters which could have spaces and punctuation in
> different places to produce different sentences
>
> e.g.
>
> Therestopenlarge
>
> parses to
>
> There stop enlarge
> or
> The rest open large
>
> Anyone have an idea of a good perl program to work these out? My
> thoughts so far involved grabbing words from /usr/share/dict/words (or
> whatever the equivalent is on your system) and loading them into a
> hash so it's quick to see if foo is a word; choosing one at random
> (e.g. there); trying to find a subword (e.g. the), then looking for a
> word starting with the difference (e.g. re.*) until you end up with a
> suitable string. Then repeat.
>
> My hope is to find some that make sense, but I'm not optimistic.
>
> Hope that some of you are interested by the challenge.
Well, this has little to do with Perl, but an exhaustive brute force search
should be easy to implement.
- sort all your words by length, shortest first.
- try to match each word against the beginning of the string.
- when you found a match try matching the rest of the string over again;
- if the rest of the string resolves, then you found a solution
- if the rest of the string doesn't resolve, then continue searching for
a different matching beginning
Of course this is probably not the smartest approach. After all this looks
like an NP-complete problem.
jue
------------------------------
Date: Thu, 11 Nov 2004 22:13:29 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: how greedy is nongreedy in regexp ?
Message-Id: <9p4d62-vm6.ln1@osiris.mauzo.dyndns.org>
Quoth Brian McCauley <nobull@mail.com>:
>
>
> Anno Siegel wrote:
> > peter pilsl <pilsl@goldfisch.at> wrote in comp.lang.perl.misc:
> >
> >>
> >>the following substitution does not what I want. So I ask myself where
> >>the knot in my brain is this time.
> >>
> >>I want to clean up urls and make => a/b/e/f
> >
> >
> > The standard module File::Spec has canonpath() to do this.
>
> But since this is a question about canonicalising URLs it would seem
> more appropriate to use the URI module. However the canonical() method
> of URI doesn't do this. Is this right or should it be considered a bug
> in URI?
This is right. The only time .. and . are significant in a URI is when
they are on the left-hand end of a relative URI which is being made
absolute, when they are specified to mean what you'd expect.
I would consider this a bug in the URI spec, myself; as it means that,
say,
http://foo/a/./b
is a valid URI distinct from
http://foo/a/b
; but neither can be made relative to
http://foo/a
without losing the distinction. Ach, well. :)
Ben
--
I've seen things you people wouldn't believe: attack ships on fire off
the shoulder of Orion; I watched C-beams glitter in the dark near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die. ben@morrow.me.uk
------------------------------
Date: Fri, 12 Nov 2004 12:16:53 GMT
From: "Peter Wyzl" <wyzelli@yahoo.com>
Subject: Re: human nature of perl (new operators etc)
Message-Id: <VQ1ld.33666$K7.23241@news-server.bigpond.net.au>
<ctcgag@hotmail.com> wrote in message
news:20041111171442.799$21@newsreader.com...
> "I H H" <iohihuh@INVALID.yahoo.com> wrote:
.snip.
>> ---
>> open(F,$file);
>> @lines=<F>;
>> close(F);
>>
>> <=>
>>
>> @lines<$file>\o /\n;
>
> I'm not sure I understand what you are getting at here.
I think he meant that the <> operator could have a modifier '\o' which
automatically handled the open and close part of the standard file read,
with an optional argument which specified the default value for $/
I think....
:)
--
Wyzelli
print 'Therefore, I am';
------------------------------
Date: Thu, 11 Nov 2004 22:30:20 +0000
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: human nature of perl (new operators etc)
Message-Id: <so5d62-vm6.ln1@osiris.mauzo.dyndns.org>
Quoth "I H H" <iohihuh@INVALID.yahoo.com>:
> Hello,
>
> perl's syntax is what it is (as I undertood correctly) because it was
> supposed to be like human languages.
> Meaning a word or a phrase has context bind meaning. If context changes, the
> meaning changes too.
> Should there be more human nature properties in perl?
>
> Could these be useful? At least might make scripting even more faster.
>
> Division operator in string context would be like 'split':
Larry has a rule-of-thumb for language design: either have polymorphic
operators or polymorphic values. Trying to have both leads to insoluble
ambiguities, where you can't tell what a given operation will actually
do. Consider if Perl had only one ==, which did for both strings and
numbers: which comparison would
$a = "a";
$b = 2;
$a == b;
perform, and how would you choose the other?
Ben
--
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based
on the strictest morality. [Samuel Butler, paraphrased] ben@morrow.me.uk
------------------------------
Date: Fri, 12 Nov 2004 12:53:43 -0500
From: wana <ioneabu@yahoo.com>
Subject: little indent script
Message-Id: <10p9qqr5kpsbmff@news.supernews.com>
#!/usr/bin/perl
$indent = '';
for (<STDIN>)
{
s/^\s+//;
$indent =~ s/\s$// if /^\}/;
print "$indent$_";
$indent .= ' ' if /^\{/;
}
I thought it might be useful to clean up my messy, inconsistent indenting.
I instinctively tab for indenting, but spaces take up less space. I used
one space here but I know that 'Programming Perl' recommends 3 spaces as a
matter of style.
Is this a dumb way to do this? I know it won't handle the popular indent
style that some love (also recommended in style section of 'Programming
Perl'):
foreach(@array) {
print
}
I always indent like this:
foreach(@array)
{
print
}
With the other way, I have to look more carefully for where blocks start.
Thanks!
wana
------------------------------
Date: Fri, 12 Nov 2004 17:29:34 GMT
From: "Jrgen Exner" <jurgenex@hotmail.com>
Subject: Re: little indent script
Message-Id: <2q6ld.16$d96.11@trnddc01>
wana wrote:
> I thought it might be useful to clean up my messy, inconsistent
> indenting. I instinctively tab for indenting, but spaces take up less
> space. I used one space here but I know that 'Programming Perl'
> recommends 3 spaces as a matter of style.
>
> Is this a dumb way to do this?
The easiest way is
M-x indent-region
Of course you need to run Emacs to be able to do that.
jue
------------------------------
Date: Fri, 12 Nov 2004 11:49:34 -0600
From: Ryan Thompson <a@ry.ca>
Subject: Re: little indent script
Message-Id: <20041112114233.D20279@coyote>
wana wrote to :
> #!/usr/bin/perl
>
> $indent = '';
> for (<STDIN>)
> {
> s/^\s+//;
> $indent =~ s/\s$// if /^\}/;
> print "$indent$_";
> $indent .= ' ' if /^\{/;
> }
>
> I thought it might be useful to clean up my messy, inconsistent indenting.
> I instinctively tab for indenting, but spaces take up less space. I used
> one space here but I know that 'Programming Perl' recommends 3 spaces as a
> matter of style.
>
> Is this a dumb way to do this?
Your above program will probably fail to do the right thing in many
cases, and getting it right is probably more work than you bargained
for. There are many pretty-printers available that will fix indenting,
and apply all sorts of consistent styles to even quite ugly code. From
the FreeBSD port of perltidy, for instance:
Perltidy reads a Perl script and writes an indented, reformatted
script. The default formatting closely follows the recommendations
in perlstyle(1). Perltidy can also display perl code in syntax-
colored HTML output.
If you want your code to conform to style.perl(7), you should use:
perltidy -i=8 -t -pt=2 -bt=2 -sbt=2 -ci=4 -noll -sfs -nasc -ce
(Written by knu)
WWW: http://perltidy.sourceforge.net/
On the other hand, if you just want to learn more about regexes and
formatting, you can probably learn a lot from the Perl source of
perltidy, too.
- Ryan
--
Ryan Thompson <ryan@sasknow.com>
SaskNow Technologies - http://www.sasknow.com
901-1st Avenue North - Saskatoon, SK - S7K 1Y4
Tel: 306-664-3600 Fax: 306-244-7037 Saskatoon
Toll-Free: 877-727-5669 (877-SASKNOW) North America
------------------------------
Date: 12 Nov 2004 07:59:02 -0800
From: tewall@lycos.com (Tom Ewall)
Subject: Re: Looking to improve program
Message-Id: <85bf428.0411120759.3f90bd0e@posting.google.com>
Thanks very much for the suggestions!
------------------------------
Date: Fri, 12 Nov 2004 18:57:47 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Looking to improve program
Message-Id: <LI7ld.149082$df2.118307@edtnps89>
Tom Ewall wrote:
> The following code looks for files in a directory with lables of "Run
> A" "Run B" "Run C" or "Run D". Each of the files has a total line.
> It grabs the total, something like "$211,153" and strips out the "$"
> and the ",".
>
> The program works, but I'm sure there are more efficient/perl
> idiomatic ways of doing things than how I've done them here. I'm
> looking for suggested improvements.
> -----------------------------------------------------------------------
>
>
> #!\Perl\bin\perl
>
> use strict;
>
> my $total;
> my @total;
> my $runA;
> my $runB;
> my $runC;
> my $runD;
> my @list;
> my $lmoDir = "/__lmo";
>
>
> opendir(LMODIR, $lmoDir) or die "could not open LMO directory";
> my @allfiles = grep !/^\.\.?\z/, readdir LMODIR; # exclude . and .. files
> closedir(LMODIR);
>
> foreach my $file (@allfiles){
> open LMO, "$lmoDir/$file" or die "Cannot open file: $!";
> my @list=<LMO>;
> foreach (@list) {
> if (/Run/){
> $run = "$_";
> chomp ($run);
> }
> if (/Total/){
> $total = "$_";
> chomp ($total);
> }
> }
> @total = split(/\t/, $total);
> $total = @total[$#total - 2];
> if ($run eq 'Run A'){
> $runA = $total;
> }
> if ($run eq 'Run B'){
> $runB = $total;
> }
> if ($run eq 'Run C'){
> $runC = $total;
> }
> if ($run eq 'Run D'){
> $runD = $total;
> }
> }
>
> $_ = $runA;
> s/,//;
> s/\$//;
> $runA = $_;
>
> $_ = $runB;
> s/,//;
> s/\$//;
> $runB = $_;
>
> $_ = $runC;
> s/,//;
> s/\$//;
> $runC = $_;
>
> $_ = $runD;
> s/,//;
> s/\$//;
> $runD = $_;
If you want idiomatic perl then:
#!\Perl\bin\perl
use warnings;
use strict;
my %totals;
{ local( @ARGV, $/ ) = grep -f, </__lmo/*>;
while ( <> ) {
my ( $run ) = /Run ([ABCD])/ or next;
next unless /(.*Total.*)/;
( $totals{ $run } = ( split /\t/, $1 )[ -3 ] ) =~ tr/$,//d;
}
}
for my $run ( sort keys %totals ) {
print "Run: $run Total: $totals{$run}\n";
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
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 7397
***************************************