[6272] in Perl-Users-Digest
Perl-Users Digest, Issue: 894 Volume: 7
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 4 19:00:35 1997
Date: Tue, 4 Feb 97 15:00:19 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 4 Feb 1997 Volume: 7 Number: 894
Today's topics:
"Scalar-list context magic sucks" and other sins of Per (Jonathan King)
Re: *** JOB: Perl program needed to analyze Web server <kevlar@ns.net>
controlling case sensitivity (Dan Lipofsky)
Re: Help with filehandles (Laurel Shimer)
How to make a ftp script <slambert@avenor.com>
Informix with Perl ? (Michael Packham)
Re: Interfacing existing C library to OO perl module (Dean Roehrich)
Re: Invoking Perl program (Laurel Shimer)
Re: JAVA-enabled Browser Detection (Abigail)
Re: Large Project Code Organization (Randy J. Ray)
opening a file in a Recursive Call (Perl Question) <sgrover@elizacorp.com>
perl and winperl <gnadan@earthlink.com>
Q on "unless $seen"? (Marshall Pierce)
Re: Q on "unless $seen"? (Marshall Pierce)
Re: Q on "unless $seen"? (Bennett Todd)
Q: Date algorithm? (Keith Thomas Sherry)
Re: Q: Date algorithm? (Bennett Todd)
Re: Q: Date algorithm? (Mike Stok)
Recursive Calls in Perl? <sgrover@elizacorp.com>
Simple Win32::ODBC question (Patty Luxton)
Re: Wanted: perl telnet examples (Jagadeesh Venugopal)
Warning: setlocale failed <kmm96jog@mds.mdh.se>
Re: Where to search for all newsgroup (Laurel Shimer)
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 4 Feb 1997 21:25:35 GMT
From: king@cogsci.ucsd.edu (Jonathan King)
Subject: "Scalar-list context magic sucks" and other sins of Perl (was: Re: Q: opening a file...)
Message-Id: <5d89gf$dku@news1.ucsd.edu>
Keywords: scalar list array transparency conversion types
I've snipped/edited stuff below as indicated, and changed one comma
to a question mark because it hurt my brain to look at the sentence
otherwise. I apologize if any of my words below sounds whiny,
ungrateful, or unfair to perl. In my defense, I can only say that
I've now written thousands of lines of Perl that implements a system
that my very scientific career could depend on, so I know some of
the joys of Perl as well as, uh, the sand that gets inside the
shell.
In article <5d7i77$qb2$1@csnews.cs.colorado.edu>
tchrist@mox.perl.com (Tom Christiansen) writes:
> [courtesy cc of this posting sent to cited author via email]
>
>In comp.lang.perl.misc, mike@stok.co.uk writes:
>:In article <8clo96hlup.fsf@gadget.cscaper.com>,
>:Randal Schwartz <merlyn@stonehenge.com> wrote:
>:
>:>Mike> scalar <FILE>;
>:
>:>What are those "scalars" doing in there?
>:>Works just fine without them. It's misleading this way.
>
>:In what way is it misleading? Not necessary, ugly, verbose, untidy I can
>:live with, but misleading?
>
>I suspect that Randal considers them misleading because
>they do not change the behaviour of the <FH> read there,
>since it's already in a scalar context.
Feel free to correct me here, but wasn't what Mike Stok wrote
actually in a *void* context? As I remember the entire example, it
was using "<FILE>" just to read and discard lines.
I bring this up, because this bit of code made me squirm at first
since I actually had the !!incorrect!! idea that this would merrily
clobber "$_" for you.
It doesn't; as True perl programmers always remember, that "special
magic" only applies inside the conditional part of a while loop (New
Camel, p. 53). Yup, I'd mistaken the sugar-coated idiom for the
rule, and that gave me pause, since I could have sworn that I
really, really knew how the angle operator worked.
And it was small comfort that a far more experienced perl programmer
than I am felt the need to scalarize the void.
>I'm siding with Mike on this one. He's just trying to protect himself
>from the Black Beast of Perl Programming: deceptful, misleading, silent,
>and often catastrophic auto-conversion between the scalar/list senses of
>too damn much in this language. It is the single most evil and wrong
>thing about Perl, and we must not judge Mike too harshly for it. It's
>strange magic at a distance.
So nobody should be surprised to see this listed as #1 on the list
of Tom Christiansen's "Seven Deadly Sins of Perl" on display at:
http://www.perl.com/perl/versus/perl.html
I'm not sure (and it doesn't say) whether the whole list is really
in order of evilness, but this has to be #1 on anybody's list.
(It's so evil that I think I could argue it's really the root cause
of the problems with parens mentioned in #2 on that list.)
And are nominations being taken to replace the obsolete #5 "No
Prototypes"? If so, I definitely nominate "no named formal
parameters". Although I could also go for some version of:
>
>Scalar-list context magic sucks.
>
But, while I'm speaking about the sins of Perl, this is probably the
place to bring up something else that's been annoying me, namely a
Perl-Python comparison you can view at:
http://www.wcmh.com/uworld/archives/95/tutorial/005.html
from this I will quote some matrix multiplication code attributed to
a post by Tom Christiansen to "a number of Internet newsgroups", and
the purportedly superior Python version. The thing that annoys me
is that looking at the actual code could make a novice want to
delete the "purportedly" from the preceding sentence. No joke:
# perl version by T. Christiansen
sub mmult { my ($m1,$m2) = @_;
my ($m1rows,$m1cols) = (scalar @$m1, scalar @{$m1->[0]});
my ($m2rows,$m2cols) = (scalar @$m2, scalar @{$m2->[0]});
unless ($m1cols == $m2rows) { # raise exception, actually
die "IndexError: matrices don't match: $m1cols != $m2rows";
}
my $result = [];
my ($i, $j, $k);
for $i (0 .. ($m1rows - 1 )) {
for $j (0 .. ($m2cols - 1 )) {
for $k ( 0 .. ($m1cols - 1)) {
$result->[$i]->[$j] += $m1->[$i]->[$k] * $m2->[$k]->[$j];
}
}
}
return $result;
}
# python version, apparently by Aaron Watters; hope I cut/pasted the
# indentation correctly, otherwise it won't run. :-)
def mmult(m1,m2):
m2rows,m2cols = len(m2),len(m2[0])
m1rows,m1cols = len(m1),len(m1[0])
if m1cols != m2rows: raise IndexError, "matrices don't match"
result = [ None ] * m1rows
for i in range( m1rows ):
result[i] = [0] * m2cols
for j in range( m2cols ):
for k in range( m1cols ):
result[i][j] = result[i][j] + m1[i][k] * m2[k][j]
return result
# end of code samples
The remarkable thing about these two examples is that they're
implementations of the same algorithm, and I really don't see much
to choose between them...except where the Perl looks cluttered or
weird because:
1) Perl lacks named formal parameters, which causes some ugliness,
and makes it hard to even dream about point 5 below.
2) Every variable used is lexically scoped, but you have to tell
Perl this every time. My, my, my, but this gets annoying after a
time.
3) Array lengths are computed via an oddball conversion to scalar
(although then the code only depends on the array bounds, which
injects more parentheses and arithmetic into the for loops than
necessary; I'll also gloss over the possible problems with
constructing big lists via "for $j (0 .. $huge_dim)" if this code
were used for big matrices or computing dot products of vectors).
4) Unless I'm *really* missing something, things like
$result->[$i]->[$j] += $m1->[$i]->[$k] * $m2->[$k]->[$j];
could have been more "sweetly" written as:
$result->[$i][$j] += $m1->[$i][$k] * $m2->[$k][$j];
where it's a bit clearer we're working with matrix thingies
5) Speaking of "matrix thingies", I know I'm probably a minority
opinion here but I'd really like to see at least the option of
using real types in Perl. Not for my one-liners, but when code
accumulates to the point of wanting to define your own matrix
multiplication routines, this is a more serious issue.
None of these things are deadly in isolation, and the Perl code is
hardly obscure, but the cumulative effect is that the Perl version
looks noisier because it *is* a bit noisier, and I'm not sure that
this is really necessary or desirable in the long run.
jking
------------------------------
Date: Tue, 04 Feb 1997 14:22:25 -0800
From: Kevin Healy <kevlar@ns.net>
Subject: Re: *** JOB: Perl program needed to analyze Web server logs ***
Message-Id: <32F7B6A1.167E@ns.net>
greg@lightningweb.com wrote:
> <snipped>
I'll let Matt Kruse field this one ;-)
Kevin
<kevlar@ns.net>
------------------------------
Date: 4 Feb 1997 22:53:28 GMT
From: danlip@proton.cyc.com (Dan Lipofsky)
Subject: controlling case sensitivity
Message-Id: <5d8el8$gaa@news3.texas.net>
I would like to control case sensitivity of matching
based on a variable in my script. Obviously this would work:
if ($sensitive) {
if ( m/$word/ ) { ... }
}
else {
if ( m/$word/i ) { ... }
}
But this involves an extra if for each match.
Since there will be a large number of repetitions,
this isnt too efficient. I tried
if ( m/$word/$tags ) { ... }
where $tags was set to "i" or "", but this gave
me syntax errors.
What is the most efficient way to accomplish my goal.
Thanks,
Dan
------------------------------
Date: Tue, 04 Feb 1997 12:53:26 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Re: Help with filehandles
Message-Id: <autopen-0402971253260001@l11.d22.quake.net>
In article <32EF16A8.41C6@hp1.uib.es>, hcm network meeting
<hcm@hp1.uib.es> wrote:
> print TEST "whatever"
>
>
> where TEST is a filehandle and "whatever" is the string I want to write
> to this file, can the filehandle be defined in some line
> other than
>
>
> open(TEST,">test.html")
>
---------------------
1) First you may need to make sure the data file can be written to
>From the shell
shellx 4% touch some.name.data
shellx 7% chmod 662 some.name.data
shellx 8% ls some.name.*
some.name.data
shellx 9% ls -lu some.*
-rw-rw--w- 1 autopen mosaic 0 Feb 4 12:37 some.name.data
shellx 10%
2) Make sure that the file which contains your Perl code has the necessary
access permissions. From the web I use 755
3)
--- Now here is some perl code ---
shellx 20% perl5
$filename = "some.name.data";
open (OUTPUT,">> $filename") || die("Cannot open $filename");
print OUTPUT "data line\n";
close (OUTPUT)|| die("Cannot close $filename");
system ("ls -lu $filename");
-rw-rw--w- 1 autopen mosaic 10 Feb 4 12:37 some.name.data
shellx 21% cat some.name.data
data line
You might try testing like I did
At the unix shell prompt type
perl5
then it will sit and wait for you to type in individual lines.
I used cut and paste (which works in my mac/telnet environment) to paste
in the test lines.
Then I typed a ^d (control d) to signal to perl I'm done.
-I used '>>' to append data to the end of an existing file. You may want
to use '>' to write over an existing file.
-I included a call to 'ls' to make sure that I had gotten some data in the file.
-I used 'cat' to look and see if that file contains data
--
The Reader's Corner: Mystery, Romance, Fantasy
Short stories, excerpts, themes and resources
http://www.autopen.com/index.shtml
Subscribe to our free StoryBytes publication
Current Mermaids Issue at http://www.autopen.com/mermaids.shtml
------------------------------
Date: 4 Feb 1997 20:58:34 GMT
From: "Sebastien Lambert" <slambert@avenor.com>
Subject: How to make a ftp script
Message-Id: <01bc12de$6af349e0$370a010a@slamber.Avenor.com>
I want to make a program who is going to get a file by ftp in
a specified site.
How could I do that automatic...
Thanks for help...
------------------------------
Date: 4 Feb 1997 20:55:22 GMT
From: packham@corp.hp.com (Michael Packham)
Subject: Informix with Perl ?
Message-Id: <5d87nq$klm@hpcc48.corp.hp.com>
Hi,
Does anybody have any sample code or tips or advice etc. for someone
trying to figure out how to Insert/update an Informix database
from Perl?
Using Perl 5 and Informix 7.2
Please reply to dan_avilla@hp.com
thanks
------------------------------
Date: 4 Feb 1997 22:04:25 GMT
From: roehrich@cray.com (Dean Roehrich)
Subject: Re: Interfacing existing C library to OO perl module
Message-Id: <5d8bp9$o6j@walter.cray.com>
In article <8ju3ntrgje.fsf@nynexst.com>,
Tom Fawcett <fawcett@nynexst.com> wrote:
>
>I'm working with a C library that is implicitly object oriented. Every
>function takes a CONTEXT argument which is a pointer to a large C structure
>containing contextual data. I'm writing an XS interface module for the
>library.
>
>Instead of a translating the function interface literally, I'd prefer
>to make the Perl module object-oriented. I've gone through perlxs,
>perlxstut, perlapi and perlguts, and unless I missed something there's
>no discussion of this. Can someone point me to an example of a
>Perl<->C object-oriented interface?
Consult the cookbooks. Find them on CPAN in authors/id/DMR. Find CPAN info
at www.perl.com. I think example 'Ex8' in CookBookA shows some basic ideas
that may apply, and I know there at least 2 examples in CookBookB that apply.
Dean
roehrich@cray.com
------------------------------
Date: Tue, 04 Feb 1997 12:31:02 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Re: Invoking Perl program
Message-Id: <autopen-0402971231020001@l11.d22.quake.net>
In article <5d4ph0$de1$2@bandit.cyberwar.com>,
tnocella@outland.cyberwar.com (L.T. Nocella) wrote:
> Maksym I Panfilov (mpanfilo@newstand.syr.edu) wrote:
> : #!/usr/local/bin/perl
>
> : # File: firstscript.perl.cgi
> : # (c) 1996 John Desborough
>
> : print "Content-type: text/html\n\n";
>
> : # Because this comes back as HTML we put into a format
> : # that is understandable, including a title
> : print "<HTML><HEAD><TITLE>First Script Response<\/TITLE><\/HEAD>\n";
>
> : # And now the body of the HTML page we will see returned
> : print "<BODY><H1>My First Script</H1><HR>Congratulations! You programmed
> : your first CGI script!</BODY></HTML>\n";
>
> : From within Unix this Perl program runs. Tutorial says that when i click
> : on a Perl's program link from a browser it should return appropriate
> : information in correct HTML format directly to the browser. Unfortunately,
> : after invoking the program via link I receive just a text of a program,
> : not HTML formatted page. It should be noted that I made Perl's program
> : executable.
> ------------------------------------------------------------------------
>
>
> Check with your patron GOD (ie. Sys admin) - many times
> perl scripts can only run from certain directories, or must
> have specific extensions (ex. .CGI) - this is specified in the
> server configuration. Otherwize it
> would have viewed the file as a text file and not executed it.
>
> -------------------------------------------------------------
**** And make sure that your path to perl really is the one shown on the
top line.
I use an ISP with a non-standard Perl setup. As in above, the sysadmin can
tell you. I also think there is a smart way to figure this out for
yourself (what is that though?)
Laurel
--
The Reader's Corner: Mystery, Romance, Fantasy
Short stories, excerpts, themes and resources
http://www.autopen.com/index.shtml
Subscribe to our free StoryBytes publication
Current Mermaids Issue at http://www.autopen.com/mermaids.shtml
------------------------------
Date: Tue, 4 Feb 1997 19:15:28 GMT
From: abigail@ny.fnx.com (Abigail)
Subject: Re: JAVA-enabled Browser Detection
Message-Id: <E53Ets.6M3@nonexistent.com>
On Mon, 03 Feb 1997 12:50:26 -0600, Robert Aldridge wrote in comp.lang.perl.misc:
++ Mike Stok wrote:
++ >
++ > In article <32F566EC.5AA6@cyberramp.net>,
++ > Robert Aldridge <roberta@cyberramp.net> wrote:
++ > >I am looking for a CGI script that will detect if a client browser is
++ > >capable of displaying a JAVA applet, the direct the java-enabled
++ > >browsers to a java savvy page, and the non-java browsers to a non-java
++ > >page.
++ >
++ > Please remember that some of us might bu using a browser which is java
++ > capable but we have the Java (and JavaScript, JScript, whatever...) turned
++ > off...
++ >
++ > Mike
++
++ Oh, I completely understand this, but there is no easy way as far as I
++ know to detect if the browser has java turned on. Or is there? Either
++ way, I'm looking for a way to add a simple java applet to my pages,
++ and send those that can't use it to the non-java page.
++
Why bother? HTML does provide you with a method, which eliminates
the need to maintain a double set of pages:
<APPLET ...>
Show this to non-java enabled/aware browsers.
</APPLET>
++ If anyone knows the user agent types to do this, please let me know.
You can't. Period.
Abigail -- Followups set.
------------------------------
Date: 04 Feb 1997 13:47:30 -0700
From: rjray@tremere.ecte.uswc.uswest.com (Randy J. Ray)
Subject: Re: Large Project Code Organization
Message-Id: <uow20awjo2l.fsf@tremere.ecte.uswc.uswest.com>
"Christopher G. Mann" <r3cgm@cdrom.com> writes:
> So from the veterans out there, may I
> ask how you have structured directories, files, and libraries as your
> projects grew to "large" status?
I don't know what other folks deal with in terms of a "large perl project",
but for the last 5 years I have maintained and developed an SCM system written
entirely in perl. It has about 55 executable scripts (several of which operate
under several aliases via symlinks), 20-odd libraries (some more odd than
others), manpages and a scattering of support files.
As it happens, since the system itself is a software configuration management
system, I use it to manage itself. I divide files into scripts ("bin"),
libraries ("lib"), manual pages ("man") and support files ("etc"). I tightly
define the scope of a given library, preferring to have 20 well-focused libs
over 10 broader-scoped ones.
Now that I am converting it all to Perl 5, I do some additional housekeeping:
* 12 of the 20 libraries use the AutoLoader and AutoSplitter (I am currently
writing an article for the Perl Journal on using these very spiffy libs).
The remaining 8 will require re-design before benefitting from them, a task
I don't (yet) have time for.
* I am obsoleting the entire "man" area in favor of inlining the documentation
as POD. At project build time, I will use pod2man to generate manual pages.
This not only cuts down the number of files, it also makes it trivial to
generate HTML in a different step. Prior, my only man->html options pre-
formatted the manual page and displayed it inside of <PRE></PRE>. pod2html
generates real HTML.
* Most importantly, the new use/import syntax with libraries and modules allows
me to completely deprecate the practice of either having a library force the
published interface routines into the MAIN namespace, or force the users of
the library to use the library namespace when calling. This added flexibility
in interface actually contributes greatly to the maintainability of the code.
* The developers that work on code for me have a style guideline. It isn't *my*
coding style, but a style that I too had to adopt when I got on this project.
Code is expected to adhere to this style.
* All executables have a set of pre-defined routine names. If I go to debug
someone else's script, I know at least a few places I can *always* place a
breakpoint, at least to start out with. These presets only govern the
transition from startup->initialization->processing->cleanup. But at least
I know that the main processing loop starts at a pre-defined point (even if
the first executable line takes me somewhere else).
* Lastly, a practice that has atrophied during the hefty effort of Perl 5
conversion, we do code reviews for each script and library. Support files
and man pages are also reviewed in conjunction with a given script or lib.
Randy
--
===============================================================================
Randy J. Ray -- U S WEST Technologies IAD/CSS/DPDS Phone: (303)595-2869
Denver, CO rjray@uswest.com
"It's not denial. I'm just very selective about the reality I accept." --Calvin
===============================================================================
------------------------------
Date: 4 Feb 1997 21:21:49 GMT
From: "Samir Grover" <sgrover@elizacorp.com>
Subject: opening a file in a Recursive Call (Perl Question)
Message-Id: <01bc12e1$f1e41710$6b00000a@e15>
Hello all,
I think my problem is overwring the same filehandle.
Consider this:
..
$inName = "foo";
&doCommand($inName);
...
...
sub doCommand {
open(FILEHANDLE, "$_[0]");
while ($x = <FILEHANDLE>) {
...
...
&doCommand($x);
...
}
#END
When doCommand is called recursively from itself, it looks like its
overwriting
FILEHANDLE and, thus it stops without completing the reading of very first
file.
How to get rid of this problem?
thansk,
------------------------------
Date: 4 Feb 1997 19:19:17 GMT
From: "Greg Nadan" <gnadan@earthlink.com>
Subject: perl and winperl
Message-Id: <01bc12d0$f9bde300$71132399@interport.interport.net>
In perl I have a program that goes through subdirectories and files from a
starting direcotory. In perl on a unix box this program works fine, in
winperl I have had to do some "porting". The problem is that the -x file
tests( -r ,-w,-x , etc.. ) do not work in winperl, as far as I can tell!
Example...
$name is the name of a file/directory from doing a readdir
.
.
.
elsif ( -d $name) {
&list($name); # if a sub-directory call function with that sub-dir
.
.
.
basically the elsif (-d $name) works on perl on the unix box, and lets me
know if the var $name is a directory or not, but not on my version of
winperl(perl32b3)
I dont know of any documentation for winperl. Does anybody know of any?
Also does anybody know how the -x file tests work for winperl, if at all?
-Thanks
------------------------------
Date: 4 Feb 1997 19:40:49 GMT
From: piercem@col.hp.com (Marshall Pierce)
Subject: Q on "unless $seen"?
Message-Id: <5d83c1$mv6@nonews.col.hp.com>
I have a file, which includes (among other things, so the lines will not
be complete matches) two field values which would be paired something
like:
animal:dog
animal:cat
animal:cat
animal:horse
thing:bone
thing:idiot
thing:idiot
thing:idiot
thing:idiot
thing:shoe
day:friday
day:the weekend!
What I want to output is, basically:
animal
dog
cat
horse
thing
bone
idiot
shoe
day
friday
the weekend!
But, instead, I always get every occurence of the second field. pg 228 of
O'Reilly details a procedure which works on complete lines in files. Any
ideas on how to do this?
Many thanks
--
A Lifelong Fan of New England Patriots Football
=-=-=-=-= Marshall V Pierce World Wide User Support Program
/_ __ marshall_pierce@hp.com Technology Team
/ //_/ (719) 590-3461
/ http://hpweb.cs.itc.hp.com/solutions/wwsms.html
------------------------------
Date: 4 Feb 1997 19:50:29 GMT
From: piercem@col.hp.com (Marshall Pierce)
Subject: Re: Q on "unless $seen"?
Message-Id: <5d83u5$mv6@nonews.col.hp.com>
How's this for a kluge;
#!/usr/bin/perl
open(file1,"f1");
while(<file1>)
{
($field1,$field2) = split(':');
chop $field2;
$array1{$field1} = join(':',$array1{$field1},$field2);
}
foreach (keys %array1)
{
$key = $_;
@array2 = split(':',$array1{$key});
print "\nfile is $_\ncontents are";
foreach $thing (@array2)
{
print "$thing\n" unless $seen{$thing}++;
}
}
Marshall Pierce (piercem@col.hp.com) wrote:
: I have a file, which includes (among other things, so the lines will not
: be complete matches) two field values which would be paired something
: like:
: animal:dog
: animal:cat
: animal:cat
: animal:horse
: thing:bone
: thing:idiot
: thing:idiot
: thing:idiot
: thing:idiot
: thing:shoe
: day:friday
: day:the weekend!
: What I want to output is, basically:
: animal
: dog
: cat
: horse
: thing
: bone
: idiot
: shoe
: day
: friday
: the weekend!
: But, instead, I always get every occurence of the second field. pg 228 of
: O'Reilly details a procedure which works on complete lines in files. Any
: ideas on how to do this?
: Many thanks
: --
: A Lifelong Fan of New England Patriots Football
: =-=-=-=-= Marshall V Pierce World Wide User Support Program
: /_ __ marshall_pierce@hp.com Technology Team
: / //_/ (719) 590-3461
: / http://hpweb.cs.itc.hp.com/solutions/wwsms.html
--
A Lifelong Fan of New England Patriots Football
=-=-=-=-= Marshall V Pierce World Wide User Support Program
/_ __ marshall_pierce@hp.com Technology Team
/ //_/ (719) 590-3461
/ http://hpweb.cs.itc.hp.com/solutions/wwsms.html
------------------------------
Date: Tue, 4 Feb 1997 20:18:14 GMT
From: bet@nospam.interactive.net (Bennett Todd)
Subject: Re: Q on "unless $seen"?
Message-Id: <slrn5ff6c6.s1m.bet@onyx.interactive.net>
How about:
#!/usr/local/bin/perl -w
use strict;
my(%dat);
while (<>) {
chop;
my($category, $variety) = split /:/;
$dat{$category}{$variety} = 1;
}
for (sort keys %dat) {
print "$_\n", map { " $_\n" } keys %{$dat{$_}};
}
You want to collect like items together by category (a fine application for an
associative array) and do duplicate elimination on them (another fine job for
an assoc); so let's use an array of arrays.
Works for me....
-Bennett
------------------------------
Date: 4 Feb 1997 20:55:37 GMT
From: ktsherry@nntp.best.com (Keith Thomas Sherry)
Subject: Q: Date algorithm?
Message-Id: <5d87o9$lks$1@nntp2.ba.best.com>
I'm looking for an algorithm that will return the first day of the week in
date format, given any week in a year. For example:
Input:
year - 1997
week - 7th week
Output
Feb 13 97
Your help is truely appreciated.
--
Keith T. Sherry
------------------------------
Date: Tue, 4 Feb 1997 22:18:15 GMT
From: bet@nospam.interactive.net (Bennett Todd)
Subject: Re: Q: Date algorithm?
Message-Id: <slrn5ffdd6.869.bet@onyx.interactive.net>
On 4 Feb 1997 20:55:37 GMT, Keith Thomas Sherry <ktsherry@nntp.best.com> wrote:
>I'm looking for an algorithm that will return the first day of the week in
>date format, given any week in a year. For example:
>
> Input:
> year - 1997
> week - 7th week
>
> Output
> Feb 13 97
Well, I'm not sure exactly how you came up with Feb. 13 there. And eschew
two-digit date formats; they will rise up and bite you in just a couple of
years.
I can get the date 7 weeks into 1997, though I come up with Feb 19; a trivial
script looks like
#!/usr/local/bin/perl -w
use strict;
use Date::Parse;
use Date::Format;
die "syntax: Nth week yyyy" unless @ARGV == 3 and $ARGV[1] eq 'week';
my($wk) = $ARGV[0]; $wk =~ s/th$//;
my($yr) = $ARGV[2];
my($secs_per_wk) = 60*60*24*7;
my($seconds) = $wk * $secs_per_wk;
print time2str("%b %d %Y\n", str2time("Jan 1 $yr")+$seconds);
-Bennett
------------------------------
Date: 4 Feb 1997 22:43:54 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Q: Date algorithm?
Message-Id: <5d8e3a$n4q@news-central.tiac.net>
In article <5d87o9$lks$1@nntp2.ba.best.com>,
Keith Thomas Sherry <ktsherry@nntp.best.com> wrote:
>I'm looking for an algorithm that will return the first day of the week in
>date format, given any week in a year. For example:
>
> Input:
> year - 1997
> week - 7th week
>
> Output
> Feb 13 97
>
>
>Your help is truely appreciated.
Have you looked at the Date::DateCalc module on CPAN (the Comprehensive
Perl Archive Network) at all? Its readme (most modules on CPAN have their
readmes unbundled so you can check to see if the module might be useful to
you) includes:
[...]
What does it do:
----------------
The package provides a Perl interface to a C library which offers a wide
variety of date calculations based on the Gregorian calendar (the one
used in all western countries today), complying with the ISO/R 2015-1971
and DIN 1355 standards which specify things as what leap years are, when
they occur, how the week numbers are defined, what's the first day of the
week, how many weeks (52 or 53) a given year has, and so on.
[...]
Moreover, the module is mainly written in C so that the C part can be used
as a stand-alone library in other applications than Perl. (!!!)
To give you an idea of what the package can do, here a list of all the
functions it exports:
[...]
($year,$mm,$dd) = first_in_week($week,$year);
[...]
You can use ftp to get a list of mirror sites from the master site at
ftp.funet.fi under /pub/languages/perl/CPAN or use Tom Christiansen's
multiplexor at http://www.perl.com/CPAN/ to be bounced to one "nearby"
automatically. The module can be found under
modules/by-category/06_Data_Type_Utilities/Date
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 4 Feb 1997 20:49:33 GMT
From: "Samir Grover" <sgrover@elizacorp.com>
Subject: Recursive Calls in Perl?
Message-Id: <01bc12dd$5c1873b0$6b00000a@e15>
Hello all,
Consider following simple perl script
#Start
...
$file_name = "foo";
&doCommand($file_name);
print "Completed\n";
...
...
sub doCommand {
open(COMFILE, <$_[0]>) # open for read
$another_file_name = <COMFILE>;
&doCommand(another_file_name);
...
print "YET MORE TO DO\n";
...
...
#END
I want to see output as:
YET MORE TO DO
Completed
However, I see following:
YET MORE TO DO
Whey does it not print "Completed" after "YET MORE TO DO"
What Modifications do I have to do?
Is recursive procedure call not allowed?
thanks
------------------------------
Date: 4 Feb 1997 22:22:27 GMT
From: pluxton@westpub.com (Patty Luxton)
Subject: Simple Win32::ODBC question
Message-Id: <5d8cr3$du22@koochiching.westpub.com>
I have created a perl script called check.pl to basically test my setup
of the Win32::ODBC module on my WinNT Server.
check.pl reads:
use Win32::ODBC;
$db=new Win32::ODBC("Paradox");
$db->Sql("SELECT * FROM Switches.db");
$db->FetchRow();
@values=$db->Data;
print @values;
$db->Close();
When I run perl specifying this script, I get the error message
"Can't call method "Sql" without a package or object reference at
check.pl line 5.
I'm not sure if I installed Win32::ODBC correctly. I put odbc.pm and
odbc.pll in \perl\lib\win32 and \perl\lib\auto\win32\odbc\odbc.pll
respectively, but what about all the other files that came in the zipped
file from ftp/roth/net? Do they need to be installed someplace?
I tried taking out the Sql portion of check.pl because I didn't trust my
SQL/Perl, but it choked on the "Close" statement with the same error message
which leads me to believe that it can't find the odbc.pm file,
since both "Sql" and "Close" are defined there.
Oh yes, if I run perl with a -w I get the following error messages also:
Name "Win32::ODBC::CacheConnection" used only once: possible typo at
\lib/Win32/ODBC.pm line 31
Name "ODBCPackage::Version" used only once: possible typo at
\lib/Win32/ODBC.pm line 29
And a few other similar lines.
So maybe it can find odbc.pm, but I'm still having problems getting it
working. Also, haven't had any problems using Paradox DSN with
IIS/IDC/ODBC (that pertain to this anyway) so I don't think that has
anything to do with it. I have a drive on my Win95 workstation mapped
to the NT server, does it matter where I run Perl from? I've been running
Perl from Win95, and test.pl seemed to work
Any suggestions would be GREATLY appreciated!
Direct emails are preferred.
Patty Luxton
pluxton@westpub.com
------------------------------
Date: 4 Feb 1997 21:08:12 GMT
From: jvenu@ctp.com (Jagadeesh Venugopal)
Subject: Re: Wanted: perl telnet examples
Message-Id: <5d88fs$9t1@concorde.ctp.com>
In article <Pine.ULT.3.94.970203162709.29296J-100000@grus07.nor.chevron.com> "Randall J. Wormser" <nrjw@nor.chevron.com> writes:
>Does anyone out there have an example which uses perl to run a telnet
>session? The Perl FAQ indicates that such an example resides at
>ftp.cis.ufl.edu:/pub/perl/scripts/getduatweather.pl, but I can't find it
>there or anywhere else. A direct reply would be most appreciated.
>
#!/usr/local/bin/perl
Hi,
I am including a script that telnets me out of a local firewall.
You can read this script and do something similar. This
uses chat2.pl which is nicely described in the book Perl 5 How-To.
Also try Comm.pl which is a Perl5 replacement to chat2.pl
Jagadeesh
require "chat2.pl";
use Term::ReadKey;
$DEBUG = 1;
# specify handlers for SIGINT, SIGQUIT, SIGTERM
$SIG{"INT"} = "GotSig";
$SIG{"QUIT"} = "GotSig";
$SIG{"TERM"} = "GotSig";
#set the buffering to character mode
$| = 1;
#now open a command and create a handle to it
$handle = &chat::open_proc("/bin/sh");
&chat::expect($handle,
10,
'\$\s',
'&chat::print($handle, "stty -echo\n");',
'EOF', '&Eof',
'TIMEOUT', '&TimeOut'
);
#ask to telnet to firewall
&chat::expect($handle, 10,
'\$\s', '&chat::print($handle, " exec telnet firewall\n");',
'EOF', '&Eof;',
'TIMEOUT', '&TimeOut'
);
#ask to telnet to xxx.xxx.xxx.xxx
&chat::expect($handle, 10,
'\>\s',
'&chat::print($handle,"telnet xxx.xxx.xxx.xxx\n");',
'EOF', '&Eof;',
'TIMEOUT', '&TimeOut'
);
#logged in to xxx.xxx.xxx.xxx now; send username
&chat::expect($handle, 30,
'ogin:\s',
'&chat::print($handle,"who-am-i\n");',
'EOF', '&Eof;',
'TIMEOUT', '&TimeOut'
);
#set the read mode to pass through all characters without
#interpretation at our end
ReadMode("ultra-raw", STDIN);
#make it interactive so we can enter our password here
&Interact($handle);
#close and quit
&chat::close($handle);
sub GotSig {
print "Got Signal Quitting\n";
&chat::close($handle);
exit;
}
sub Interact {
my($Ihandle) = @_;
my(@Ready, $Count, $InBuffer, $OutBuffer);
while(1) {
@Ready = &chat::select(undef, STDIN, $Ihandle);
if(grep($_ eq 'STDIN', @Ready)) {
$Count = sysread(STDIN, $InBuffer, 1024);
($Count >=1) || last;
($InBuffer =~ /\004/) && return;
&chat::print($Ihandle, $InBuffer);
}
if(grep($_ eq $Ihandle, @Ready)) {
($OutBuffer = &chat::expect($Ihandle, 0, '[\s\S]+', '$&')) || last;
print $OutBuffer;
}
}
}
sub END {
ReadMode("original", STDIN);
}
sub Eof {
print ("Unexpected EOF\n");
&chat::close($handle);
exit 1;
}
sub TimeOut {
print ("Unexpected TimeOut\n");
&chat::close($handle);
exit 2;
}
--
/\/\ |Jagadeesh K. Venugopal, jvenu@ctp.com |http://w3.ctp.com/~jvenu
/ /_.\|Cambridge Technology Partners, Inc. |http://www.ccs.neu.edu/home/jkvg
\ /./|304 Vassar St. Cambridge, MA 02139 |
\/\/ |Phone: 617.374.2028 FAX: 617.374.8300 +
------------------------------
Date: Tue, 4 Feb 1997 22:39:53 +0100
From: Jonas Oberg <kmm96jog@mds.mdh.se>
Subject: Warning: setlocale failed
Message-Id: <Pine.GSO.3.95.970204223908.2800A-100000@legolas.mdh.se>
When I execute a perl program I get these warnings:
warning: setlocale(LC_CTYPE, "") failed.
warning: LC_ALL = "(null)", LC_CTYPE = "iso8859-1", LANG = "(null)",
warning: falling back to the "C" locale.
What could be the trouble?
------[ Jonas - Just another intelligent shade of blue ]------
http://www.mds.mdh.se/~kmm96jog - PGP key available via finger
--------------------------------------------------------------
------------------------------
Date: Tue, 04 Feb 1997 12:26:48 -0700
From: autopen@quake.net (Laurel Shimer)
Subject: Re: Where to search for all newsgroup
Message-Id: <autopen-0402971226480001@l11.d22.quake.net>
In article <32F6C0B6.4C5E@address.net>, itr@address.net wrote:
> My question for the experienced newsgroup users are where can you go to
> find a whole host of newsgroup channels? Is there a newsgroup listing
> of all newsgroup sites? As you can tell, I'm new to the newsgroup
> world. So if someone knows, please help!
>
> Thank you
>
> Kevin
I use the NewsWatcher application. Then I choose 'Full Group List' from
the WINDOWS pulldown menu.
Laurel
--
The Reader's Corner: Mystery, Romance, Fantasy
Short stories, excerpts, themes and resources
http://www.autopen.com/index.shtml
Subscribe to our free StoryBytes publication
Current Mermaids Issue at http://www.autopen.com/mermaids.shtml
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 97)
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". 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.
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 V7 Issue 894
*************************************