[6958] in Perl-Users-Digest
Perl-Users Digest, Issue: 583 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 6 21:07:19 1997
Date: Fri, 6 Jun 97 18:00:23 -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, 6 Jun 1997 Volume: 8 Number: 583
Today's topics:
Re: Applets in Perl <jbokma@caiw.nl>
BUG??? - "$Foo = unpack 'u', $Var" and unitialized valu <zenin@best.com>
Re: BUG??? - "$Foo = unpack 'u', $Var" and unitialized (Jot Powers)
Re: Cant get Perl up and running <bzhou@sid.hp.com>
Case Conversion <dsonak@us.oracle.com>
Re: Case Conversion (Tung-chiang Yang)
Re: Case Conversion (A. Deckers)
Re: Case Conversion <bzhou@sid.hp.com>
Re: Checking if write to file is complete <nnyxcu@ny.ubs.com>
Comparing large files. <pkennis@inetnow.net>
Re: Comparing large files. <atlholl@inetnow.net>
Re: Comparing large files. (Jot Powers)
filehandle problem <maurog@csi.forth.gr>
Re: filehandle problem <zenin@best.com>
Re: Getting datestamp files? <rootbeer@teleport.com>
Re: help! CGI ignorant! (Craig Berry)
Re: inconsistent opendir behaviour in Perl for win32 <wm_n00@tarrcity.demon.co.uk>
Re: Interpolated regular expressions <rootbeer@teleport.com>
Re: Interpolated regular expressions (Chipmunk)
looking for a DC area course on PERL (Wayne Dernoncourt)
Looking for a Perl program to do CGI style newsgroup " mickeyc"@amgen.com
Re: perl version - how do you get it? (A. Deckers)
Re: Printing Prime Numbers (Michael Slone)
Re: read file while running <rootbeer@teleport.com>
Redefining STDOUT twice <ameesh@megatest.com>
Re: x operator <rootbeer@teleport.com>
Re: x operator (Chipmunk)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 6 Jun 1997 19:08:32 GMT
From: "John Bokma" <jbokma@caiw.nl>
Subject: Re: Applets in Perl
Message-Id: <01bc72ad$33820940$9e0ab2c2@tschai>
Arthur Merar <amerar@unsu.com> wrote in article
<33972523.2EA1@unsu.com>...
> Hello, I am writing my first PERL script for my homepage. The
script
> will accept some data from the user and pass that data to an applet
> which will run.
>
> Can I execute an applet from within a Perl script? If so, how do I
do
> this?
AFAIK, no. An applet is a program which needs some shell to work
(e.g. a browser).
The only way I can think of your Perl program can communicate with an
applet is by
making a socket connection with your applet (i.e. the Perl program
becomes a server, and
the applet a client).
Regards,
John
--
----------------------------------------------------------------------
Need a Freelance Software Developer (MSc)? (CGI, Perl, Java, C, C++)
http://www.caiw.nl/~jbokma [Java demo's, Curriculum Vitae and
more...]
email: jbokma@caiw.nl phone: +31 10 4291827
------------------------------
Date: 6 Jun 1997 22:42:11 GMT
From: Zenin <zenin@best.com>
Subject: BUG??? - "$Foo = unpack 'u', $Var" and unitialized value errors
Message-Id: <5na3o3$j6n$1@nntp2.ba.best.com>
My code is simply this:
1) #!/usr/local/bin/perl -w
2) use strict
3)
4) my $String = '';
5) my $UueString = '';
6) my $NewString = '';
7)
8) $String = "this is a test";
9) $UueString = pack 'u', $String;
10) $NewString = unpack 'u', $UueString;
11)
12) print "$String\n";
13) print "$NewString\n";
But I get the output:
Use of uninitialized value at ./foo line 10.
this is a test
this is a test
This makes no sence to me since none of my variables are uninitialized.
The only thing that causes this problem that I've found so far is the
call to unpack() with the 'u' template.
I'm running Perl 5.003 on a Sparc.
I'd try 5.004, but there have been too many bug reports about it in the
last few weeks to trust it quite yet.
Thanks!
$ perl -V
Summary of my perl5 (5.0 patchlevel 3 subversion 0) configuration:
Platform:
osname=solaris, osver=2.5.1, archname=sun4-solaris
uname='sunos omix8 5.5.1 generic_103640-08 sun4u sparc '
hint=recommended, useposix=true, d_sigaction=define
Compiler:
cc='gcc', optimize='-O2', gccversion=2.7.2.1
cppflags=''
ccflags =''
stdchar='unsigned char', d_stdstdio=define, usevfork=false
voidflags=15, castflags=0, d_casti32=define, d_castneg=define
intsize=4, alignbytes=8, usemymalloc=y, randbits=15
Linker and Libraries:
ld='gcc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /usr/ccs/lib
libs=-lsocket -lnsl -ldl -lm -lc -lcrypt
libc=/lib/libc.so, so=so
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags=' '
cccdlflags='-fpic', lddlflags='-G -L/usr/local/lib'
@INC: /usr/local/lib/perl5/sun4-solaris/5.003 /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl/sun4-solaris /usr/local/lib/perl5/site_perl /usr/local/lib/perl5/sun4-solaris .
--
-Zenin
zenin@best.com
------------------------------
Date: 6 Jun 1997 23:19:33 GMT
From: jot@tmp.medtronic.com (Jot Powers)
Subject: Re: BUG??? - "$Foo = unpack 'u', $Var" and unitialized value errors
Message-Id: <5na5u5$s3r$2@gazette.corp.medtronic.com>
node127% cat /tmp/xx
#!/usr/local/bin/perl -w
use strict
my $String = '';
my $UueString = '';
my $NewString = '';
$String = "this is a test";
$UueString = pack 'u', $String;
$NewString = unpack 'u', $UueString;
print "$String\n";
print "$NewString\n";
node127% /tmp/xx
this is a test
this is a test
node127% perl -v
This is perl, version 5.004
Copyright 1987-1997, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5.0 source kit.
If I were you I'd upgrade to 5.004 just because CERT tell you to.
-Jot
--
Jot Powers jot@tmp.medtronic.com
Unix System Administrator, Medtronic Micro-Rel
"Subtlety is the art of saying what you think and getting out of the way
before it is understood."
------------------------------
Date: Fri, 06 Jun 1997 16:16:46 -0700
From: Brian Zhou <bzhou@sid.hp.com>
Subject: Re: Cant get Perl up and running
Message-Id: <33989A5E.14CE5374@sid.hp.com>
ddean@aracnet.net wrote:
> HI
>
> I've just installed perl on a Unix box. For some reason it installed
> it
> in /opt/perl5 instead of /usr/local/bin/perl5. Anyway, the
> installation
> went fine but when I try to run a script is tells me that it cannot
> execute the file.
>
> Can anyone tell me what is the matter with this tiny script
>
> #!/opt/perl5
>
> print"hello";
> exit(0);
>
> I'm new to this stuff so be gentle
On my system, there's symbolic link pointing to the actual installation
place. You can always use #!/usr/bin/perl as the first line of your perl
script.
Try this:
$ type perl
/opt/perl5/bin/perl
$ perl -v
...5.003...
$ ls -l /opt/perl5/bin/perl # make sure it is executable by you
$ put #!/opt/perl5/bin/perl in your script
Hope this helps,
-Brian
------------------------------
Date: Fri, 06 Jun 1997 14:20:08 -0700
From: "Dipti V. Sonak" <dsonak@us.oracle.com>
Subject: Case Conversion
Message-Id: <33987F08.2587@us.oracle.com>
I have a mixed case string and I want to reverse the case of the
characters in the string.
For example :
Input String : pErL
Output String : PeRl
What is the best way to do this ?
Thanks,
Dipti
------------------------------
Date: Fri, 6 Jun 1997 22:19:08 GMT
From: tcyang@netcom.com (Tung-chiang Yang)
Subject: Re: Case Conversion
Message-Id: <tcyangEBDKnw.Iu9@netcom.com>
tr/A-Za-z/a-zA-Z/;
=============================
Dipti V. Sonak (dsonak@us.oracle.com) wrote:
: I have a mixed case string and I want to reverse the case of the
: characters in the string.
: For example :
: Input String : pErL
: Output String : PeRl
: What is the best way to do this ?
--
Tung-chiang Yang tcyang@netcom.com
soc.culture.taiwan, soc.culture.china (by SCC FAQ Team) FAQ's:
http://www.iglou.com/tcyang/Taiwan_faq.shtml, China_faq.shtml
------------------------------
Date: 6 Jun 1997 22:33:26 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: Case Conversion
Message-Id: <slrn5ph41l.4s1.I-hate-cyber-promo@news.rediris.es>
In <33987F08.2587@us.oracle.com>,
Dipti V. Sonak <dsonak@us.oracle.com> wrote:
>I have a mixed case string and I want to reverse the case of the
>characters in the string.
>
>For example :
>
>Input String : pErL
>Output String : PeRl
>
>What is the best way to do this ?
Provided you're not worried about 8 bit characters:
$string =~ tr/A-Za-z/a-zA-Z/;
If 8 bit characters matter to you, you'll have to wait for someone more
cluefull than me to answer. :-)
Alain
--
Perl information: <URL:http://www.perl.com/perl/>
Perl archive: <URL:http://www.perl.com/CPAN/>
Perl FAQ: <URL:http://www.perl.com/CPAN/doc/FAQs/FAQ/>
------------------------------
Date: Fri, 06 Jun 1997 16:42:45 -0700
From: Brian Zhou <bzhou@sid.hp.com>
Subject: Re: Case Conversion
Message-Id: <3398A075.925C2523@sid.hp.com>
Dipti V. Sonak wrote:
> I have a mixed case string and I want to reverse the case of the
> characters in the string.
>
> For example :
>
> Input String : pErL
> Output String : PeRl
>
> What is the best way to do this ?
>
> Thanks,
> Dipti
$inputString =~ y/a-zA-Z/A-Za-z/;
-Brian
------------------------------
Date: Fri, 06 Jun 1997 14:34:49 -0400
From: Glen Culbertson <nnyxcu@ny.ubs.com>
Subject: Re: Checking if write to file is complete
Message-Id: <33985849.E86@ny.ubs.com>
We run into this situation quite a bit, since we get sent a goodly number of
files at odd times. The best thing that we have found to do is to check the size
of the file, and then in a loop sleep a while, and check the size again. When the
size of the file stops increasing between checks, we then assume that it is done.
This is not elegant, but we haven't found anything better.
I would love to hear from anyone with something more slick.
Andrey Zmievski wrote:
>
> I need to write a script that when periodically launched by cron will
> check a certain directory for all the new files since the last time it
> checked and do a certain operation on those files. The files in the
> directory will be ftp'ed from outside. But! if a file is still being
> written to, I don't want to do that operation on it.
>
> So, how can I check if a file is currently being modified or written to?
>
> --
> Andrey Zmievski | tel: +1.402.441.3295 | To understand recursion,
> Code Wizard | fax: +1.402.483.5418 | first you must
> zmievski@ispi.net | URL: http://www.ispi.net | understand recursion.
------------------------------
Date: Fri, 06 Jun 1997 12:52:45 -0400
From: Peter Kennis <pkennis@inetnow.net>
Subject: Comparing large files.
Message-Id: <3398405D.609D@inetnow.net>
Here's the case:
Two files containing 30.000 or more lines, I would like to
find all lines from file1 that do not exist in file2.
I know there are a lot of ways to do this but I'd like to find
one that is not to CPU intensive....
Both files are sorted alike so record 1 from file 1 should also
be record 1 in file 2
File 1 example: aaaaaaa
bbbbbbb
ccccccc
ddddddd
File 2 example: aaaaaaa
ccccccc
Output should be : aaaaaaa
ddddddd
Any suggestions?
Thanks!
Peter Kennis
Atlanta GA
------------------------------
Date: Fri, 06 Jun 1997 14:02:28 -0400
From: Peter Kennis <atlholl@inetnow.net>
Subject: Re: Comparing large files.
Message-Id: <339850B4.401C@inetnow.net>
Peter Kennis wrote:
>
> Here's the case:
>
> Two files containing 30.000 or more lines, I would like to
> find all lines from file1 that do not exist in file2.
> I know there are a lot of ways to do this but I'd like to find
> one that is not to CPU intensive....
> Both files are sorted alike so record 1 from file 1 should also
> be record 1 in file 2
>
> File 1 example: aaaaaaa
> bbbbbbb
> ccccccc
> ddddddd
>
> File 2 example: aaaaaaa
> ccccccc
>
> Output should be : aaaaaaa
> ddddddd
>
> Any suggestions?
> Thanks!
>
> Peter Kennis
> Atlanta GA
ooops, that should read:
Output should be bbbbbbb
ddddddd
------------------------------
Date: 6 Jun 1997 23:16:22 GMT
From: jot@tmp.medtronic.com (Jot Powers)
Subject: Re: Comparing large files.
Message-Id: <5na5o6$s3r$1@gazette.corp.medtronic.com>
In article <3398405D.609D@inetnow.net>, Peter Kennis <pkennis@inetnow.net> writes:
>Here's the case:
>
>Two files containing 30.000 or more lines, I would like to
>find all lines from file1 that do not exist in file2.
>I know there are a lot of ways to do this but I'd like to find
>one that is not to CPU intensive....
>Both files are sorted alike so record 1 from file 1 should also
>be record 1 in file 2
>
>File 1 example: aaaaaaa
> bbbbbbb
> ccccccc
> ddddddd
>
>File 2 example: aaaaaaa
> ccccccc
>
>Output should be : bbbbbbb
> ddddddd
>
[Note: I've corrected the output as you stated it should be is a later post]
The real problem here is _how_ do you know their different?
For instance you say that record 1 is the same in both file (I assume we're talking
lines). Using that interpretation I would say that the difference between these
two files is
bbbbbbb
ccccccc
ddddddd
Because File 1[1] = a
File 2[1] = a same
File 1[2] = b
File 2[2] = c different
File 1[3] = c
File 2[3] = undef different
Etc....
Of course, if I were doing it, I would use diff. ;)
Here are two thoughts (of untested code) that will produce different results
and are _very_ sub-optimal (ie, and number of posters here will shudder at
the fact these look like O(n^2) ;)
Also, for big files these are going to use a lot of memory loading in the
arrays.
#!/usr/local/bin/perl -w
my ($file1,$file2) = ('file1.txt','file2.txt');
my (@file1,@file2);
open(FILE1,$file1) or die "$file1: $!\n";
open(FILE2,$file2) or die "$file2 : $!\n";
@file1 = <FILE1>;
@file2 = <FILE2>;
close(FILE1) or die "$!\n";
close(FILE2) or die "$!\n";
foreach $index ( 1 .. $#file1) {
if ($file1[$index] ne $file2[$index]) {
print "$file1[$index] != $file2[$index];
}
}
OR:
#!/usr/local/bin/perl -w
my ($file1,$file2) = ('file1.txt','file2.txt');
my (%file1,%file2,$element);
open(FILE1,$file1) or die "$file1: $!\n";
open(FILE2,$file2) or die "$file2 : $!\n";
while(<FILE1>) {
chomp;
%file1{$_} = 1;
}
while(<FILE2>) {
chomp;
%file2{$_} = 1;
}
close(FILE1) or die "$!\n";
close(FILE2) or die "$!\n";
foreach $element (keys %file1) {
if (!defined($file2{$element})) {
print "$element not the same\n";
}
}
Hope this doesn't hurt too much :)
-Jot
--
Jot Powers jot@tmp.medtronic.com
Unix System Administrator, Medtronic Micro-Rel
"Subtlety is the art of saying what you think and getting out of the way
before it is understood."
------------------------------
Date: Sat, 07 Jun 1997 00:28:03 +0300
From: Mauroidis Giannis <maurog@csi.forth.gr>
Subject: filehandle problem
Message-Id: <339880E3.41C67EA6@csi.forth.gr>
Hi,
Is there any way i can return a filehandle from a child process tou
its father so that the father can access it like <$filehandle> ??
I tried to pipe it to the father but didn't work..
Please answer because i really need it ASAP..
Answer by email at: maurog@csd.uch.gr
thanks in anadvance.
-john
------------------------------
Date: 7 Jun 1997 00:30:48 GMT
From: Zenin <zenin@best.com>
Subject: Re: filehandle problem
Message-Id: <5naa3o$mfo$1@nntp2.ba.best.com>
Mauroidis Giannis <maurog@csi.forth.gr> wrote:
> Is there any way i can return a filehandle from a child process tou
> its father so that the father can access it like <$filehandle> ??
> I tried to pipe it to the father but didn't work..
use FileHandle;
my $filehandle = new FileHandle;
my $Pid = open $filehandle, "-|";
if ($Pid) {
## Parent
my @StuffFromChild = <$filehandle>;
} elsif (defined $Pid) {
## Child
print "Stuff to parent via STDOUT";
} else {
die "fork() error: $!";
}
--
-Zenin
zenin@best.com
------------------------------
Date: Fri, 6 Jun 1997 14:26:50 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: HdV <J.A.deVries@lr.tudelft.nl>
Subject: Re: Getting datestamp files?
Message-Id: <Pine.GSO.3.96.970606142559.17967G-100000@kelly.teleport.com>
On Fri, 6 Jun 1997, HdV wrote:
> I'm trying to write a routine that returns the flastmod date in the
> Dutch format with the written day and month names. No problem as far
> as the formatting of the date is concerned, but how do I retrieve the
> actual date of the file?
Check out stat() and -X in perlfunc(1). Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 6 Jun 1997 22:42:29 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: help! CGI ignorant!
Message-Id: <5na3ol$gk1$1@marina.cinenet.net>
: Sam Fulton <hogsauce@wwa.com> wrote in article <33981C91.5F9A@wwa.com>...
[re CGI forms for acquiring user data]
: > b) is there a way to verify the supplied information to see if it's bogus
: or not? Like, > can it be made to check the supplied e-mail info to make
: sure it's an actual addy?
One good way to verify an email address used as part of a site access
control scheme (which the rest of the poster's message implied) is to use
a generated password to control access to the remainder of your site, and
send this password to the registering user via the supplied email address.
If the user later shows up using the supplied password, the email address
was real.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Fri, 6 Jun 1997 23:52:50 +0100
From: Wm <wm_n00@tarrcity.demon.co.uk>
Subject: Re: inconsistent opendir behaviour in Perl for win32
Message-Id: <nZlwWNACTJmzEwwq@tarrcity.demon.co.uk>
Fri, 6 Jun 1997 18:22:52 <5n9khs$8sg@pandora.cs.utwente.nl>
Simon Oosthoek <s.oosthoek@student.utwente.nl> posted...
<snips below>
>why doesn't it test 'c:/tmp/'?
>I bet that gives the same result as 'c:/'
Not here.
>it seems to be the '/' at the end that is causing the problem....
How about this:
----
Checking on 'c:'
-d says false!
Checking on 'c:/'
-d says true...
but opendir can't open it: No such file or directory
Checking on 'c:/tmp'
-d says true...
and opendir can open it...
and it has 46 items in it.
Checking on 'c:/tmp/'
-d says false!
----
Hence my thought that its the behaviour at root vs subdirs that is
inconsistent.
>>The case of the drive letter does not appear to be significant but the
>>working of opendir at root level and subdirectory level vs -d does
>>change. Whether or not this should be the case I am unable to say.
>
>I believe it shouldn't be the case. All tests are in some way a directory:
>d: = current directory on drive d:
>d:/ = root directory of drive d:
>d:/. = root directory of drive d:
>
>and
>
>d:/tmp = /tmp on d:
>d:/tmp/ = /tmp on d:
>d:/tmp/. = /tmp on d:
I agree. What I wasn't sure about was if opendir and -d were *meant* to
behave differently in some circumstances. Anyway, if Tom thinks its a
bug that'll do for me.
>I have reported the bug to activeware, so hopefuly it will be fixed in a future
>version....
On which point you've saved me the embarrassment of having to say that I
don't have perlbug and can't find any documentation that I can see from
Activeware saying how I should go about reporting one. Could you help
me out by saying what the procedure, format, etc is for future
reference or point me to where I might find this information. I will
also ask in the Win32 mailing list. TIA.
>Thanks for the results!
My pleasure.
--
Wm ... did you know? My spell checker wants tarrcity to be atrocity.
------------------------------
Date: Fri, 6 Jun 1997 14:14:12 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Matthew Burnham <danew@enterprise.net>
Subject: Re: Interpolated regular expressions
Message-Id: <Pine.GSO.3.96.970606141324.17967A-100000@kelly.teleport.com>
On Fri, 6 Jun 1997, Matthew Burnham wrote:
> The problem is that if the prefix is [FM] then:
>
> m/^Re: $prefix/i
>
> will interpret the [FM] as a character class - how can I stop perl from
> interpolating the $prefix variable to that extent?
Check out \Q and \E, along with quotemeta(). Hope this helps!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 6 Jun 1997 23:47:33 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Interpolated regular expressions
Message-Id: <5na7il$hsm$1@dartvax.dartmouth.edu>
In article <339d46fa.6817707@194.72.192.4>
danew@enterprise.net (Matthew Burnham) writes:
> The problem is that if the prefix is [FM] then:
>
> m/^Re: $prefix/i
>
> will interpret the [FM] as a character class - how can I stop perl from
> interpolating the $prefix variable to that extent?
m/^Re: \Q$prefix\E/i;
>From the perlre manpages:
\Q quote regexp metacharacters till \E
Chipmunk
------------------------------
Date: 6 Jun 1997 17:06:17 -0400
From: wayne@stuff.cpcug.com (Wayne Dernoncourt)
Subject: looking for a DC area course on PERL
Message-Id: <7OHmzQgpgi+c089yn@stuff.cpcug.com>
I'm looking to attend a class in PERL in the DC area. Learning
Tree has a course or two. How do the course there compare to
the ones by Randall and Tom C.? I mentioned the one that was
posted here a couple of weeks ago in Boston and my boss laughed
at the idea. Oh well. Actually, I should go somewhere else
where I don't have access to some of these games I have on this
system.
--
Take care | This clown speaks for himself, his job doesn't
Wayne D. | pay for this, etc. (directly anyway)
my real address is: w a y n e d @ cpcug.org (eliminate the spaces)
------------------------------
Date: Fri, 06 Jun 1997 09:30:38 -0800
From: " mickeyc"@amgen.com
Subject: Looking for a Perl program to do CGI style newsgroup
Message-Id: <339848BA.684A@amgen.com>
Dear experts:
I am interested in setting up a CGI style Newsgroup on my web server.
Does
anybody know where I can find a Perl CGI program to do that?
Thanks in advance!
*** Disclaimer: These are the opinions of the poster not Amgen Inc.***
------------------------------
Date: 7 Jun 1997 00:50:39 GMT
From: I-hate-cyber-promo@man.ac.uk (A. Deckers)
Subject: Re: perl version - how do you get it?
Message-Id: <slrn5phc2b.dhd.I-hate-cyber-promo@nessie.mcc.ac.uk>
In <3398A6B5.7AEB@mail.tammany.com>,
Andrew Simpson <guides@mail.tammany.com> wrote:
>Newsreaders,
>
>I am trying to create some datastructures in Perl, but am not sure whether the
>version I am using supports "hashes of hashes".
>
>Can anyone tell me what version allows these, and how to tell what version of
>Perl is installed on the system I am using.
>
>Thanks in advance.
$perl -h # :-)
Usage: perl [switches] [--] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into @F)
-c check syntax only (runs BEGIN and END blocks)
-d[:debugger] run scripts under debugger
-D[number/list] set debugging flags (argument is a bit mask or flags)
-e 'command' one line of script. Several -e's allowed. Omit [programfile].
-F/pattern/ split() pattern for autosplit (-a). The //'s are optional.
-i[extension] edit <> files in place (make backup if extension supplied)
-Idirectory specify @INC/#include directory (may be used more then once)
-l[octal] enable line ending processing, specifies line teminator
-[mM][-]module.. executes `use/no module...' before executing your script.
-n assume 'while (<>) { ... }' loop arround your script
-p assume loop like -n but print line also like sed
-P run script through C preprocessor before compilation
-s enable some switch parsing for switches after script name
-S look for the script using PATH environment variable
-T turn on tainting checks
-u dump core after parsing script
-U allow unsafe operations
-v print version number and patchlevel of perl
-V[:variable] print perl configuration information
-w TURN WARNINGS ON FOR COMPILATION OF YOUR SCRIPT.
-x[directory] strip off text before #!perl line and perhaps cd to directory
Alain
--
Perl information: <URL:http://www.perl.com/perl/>
Perl FAQ: <URL:http://www.perl.com/perl/faq/>
Perl archive: <URL:http://www.perl.com/CPAN/>
>>>>>>>> comp.lang.perl.misc is NOT a CGI group <<<<<<<<<<
------------------------------
Date: 06 Jun 1997 14:57:28 -0400
From: harvel@maxwell.ml.org (Michael Slone)
To: Darryl Caldwell <darrylc@eznet.com>
Subject: Re: Printing Prime Numbers
Message-Id: <lnoh9jef0k.fsf@valjean.sfhs.floyd.k12.ky.us>
[posted & emailed]
In article <5n9fjc$p43$1@pepper.eznet.com> Darryl Caldwell <darrylc@eznet.com>
writes:
>A friend told me about a software test he had to do at a job interview.
>He was told "print out all the prime numbers between 1 and 50." Coming
>from a liberal arts background, I had to first find out what a prime
>number _is_, then I set to working it out in Perl.
>
>The result is below. Essential it first prints out 1 since we know that
>it a prime number, then it discards even numbers. Next, it runs a series
>of tests on the remain odd numbers. If the variable $b holds a decimal
>number, it skips to the next TRY test, if it holds a whole number other
>than 1, it stops the TRY test and begins the whole series again with the
>next number from the initial range.
>
>It took me a night to think about it to get it to work. I'm curious if
>there are more efficient approaches. I am really interested in algorithms
>-- one of my weaker areas. I wouldn't have been able to come up with
>anything on the spot. I would appreciate any comments. Thanks.
>
>[code snipped]
For such a small range (1 - 50), perhaps the best algorithm is
the Sieve of Erastosthenes. Here is a sample script:
#! /usr/bin/perl -w
# Algorithm: Erastosthenes's sieve
#
# 1. Start with (1..50).
# 2. Throw out 1.
# 3. Throw out multiples of 2.
# 4. Proceed to the next non-thrown-out number and throw out multiples of it.
# 5. Repeat step 4 until 50 is reached.
# 6. Output prime numbers.
@prime = (0..50);
# $prime[0] is included so that the index will align with the value.
$prime[1] = 0; #Throw out 1.
for ($index = 2; $index < 50; $index++) {
if ($prime[$index] != 0) { # because it would then be non-prime
$jndex = 2;
while($index * $jndex < 49) {
$prime[$index * $jndex] = 0; # mark n*prime number as non-prime
$jndex++;
}
print $prime[$index] . " "; # Output a prime number
}
}
print "\n";
__END__
Hope this helps.
--
Michael Slone harvel@maxwell.ml.org http://harvel.home.ml.org/
Liten Project: http://harvel.home.ml.org/leten
------------------------------
Date: Fri, 6 Jun 1997 14:20:58 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Joe Kline <Joe.Kline@sdrc.com>
Subject: Re: read file while running
Message-Id: <Pine.GSO.3.96.970606141635.17967C-100000@kelly.teleport.com>
On Fri, 6 Jun 1997, Joe Kline wrote:
> while a script is running and writing to a file,
> is it possible to read the contents of that file
> without closing/opening that file repeatedly?
Yes it is possible. It's even possible to read the contents more than
once. :-)
It sounds like you're looking for what 'tail -f' does. If you're writing
the file from a Perl script, you may need to set $| to force flushing as
you go along. If you're reading from a Perl script, you may want to see
what perlfunc says about seek's ability to emulate tail.
> /================================\ insert favorite disclaimer\
> | Joe Kline | cute phrase\
> | E-Mail: Joe.Kline@sdrc.com | JAPH
> \================================/
You need a cute phrase there. How about "I used to be Anonymous."? :-)
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: Fri, 06 Jun 1997 12:00:47 -0700
From: Ameesh Oza <ameesh@megatest.com>
Subject: Redefining STDOUT twice
Message-Id: <33985E5F.71FD@megatest.com>
I would like to
open (STDOUT , "> $LOGFILE");
...do my thing where all standard out does to $LOGFILE...
close (STDOUT);
#want next print to go to screen but do not know how to
#redefine STDOUT after the close statement above
print "program completed sucessfully...";
thanks,
Ameesh
------------------------------
Date: Fri, 6 Jun 1997 14:15:52 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: the count <eglamkowski@mathematica-mpr.com>
Subject: Re: x operator
Message-Id: <Pine.GSO.3.96.970606141540.17967B-100000@kelly.teleport.com>
On Fri, 6 Jun 1997, the count wrote:
> I have an array I want to initialize, and was curious if the
> following syntax was valid:
>
> @current_disp_table = ( 32, (-1) x 19, 19..31, (-1) x 7 );
>
> which I want to be a 40 element array of integers.
Works for me!
-- Tom Phoenix http://www.teleport.com/~rootbeer/
rootbeer@teleport.com PGP Skribu al mi per Esperanto!
Randal Schwartz Case: http://www.lightlink.com/fors/
------------------------------
Date: 6 Jun 1997 23:52:16 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: x operator
Message-Id: <5na7rg$hsm$2@dartvax.dartmouth.edu>
In article <33984F03.32E3@mathematica-mpr.com>
the count <eglamkowski@mathematica-mpr.com> writes:
> I have an array I want to initialize, and was curious if the
> following syntax was valid:
>
> @current_disp_table = ( 32, (-1) x 19, 19..31, (-1) x 7 );
You didn't bother to try it, did you?
% perl -e '@current_disp_table = ( 32, (-1) x 19, 19..31, (-1) x 7 );\
print "@current_disp_table\n$#current_disp_table\n";'
32 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 19 20 21 22
23 24 25 26 27 28 29 30 31 -1 -1 -1 -1 -1 -1 -1
39
Looks like it works okay to me!
Chipmunk
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 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.
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 583
*************************************