[24776] in Perl-Users-Digest
Perl-Users Digest, Issue: 6929 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 29 14:06:01 2004
Date: Sun, 29 Aug 2004 11:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 29 Aug 2004 Volume: 10 Number: 6929
Today's topics:
Re: angle operator behavior with filehandles in @_ <usenet@vyznev.invalid>
Re: Execute Windows program from Perl script (??) (Tony McGuire)
Re: Execute Windows program from Perl script (??) (Tony McGuire)
Re: Execute Windows program from Perl script (??) (Tony McGuire)
Re: Execute Windows program from Perl script (??) <nobull@mail.com>
Re: Execute Windows program from Perl script (??) (Tony McGuire)
Re: Execute Windows program from Perl script (??) (Caj Zell)
Re: how many days ago is 2003-07-20 ? (Anno Siegel)
Re: how many days ago is 2003-07-20 ? (Anno Siegel)
Re: Larry Wall & Cults <Joe.Smith@inwap.com>
Re: Larry Wall & Cults jmfbahciv@aol.com
Re: Larry Wall & Cults jmfbahciv@aol.com
OS/2 port of Perl 5.8 not adding CR to \n (Seymour J.)
Re: perl - data structure build to transpose data <wfsp@removeyahoo.com>
Re: perl - data structure build to transpose data <wfsp@removeyahoo.com>
Re: perl - data structure build to transpose data <bowsayge@nomail.afraid.org>
Re: Slide show: this should be fairly straightforward - <Joe.Smith@inwap.com>
Re: The best way to parse a date in a known format <noreply@gunnar.cc>
Re: The best way to parse a date in a known format (Anno Siegel)
Re: Xah Lee's Unixism jmfbahciv@aol.com
Re: XP prints out html not page ? <nobull@mail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 29 Aug 2004 12:53:23 +0300
From: Ilmari Karonen <usenet@vyznev.invalid>
Subject: Re: angle operator behavior with filehandles in @_
Message-Id: <slrncj39sj.15t.usenet@yhteiskone.vyznev.net>
On 2004-08-29, John Bullock <john.bullock@stanford.edu> wrote:
>
> $tst = $readline($_[0]); # works
> $tst1 = <$_[0]>; # doesn't work
> $tst1 = < {$_[0]} >; # doesn't work
The last two lines get parsed as filename globs, not as readlines.
The angle bracket syntax is ambiguous in this sense, and in this case
perl doesn't do quite what you meant.
You've already discovered the two obvious ways around this: either
call readline() explicitly or assign $_[0] to a simple scalar
variable. Either way will work.
--
Ilmari Karonen
If replying by e-mail, please replace ".invalid" with ".net" in address.
------------------------------
Date: 29 Aug 2004 07:16:20 -0700
From: tony@paradoxcommunity.com (Tony McGuire)
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <f896a829.0408290616.31b184ef@posting.google.com>
Well, I'm going to take the easy way out.
I'll just write something to a file with perl, and have the scheduler
watch for that file to be modified.
Then the scheduler program can start the external program.
Thank you to everyone who participated. I really do appreciate the
feedback, regardless of whether it helped or not.
------------------------------
Date: 29 Aug 2004 07:19:50 -0700
From: tony@paradoxcommunity.com (Tony McGuire)
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <f896a829.0408290619.76fabdef@posting.google.com>
Zebee Johnstone <zebee@zip.com.au> wrote in message
> You know what you want to do, but you don't know what bits are important
> and what bits aren't. You don't know what things you are doing have an
> effect. You didn't, for example, realise that doing it from a web page
> might be important, so you didn't mention it. THere might be other
> things that are important, but you don't know what they are, and they
> might seem unimportant to you. But they might make all the difference
> to the answers you get.
>
I'm a newbie to Perl, not newsgroups. I've been running a news server
myself for over 2 years, and I've been on the 'answering' side a
couple thousand times.
Yes, I probably should have explained the environment better. And
yes, I should have known better.
But you don't know what you don't know.
This thread DID help me to understand those I reply to a bit better.
------------------------------
Date: 29 Aug 2004 07:33:17 -0700
From: tony@paradoxcommunity.com (Tony McGuire)
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <f896a829.0408290633.f6b71a0@posting.google.com>
"Tintin" <tintin@invalid.invalid> wrote
> Certainly possible, but you'd have to take webserver permissions into
> consideration. Also, if all you are doing is modifying the Apache config
> file, you'd be better off doing the mods directly with Perl (webserver
> permissions aside).
I also need to restart Apache. And since the script doing this is
executing under Apache, I don't think it'd work since no one has been
able to help me figure out how to do an execute and continue.
And if I have to do some of the work externally, why bother to learn
how to do it in a language as archane as Perl? Much easier to use a
modern program that comes with actual examples of how to accomplish
things.
> It can be done, but ask yourself the question, "How would I do this in C,
> VB, Fortran etc"? The answer will be the same.
I don't know any of those languages, so I have no idea what the 'same'
answer might be.
And thanks, Tintin. I do appreciate your time and wisdom, although
the tone of this message would probably give you a different
impression.
------------------------------
Date: Sun, 29 Aug 2004 16:27:15 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <cgsskj$orq$1@slavica.ukpost.com>
Tony McGuire wrote:
> "Tintin" <tintin@invalid.invalid> wrote
>
>
>>Certainly possible, but you'd have to take webserver permissions into
>>consideration. Also, if all you are doing is modifying the Apache config
>>file, you'd be better off doing the mods directly with Perl (webserver
>>permissions aside).
>
>
> I also need to restart Apache.
You mean something like:
system("net restart apache");
Or if you prefer you could do it more directly in Perl using StopService
and StartService from the Win32::Service module. Before you turn round
and say "how was I supposed to know about Win32::Service?" I should
point out that I didn't know about it either when I started writing this
response. All I knew was that there were Win32::* modules that provided
Perl interfaces to the Windows API - something I'd pointed out earlier
in this thread.
> And since the script doing this is
> executing under Apache, I don't think it'd work since no one has been
> able to help me figure out how to do an execute and continue.
Win32::Spawn(COMMAND, ARGS, PID)
[CORE] Spawns a new process using the supplied COMMAND, passing in
arguments in the string ARGS. The pid of the new process is stored in
PID. This function is deprecated. Please use the Win32::Process module
instead.
> And if I have to do some of the work externally, why bother to learn
> how to do it in a language as archane as Perl? Much easier to use a
> modern program that comes with actual examples of how to accomplish
> things.
Yes, if you can find a ready written program that does exactly what you
want this is in any particular case often easier than learing to program
in a general purpose programming language. If you do know a general
purpose programming language and you are happy that you can achieve
everything you want with it then there is no need to learn another
(unless of course you want to make a living as a programmer in which
case knowing at least a half a dozen general purpose programming
languages is a good idea). Be aware however that when choosing a
general purpose prgramming language to learn, choosing one in which you
happen to find examples that address the first problem you encountered
is probably not a good basis.
>>It can be done, but ask yourself the question, "How would I do this in C,
>>VB, Fortran etc"? The answer will be the same.
>
>
> I don't know any of those languages, so I have no idea what the 'same'
> answer might be.
Well, if you know any general purpose languages then substitute their
names into that sentence.
If you can't program at all then we're back to the choice of learning to
program or hoping that someone else has written a program that does what
you want.
------------------------------
Date: 29 Aug 2004 08:50:00 -0700
From: tony@paradoxcommunity.com (Tony McGuire)
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <f896a829.0408290750.5f7564ce@posting.google.com>
Joe Smith <Joe.Smith@inwap.com> wrote
> Perl is up to the task.
>
> Doing it via web request is the problem.
>
> Programs invoked via a web server tend do so using the same credentials
> as the webserver, not as the owner of the machine. The account that the
> web service uses is not an administrator. That's one of the reasons
> why a given program works when run from the command line and not from
> the web service.
> -Joe
And that explains the main problem I've been seeing.
So I'm just going to use the perl script (or CGI script, whatever the
@#$$ it is), kicked off from a web browser POST, to write to a file
after modifying the Apache conf file.
Then the scheduler program will take care of restarting Apache.
It'd sure have been nice to work this from a single location, though.
------------------------------
Date: 29 Aug 2004 10:58:52 -0700
From: cajzell@hotmail.com (Caj Zell)
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <c9eae90e.0408290958.592d60ba@posting.google.com>
tony@paradoxcommunity.com (Tony McGuire) wrote in message news:<f896a829.0408271729.5ec696b0@posting.google.com>...
> Brian McCauley <nobull@mail.com> wrote
> >
> > This is not a question about Perl, it is a question about the host
> > operating system's (in this case Window's) command line interpreter to
> > which system() give you access.
>
> It isn't? "How do you do XXX in Perl?" isn't appropriate to this
> forum? Do the questions all have to be a technical discussion of a
> function, rather than how to get a desired result from a function?
I browse this ng quite often and from many of the threads I've seen, I
have grown so conscious of what I would be asking (and thinking about
whether it is stupid, or not) that I very seldom put a question here.
These guys are probably right (at least to some extent), but it cannot
be the meaning that a stupid perl newbie like myself feels so
intimidated by the responses that he dare not pose a question.
The old saying "There are no stupid questions" does not seem to have
gained much ground here.
Caj Zell
------------------------------
Date: 29 Aug 2004 12:19:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <cgshl7$fc0$1@mamenchi.zrz.TU-Berlin.DE>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gunnar Hjalmarsson wrote:
> >> Anno Siegel wrote:
> >>> Do you have a simple, water-tight solution using only
> >>> Time::Local?
> >>
> >> Think so.
> >>
> >> sub daysago {
> >> shift =~ /^(\d{4})-(\d{2})-(\d{2})$/
> >> or die "Invalid date format";
> >> require Time::Local;
> >> import Time::Local 'timelocal';
> >> my $diff = timelocal(0,0,0,(localtime $^T)[3..5])
> >> - timelocal(0,0,0,$3,$2-1,$1-1900);
> >> $diff >= 0 or die "Future date not allowed";
> >> sprintf '%.0f', $diff / 86400
> >> }
> >>
> >> print daysago('2003-07-20'), "\n";
> >>
> >>> Note that in the presence of DST a day may have more or less
> >>> than 24 hours.
> >>
> >> Doesn't the above sub take care of that?
> >
> > I don't know, but it is only obviously correct if the interval
> > between the two times is a multiple of 24 hours.
>
> Hey, how is your math? ;-) We know it may differ 1/24 day, and since
> that it far less than 1/2, to me it's pretty obvious that sprintf()
> makes it return the correct number of days.
Then there's the problem of non-existent and ambiguous times that
comes with DST.
> > Since that isn't always so, I'd prefer a solution that has been
> > checked for these cases instead of checking myself.
>
> Sometimes I feel that there is something religious about the faith in
> using oversized modules. :(
There is a well-founded preference for peer-reviewed solutions over
ad-hoc ones.
Anno
------------------------------
Date: 29 Aug 2004 16:02:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <cgsuna$meu$2@mamenchi.zrz.TU-Berlin.DE>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gunnar Hjalmarsson wrote:
> >> Anno Siegel wrote:
> >>> Do you have a simple, water-tight solution using only
> >>> Time::Local?
> >>
> >> Think so.
> >>
> >> sub daysago {
> >> shift =~ /^(\d{4})-(\d{2})-(\d{2})$/
> >> or die "Invalid date format";
> >> require Time::Local;
> >> import Time::Local 'timelocal';
> >> my $diff = timelocal(0,0,0,(localtime $^T)[3..5])
> >> - timelocal(0,0,0,$3,$2-1,$1-1900);
> >> $diff >= 0 or die "Future date not allowed";
> >> sprintf '%.0f', $diff / 86400
> >> }
> >>
> >> print daysago('2003-07-20'), "\n";
> >>
> >>> Note that in the presence of DST a day may have more or less
> >>> than 24 hours.
> >>
> >> Doesn't the above sub take care of that?
> >
> > I don't know, but it is only obviously correct if the interval
> > between the two times is a multiple of 24 hours.
>
> Hey, how is your math? ;-) We know it may differ 1/24 day, and since
> that it far less than 1/2, to me it's pretty obvious that sprintf()
> makes it return the correct number of days.
...supposing that the rounded number is indeed what is wanted in
this case. It may differ from the number of complete calendar days
between the dates.
Then there's the problem of non-existent and ambiguous times that
comes with DST.
> > Since that isn't always so, I'd prefer a solution that has been
> > checked for these cases instead of checking myself.
>
> Sometimes I feel that there is something religious about the faith in
> using oversized modules. :(
There is a well-founded preference for peer-reviewed solutions over
ad-hoc ones.
Anno
------------------------------
Date: Sun, 29 Aug 2004 11:05:32 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Larry Wall & Cults
Message-Id: <0MiYc.109993$TI1.98802@attbi_s52>
jmfbahciv@aol.com wrote:
>>AND HOW MANY SPACES PER TAB STOP?
>
> Eight. Now talk about indenting skip returns...that one
> required blood transfusions. [emoticon looks at list of n.g.]
> I guess not many will understand.
I understand.
The style I used for PDP-10 macro assembly language was
*) Indent two spaces for error return from subroutine or UUO (or jsys)
*) Indent one space for instructions that skip or may skip.
The other point of contention was what to put between the opcode and
its arguments; space vs tab. I had some TECO macros that would
undo the damage after pristine code had been munged by someone
not conforming to style. :-)
-Joe
------------------------------
Date: Sun, 29 Aug 04 09:55:33 GMT
From: jmfbahciv@aol.com
Subject: Re: Larry Wall & Cults
Message-Id: <4131babd$0$19722$61fed72c@news.rcn.com>
In article <cJWdnetJbNOixazcRVn-iA@speakeasy.net>,
rpw3@rpw3.org (Rob Warnock) wrote:
>+---------------
>| jdoherty@nowhere.null.not (John Doherty) wrote:
>| >AND HOW MANY SPACES PER TAB STOP?
>|
>| Eight. Now talk about indenting skip returns...that one
>| required blood transfusions. [emoticon looks at list of n.g.]
>| I guess not many will understand.
>+---------------
>
>You might be surprised, Barb. Quite a few of the comp.lang.lisp crew
>are former PDP-10 geeks. ;-}
<GRIN> Yep for Lisp, but Perl and Python? Everything after python is
printing off my screen (I hate forms).
>
>And just to be sure *I'm* understanding what you're talking about, ;-}
>did you mean the convention of the second line of the following snippet?
Yep, but you have a bug. The MOVEI [emoticon scrolls down to look]
heh... my reply form is non-porportional and now everything is
wrong. That's why the hard and fast rule of 8 was used in PDP-10
land.
>
> foo: pushj p,ckperm
> pjrst badprm ; user lacks privs, complain & return.
> movei t0,cmdblk ; o.k. to proceed.
> ...
>
>Indenting the non-skip return for a subroutine call was always pretty
>clear to me.
It was to the -20 types, too. The -10 types maintained that,
if the human code reader didn't know the call had a skip return,
he had no business looking at the code. Having the opcodes all
line up left-justified made reading code quickly possible.
> ..Where things got really muddled (and contentious!) was
>when you had long skip chains of T{R,L}{Z,O,C,~}{N,E} instructions
>in which whether a particular instruction was in the skipped-to or
>non-skipped position depended dynamically on the flow of control
>above it. [HAKMEM was chock-full of that kind of "efficient" code.]
>In that case, it seemed more readable to simply not indent anything in
>the skip chain, and put a scary comment warning about the tricky code.
If you knew your biz, you didn't need the scary warning. Now
consider a list of PUSHJs where each could have a skip,
double-skip or triple-skip return. Depending on which way
you're flowing through the code, each and every one could be
indented and not-indented.
/BAH
Subtract a hundred and four for e-mail.
------------------------------
Date: Sun, 29 Aug 04 10:38:53 GMT
From: jmfbahciv@aol.com
Subject: Re: Larry Wall & Cults
Message-Id: <4131c4e4$0$19722$61fed72c@news.rcn.com>
In article <0MiYc.109993$TI1.98802@attbi_s52>,
Joe Smith <Joe.Smith@inwap.com> wrote:
>jmfbahciv@aol.com wrote:
>
>>>AND HOW MANY SPACES PER TAB STOP?
>>
>> Eight. Now talk about indenting skip returns...that one
>> required blood transfusions. [emoticon looks at list of n.g.]
>> I guess not many will understand.
>
>I understand.
>The style I used for PDP-10 macro assembly language was
> *) Indent two spaces for error return from subroutine or UUO (or jsys)
> *) Indent one space for instructions that skip or may skip.
>
>The other point of contention was what to put between the opcode and
>its arguments; space vs tab. I had some TECO macros that would
>undo the damage after pristine code had been munged by someone
>not conforming to style. :-)
<GRIN> And we had some that put them back.
/BAH
Subtract a hundred and four for e-mail.
------------------------------
Date: Sun, 29 Aug 2004 13:06:27 -0300
From: "Shmuel (Seymour J.) Metz" <spamtrap@library.lspace.org.invalid>
Subject: OS/2 port of Perl 5.8 not adding CR to \n
Message-Id: <41320d13$3$fuzhry+tra$mr2ice@news.patriot.net>
I installed Perl 5.8 from
<http://www.cpan.org/authors/id/I/IL/ILYAZ/os2/582+/> and was dismayed
to see output lines on STDOUT terminated with just linefeed instead of
CRLF. According to the dromedary and the online documentation, Perl
should have replaced the LF with the appropriate ending sequence for
the platform, and OS/2 uses the same convention as DOS, CRLF.
When I installed 5.8, I used the option to upgrade an existing
installation. Could that be the problem? Did I download the wrong
version?
Thanks for any assistance.
--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>
Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spamtrap@library.lspace.org
------------------------------
Date: Sun, 29 Aug 2004 10:26:21 +0000 (UTC)
From: "wfsp" <wfsp@removeyahoo.com>
Subject: Re: perl - data structure build to transpose data
Message-Id: <cgsb0d$4mo$1@sparta.btinternet.com>
"shree" <srigowrisn@hotmail.com> wrote in message
news:49b5740e.0408281934.2209e2fa@posting.google.com...
> Hi,
>
> I have been asked to transpose a data file extracted from an Excel
> report and saved as a .txt file. It lists time (MonthYear) in the
> header (first row). The data consists of blocks of 3 lines per
> supplier. In the example extract shown below, for Jan-04, total items
> supplied by supplier 1 were 1000, of which there were 200 defects,
> giving a defect ratio of 20%. I need to read-in this data file and
> output a file whose format I can best illustrate via an example shown
> below. Please note in the outfile's last column, it shows MonthID. If
> the data were to begin with Feb-04 and go till July-04, instead of
> Jan-04 to Mar-04 as shown below, then Feb-04 would be 1, Mar-04 2 and
> so on.
>
> Anyway, I'm struggling on thoughts of how to build a data structure to
> transform the data into the desired output file. Any pointers, code
> snippets will be greatly appreciated and I thank you in advance.
>
> Best wishes,
> Shree
>
> Sample Data filein.dat
> Jan-04 Feb-04 Mar-04
> Supp1 % 20.00% 10.17% 7.14%
> Defects 200 122 100
> Total 1000 1200 1400
> Supp2 % 3.00% 1.82% 1.90%
> Defects 60 40 40
> Total 2000 2200 2100
>
> Desired Output fileout.txt
> Supp1 % 20.00% Jan-04 1
> Supp1 Defects 200 Jan-04 1
> Supp1 Total 1000 Jan-04 1
> Supp1 % 10.17% Feb-04 2
> Supp1 Defects 122 Feb-04 2
> Supp1 Total 1200 Feb-04 2
> Supp1 % 7.14% Mar-04 3
> Supp1 Defects 100 Mar-04 3
> Supp1 Total 1400 Mar-04 3
> Supp2 % 3.00% Jan-04 1
> Supp2 Defects 60 Jan-04 1
> Supp2 Total 2000 Jan-04 1
> Supp2 % 1.82% Feb-04 2
> Supp2 Defects 40 Feb-04 2
> Supp2 Total 2200 Feb-04 2
> Supp2 % 1.90% Mar-04 3
> Supp2 Defects 40 Mar-04 3
> Supp2 Total 2100 Mar-04 3
This produces the output you indicated. If you do need a structure (e.g. a
hash of hashes) you could build it instead of using the for loop.
perlreftut, perldsc and perllol provide everything you need to construct
complex data structures.
#!/bin/perl5
use strict;
use warnings;
chomp( my $header = <DATA> );
my @months = split ' ', $header;
my $month = $#months;
while ( ! eof(DATA) ){
my @pc = split ' ', <DATA>;
my $supplier = shift @pc;
my @defects = split ' ', <DATA>;
my @total = split ' ', <DATA>;
for (my $i=1;$i<=$month+1;$i++){
my $month = $months[$i-1];
print $supplier, "\t",
$pc[0], "\t",
$pc[$i], "\t",
$month, "\t",
$i, "\n",
$supplier, "\t",
$defects[0], "\t",
$defects[$i], "\t",
$month, "\t",
$i, "\n",
$supplier, "\t",
$total[0], "\t",
$total[$i], "\t",
$month, "\t",
$i, "\n";
}
}
__DATA__
Jan-04 Feb-04 Mar-04
Supp1 % 20.00% 10.17% 7.14%
Defects 200 122 100
Total 1000 1200 1400
Supp2 % 3.00% 1.82% 1.90%
Defects 60 40 40
Total 2000 2200 2100
------------------------------
Date: Sun, 29 Aug 2004 10:59:00 +0000 (UTC)
From: "wfsp" <wfsp@removeyahoo.com>
Subject: Re: perl - data structure build to transpose data
Message-Id: <cgsctk$6lv$1@sparta.btinternet.com>
<snip question>
> This produces the output you indicated. If you do need a structure (e.g. a
> hash of hashes) you could build it instead of using the for loop.
> perlreftut, perldsc and perllol provide everything you need to construct
> complex data structures.
>
> #!/bin/perl5
>
> use strict;
> use warnings;
>
> chomp( my $header = <DATA> );
> my @months = split ' ', $header;
> my $month = $#months;
> while ( ! eof(DATA) ){
> my @pc = split ' ', <DATA>;
> my $supplier = shift @pc;
> my @defects = split ' ', <DATA>;
> my @total = split ' ', <DATA>;
> for (my $i=1;$i<=$month+1;$i++){
> my $month = $months[$i-1];
> print $supplier, "\t",
> $pc[0], "\t",
> $pc[$i], "\t",
> $month, "\t",
> $i, "\n",
> $supplier, "\t",
> $defects[0], "\t",
> $defects[$i], "\t",
> $month, "\t",
> $i, "\n",
> $supplier, "\t",
> $total[0], "\t",
> $total[$i], "\t",
> $month, "\t",
> $i, "\n";
> }
> }
>
> __DATA__
> Jan-04 Feb-04 Mar-04
> Supp1 % 20.00% 10.17% 7.14%
> Defects 200 122 100
> Total 1000 1200 1400
> Supp2 % 3.00% 1.82% 1.90%
> Defects 60 40 40
> Total 2000 2200 2100
>
Poor choice of variable names!
I should have said:
> my $month_count = $#months;
and:
> for (my $i=1;$i<=$month_count+1;$i++){
It works as is but looking at it again it's clearer this way.
------------------------------
Date: Sun, 29 Aug 2004 16:53:45 GMT
From: bowsayge <bowsayge@nomail.afraid.org>
Subject: Re: perl - data structure build to transpose data
Message-Id: <tSnYc.3808$JT3.3404@newsread3.news.atl.earthlink.net>
shree said to us:
[...]
> Anyway, I'm struggling on thoughts of how to build a data structure to
> transform the data into the desired output file. Any pointers, code
> snippets will be greatly appreciated and I thank you in advance.
[...]
This isn't pretty, but it is one way of doing it.
local $_;
my ($current, %supp, @months);
while ($_ = <STDIN>) {
chomp;
if (@months < 1) {
s/(\w{3}-\d{2})/push @months, $1; ''/eg;
} else {
if (/^([a-zA-Z0-9]+)\s+\%\s+/) {
my $sn = $1;
push @{$supp{suppliers}}, $sn;
s/^.*?%\s+//;
s/([\d\.\%]+)/push @{$supp{"$sn,\%"}}, $1; ''/eg;
$current = $sn;
} elsif (/^\s+Defects/) {
s/^\D+//;
s/(\d+)\s*/push @{$supp{"$current,defects"}}, $1; ''/eg;
} elsif (/^\s+Total/) {
s/^\D+//;
s/(\d+)\s*/push @{$supp{"$current,total"}}, $1; ''/eg;
}
}
}
foreach my $sn (@{$supp{suppliers}}) {
foreach my $no (0..$#months) {
my $pref = $supp{"$sn,%"};
my $dref = $supp{"$sn,defects"};
my $tref = $supp{"$sn,total"};
my $suffix = "\t$months[$no]\t@{[ $no + 1 ]}\n";
print "$sn\t\%\t$pref->[$no]$suffix";
print "$sn\tDefects\t$dref->[$no]$suffix";
print "$sn\tTotal\t$tref->[$no]$suffix";
}
}
__END__
EXPLANATION:
The list of months is grabbed from the first line.
Then a hash is created that contains a list of supplier names. The hash also
is built up to contain the defect percentages, the number of defects and
the totals.
When it's time to create the output, the program iterates over the
list of suppliers. For each supplier, the program iterates over the
months, outputting the various statistics for that month.
The program doesn't do exactly what you want, since it gets input from
STDIN and outputs to STDOUT, but you can easily adjust it.
Now watch someone convert this into a one-liner :)
--
my (@str) = split //,'eitrhbe ta.Jw eonerl snpu';
my (@ndx, @arr) = qw(19 22 3 15 9 21 14 17 8 5 24 0 20
4 23 7 18 10 11 16 12 2 6 13 1);
@arr[ @ndx ] = @str; print @arr, "\n";
------------------------------
Date: Sun, 29 Aug 2004 10:19:19 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Slide show: this should be fairly straightforward - a what language to use question
Message-Id: <H4iYc.88320$mD.29259@attbi_s02>
Al Davis wrote:
> slide show
Many years ago I wrote something to do that.
An example of it in use is http://www.inwap.com/inwap/cats/murdock/
-Joe
------------------------------
Date: Sun, 29 Aug 2004 15:51:58 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: The best way to parse a date in a known format
Message-Id: <2pe5laFjs950U1@uni-berlin.de>
Anno Siegel wrote:
> Gunnar Hjalmarsson wrote:
>> Leif Wessman wrote:
>>>
>>> my @months = ("janu","febr","mars","apri","maj","juni",
>>> "juli","augu","sept","okto","nove","dece");
>>
>> From here you can for instance do:
>>
>> my $datetext = '05 04/janu';
>> my $regexp = qr!^(\d\d) (\d\d)/(@{ [ join '|', @months ] })$!;
>
> It would be more robust to sort the month names into descending
> order by length before building the month-parsing part:
>
> join '|' sort { length( $b) <=> length( $a) } @months
>
> It doesn't make a difference with this set of month names, but who
> knows...
It doesn't make a difference with any set of month names, since the
pattern is anchored to the end of the string.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 29 Aug 2004 15:58:50 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: The best way to parse a date in a known format
Message-Id: <cgsufq$meu$1@mamenchi.zrz.TU-Berlin.DE>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gunnar Hjalmarsson wrote:
> >> Leif Wessman wrote:
> >>>
> >>> my @months = ("janu","febr","mars","apri","maj","juni",
> >>> "juli","augu","sept","okto","nove","dece");
> >>
> >> From here you can for instance do:
> >>
> >> my $datetext = '05 04/janu';
> >> my $regexp = qr!^(\d\d) (\d\d)/(@{ [ join '|', @months ] })$!;
> >
> > It would be more robust to sort the month names into descending
> > order by length before building the month-parsing part:
> >
> > join '|' sort { length( $b) <=> length( $a) } @months
> >
> > It doesn't make a difference with this set of month names, but who
> > knows...
>
> It doesn't make a difference with any set of month names, since the
> pattern is anchored to the end of the string.
Ah, okay. I didn't see that.
Anno
------------------------------
Date: Sun, 29 Aug 04 10:15:01 GMT
From: jmfbahciv@aol.com
Subject: Re: Xah Lee's Unixism
Message-Id: <4131bf4d$0$19722$61fed72c@news.rcn.com>
In article <87llfzqmck.fsf@thalassa.informatimago.com>,
Pascal Bourguignon <spam@mouse-potato.com> wrote:
>Ian Wilson <scobloke2@infotop.co.uk> writes:
>
>> David Schwartz wrote:
>>
>> > <ctcgag@hotmail.com> wrote in message
>> > news:20040827135423.154$1T@newsreader.com...
>> >
>> >>"David Schwartz" <davids@webmaster.com> wrote:
>> >
>> >>> I don't follow you at all. I think you'll find the most useful,
>> >>>meaningful complaints about, say, a Ford Explorer from the people who
>> >>>drive one every day.
>> >
>> >>And if they continue to drive one everyday, perhaps you would conclude
>> >>that their complaints are insincere.
>> > That's a load of crap.
>> > DS
>> >
>>
>>
>> You're both right but ...
>>
>> Xah Lee: "I'm starting my own cult to exterminate morons on
>> this earth. Two things are on the top of my agenda: Unixism and Perl."
>>
>> Pascal Bourguignon: <Xah Lee's website runs on Linux, a Unix-like OS>
>>
>>
>> Is more like
>>
>> Joe Blow: I'm going to exterminate all morons who drive a Ford Explorer.
>>
>> Fred Bloggs: But Joe, you drive a Ford Explorer!
>>
>>
>> Rather than
>>
>> Joe Blow: Ford Explorers are a little bit expensive to service and the
>> doors squeak after a couple of years.
>>
>> Fred Bloggs: Thanks for the tip Joe, I see you drive one, so you
>> should know.
>
>Case closed. (And probably Xah has suicidal impulses).
Nah, he's a Democrat of the Liberal flavor.
/BAH
Subtract a hundred and four for e-mail.
------------------------------
Date: Sun, 29 Aug 2004 12:16:04 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: XP prints out html not page ?
Message-Id: <cgsdtl$hm0$1@slavica.ukpost.com>
newzguy wrote:
> One a computer I use when a cgi script is called on,
> instead of getting the web page I get the html code
> as text. Can anyone tell me what settings to change
> to fix this?
Ones in your webserver that tell it how to deside how to threat files.
Without knowing which webserver you are using and how you want it to
determine that a file is to pre treated as a CGI script it's impossible
to be more precise.
> Probably off topic sorry.
Yes it is - ince this ha nothing to do with Perl (less than nothing to
do with Perl6). Perhaps you should try one of the newroups that deals
with web servers - and specifically with whatever web server you are using.
------------------------------
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 6929
***************************************