[10345] in Perl-Users-Digest
Perl-Users Digest, Issue: 3937 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 9 18:07:15 1998
Date: Fri, 9 Oct 98 15:00:27 -0700
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, 9 Oct 1998 Volume: 8 Number: 3937
Today's topics:
Re: adding to the @INC at install time droby@copyright.com
Re: Are there any "perl.newbie" group or forum? <jdporter@min.net>
Re: Are there any "perl.newbie" group or forum? <jdporter@min.net>
Re: Are there any "perl.newbie" group or forum? <mp@mkt2mkt.com>
Re: Are there any "perl.newbie" group or forum? <mp@mkt2mkt.com>
Re: Are there any "perl.newbie" group or forum? <eashton@bbnplanet.com>
CGI upload problem nepatsfan@my-dejanews.com
Re: Difficulty with HTML & Perl & CGI <jdporter@min.net>
Re: Difficulty with HTML & Perl & CGI <jdporter@min.net>
Re: Difficulty with HTML & Perl & CGI (Craig Berry)
Re: Getting the last date modified <simon@surfers.org>
How do I do a recursive glob? <mark_wright@datacard.com>
Re: How do I do a recursive glob? (Sean McAfee)
How do I use die? <brettr@centuryinter.net>
How do you save a state? <kchunt@mail.hac.com>
Re: Hrm. Linguistic Quandry <eashton@bbnplanet.com>
Re: Hrm. Linguistic Quandry <jdporter@min.net>
mSQL and DBI Problem in PERL (Mdevivio)
Re: mSQL and DBI Problem in PERL <alex@kawo2.rwth-aachen.de>
Re: Name from IP (Mike D. Kail)
Re: Newbie question RE: SSI and .cgi scripts on NT4 droby@copyright.com
Newbie:parse into a hash table <ywang@engsoc.carleton.ca>
Re: Newbie:parse into a hash table <ludlow@us.ibm.com>
Re: Newbie:parse into a hash table (Mark-Jason Dominus)
Re: Newbie:parse into a hash table <r28629@email.sps.mot.com>
Re: print bug/feature? (Larry Rosler)
Re: Problems Using a Compare Subroutine with Sort <jdporter@min.net>
prograMing: CompleteIndexSet <xah@best.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 09 Oct 1998 17:47:34 GMT
From: droby@copyright.com
Subject: Re: adding to the @INC at install time
Message-Id: <6vli7m$hs$1@nnrp1.dejanews.com>
In article <6vk88c$qa3$1@ultra.sonic.net>,
"Jay Di Silvestri" <jay@adei.com> wrote:
> How do I add to perl's *default* @INC path, I'll reinstall if I need to . .
> .
You don't need to.
>
> I'm looking for a solution that does not require visiting any of the
> individual scripts and unshifting the array myself.
> --Jay
>
>
Then perhaps you want to set the environment variable PERL5LIB. At least
that's the alternative perlfaq8 suggests.
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 09 Oct 1998 16:05:44 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <361E6C98.A6A6D61B@min.net>
madame philosophe wrote:
>
> ...and what pray tell is a troll?
I'm certain this is a FAQ; but not of this newsgroup...
--
John "Many Jars" Porter
------------------------------
Date: Fri, 09 Oct 1998 16:08:05 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <361E6D25.DEBABC29@min.net>
Elaine -HappyFunBall- Ashton wrote:
>
> John Porter wrote:
>
> > What other conclusion could I draw? You have obviously not
> > read any of the many kilobytes this newsgroup has generated
> > in the past on this subject.
>
> The only conclusion I can draw is that this person simply must be a
> troll.
Strange, I don't find that conclusion inescapable.
IMHO, there is a wide world of difference between self-styled
philosophers, and trolls like George Vogon Reese.
--
John "Many Jars" Porter
------------------------------
Date: Fri, 09 Oct 1998 13:32:04 -0800
From: madame philosophe <mp@mkt2mkt.com>
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <361E80C8.D2B692AC@mkt2mkt.com>
> Sorry fellow weather-person[*], but I disagree with both you and our
> philospher. Newbies eventually grow up, or they give up in frustration.
> However, once they've grown up, they're not newbies any more.
>
> Eventually they'll start chanting the mantra: FAQ FAQ FAQ. :)
>
> + but that does NOT mean that everybody should
> + just lean back and go, "well, there'll be more newbies anyway, so we might
> + as well give up".
>
> *ding*ding*ding* If we give up, we just end up creating a permanent sub-class
> called 'newbies' who'll come to expect to get their answers on a silver
> plate.
Sure I agree, one should not expect to ask a question and get the answer on a
silver platter.
There's no learning going on there.
But how much jumping through hoops should a person go through as they are
learning Perl?
How much humiliation from just being darned ignorant?
I don't want to be a viking, I just want to ask a question to the right people
in the right way.
Would there be a way of programming the software so that a posting for perl
faqs, and newsgroup protocols always landed at the top of the list of postings?
I see that Tom Phoenix regularly posts a How to use the Perl Faq, but unless you
stumble on it it's hard to find in the muddle!
mp
------------------------------
Date: Fri, 09 Oct 1998 13:35:57 -0800
From: madame philosophe <mp@mkt2mkt.com>
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <361E81B1.B7FCC778@mkt2mkt.com>
> > I would love to write a decent Perl book or publish a Perl Faq. When I have a
> > free moment I may do it.
>
> May I ask what's wrong with the current FAQ? Also, what kind of book is it
> you feel is missing?
One that doesn't assume you are an idiot, or a dummy, and one that doesn's assume
you have a degree in computer progamming and can program in C, C++, etc. etc.
Somewhere in the middle.
>
>
> > However, what I'm more interested in is solutions than combat. If this is a
> > FAQ then let it be one. If it is some sort of clique, get over yourselves!
>
> Well, then I don't understand why you're posting this:
>
> PerlFAQ.pod:=head2 How do I shuffle an array randomly?
>
> It is an FAQ, and was answered as such. No clique involved.
Sorry don't know what you mean. Are you saying that I posted that?
------------------------------
Date: Fri, 09 Oct 1998 20:48:23 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Are there any "perl.newbie" group or forum?
Message-Id: <361E741B.4D1C392E@bbnplanet.com>
John Porter wrote:
> Strange, I don't find that conclusion inescapable.
> IMHO, there is a wide world of difference between self-styled
> philosophers, and trolls like George Vogon Reese.
Reese is Reese. I suspect this person is well known to the group and
playing the anti-abigail routine. I could be wrong, but my intuition
says likely. It's entertaining. :)
e.
But my mind was unclear and shaky. Nothing
was happening. Everything was happening. Life
was a stone, grinding and sharpening. - R. Carver -
------------------------------
Date: Fri, 09 Oct 1998 19:21:48 GMT
From: nepatsfan@my-dejanews.com
Subject: CGI upload problem
Message-Id: <6vlnoc$9ng$1@nnrp1.dejanews.com>
I've written a CGI application to allow users to upload files.
After defining $file = param('filename') I'm attempting to read it and store
it into another file.
while (<$file>){
$new_file .= $_;
}
All I seem to get is the name of the file rather than the contents of the
file. What am I doing wrong?
Any suggestions would be welcomed.
Thanks,
Ray Kiernan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Fri, 09 Oct 1998 16:22:49 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Difficulty with HTML & Perl & CGI
Message-Id: <361E7099.7DCE93C1@min.net>
madame philosophe wrote:
>
> it could have to do with your capitalization for start_html
> attributes. you might try this instead:
>
> $query->start_html(-title=>'No Title', -bgcolor=>'white'),
No, that advice is incorrect.
-TITLE and -title work equally well; same for all the other
attributes.
--
John "Many Jars" Porter
baby mother hospital scissors creature judgment butcher engineer
------------------------------
Date: Fri, 09 Oct 1998 16:33:52 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Difficulty with HTML & Perl & CGI
Message-Id: <361E7330.427D8E34@min.net>
madame philosophe wrote:
>
> Well I tried my own way: I made a specific trip the the CGI.pm book
> to look
> and see if the new() method was a part of :cgi (which is a part of
> :standard) and there was no new() listed. Ditto for the other parts
> of standard.
>
> But after reading your mail I guess new(), being a constructor, may
> be above
> all that. Unless running from the command line is different with
> those funny quotes at the end. :)
Check out the Exporter module, with its import() function.
Thinks like ':standard' control what symbols get imported from
the module into the caller's namespace; it has no effect on what
symbols in the module can be accessed explicitly.
> print $query->header(),
>
> $query->start_html(-title=>'No Title', -bgcolor=>'white'),
>
> $query->h4({-align=>'center'}, "Testing 4..."),
>
> $query->end_html;
Personally I have found that it actually is nicer to have the
arguments to print in parens, like this:
print(
$query->header(),
$query->start_html(-title=>'No Title', -bgcolor=>'white'),
$query->h4({-align=>'center'}, "Testing 4..."),
$query->end_html,
);
> I like spacing my code out, personally. And yeah sure the () after
> header can go, since it defaults to the Content-type: text/html
No, technically it can go because subroutine (header) ignores the
argument list. () passes no arguments (besides the object ref),
and leaving it off passes the current @_. Safe, because the sub
ignores it.
> Which leads me to a question actually:
>...
> let's say I have a text file that looks something like this:
> Now if I were to place a conditional that said something like
>...
> If there is text delimited by tags #**## (to start) and ##**# (to end)
> print that text.
I encourage you to check module listing on CPAN; search for the
word 'template'.
--
John "Many Jars" Porter
baby mother hospital scissors creature judgment butcher engineer
------------------------------
Date: 9 Oct 1998 21:01:14 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Difficulty with HTML & Perl & CGI
Message-Id: <6vltiq$5k2$1@marina.cinenet.net>
madame philosophe (mp@mkt2mkt.com) wrote:
: Craig Berry wrote:
: > Hmm: > perl -e 'use CGI qw(:standard); new CGI' ''
: >
: > Seems to work fine. Isn't it better to try it rather than making
: > inaccurate assertions?
:
: Well I tried my own way: I made a specific trip the the CGI.pm book to look
: and see if the new() method was a part of :cgi (which is a part of
: :standard) and there was no new() listed. Ditto for the other parts of
: standard.
:
: But after reading your mail I guess new(), being a constructor, may be above
: all that.
Must be the case. That's fairly common practice, it seems; new and the
like are considered to be implicitly exported for doc purposes.
: Unless running from the command line is different with those
: funny quotes at the end. :)
Yeah, nearly wore out my ' key.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "Ripple in still water, when there is no pebble tossed,
nor wind to blow..."
------------------------------
Date: 9 Oct 1998 16:58:04 GMT
From: Simon Fraser <simon@surfers.org>
Subject: Re: Getting the last date modified
Message-Id: <6vlfas$q49$1@wave.cam.uk.internal>
Brandon Lin wrote:
: $write_secs = (stat($file))[9];
: print "file $file updated at ", scalar(localtime($file)), "\n";
: I followed the code above, but no matter what file it is, the outpus is always:
: Wed Dec31 17:00:00 1969
: Any ideas?
Try replacing
scalar(localtime($file))
with
scalar(localtime($write_secs))
to display the time returned from stat(), which you got in the line before.
Simon.
: James Ludlow wrote:
:> Brandon Lin wrote:
:> >
:> > I'm a novice to perl. Can anyone please tell me how to get
:> > the last date modified of a file using perl?
:>
:> The FAQ is your friend...
:> http://www.perl.com/CPAN-local/doc/FAQs/FAQ/PerlFAQ.html#How_do_I_get_a_file_s_timestamp_
:>
:> The documentation that comes with Perl is good reading too.
:>
:> --
:> James Ludlow (ludlow@us.ibm.com)
:> Disclaimer: This isn't technical support, and all opinions are my own.
--
Simon Fraser simon@surfers.org
-
Computer, n: A nimble electronic brain devoid of animal
passions and human wit, and therefore admirably suited
to the contemporary corporate environment.
------------------------------
Date: Fri, 9 Oct 1998 13:34:13 -0500
From: "Mark Wright" <mark_wright@datacard.com>
Subject: How do I do a recursive glob?
Message-Id: <361e572d.0@news2.uswest.net>
I'm coming from the win32 world, so I'm not very familiar with real
filename globbing. What I'd like to do is get a list of all of the
files in subdirectories of directory X with extention .xxx. In other
words, I'd like to be able to do the following:
@makefiles = glob('\engr\*.mak');
But have glob recurse all of the subdirectories of '\engr'. Is there
a way to do this? I suppose that I could do:
@makefiles = `dir /s/b \engr\*.mak`;
but that's not very portable. Is that a hokey solution?
---
Mark Wright
Blue Frog Software, Inc
mwright@pro-ns.net
------------------------------
Date: Fri, 09 Oct 1998 19:31:22 GMT
From: mcafee@stargate.rs.itd.umich.edu (Sean McAfee)
Subject: Re: How do I do a recursive glob?
Message-Id: <ewtT1.991$fS.2589596@news.itd.umich.edu>
In article <361e572d.0@news2.uswest.net>,
Mark Wright <mark_wright@datacard.com> wrote:
>I'm coming from the win32 world, so I'm not very familiar with real
>filename globbing. What I'd like to do is get a list of all of the
>files in subdirectories of directory X with extention .xxx. In other
>words, I'd like to be able to do the following:
> @makefiles = glob('\engr\*.mak');
>But have glob recurse all of the subdirectories of '\engr'. Is there
>a way to do this? I suppose that I could do:
> @makefiles = `dir /s/b \engr\*.mak`;
>but that's not very portable. Is that a hokey solution?
Yes. Use the File::Find module, part of the standard Perl distribution:
use File::Find;
find sub { push @makefiles, $File::Find::name if /\.mak$/ }, '\engr';
--
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
| K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
| tv+ b++ DI++ D+ G e++>++++ h- r y+>++** | umich.edu
------------------------------
Date: Fri, 9 Oct 1998 16:50:40 -0500
From: "brettr" <brettr@centuryinter.net>
Subject: How do I use die?
Message-Id: <6vm0i1$pi1$1@newsread1-mx.centuryinter.net>
I'd like to know how to use die for catching errors. I have a module that
uses die. The module is "required" in my script but I'm not sure where in my
script I should use die().
Thanks,
brettr
------------------------------
Date: Fri, 09 Oct 1998 14:36:19 -0700
From: Kenneth Hunt <kchunt@mail.hac.com>
Subject: How do you save a state?
Message-Id: <361E81D3.D1E1EE7C@mail.hac.com>
I need to keep information on a file pathname which is generated in one
frame of frameset A, and use that info in another frame in frameset B.
How can I do that?
The info in question is passed to frameset B, but how do you transfer
that info to a frame in frameset B??
--
------------------------------------------------------
Kenneth Hunt
SC S12 V321 Rm. C233
office: 364-7755 pager: 715-0600
------------------------------------------------------
------------------------------
Date: Fri, 09 Oct 1998 20:33:55 GMT
From: Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com>
Subject: Re: Hrm. Linguistic Quandry
Message-Id: <361E70B6.233ED094@bbnplanet.com>
Dennis M. Parrott wrote:
> Actually, trolling (as a form of fishing) is done from a slowly
> moving boat. The object is to drag interesting looking bait in
> front of the fish you intend to catch at a speed and depth that
> will maximize the size and number of fish you catch.
/me *smacks* head against wall. I was having a bit of fun here. A troll
is also a Scandinavian creature with magical powers. I thought the
troll/trawl/trowel distinction when applied to the definition was
interesting.
> It is a well-understood term amongst the Usenet community.
Just because it is well understood doesn't necessarily mean that it is
the best.
It's been around for years, I'm not expecting that to change.
> Remember, a word means exactly what I choose it to mean;
> nothing more and nothing less.
Oh really? I highly doubt that as you must also take into account the
reader. Text is two-dimensional, people are three-dimensional and words
have both definitions and connotations.
e.
But my mind was unclear and shaky. Nothing
was happening. Everything was happening. Life
was a stone, grinding and sharpening. - R. Carver -
------------------------------
Date: Fri, 09 Oct 1998 17:04:38 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Hrm. Linguistic Quandry
Message-Id: <361E7A66.A8BB3F43@min.net>
Elaine -HappyFunBall- Ashton wrote:
>
> Since the word 'troll' came up recently I did a little etymological
> digging and I find myself wondering about it. To troll is fishing
> casually on a long line. To trawl is to fish the bottom. I'm wondering
> if 'troll' is the proper term.
I think what usenet trolls do could be well described as fishing,
rather than dredging. After all, "read the fishing manual".
> Perhaps to 'trowel' is the most a
> propos term. To dig and not to fish. What say you boys?
I say let's trowel up that troll. Think "Amontillado".
--
John "Many Jars" Porter
baby mother hospital scissors creature judgment butcher engineer
------------------------------
Date: 9 Oct 1998 20:03:00 GMT
From: mdevivio@aol.com (Mdevivio)
Subject: mSQL and DBI Problem in PERL
Message-Id: <19981009160300.28298.00015065@ng89.aol.com>
Hello,
Can anyone tell me why this runs from the command line and not a web page?
#!/usr/local/bin/perl -w
print "Content-type: text/html\n\n";
use lib qw(/usr/local/lib/perl5/site_perl);
use DBI;
# The mSQL datasource string consists of the DBI identifier,
# the name of the driver (mSQL), the database name, and the
# hostname. These should all be separated by a colon.
#
my $datasource = "dbi:mSQL:testdb";
# Attempt to connect to the datasource. If this connection
# fails, then report the error.
#
my $dbh = DBI->connect($datasource) ||
die "Could not connect:$DBI::errstr";
# Report the success.
#
print "Connected ok.\n";
# Disconnect from the server.
#
$dbh->disconnect;
My msql.acl file for the test database is as follows:
database=testdb
read=*
write=*
access=remote
If you can, please reply via e-mail as well. Thank you in advance for your
replies.
Regards,
Michael
------------------------------
Date: Fri, 09 Oct 1998 20:46:06 +0000
From: Alex Farber <alex@kawo2.rwth-aachen.de>
To: mdevivio@aol.com
Subject: Re: mSQL and DBI Problem in PERL
Message-Id: <361E760E.903652A6@kawo2.rwth-aachen.de>
Mdevivio wrote:
> Can anyone tell me why this runs from the command line and not a web page?
>
> print "Content-type: text/html\n\n";
>
Shouldn't it be print "Content-Type: text/html\n\n"; ?
^
/Alex
--
http://www.simplex.ru/pref.html
------------------------------
Date: Fri, 09 Oct 1998 18:15:32 GMT
From: mdkail@fv.com (Mike D. Kail)
Subject: Re: Name from IP
Message-Id: <slrn71skm1.ruh.mdkail@dime.fv.com>
On Fri, 9 Oct 1998 16:25:07 +0200, Christian Koch
<christian.koch@fuzzy-online.de> wrote:
>
>How can I get the server- or domain-name of a IP with a perl-script or an
>executable file??
'man perlipc' and search for 'gethostbyaddr'
--
/*-------------------------------------------------------------*/
/* Mike D. Kail | voice: (619) 410-3773 */
/* Unix System Architect | fax: (619) 410-3701 */
/* FIRST VIRTUAL Holdings Inc. | e-mail: mdkail@fv.com */
/*-------------------------------------------------------------*/
------------------------------
Date: Fri, 09 Oct 1998 20:02:01 GMT
From: droby@copyright.com
Subject: Re: Newbie question RE: SSI and .cgi scripts on NT4
Message-Id: <6vlq3p$dem$1@nnrp1.dejanews.com>
In article <KREh9CAPSiH2Ew49@pearl.demon.co.uk>,
Adrian Albin-Clark <adrian@pearl.demon.co.uk> wrote:
> I have looked in many FAQs but have not been able to see answers to my
> questions.
>
> I have recently been experimenting with ActiveState's Win 32 perl
> implementation on Windows NT Server.
>
> I have had some some success using scripts with the .pl extension but
> have not had any joy with any scripts that end in .cgi.
>
> When required, I have tried inserting the lines into the calling web
> pages (with the correct path to the script) like the following but this
> has not worked:
> <!--#exec cgi="/InetPub/scripts/lookwho.cgi" -->
>
> Is this likely to work on an NT system with my setup?
That rather depends on some things you haven't told us about your setup.
>
> Some scripts say they need SSI. What is SSI and can I enable/install it
> on NT Server? If so, what would I need to do?
>
If you want to do the <!--#exec cgi ... --> stuff referenced above you need
SSI.
Because that stuff IS SSI (which means Server-Side-Includes by the way).
To install it on an NT server? Well first you install webserver software on
you NT server... The documentation for that webserver software may tell you
where to go next.
> Help would be very much appreciated. Please refrain from offering
> sarcastic/unhelpful comments or meaningless references to www.perl.com.
>
Sometimes sarcasm can just not be resisted. I hope I have nonetheless not
been entirely unhelpful.
References to www.perl.com would indeed be nearly meaningless here, as none of
this has anything whatsoever to do with Perl.
However, there are FAQs that might be useful. Oh but you've read all of
those. So sorry.
There are also other newsgroups that do discuss CGI, SSI, and such rather than
Perl. Perhaps a dejanews search for those keywords will find some of them.
Very bad form to ask us to hold the sarcasm. It just provokes us.
Then again, you may be a troll. Hmmmm.
--
Don Roby
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 9 Oct 1998 17:52:31 GMT
From: Yue Wang <ywang@engsoc.carleton.ca>
Subject: Newbie:parse into a hash table
Message-Id: <6vligv$2ne$1@bertrand.ccs.carleton.ca>
my tab-delimited txt file:
col1 col2 col3 col4
row1 23 23 22 23
row2 34 34 43 34
row3 34 34 34 34
can someone show me a simple way to parse this text file into hash table
so that 22 is returned when print $table{row1, col3}
thanks !
Yue
------------------------------
Date: Fri, 09 Oct 1998 14:35:20 -0500
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: Newbie:parse into a hash table
Message-Id: <361E6578.BB591DE2@us.ibm.com>
Yue Wang wrote:
> can someone show me a simple way to parse this text file into hash table
> so that 22 is returned when print $table{row1, col3}
Check the documentation for the split function. Also, you probably
don't really want to use $table{row1, col3}. If you insist on using
hashes, then I'd suggest $table{row1}{col3}.
--
James Ludlow (ludlow@us.ibm.com)
Disclaimer: This isn't technical support, and all opinions are my own.
------------------------------
Date: 9 Oct 1998 17:35:00 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Newbie:parse into a hash table
Message-Id: <6vlvi4$9lk$1@monet.op.net>
In article <6vligv$2ne$1@bertrand.ccs.carleton.ca>,
Yue Wang <ywang@engsoc.carleton.ca> wrote:
>
>my tab-delimited txt file:
>
> col1 col2 col3 col4
>row1 23 23 22 23
>row2 34 34 43 34
>row3 34 34 34 34
>
>
>can someone show me a simple way to parse this text file into hash table
>so that 22 is returned when print $table{row1, col3}
# Warning #1: Premature closure
# Warning #2: The person who most needs to understand warning #1 will not.
$HEADER = <INPUT>;
@COLS = split;
while (<INPUT>) {
($ROWTAG, @items) = split;
unless (@items == @COLS) {
my $c = @COLS;
my $n = @items;
warn "Row `$ROWTAG' has $n items, but I expected $c.\n";
}
for ($i=0; $i < @COLS; $i++) {
$table{$ROWTAG,$COLS[$i]} = $items[$i];
}
}
# Warning #3: The author is a Discordian.
------------------------------
Date: Fri, 09 Oct 1998 16:16:35 -0500
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Newbie:parse into a hash table
Message-Id: <361E7D33.92B29BCB@email.sps.mot.com>
James Ludlow wrote:
>
> Yue Wang wrote:
>
> > can someone show me a simple way to parse this text file into hash table
> > so that 22 is returned when print $table{row1, col3}
>
> Check the documentation for the split function. Also, you probably
> don't really want to use $table{row1, col3}. If you insist on using
> hashes, then I'd suggest $table{row1}{col3}.
>
> --
> James Ludlow (ludlow@us.ibm.com)
> Disclaimer: This isn't technical support, and all opinions are my own.
IN this case, 'list of list' should work better. More flexible if you
have variable number of columns and rows, and more efficient.
------------------------------
Date: Fri, 9 Oct 1998 10:20:29 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: print bug/feature?
Message-Id: <MPG.1087e5b380df6b539897fe@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a copy mailed.]
In article <6vk9vu$jck$1@towncrier.cc.monash.edu.au> on 9 Oct 1998
06:20:46 GMT, Damian Conway <damian@cs.monash.edu.au> says...
! lr@hpl.hp.com (Larry Rosler) writes:
!
! >The answer lies in the IEEE 754 standard. I can't find it on the Web
! >(copyrighted material?) and I can't locate my copy, so I'll have to
! >wing it.
!
! >To avoid upward bias in always rounding to the next higher value a
! >number whose value is "exactly" 0.5 in the position to be rounded, the
! >implementation is expected to do such rounding upward or downward "at
! >random".
! ^^^^^^
!
! I was always under the impression that rounding of "half" values under
! 754 was to the nearest even integer.
I said I was winging it. Absent an authoritative quote from the
standard, I fear we both are winging it. But the answer to the original
question is clear.
! Hmmmm....
!
! % perl -e 'foreach (-2000..2000) { printf "%.0f ", $_-0.5 }'
!
! -2000 -2000 -1998 -1998 -1996 -1996 -1994 -1994 -1992 -1992 -1990 -1990
!
! [SNIP]
!
! -10 -10 -8 -8 -6 -6 -4 -4 -2 -2 0 0 2 2 4 4 6 6 8 8 10 10
!
! [SNIP]
!
! 1990 1990 1992 1992 1994 1994 1996 1996 1998 1998 2000 2000
!
! Well, that's good enough for this engineer ;-)
As good as the 'engineering' proof that all odd positive integers are
prime: '1' is prime, '3' is prime, '5' is prime, '7' is prime, ...
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 09 Oct 1998 15:52:04 -0400
From: John Porter <jdporter@min.net>
Subject: Re: Problems Using a Compare Subroutine with Sort
Message-Id: <361E6964.9AC57F95@min.net>
droby@copyright.com wrote:
>
> > All IPv7 addresses are four-letter words. Neat!
>
> Unfortunately, it's a step backward. After posting this silliness, I went
> looking at RFCs. IPv6 addresses are 128 bits, and I'm sure you'll be happy to
> know the text representation is described in RFC 1884 as:
>
> <quote> The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the
> hexadecimal values of the eight 16-bit pieces of the address. </quote>
>
> I guess we'll just have to be twice as vulgar.
Well, maybe they're four 32-bit characters.
Unicode can do that, right?
So you can be vulgar in vulcan.
--
John "Many Jars" Porter
baby mother hospital scissors creature judgment butcher engineer
------------------------------
Date: Fri, 09 Oct 1998 14:37:26 +0000
From: "Xah" <xah@best.com>
Subject: prograMing: CompleteIndexSet
Message-Id: <6vlv6c$ft6$1@nntp2.ba.best.com>
Programing competition
Not any official competition, but I have a every interesting academic-type
programing problem involving array generation, and am interested to see
creative results.
Here's the problem:
Write the function CompleteIndexSet.
CompleteIndexSet([index1, index2,...]) returns a modified version of input
in which indexes that can be inferred from other indexes are deleted.
Indexes are of the form [n1,n2,n3,...] where the n are non-negative
integers. The result should be sorted by indexes' length. If tied, then the
entries in the indexs. The result should not contain duplicates.
Definition:
Suppose indexA = {'begin...', n, m != 0} where 'begin...' stands for its
beginning sequence. indexA implies any sequence {'begin...', n, x < m}.
Suppose indexB = {'begin...', n, 0}, then indexB implies {'begin...', n}.
Here's one sample algorithm: Suppose one of the given index is {a,b,c,d}. If
the last digit is not 0, then generate {a,b,c,d-1}. If the last digit is 0,
then generate {a,b,c}. Add the new element into a result list. Now take new
element as input and repeat the process until it becomes {}. Now do the
above with every given index. Now eliminate duplicates and {} in the result
list. The result is as desired.
Here are some sample inputs and outputs. (from Mathematica)
In[86]:=
CompleteIndexSet[{{3}}]
Out[86]=
{{},{0},{1},{2},{3}}
In[87]:=
CompleteIndexSet[{{3},{3}}]
Out[87]=
{{},{0},{1},{2},{3}}
In[88]:=
CompleteIndexSet[{{3,2}}]
Out[88]=
{{},{0},{1},{2},{3},{3,0},{3,1},{3,2}}
In[89]:=
CompleteIndexSet[{{3,2,0}}]
Out[89]=
{{},{0},{1},{2},{3},{3,0},{3,1},{3,2},{3,2,0}}
In[90]:=
CompleteIndexSet[{{3,0,1}}]
Out[90]=
{{},{0},{1},{2},{3},{3,0},{3,0,0},{3,0,1}}
In[91]:=
CompleteIndexSet[{{0,0,3}}]
Out[91]=
{{},{0},{0,0},{0,0,0},{0,0,1},{0,0,2},{0,0,3}}
In[92]:=
CompleteIndexSet[{{3,2},{1,1}}]
Out[92]=
{{},{0},{1},{2},{3},{1,0},{1,1},{3,0},{3,1},{3,2}}
In[93]:=
CompleteIndexSet[{{3,2},{1,1},{5}}]
Out[93]=
{{},{0},{1},{2},{3},{4},{5},{1,0},{1,1},{3,0},{3,1},{3,2}}
(The empty braces represent the root node. We can ignore it in Perl. Of
course, the result in perl's CompleteIndexSet should be of the form
[[a1,a2,...],[b1,b2,...],...].)
---
I'm mostly interested in code quality with respect to time and space
complexity. If you think about it, it is not trivial to avoid accumulating
indexes already generated. An input like
CompleteIndexSet([100,100,100],[100,100,100],[100,100,100]) will sent a dump
algorithm to space limits. There should be no assumption on input, except
they are syntactically correct. (we need not do error checking.)
I'll come up and post a solution of my own this weekend, and hope to see
other people's codes to compare notes.
Enjoy!
Xah, xah@best.com
http://www.best.com/~xah/PageTwo_dir/more.html
>They fight! They bite! They fight and bite and fight!
>Fight fight fight! Bite bite bite!
>The Itchy and Scratchy Show!
PS
Here's the Mathematica code that generated the samples.
CompleteIndexSet[indexes_List]:=
Union[Flatten[
Map[(FixedPointList[
Replace[#,{frest___,x_}:>If[x=!=0,{frest,x-1},{frest}]]&,#]&),
indexes],1]]
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3937
**************************************