[13149] in Perl-Users-Digest
Perl-Users Digest, Issue: 559 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 16 20:11:20 1999
Date: Mon, 16 Aug 1999 17:10:14 -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 Mon, 16 Aug 1999 Volume: 9 Number: 559
Today's topics:
Storing data from each column of each line in a hash. <jogoodma@lanl.gov>
Re: Storing data from each column of each line in a has <makkulka@cisco.REMOVETHIS.com>
Re: Storing data from each column of each line in a has <Joe.Kline@sdrc.com>
Re: Storing data from each column of each line in a has (Martien Verbruggen)
Re: Storing data from each column of each line in a has <jogoodma@lanl.gov>
Re: text graphics? <callen@boxcar.driver8.org>
Re: unCRAP (was Re: Perl Services) <elaine@chaos.wustl.edu>
Re: unCRAP (was Re: Perl Services) <uri@sysarch.com>
Re: unpacking - help <Rockett@Audiotel.com>
USENIX Tcl/Tk Conference Call for Papers-Paper submissi (Moun Chau)
Re: Why It's Cool To Make Fun Of Bad Code <cassell@mail.cor.epa.gov>
Re: Why It's Cool To Make Fun Of Bad Code <cassell@mail.cor.epa.gov>
Re: Working with Win32 Network API <carvdawg@patriot.net>
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 16 Aug 1999 16:07:19 -0600
From: Josh Goodman <jogoodma@lanl.gov>
Subject: Storing data from each column of each line in a hash.
Message-Id: <37B88B97.FCFE90B8@lanl.gov>
I was wondering if anyone had a cleaner way to perform the same task
that I have written out below. This code works but I think it
is somewhat crude and I would like to try to improve my code. Basically
the program reads in a file and splits each line into columns.
What I want to do next is to read in each column into a hash associated
by the column number. In my file each column on each line
has a unique number (e.g. if line 1 has columns 1-10 the column number
on line 2 would start with 11). I solved this problem
by saving all the columns in the line into an array and then I iterate
over all the array values in a for loop. Saving the data into a hash
as I go along. Like I said it works but I would like to find out if
there is a "correct" way to do this task. I read Tom C. postings
dealing
with using a variable for a variable name but I couldn't figure out how
to apply it to my problem.
Josh
open(GENETIC,$genetic_dist) || die "Can't open file $genetic_dist:
$!\n";
@genetic = <GENETIC>;
close(GENETIC);
chop(@genetic);
my $bonn = 3;
my $count = 1;
foreach $_ (@genetic) {
my
($bar1,$line,$bar2,$column1,$column2,$column3,$column4,$column5,$column6,$column7,$column8,$column9,$column10,$column11,$column12)
= split(' ',$_,15);
if ($bar1 && $bar1 =~ /\|/ && $bar2 =~ /\|/ && $line == $bonn) {
my @columns
=($column1,$column2,$column3,$column4,$column5,$column6,$column7,$column8,$column9,$column10,$column11,$column12);
my $num_col = @columns;
for (my $i=0; $i<$num_col; $i++) {
$dist{$count} = $columns[$i];
$count++;
}
}
}
------------------------------
Date: Mon, 16 Aug 1999 15:58:28 -0700
From: Makarand Kulkarni <makkulka@cisco.REMOVETHIS.com>
Subject: Re: Storing data from each column of each line in a hash.
Message-Id: <37B89794.1EAB9341@cisco.REMOVETHIS.com>
> I was wondering if anyone had a cleaner way to perform the same task
> that I have written out below.
Try
($bar1,$line,$bar2,@columns )= split(' ',$_,15);
if ($bar1 && $bar1 =~ /\|/ && $bar2 =~ /\|/ && $line == $bonn) {
foreach ( @columns ){
$dist{$count++} = $_ ;
}
}
--
------------------------------
Date: Mon, 16 Aug 1999 19:13:10 -0400
From: Joe Kline <Joe.Kline@sdrc.com>
To: Josh Goodman <jogoodma@lanl.gov>
Subject: Re: Storing data from each column of each line in a hash.
Message-Id: <37B89B06.379FE684@sdrc.com>
Josh Goodman wrote:
> <SNIP>
> What I want to do next is to read in each column into a hash associated
> by the column number. In my file each column on each line
> has a unique number (e.g. if line 1 has columns 1-10 the column number
> on line 2 would start with 11). I solved this problem
> <SNIP>
>
> open(GENETIC,$genetic_dist) || die "Can't open file $genetic_dist:
> $!\n";
> @genetic = <GENETIC>;
> close(GENETIC);
> chop(@genetic);
I prefer chomp over chop, just removes newlines.
>
> my $bonn = 3;
> my $count = 1;
my @elements;
>
> foreach $_ (@genetic) {
don't need to define $_, it's automagically set to it unless you define it to be something else.
>
> my
> ($bar1,$line,$bar2,$column1,$column2,$column3,$column4,$column5,$column6,$column7,$column8,$column9,$column10,$column11,$column12)
> = split(' ',$_,15);
@elements = split(/' '/, $_);
>
> if ($bar1 && $bar1 =~ /\|/ && $bar2 =~ /\|/ && $line == $bonn) {
> my @columns
> =($column1,$column2,$column3,$column4,$column5,$column6,$column7,$column8,$column9,$column10,$column11,$column12);
>
Not totally sure what you're trying to do, but I'll give it a go...
$bar1 = shift @elements;
$line = shift @elemnts;
$bar2 = shift@elements;
this should leave only "column" elements in the list;
>
> my $num_col = @columns;
> for (my $i=0; $i<$num_col; $i++) {
> $dist{$count} = $columns[$i];
> $count++;
> }
> }
> }
if ( $bar1 && $bar1 =~ /\|/ && $bar2 =~ /\|/ && $line == $bonn)
{
foreach (@elements)
{
$dist{$count} = $_;
$count++;
}
}
I know this isn't the cleanest, but it is a little better than what you had.
HTH,
joe
--
/===================================================\
| Joe Kline | I used to be |
| | anonymous - Anon|
\===================================================/
------------------------------
Date: Mon, 16 Aug 1999 23:23:27 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Storing data from each column of each line in a hash.
Message-Id: <P31u3.114$Dq2.3596@nsw.nnrp.telstra.net>
In article <37B88B97.FCFE90B8@lanl.gov>,
Josh Goodman <jogoodma@lanl.gov> writes:
> open(GENETIC,$genetic_dist) || die "Can't open file $genetic_dist: $!\n";
> @genetic = <GENETIC>;
> close(GENETIC);
I probably wouldn't read all of the lines into an array, if you are
going to loop over them anyway.
> chop(@genetic);
chomp is safer, and probably what you really want here.
> my $bonn = 3;
> my $count = 1;
> foreach $_ (@genetic) {
> my
> ($bar1,$line,$bar2,$column1,$column2,$column3,$column4,$column5,$column6,$column7,$column8,$column9,$column10,$column11,$column12)
> = split(' ',$_,15);
my ($bar1, $line, $bar2, @columns) = split ' ', $_, 15;
I would only use the 15 if you really need to limit the split, but is suppose that us actually what you need to do :)
> if ($bar1 && $bar1 =~ /\|/ && $bar2 =~ /\|/ && $line == $bonn) {
> my @columns
> =($column1,$column2,$column3,$column4,$column5,$column6,$column7,$column8,$column9,$column10,$column11,$column12);
I am not sure what you are trying to do here, but this will test true
if $bar1 = 'foo|bar' and $bar2 = 'baz|boo'. Is that what you really
want, or are you looking for exact matches? And I suppose you test for
the true-ness of $bar1 to make sure the split succeeded? Why don't you
check for true-ness of $bar2, $line, and the correct number of
elements in @columns as well? I'd probably split this up:
# You know for certain that the split succeeded if the @columns array
# contains 15 - 3 elements
unless (@columns == 12)
{
warn "Incorrect line format: $_";
next;
}
if ($bar1 eq '|' && $bar2 eq '|' && $line == $bonn)
{
> my $num_col = @columns;
> for (my $i=0; $i<$num_col; $i++) {
> $dist{$count} = $columns[$i];
> $count++;
> }
foreach my $col (@columns)
{
$dist{$count} = $col;
$count++;
}
But do you really want to store this in a hash using numeric keys
starting at 1? An array seems much more sensible, especially since you
already have it all in an array.
push @dist, @columns;
As a completer solution (checked syntax, but not tested, because I
don't have your data, next time you should maybe submit a few lines of
your data files as well):
my $genetic_dist = 'foo';
my @dist;
my $bonn = 3;
open(GENETIC,$genetic_dist) || die "Can't open file $genetic_dist: $!\n";
while (<GENETIC>)
{
chomp;
my ($bar1, $line, $bar2, @columns) = split ' ', $_, 15;
unless (@columns == 12)
{
# Because you are now looping over the file, you can at least
# tell the user _which_ line is incorrect
warn "Line too short at $genetic_dist line $.\n";
next;
}
if ($bar1 eq '|' && $bar2 eq '|' && $line == $bonn)
{
push @dist, @columns
}
else
{
warn "Incorrect line format at $genetic_dist line $.\n";
next;
}
}
close GENETIC;
If you really want the elements out of the file to be stored with an
offset of 1, just declare @dist with:
my @dist = (undef);
Martien
--
Martien Verbruggen |
Interactive Media Division | You can't have everything, where would
Commercial Dynamics Pty. Ltd. | you put it?
NSW, Australia |
------------------------------
Date: Mon, 16 Aug 1999 17:45:06 -0600
From: Josh Goodman <jogoodma@lanl.gov>
Subject: Re: Storing data from each column of each line in a hash.
Message-Id: <37B8A282.13FA8BA0@lanl.gov>
Thanks for all your help. I am a self taught perl person so sometimes I find that I do things the hard way
first only to find an easier way afterwards. I will be sure to use all of your suggestions in the future.
Martien:
Now that I think about it, just using an array for this problem would of been suitable. I think that my original
approach required that I use a hash but I mofidied the program and never re-analyzed that step of it.
Thanks,
Josh
------------------------------
Date: 16 Aug 1999 22:18:33 GMT
From: Christopher Allen <callen@boxcar.driver8.org>
Subject: Re: text graphics?
Message-Id: <7pa2np$1nl0$1@news1.spacestar.net>
Lan Chai <anonymous@web.remarq.com> spake:
> Perl/TK that allows me to do some text graphics
Yes in Perl/Tk, Check here for a search:
http://www.xray.mpe.mpg.de/mailing-lists/ptk/
you can easily change the look of the cursor with an option like this:
-cursor =>X_cursor this applies to the widget of course.
As far as the "text graphics" part of you question what are you asking?
The O'reilly book "Learning Perl/Tk" is very basic but can boot you off
into creating gui apps quite easily.
<--0-->
callen@driver8.org
------------------------------
Date: Mon, 16 Aug 1999 19:18:04 -0400
From: Elaine -HFB- Ashton <elaine@chaos.wustl.edu>
Subject: Re: unCRAP (was Re: Perl Services)
Message-Id: <37B89C28.6BF9A405@chaos.wustl.edu>
[courtesy copy mailed to author]
Uri Guttman wrote:
> E-A> I'm tired of the wright rants. Why don't we do something to change that.
>
> we are, sort of. there is a recent thread on CRAP and i posted we create
> a site of good cgi scripts. i volunteered to review them but not write
> them. others said they would write them. i think the first stage is to
> list the kinds of cgi scripts we want: ( e.g. survey/votes, etc.) and
> then spec them with nice clean specs (e.g. the survey should work with a
> flat file db, take questions and choices from a file, display in table
> and/or graphics, etc.).
Right, I remember seeing that. Randal mentioned CPAN scripts, but I'm
thinking of having a web site that is attractive and sells like shiny
bits to rats as CPAN is about as un-sexy as it gets [which i
like..but..marketing]. Also, we could stuff the crawler bots with a matt
wright tag and get placed higher in context searches than his site :)
And, we would need the top 10 most used and abused scripts out there.
So, I've got a machine and you will review them. Kurt and Jeff can
funnel in scripts from CRAP and CPAN, and all we need to find is some
poor willing soul to organise and crack the whip! :) We should talk
about this more at TPC. Actually, why don't we get a little BOF going on
...hmm...sunday night maybe? The CRAP/unCRAP BOF :)
Of course we would want all the code review possible.
e.
------------------------------
Date: 16 Aug 1999 20:03:28 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: unCRAP (was Re: Perl Services)
Message-Id: <x7zozr1df3.fsf@home.sysarch.com>
>>>>> "E-A" == Elaine -HFB- Ashton <elaine@chaos.wustl.edu> writes:
E-A> [courtesy copy mailed to author]
E-A> Uri Guttman wrote:
E-A> I'm tired of the wright rants. Why don't we do something to change that.
>>
>> we are, sort of. there is a recent thread on CRAP and i posted we create
>> a site of good cgi scripts. i volunteered to review them but not write
>> them. others said they would write them. i think the first stage is to
>> list the kinds of cgi scripts we want: ( e.g. survey/votes, etc.) and
>> then spec them with nice clean specs (e.g. the survey should work with a
>> flat file db, take questions and choices from a file, display in table
>> and/or graphics, etc.).
E-A> Right, I remember seeing that. Randal mentioned CPAN scripts, but
E-A> I'm thinking of having a web site that is attractive and sells
E-A> like shiny bits to rats as CPAN is about as un-sexy as it gets
E-A> [which i like..but..marketing]. Also, we could stuff the crawler
E-A> bots with a matt wright tag and get placed higher in context
E-A> searches than his site :) And, we would need the top 10 most used
E-A> and abused scripts out there.
fine with me. cpan can link to it. and cpan does have a better look with
this site: http://theoryx5.uwinnipeg.ca/mod_perl/pause
also graham is doing a sexy web front end as well.
E-A> So, I've got a machine and you will review them. Kurt and Jeff can
E-A> funnel in scripts from CRAP and CPAN, and all we need to find is some
E-A> poor willing soul to organise and crack the whip! :) We should talk
E-A> about this more at TPC. Actually, why don't we get a little BOF going on
E-A> ...hmm...sunday night maybe? The CRAP/unCRAP BOF :)
i like the BOF idea. but sunday night is no good for me. how about
either lunch or 5/6pm on mon or tues? the evening hour would be before
we pub crawl.
E-A> Of course we would want all the code review possible.
too true. but we should start with a list of scripts. can someone just
seed it with the categories from a cgi site? even matt's cgi-resources
would be ok for that. after we get a list of 10+ apps, we have to create
some specs for them and people can volunteer to write them. our specs
should have coding ideas, modules to use and other useful stuff as
well. that way they can be written by the legions of intermediate perl
hackers out there and we know they won't be so far out thet we would
reject them out of hand.
the specs cn be tricky. just on the survey one alone, doe sit generate
html on the fly or use a template? if a template what kind? server
support should not be expected. we want these to be widely useable but
not bloated either.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
uri@sysarch.com --------------------------- Perl, Internet, UNIX Consulting
Have Perl, Will Travel ----------------------------- http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.
------------------------------
Date: Mon, 16 Aug 1999 17:15:39 -0500
From: Rockett Crawford <Rockett@Audiotel.com>
Subject: Re: unpacking - help
Message-Id: <A614978C58D55A45.FC411EE93599ED17.D943411255CB387E@lp.airnews.net>
Rockett Crawford wrote:
> It looks like this isn't a matter of packing after all.
>
> When I used substr I pulled this string out:
> "Win32::OLE=HASH(0x1aa1718)"
>
> Does this mean that the real string is elsewhere?
> If so, how can I get it into a string variable?
>
Looks like I'm the only one on this thread. The
answer turned out to be that you have to use
->Item(); to get the actual string.
$Response->ServerVariables('Query_String')->Item();
instead of just
$Response->ServerVariables('Query_String');
Thanks,
Rockett
------------------------------
Date: Mon, 16 Aug 1999 23:21:23 GMT
From: moun@usenix.org (Moun Chau)
Subject: USENIX Tcl/Tk Conference Call for Papers-Paper submissions due soon: 9/1/99
Message-Id: <FGKzJn.LwF@usenix.org>
Keywords: USENIX, Tcl/TK, Tcl, TK, conference, tutorials, training, Invited Talks, research, Refereed Papers, Unix, Cross-Platform Development, CGI Scripting, Object Oriented Programing, Mega Widgets, Database, Client/Server Applications, extension Building, SWIG, C, Debugging, testing, Packaging, Java, HTTP Tcl Daemon, CGI-BIN, mapping, embedding, applications, commands, Data Objects, Tycho Slate, WinACIF, Iclient/Iserver, Distributed, language, management, Yacc, Corba, Novell, extensions, designing, supporting, deve
The 7th USENIX Tcl/Tk Conference is a forum to:
* bring together Tcl/Tk researchers and practition
* publish and present current work involving Tcl/Tk
* learn about the latest developments in Tcl/Tk
* plan for future Tcl/Tk related developments
Tcl/2K : The 7th USENIX Tcl/Tk Conference
February 14-18, 2000
Austin, Texas, USA
Sponsored by USENIX, The Advanced Computing Systems Association
----------------------------------------------------------------------------
Please find the Call for Papers at
http://www.usenix.org/events/tcl2k/cfp
----------------------------------------------------------------------------
Paper submissions due: September 1, 1999
Demonstration, and Panel Proposals due: September 1, 1999
Poster submissions due: December 8, 1999
The conference program will include formal paper and panel presentations,
poster and both reviewed and informal demonstrations, works-in-progress,
Birds-of-a-Feather sessions, and two-days of high-quality tutorials. All
forms of participation provide an opportunity to report on original Tcl/Tk
research.
Formal papers should address topics of interest to experienced Tcl/Tk
programmers; posters and informal demos may be geared to any level of user
from beginner to expert. Awards will be given for the best
paper and best student paper at the conference.
============================================================================
The USENIX Association's international membership includes engineers,
system administrators, and computer scientists working on the cutting edge
of systems and software. Our conferences are recognized for their
technical excellence and pragmatic emphasis.
------------------------------
Date: Mon, 16 Aug 1999 16:36:48 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Why It's Cool To Make Fun Of Bad Code
Message-Id: <37B8A090.7325E065@mail.cor.epa.gov>
Chris wrote:
[snip]
> I'm learning Perl, and for the most part I'm learning from other
That's good.
> people's code. (I read THE CAMEL and it didn't help, but hey, that
I learned an awful lot from other people's code myself. But
at first I didn't know the difference between good and bad
Perl code. You can learn that difference faster reading this
group than anything else, IMHO.
> could be my problem). My web hosters have this script they provide to
If the camel seems intractable, get the llama. Learning Perl.
It's worth it.
[snip of story]
> You know what though? After reading that initial post making fun of
> those old scripts, I thought "Hmmmmmm, maybe that code I was studying
> ISN'T so great." And I realized that whole extraneous chop() stuff was
> just sloppiness, and I found some socket code samples that didn't use
> all that pack crap and that actually work, and now I see sockets in
> Perl are easy as pie.
>
> What's all that mean? Well, for starters, is was extremely helpful for
> me for someone to speak out against the bad code. (That also took some
> gumption, since the guy must have known he'd get slammed). Also, I
Around here, PEDANTREE ROOLS! :-)
['nother snip]
> Bitch all you want.
Who's going to complain about that? :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 16 Aug 1999 16:40:59 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Why It's Cool To Make Fun Of Bad Code
Message-Id: <37B8A18B.70373520@mail.cor.epa.gov>
Chris wrote:
[snip]
> Rock On! In particular I couldn't agree more about what you say about
> modules and OOP. I looked at perlmod, and it just had me asking "Okay,
> where's the REAL docs on modules?"
Good point. The info on *using* modules is buried 80% of the
way down the manpage, where only an extremely diligent beginner
is going to find it. But go down to the point where it
discusses using modules in a program, and you'll see it's easy.
It's *really* easy. Then look in this ng (and its archives
on deja.com), and you'll see plenty of examples of how to do it.
You can even search in the archives and find easy examples from
this ng on how to *write* simple modules. For complex modules,
look in the ram: the Perl Cookbook.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Mon, 16 Aug 1999 18:43:49 -0400
From: "Harlan Carvey, CISSP" <carvdawg@patriot.net>
Subject: Re: Working with Win32 Network API
Message-Id: <37B89425.D7EFD165@patriot.net>
> Does anyone know where there is a "great" reference that deals with how to
> use the API from within perl? I have looked at the docs that come with the
> win32::api mod, but it is quite cryptic.
>
Todd,
Drop me a line...you may not need to use Win32::API to do what you want to
do...
there are modules that you can use. Let me know what you are trying to do, I
can
point you to the module. From there, I can help with code.
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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.
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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu.
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 V9 Issue 559
*************************************