[24774] in Perl-Users-Digest
Perl-Users Digest, Issue: 6927 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 29 06:06:46 2004
Date: Sun, 29 Aug 2004 03:05:09 -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: 6927
Today's topics:
angle operator behavior with filehandles in @_ <john.bullock@stanford.edu>
Re: angle operator behavior with filehandles in @_ <noreply@gunnar.cc>
Re: angle operator behavior with filehandles in @_ <john.bullock@stanford.edu>
Re: angle operator behavior with filehandles in @_ <Joe.Smith@inwap.com>
current time in different timezones incl DST (Marcus)
Re: current time in different timezones incl DST <nospam@bigpond.com>
Re: Execute Windows program from Perl script (??) <tintin@invalid.invalid>
Re: Flat file database that supports mulitiple lines, e <invalid-email@rochester.rr.com>
Re: how many days ago is 2003-07-20 ? (Marcus)
Re: how many days ago is 2003-07-20 ? (Anno Siegel)
Re: how many days ago is 2003-07-20 ? <noreply@gunnar.cc>
Re: How to find out if a string is in uppercase only <leifwessman@hotmail.com>
Re: How to find out if a string is in uppercase only (Bart Van der Donck)
Re: How to randomize foreach <bart.lateur@pandora.be>
Re: Image::Magick problem after (failed?) install <Joe.Smith@inwap.com>
Re: Larry Wall & Cults <foo@bar.net>
Re: Larry Wall & Cults (Rob Warnock)
Re: Larry Wall & Cults <Brian.Inglis@SystematicSW.Invalid>
Re: Larry Wall & Cults <steveo@eircom.net>
Re: Parsing a text file into an array <Joe.Smith@inwap.com>
Re: pass 2d array to C function ctcgag@hotmail.com
perl - data structure build to transpose data (shree)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 28 Aug 2004 22:35:56 -0700
From: "John Bullock" <john.bullock@stanford.edu>
Subject: angle operator behavior with filehandles in @_
Message-Id: <cgrq03$mr0$1@news.Stanford.EDU>
Hello,
I am puzzled by the behavior of the angle
operator (<>) when it operates on a filehandle
that is passed to a subroutine.
Given filehandle FH, these lines are equivalent:
my $tst1 = <FH>;
my $tst1 = readline(FH);
But if I set up a subroutine, there is an oddity:
do_something(*FH);
sub do_something {
my $tst1;
$tst = $readline($_[0]); # works
$tst1 = <$_[0]>; # doesn't work
$tst1 = < {$_[0]} >; # doesn't work
}
Of course, I can get around this by storing the filehandle
in a scalar that I define in the subroutine. But I want to
understand why neither of the last two lines here works
as intended. (They just leave $tst1 undefined, provided
that it hasn't already been defined.) I've looked to what
I thought were the salient parts of the camel book, but I
had no luck. Can you enlighten me or point me to some
relevant reading?
Thanks,
--John
------------------------------
Date: Sun, 29 Aug 2004 08:43:42 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: angle operator behavior with filehandles in @_
Message-Id: <2pdcefFjns2kU1@uni-berlin.de>
John Bullock wrote:
> I am puzzled by the behavior of the angle
> operator (<>) when it operates on a filehandle
> that is passed to a subroutine.
>
> Given filehandle FH, these lines are equivalent:
>
> my $tst1 = <FH>;
> my $tst1 = readline(FH);
>
> But if I set up a subroutine, there is an oddity:
>
> do_something(*FH);
> sub do_something {
> my $tst1;
> $tst = $readline($_[0]); # works
> $tst1 = <$_[0]>; # doesn't work
> $tst1 = < {$_[0]} >; # doesn't work
> }
>
> Of course, I can get around this by storing the filehandle
> in a scalar that I define in the subroutine.
Not sure what you mean by that.
But you can do:
use Symbol 'qualify_to_ref';
do_something(*FH);
sub do_something {
my $fh = qualify_to_ref($_[0], caller);
my $tst1 = <$fh>;
}
This use of the Symbol module is mentioned in "perldoc perlsub".
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 29 Aug 2004 00:58:06 -0700
From: "John Bullock" <john.bullock@stanford.edu>
Subject: Re: angle operator behavior with filehandles in @_
Message-Id: <cgs2cs$s6p$1@news.Stanford.EDU>
> > Of course, I can get around this by storing the
> > filehandle in a scalar that I define in the
> > subroutine.
>
> Not sure what you mean by that.
Sorry. What I mean is that by assigning the
filehandle to a scalar, and then using the angle operator
on that scalar, I can get the angle operator to work as I
desire. For example, this code uses that procedure to
store the contents of a file in an array:
do_something(*FH);
sub do_something {
my $tst1 = shift;
my @tst1 = <$tst1>;
}
But if I don't assign the filehandle to a scalar,
I don't know how to achieve the same result. The
following code, for example, is no good:
do_something(*FH);
sub do_something {
my @tst1 = $_[0]; # @tst1 gets filehandle rather than file contents
my @tst1 = < $_[0] >; # @tst1 is undefined
my @tst1 = < {$_[0]} >; # @tst1 is undefined
}
Thank you for letting me know about the Symbol
module. I'm curious, though, to know why the last lines
of code in my original post don't work as intended --
what rules do they violate, and what's the logic behind
those rules? I checked perldoc perlsub/perldata/Symbol,
but couldn't find a clarification.
Thanks again,
--John
"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message news:2pdcefFjns2kU1@uni-berlin.de...
> John Bullock wrote:
> > I am puzzled by the behavior of the angle
> > operator (<>) when it operates on a filehandle
> > that is passed to a subroutine.
> >
> > Given filehandle FH, these lines are equivalent:
> >
> > my $tst1 = <FH>;
> > my $tst1 = readline(FH);
> >
> > But if I set up a subroutine, there is an oddity:
> >
> > do_something(*FH);
> > sub do_something {
> > my $tst1;
> > $tst = $readline($_[0]); # works
> > $tst1 = <$_[0]>; # doesn't work
> > $tst1 = < {$_[0]} >; # doesn't work
> > }
> >
> > Of course, I can get around this by storing the filehandle
> > in a scalar that I define in the subroutine.
>
> Not sure what you mean by that.
>
> But you can do:
>
> use Symbol 'qualify_to_ref';
>
> do_something(*FH);
> sub do_something {
> my $fh = qualify_to_ref($_[0], caller);
> my $tst1 = <$fh>;
> }
>
> This use of the Symbol module is mentioned in "perldoc perlsub".
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 29 Aug 2004 09:38:18 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: angle operator behavior with filehandles in @_
Message-Id: <euhYc.79452$Fg5.44150@attbi_s53>
John Bullock wrote:
> $tst = $readline($_[0]); # works
> $tst1 = <$_[0]>; # doesn't work
> $tst1 = < {$_[0]} >; # doesn't work
>
> Of course, I can get around this by storing the filehandle
> in a scalar that I define in the subroutine. But I want to
> understand why neither of the last two lines here works
> as intended. (They just leave $tst1 undefined, provided
> that it hasn't already been defined.) I've looked to what
> I thought were the salient parts of the camel book, but I
> had no luck. Can you enlighten me or point me to some
> relevant reading?
This section from 'perldoc perlop':
If what the angle brackets contain is a simple scalar variable (e.g.,
<$foo>), then that variable contains the name of the filehandle to
input from, or its typeglob, or a reference to the same. For example:
$fh = \*STDIN;
$line = <$fh>;
If what's within the angle brackets is neither a filehandle nor a sim-
ple scalar variable containing a filehandle name, typeglob, or typeglob
reference, it is interpreted as a filename pattern to be globbed, and
either a list of filenames or the next filename in the list is
returned, depending on context. This distinction is determined on syn-
tactic grounds alone. That means "<$x>" is always a readline() from an
indirect handle, but "<$hash{key}>" is always a glob(). That's because
$x is a simple scalar variable, but $hash{key} is not--it's a hash ele-
ment.
-Joe
------------------------------
Date: 28 Aug 2004 19:10:21 -0700
From: mygooglegroupsaccount@yahoo.com (Marcus)
Subject: current time in different timezones incl DST
Message-Id: <6fc26ca7.0408281810.63d3a830@posting.google.com>
Im currently calculating the current time for cities around the globe,
based on my servers time, trying to keep track on DST dates in a
separete file to make it accurate(ish).
Im sure there are solid solutions out there to do this? Eg, print the
current time in New York, Berlin, Sydney etc.
Thanks for any suggestions
M
------------------------------
Date: Sun, 29 Aug 2004 13:42:21 +1000
From: Gregory Toomey <nospam@bigpond.com>
Subject: Re: current time in different timezones incl DST
Message-Id: <2pd1ktFj1jimU1@uni-berlin.de>
Marcus wrote:
> Im currently calculating the current time for cities around the globe,
> based on my servers time, trying to keep track on DST dates in a
> separete file to make it accurate(ish).
>
> Im sure there are solid solutions out there to do this? Eg, print the
> current time in New York, Berlin, Sydney etc.
>
> Thanks for any suggestions
> M
Screen scrape the offsets from http://www.timeanddate.com/worldclock/
gtoomey
------------------------------
Date: Sun, 29 Aug 2004 13:37:28 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <2pcqa2FjeopuU1@uni-berlin.de>
"Tony McGuire" <tony@paradoxcommunity.com> wrote in message
news:f896a829.0408280814.760cf02c@posting.google.com...
> tony@paradoxcommunity.com (Tony McGuire)
> I was looking to start a Windows program independent of the Apache
> umbrella. This program would then rewrite the config file for Apache
> and restart Apache.
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 was hoping to coordinate everything with just perl, but it doesn't
> seem to be up to this particular task.
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.
------------------------------
Date: Sun, 29 Aug 2004 03:56:00 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Flat file database that supports mulitiple lines, embedded commas, etc.
Message-Id: <413153D0.1020406@rochester.rr.com>
Darrell L. Schmitt wrote:
> I'm looking for a CSV type flat-file database. This is for a text entry
Check out:
use DBI;
along with DBD::CSV . That will permit the use of SQL on CSV files
containing header lines which give the field names. And, even though
the CSV files are flat, you can still use sets of them like a relational
database. Cool but maybe slow.
Alternatively, you might also check out:
use Text::CSV_XS;
or
use Text::Balanced;
and, indeed, anything on CPAN that contains CSV.
> "logbook" that will have 3 major fields. Each field may contain up to 2048
> ASCII characters including commas, quotation marks, and newline characters.
>
> Does such a beast already exist? This must be able to run on Perl 5.0 (no
> Tk).
Perl 5.0? Do you maybe mean 5.8.0? Or 5.005? (the latter is really
quite ancient by now). I can't image what your question would have to
do with anything in Tk, or why it would be important whether Tk is
installed/used or not.
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: 28 Aug 2004 19:05:35 -0700
From: mygooglegroupsaccount@yahoo.com (Marcus)
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <6fc26ca7.0408281805.27f83c0c@posting.google.com>
Brilliant. Both solutions works really well. Thanks
Zebee Johnstone <zebee@zip.com.au> wrote in message news:<slrncivin8.gig.zebee@zeus.zipworld.com.au>...
> In comp.lang.perl.misc on 27 Aug 2004 16:35:04 -0700
> Marcus <mygooglegroupsaccount@yahoo.com> wrote:
> > Can someone pls show the most solid way in perl to retrieve the number
> > of days ago a specific date string was?
> >
> > Input: 2003-07-20
> > Output: 395
> >
>
> Date::Manip is one way.
>
> 4. The amount of time between two dates.
>
> $date1=&ParseDate($string1);
> $date2=&ParseDate($string2);
> $delta=&DateCalc($date1,$date2,\$err);
> => 0:0:WK:DD:HH:MM:SS the weeks, days, hours, minutes,
> and seconds between the two
> $delta=&DateCalc($date1,$date2,\$err,1);
> => YY:MM:WK:DD:HH:MM:SS the years, months, etc. between
> the two
>
> There are other Date modules, that's just the one I've been using
> because I handle dates in all sorts of weird formats and do all sorts of
> weird thigns with them, it handles everything so far.
>
> Zebee
------------------------------
Date: 29 Aug 2004 08:02:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <cgs2j5$7df$1@mamenchi.zrz.TU-Berlin.DE>
Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gunnar Hjalmarsson wrote:
> >> Marcus wrote:
> >>> Can someone pls show the most solid way in perl to retrieve the
> >>> number of days ago a specific date string was?
> >>>
> >>> Input: 2003-07-20 Output: 395
> >>
> >> What have you tried? Personally I'd probably use Time::Local,
> >> which would require a couple of extra lines of code, while others
> >> would use e.g. Date::Calc.
> >
> > 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. Since that isn't always so,
I'd prefer a solution that has been checked for these cases instead of
checking myself.
Anno
------------------------------
Date: Sun, 29 Aug 2004 10:32:01 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <2pdiqnFhbqn5U1@uni-berlin.de>
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.
> 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. :(
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 28 Aug 2004 23:37:04 -0700
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Re: How to find out if a string is in uppercase only
Message-Id: <cgrtig$j4m@odak26.prod.google.com>
Yes, I wanted to check if the string didn't have any lowercase
characters. However, dots and commas and other characters are allowed.
Thanks for all your input!
------------------------------
Date: 29 Aug 2004 02:30:50 -0700
From: bart@nijlen.com (Bart Van der Donck)
Subject: Re: How to find out if a string is in uppercase only
Message-Id: <b5884818.0408290130.2c5bb2c3@posting.google.com>
Jürgen Exner wrote:
> Arrrg, if a developer would present this as a global solution to me I would
> have a serious talk with his manager the same day!
What makes you think I posted this as a global solution?? Of course
it's not. It is a piece of code that solves the problem he described.
> This doesn't scale well to other languages because it requires detailed
> knowlegde of the other language (or do you know which extended characters to
> add for Spanish, Italian, or Turkish).
> It doesn't scale well to other character sets (what are the capital letters
> for cyrillic Serbian)? Do you as an English-speaking programmer know how to
> enter them on your keyboard?
> And it doesn't scale to additional language because it requires a code
> change whenever you add a new language/character set.
All correct, but the original poster only needs Swedish characters as
he said.
Best regards,
Bart
------------------------------
Date: Sun, 29 Aug 2004 09:48:27 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: How to randomize foreach
Message-Id: <tg93j01mjnuu0tr2lvve428lqt9egkb1do@4ax.com>
Anno Siegel wrote:
>There will usually be a few duplicates among the generated numbers.
Not *exact* duplicates, in the numerical sense (though perhaps it
looksthat way when stringified). Otherwise, you'd have reached the end
of the loop, and start getting the exact same sequence again.
--
Bart.
------------------------------
Date: Sun, 29 Aug 2004 09:58:01 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Image::Magick problem after (failed?) install
Message-Id: <JMhYc.64189$9d6.10255@attbi_s54>
Kris Munroe wrote:
> Does any one have any idea what is wrong here?
> /usr/bin/ld: cannot find -lfreetype
Have you installed the freetype library?
------------------------------
Date: Sat, 28 Aug 2004 20:59:08 -0700
From: Mac <foo@bar.net>
Subject: Re: Larry Wall & Cults
Message-Id: <pan.2004.08.29.03.59.02.719953@bar.net>
On Wed, 25 Aug 2004 14:56:06 -0700, Xah Lee wrote:
> Larry Wall and Cults
> (Lazyness, Impatience and Hubris)
> 200012
>
> Dear readers,
>
[snip]
> Surely you have heard of Adolf Hitler
> and his atrocities of genocide? I must alert you, that a single person
> couldn't commit such a crime.
Wow, Godwin's law invoked on the first post of the thread.
--Mac
------------------------------
Date: Sat, 28 Aug 2004 23:14:55 -0500
From: rpw3@rpw3.org (Rob Warnock)
Subject: Re: Larry Wall & Cults
Message-Id: <cJWdnetJbNOixazcRVn-iA@speakeasy.net>
+---------------
| 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. ;-}
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?
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. 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.
-Rob
-----
Rob Warnock <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607
------------------------------
Date: Sun, 29 Aug 2004 06:58:30 GMT
From: Brian Inglis <Brian.Inglis@SystematicSW.Invalid>
Subject: Re: Larry Wall & Cults
Message-Id: <25u2j0d9bfulqljo6d2jbls2v52l1jk3sd@4ax.com>
On Sat, 28 Aug 2004 20:59:08 -0700 in alt.folklore.computers, Mac
<foo@bar.net> wrote:
>On Wed, 25 Aug 2004 14:56:06 -0700, Xah Lee wrote:
>
>> Larry Wall and Cults
>> (Lazyness, Impatience and Hubris)
>> 200012
>> Surely you have heard of Adolf Hitler
>> and his atrocities of genocide? I must alert you, that a single person
>> couldn't commit such a crime.
>
>Wow, Godwin's law invoked on the first post of the thread.
Not quite, no comparison was made; see:
http://groups.google.com/groups?as_umsgid=1991Oct22.140831.23313%40eff.org
--
Thanks. Take care, Brian Inglis Calgary, Alberta, Canada
Brian.Inglis@CSi.com (Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
fake address use address above to reply
------------------------------
Date: Sat, 28 Aug 2004 21:34:07 +0100
From: Steve O'Hara-Smith <steveo@eircom.net>
Subject: Re: Larry Wall & Cults
Message-Id: <20040828213407.18cc9f1e.steveo@eircom.net>
On Fri, 27 Aug 2004 16:31:07 -0500
jdoherty@nowhere.null.not (John Doherty) wrote:
> In article <412e199e$0$8076$a1866201@newsreader.visi.com>, Grant Edwards
> <grante@visi.com> wrote:
> > Of course, but are they consistently indented using tabs or
> > spaces?
>
> AND HOW MANY SPACES PER TAB STOP?
One half inch is my preference for tab stops usually. A tab is a
tab and not some number of spaces.
--
C:>WIN | Directable Mirror Arrays
The computer obeys and wins. | A better way to focus the sun
You lose and Bill collects. | licences available see
| http://www.sohara.org/
------------------------------
Date: Sun, 29 Aug 2004 09:18:18 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Parsing a text file into an array
Message-Id: <ubhYc.328713$a24.260307@attbi_s03>
Scott wrote:
> I having a bit of trouble trying to parse...
>
> 789798798 test,test 12/5/3005
>
> with tabs between each column. Does any one have some suggestions?
If you go to http://search.cpan.org and enter TSV or Tab Separated Values
you'll get matches like
http://search.cpan.org/~jzucker/AnyData-0.10/AnyData/Format/Tab.pm
or
http://search.cpan.org/~ezdb/Data-Table-1.40/Table.pm
Data::Table - Data type related to database tables, spreadsheets,
CSV/TSV files, HTML table displays, etc.
For simple data, using perl's split() function will suffice.
-Joe
------------------------------
Date: 29 Aug 2004 04:32:07 GMT
From: ctcgag@hotmail.com
Subject: Re: pass 2d array to C function
Message-Id: <20040829003207.099$OQ@newsreader.com>
minsanco@gmail.com (min) wrote:
> I need to call a C function from perl. How do I pass a 2D array into
> the C function that I am invoking from perl? Can anyone direct me to
> a tutorial?
It depends. Are you writing the C function, or merely using one that
already exists? If the later, what kind of 2D array does the C function
expect to receive?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 28 Aug 2004 20:34:13 -0700
From: srigowrisn@hotmail.com (shree)
Subject: perl - data structure build to transpose data
Message-Id: <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
------------------------------
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 6927
***************************************