[18679] in Perl-Users-Digest
Perl-Users Digest, Issue: 847 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 7 14:06:05 2001
Date: Mon, 7 May 2001 11:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <989258708-v10-i847@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 7 May 2001 Volume: 10 Number: 847
Today's topics:
Access 97 *.mdb & Perl <jtjohnston@courrier.usherb.ca>
Bcc contents from file <paanwa@hotmail.com>
Re: Bcc contents from file <paanwa@hotmail.com>
Can this newsgroup read perl/html files <newuser@nospam.slip.net>
Re: Can this newsgroup read perl/html files (Clinton A. Pierce)
Re: Can this newsgroup read perl/html files (Craig Berry)
Capturing matches from several regexpes <dzinsli+news@snapp.no>
Re: Capturing matches from several regexpes (Randal L. Schwartz)
Re: Capturing matches from several regexpes <godzilla@stomp.stomp.tokyo>
Re: Capturing matches from several regexpes (Rudolf Polzer)
Re: Capturing matches from several regexpes (Craig Berry)
Re: DBI and fetch (Abigail)
Executing CGI on a Mac, help? <krk@speakeasy.org>
Re: getting line by line from $ (Craig Berry)
global variables <nobody@nobody.com>
Re: Help on optimization wanted <ren@tivoli.com>
Re: Help on optimization wanted <juex@deja.com>
Re: Help on optimization wanted <juex@deja.com>
Re: Help on optimization wanted (Rudolf Polzer)
Local Time ryan@dcntet.net
Re: Local Time <peter.sogaard@tjgroup.com>
Re: Local Time <bart.lateur@skynet.be>
Re: Local Time ryan@dcntet.net
Re: Local Time <flavell@mail.cern.ch>
Re: Local Time (Craig Berry)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 07 May 2001 13:54:09 -0400
From: jtjohnston <jtjohnston@courrier.usherb.ca>
Subject: Access 97 *.mdb & Perl
Message-Id: <3AF6E141.151308FE@courrier.usherb.ca>
>First, install the Windows ports of DBI and DBD::ODBC. You can get them
>from <http://www.activestate.com/PPMpackages/5.6/> and its
>"MSWin32-x86-multi-thread" subdirectory (for 5.6.0).
Can I use win32::obdc without http://www.activestate.com/PPMpackages/5.6/ ?
I don't want to use a SQL server. I have the necessary *.pm & *.dll
successfully installed, which I got from here:
http://www.geocities.com/Area51/Cavern/4503/perl_odbc.htm .
I know I've seen it somewhere where I can
open (MADBFILE, "./thisfile.mdb");
I don't want to install servers or other stuff. And I'll show you why. I'm
using perl on this type of a server:
http://www.indigostar.com/microweb.htm
(As crazy as it sounds, it works very well. It's a educational project I'm
working on.)
All I need is a few lines of code to get started. Open the *.mdb, open the
table, display the data.
Table1
-------------------------------
| Name | John |
-------------------------------
| Address | 123, Boeing Way |
-------------------------------
Thanks,
john
------------------------------
Date: Mon, 7 May 2001 12:51:18 -0400
From: "PaAnWa" <paanwa@hotmail.com>
Subject: Bcc contents from file
Message-Id: <tfdkkabd2bhu2b@corp.supernews.com>
I am trying to get a script to open a text file (containing email addresses)
and write the data in the Bcc component of sendmail. I am using PERL5 as
you can see below - I am getting an error for some reason....the path name
for the text file is correct - I checked it by printing the contents to an
HTML success screen (which worked fine). Gurus, what am I doing wrong?
PAW
##########################################################
#!/usr/local/bin/perl5
use CGI qw(:standard);
open(FILE, "</path/update.txt") || die $!;
while (<FILE>)
{$BCC=$_;}
close(FILE) || die $!;
###########################################################
open(MAIL, "| sendmail -t") || die "Can't open mailprog $mailprog,
stopped";
print MAIL "From: updates\@wiggle.com\n";
print MAIL "To: webforms\@wobble.com\n";
print MAIL "Bcc: ",$BCC,"\n";
print MAIL "WEBSITE UPDATE\n\n";}
print MAIL param('Update'),"\n";
print MAIL ".\n"; # send a "." and return to mail
close(MAIL) || die "mail pipe exited $?";
------------------------------
Date: Mon, 7 May 2001 13:14:33 -0400
From: "PaAnWa" <paanwa@hotmail.com>
Subject: Re: Bcc contents from file
Message-Id: <tfdlvr1smn3k9c@corp.supernews.com>
DOH!
I corrected this line of code and it still does not work...
> print MAIL "WEBSITE UPDATE\n\n";}
print MAIL "WEBSITE UPDATE\n\n";
------------------------------
Date: Sun, 6 May 2001 11:05:17 -0700
From: "newuser" <newuser@nospam.slip.net>
Subject: Can this newsgroup read perl/html files
Message-Id: <2kgJ6.130$oS1.127@news2.dnvrcoidc.firstworld.net>
Hello,
I am currently having a problem with a perl script and in order for me
to explain the problem I need to post a html file. I was just wondering what
is the best way to post the perl script and the html file.
Thanks
------------------------------
Date: Mon, 07 May 2001 16:26:41 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Can this newsgroup read perl/html files
Message-Id: <51AJ6.1435$V5.167652@news1.rdc1.mi.home.com>
In article <2kgJ6.130$oS1.127@news2.dnvrcoidc.firstworld.net>,
"newuser" <newuser@nospam.slip.net> writes:
> I am currently having a problem with a perl script and in order for me
> to explain the problem I need to post a html file. I was just wondering what
> is the best way to post the perl script and the html file.
Usenet is not the place for attachments. Use the wondrous miracle
of cut-and-paste and paste the relevant pieces into a posting as though
you'd typed it.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Mon, 07 May 2001 17:41:30 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Can this newsgroup read perl/html files
Message-Id: <tfdnia7vg05b18@corp.supernews.com>
Clinton A. Pierce (clintp@geeksalad.org) wrote:
: In article <2kgJ6.130$oS1.127@news2.dnvrcoidc.firstworld.net>,
: "newuser" <newuser@nospam.slip.net> writes:
: > I am currently having a problem with a perl script and in order for me
: > to explain the problem I need to post a html file. I was just wondering what
: > is the best way to post the perl script and the html file.
:
: Usenet is not the place for attachments. Use the wondrous miracle
: of cut-and-paste and paste the relevant pieces into a posting as though
: you'd typed it.
Note that if the script or the html are larger than a few dozen lines, you
would be well advised to create a smaller test case which illustrates the
problem. Most people will skip past giant code listings in which your
actual problem is buried.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Mon, 07 May 2001 15:05:26 GMT
From: Daniel Zinsli <dzinsli+news@snapp.no>
Subject: Capturing matches from several regexpes
Message-Id: <m2r8y12o3u.fsf@imp.snapp.no>
I've falled into a trap that i think might be newbe'ish :)
$_ = 'foozbaz';
m/(fooz)/; # matches, $1 is now fooz
m/(xyzzy)/; # don't match, $1 is still fooz
If i now test the value of $1, i might falsely belive that it captured
something in the second regexp, while it still contains the match from
the first one.
Any advice on avoiding these situations?
Now, i've been using:
if (1) { # Entering a new scope
m/(fooz)/;
#$1 is 'fooz' here
}
$1 is undef here
if (1) { # Same thing
m/(xyzzy)/;
}
But this seems plain hackish :)
What is a correct way to do this?
Thanks in advance,
--
Daniel Zinsli
Oslo, Norway
------------------------------
Date: 07 May 2001 08:16:01 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Capturing matches from several regexpes
Message-Id: <m1g0ehfavi.fsf@halfdome.holdit.com>
>>>>> "Daniel" == Daniel Zinsli <dzinsli+news@snapp.no> writes:
Daniel> $_ = 'foozbaz';
Daniel> m/(fooz)/; # matches, $1 is now fooz
Daniel> m/(xyzzy)/; # don't match, $1 is still fooz
Daniel> If i now test the value of $1, i might falsely belive that it captured
Daniel> something in the second regexp, while it still contains the match from
Daniel> the first one.
Daniel> Any advice on avoiding these situations?
Yes. Never use $1 unless you are in the context of the conditional
noticing whether the match succeeded.
if (/(fooz)/) {
use $1 safely here...
} elsif (/(barz)/) {
use $1 safely here...
}
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 07 May 2001 09:10:03 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Capturing matches from several regexpes
Message-Id: <3AF6C8DB.76A4758@stomp.stomp.tokyo>
"Randal L. Schwartz" wrote:
> Daniel wrote:
> > $_ = 'foozbaz';
> > m/(fooz)/; # matches, $1 is now fooz
> > m/(xyzzy)/; # don't match, $1 is still fooz
> > If i now test the value of $1, i might falsely belive that it captured
> > something in the second regexp, while it still contains the match from
> > the first one.
> > Any advice on avoiding these situations?
> Yes. Never use $1 unless you are in the context of the conditional
> noticing whether the match succeeded.
> if (/(fooz)/) {
> use $1 safely here...
> } elsif (/(barz)/) {
> use $1 safely here...
> }
Hey Randal! Causing trouble around here again?
You should follow my lead of being an exemplary
poster to this newsgroup.
Heh! Heh!
Your advice is both sound and well qualified, this is
beyond debate as is always the case with your advice.
This advice you provide, should be followed, carefully.
My advice? Well, yes, ahem, how about those Brooklyn Dodgers?
Delightfully, Perl allows a lot of leeway for imagination.
There are always some exceptions, perhaps limited in numbers
or perhaps not.
$InlaHolisso = "Godzilla Rocks!";
sub RandCase
{ rand(40) < 20 ? "\u$1" : "\l$1" ; }
$InlaHolisso =~ s/([a-z])/RandCase($1)/gie;
print $InlaHolisso;
Cute huh?
Godzilla! Queen of Schizo Programmers.
------------------------------
Date: Mon, 7 May 2001 21:35:49 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: Capturing matches from several regexpes
Message-Id: <slrn9fdu8k.n6v.eins@www42.t-offline.de>
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
* use strict;
> $InlaHolisso = "Godzilla Rocks!";
> sub RandCase
> { rand(40) < 20 ? "\u$1" : "\l$1" ; }
> $InlaHolisso =~ s/([a-z])/RandCase($1)/gie;
> print $InlaHolisso;
#!/usr/bin/perl -w
use strict;
$_ = '"Godzilla!" s*xx!';
s/./(rand() < .5) ? uc $& : lc $&/ge;
print;
> Cute huh?
Why?
> Godzilla! Queen of Schizo Programmers.
Perhaps.
--
www42:~ # mv /mnt/c/windows/win.com /dev/null
mv: /dev/null: data refused
------------------------------
Date: Mon, 07 May 2001 18:04:30 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Capturing matches from several regexpes
Message-Id: <tfdotejdpgor79@corp.supernews.com>
Daniel Zinsli (dzinsli+news@snapp.no) wrote:
: I've falled into a trap that i think might be newbe'ish :)
:
: $_ = 'foozbaz';
: m/(fooz)/; # matches, $1 is now fooz
: m/(xyzzy)/; # don't match, $1 is still fooz
:
: If i now test the value of $1, i might falsely belive that it captured
: something in the second regexp, while it still contains the match from
: the first one.
:
: Any advice on avoiding these situations?
Yes; never use the match variables further away than right after the match
that (may have) set them. If you need them to last longer than that,
stash them in your own variables.
: Now, i've been using:
:
: if (1) { # Entering a new scope
No need to fake a condition. Just using { to open a bare block works
fine.
But again, I'd advise explicit stashing over scope tricks any day of the
week.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Mon, 7 May 2001 14:59:52 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: DBI and fetch
Message-Id: <slrn9fde38.n8p.abigail@tsathoggua.rlyeh.net>
Bob Walton (bwalton@rochester.rr.com) wrote on MMDCCCVI September
MCMXCIII in <URL:news:3AF60FDC.CB899A82@rochester.rr.com>:
:}
:} Well, my understanding of SQL says this isn't directly possible (maybe
:} some databases have extensions for this?). If, though, the row number
:} were stored as a column of the table, then you could add a 'where'
:} clause to your SQL to pick out row 13, which would then be the only row
:} returned. That would be the proper "SQL-ish" way -- let SQL do the
:} selection work, rather than doing it yourself. Note also that (unless
:} an 'order by' clause is present), SQL may not always return rows in the
:} same order, so the meaning of "row 13" may be nebulous.
The reason SQL don't have this feature is that SQL is a *Set* Query
Language, using Set Algebra. Sets are not ordered. An "Nth record"
doesn't fit the paradigm.
Some servers do have an extension for this.
Abigail
--
perl -wle\$_=\<\<EOT\;y/\\n/\ /\;print\; -eJust -eanother -ePerl -eHacker -eEOT
------------------------------
Date: Mon, 07 May 2001 11:10:06 -0400
From: Kenneth Knight <krk@speakeasy.org>
Subject: Executing CGI on a Mac, help?
Message-Id: <krk-7D1222.11100607052001@news.speakeasy.net>
I'm trying to get a relatively simple CGI applicaiton up and running on
a system that uses a Macintosh to host its web sites. The CGI is written
using MacPerl (v 5.2.0r4 - latest version I know of and that's pretty
old). It runs fine if I serve it using something like Apple's Personal
Web Sharing, but on this other machine I continually get "Error. Unable
to launch ACGI application" messages. Can anyone suggest what might be
going on. Here is the script code (admittedly not very pretty; I'm a
Perl neophyte).
# Get the input
$buffer = $ENV{'QUERY_STRING'};
# Get working directory.
$base = `pwd`;
$base =~ s/CGI-Bin//;
$base =~ tr/:/\//;
# Split the name-value pairs
@ids = split(/&/, $buffer);
foreach $id (@ids) {
# Un-Webify plus signs and %-encoding
$id =~ tr/+/ /;
$id =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$id =~ s/<!--(.|\n)*-->//g;
}
# Retrieve the contens of the table of contents.
open (FILE,"biographies.data") || die "Can't Open file: $!\n";
@LINES=<FILE>;
close(FILE);
$SIZE = @LINES;
# make one big string.
$data = "";
for ($i=0;$i<=$SIZE;$i++) {
$data = $data . $LINES[$i];
}
# Print the header of the table of contents file
print "Content-type: text/html\n\n";
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0
Transitional//EN\"\t\t\t\"http:\/\/www.w3.org\/TR\/REC-html40\/loose.dtd\
">\n";
print "<html><head>\n\t<title>BackpackingLight.Com Biogaphy</title>\n";
print "\t<meta http-equiv=\"Content-Type\" content=\"text/html;
charset=iso-8859-1\">\n";
print "\t<link rel=\"stylesheet\" href=\"stylesheets/article.css\"
type=\"text/css\">\n";
print "\t<meta name=\"generator\" content=\"BBEdit 5.1.1\">\n";
print "\t<script language=\"javascript\" type=\"text/javascript\"
src=\"functions.js\"></script>\n";
#print "\t<base href=\"$base\">\n</head>\n"
print "<body bgcolor=\"#FFFFFF\">\n";
$i = 1; # index variable
$numIDs = @ids; # number of IDs
if ($numIDs == 1) {
print "<table width=\"100%\" cellpadding=\"5\" border=\"1\">";
} else {
print "<table width=\"100%\" cellpadding=\"5\" border=\"1\"><col
width=\"50%\"><col width=\"50%\">\n";
}
# if there is more than 2 ids and the last one is an odd numbered one it
gets its own line. Flag it.
if ( ( $numIDs >= 3) && ( ($numIDs % 2) == 1) ) {
$lastIDAlone = 1;
} else {
$lastIDAlone = 0;
}
# start processing each id
foreach $id (@ids) {
# Does the person exist?
if ( $data =~ /(.*?)id:[ \t]*?$id(.*?)\n(.*?)\n/ ) {
$theData = $&;
($bioHeader, $bioData) = split(/\n/, $theData);
# There is probably a better way to do this. But, this seems to work.
Get the name and image info.
# If no image is present then "" is put in $image.
($temp, $name, $image) = split(/;/, $bioHeader);
($temp, $name) = split(/:/, $name);
($temp, $image) = split(/:/, $image);
$name =~ s/^\s*(.*?)\s*$/$1/; # trim whitespace
$image =~ s/^\s*(.*?)\s*$/$1/; # trim whitespace
$bioData =~ s/^\s*(.*?)\s*$/$1/; # trim whitespace
# if this is the last ID and $lastIDAlone is set then don't print this
ID yet.
if ( ( ( $i == $numIDs ) && ( $lastIDAlone == 1) ) == false) {
# print out HTML code for each bio here.
if ( ($i % 2) == 1) {
print "\t<tr>\n";
}
print "\t\t<td valign=\"top\">\n\t\t\t<p
class=\"title\">$name</p>\n";
if ( $image ne "" ) { print "\t\t\t<p><script
language=\"javascript\"
type=\"text/javascript\">document.write(LoadBioImage(\"$image\",\"$name\"
))</script></p>\n"; }
print "\t\t\t$bioData\n";
print "\t\t</td>\n";
if ( ($i % 2) == 0) {
print "\t</tr>";
}
}
$i = $i + 1;
}
} # foreach
if ( ( ($i - 1) % 2) == 1) {
print "\t</tr>";
}
print "\n</table>";
# do we have one ID left to print?
if ($lastIDAlone == 1) { # yes
print "<table border=\"`\" cellpadding=\"5\" width=\"50%\"
align=\"center\">\n\t<tr>\n\t\t<td valign=\"top\">\n";
print "\t\t\t<p class=\"title\">$name</p>\n";
if ( $image ne "" ) { print "\t\t\t<p><script language=\"javascript\"
type=\"text/javascript\">document.write(LoadBioImage(\"$image\",\"$name\"
))</script></p>\n"; }
print "\t\t\t$bioData\n";
print "\t\t</td>\n";
print "\t</tr>\n</table>";
}
print "</body></html>";
--
** Kenneth Knight Web Design, IT Consultant, Software Engineer **
** krk@speakeasy.org http://www.speakeasy.org/~krk **
------------------------------
Date: Mon, 07 May 2001 17:51:59 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: getting line by line from $
Message-Id: <tfdo5v6a3kin8f@corp.supernews.com>
Robert Wedge (RWEDGE@webtv.net) wrote:
[snip]
: How can I get a numbered line by line print out of $source or convert it
: to an array to do the same?
Just split the scalar returned by LWP::Simple::get() on /\n/. Note that
the newlines will be missing from the resulting array of lines, but this
is often desirable anyway.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: Mon, 07 May 2001 12:46:49 -0500
From: MJ <nobody@nobody.com>
Subject: global variables
Message-Id: <3AF6DF89.5D508185@nobody.com>
How do I set a variable within a package so that subsequent
calls to routines in that same package will see that value?
I'd also like to have access to that initially-set variable
from the calling program.
Thanks in advance,
MJ
------------------------------
Date: 07 May 2001 11:43:46 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Help on optimization wanted
Message-Id: <m3wv7thzy5.fsf@dhcp9-172.support.tivoli.com>
On Sun, 06 May 2001, bjoern@hoehrmann.de wrote:
> See `perldoc perlop`/"Multiplicative Operators" for the 'x'
> (repetition operator). Parens create lists in Perl
Actually, they don't.
> my @list = (1);
>
> creates a list with '1' as the first element,
Assignment to the array creates the list here. Those parens are
optional.
>
> my @list = (1) x 10;
>
> creates a list with '1' as the first, second ... 10th element.
Now the parens are necessary, but they do not create a list. Instead,
they trigger special behavior of the "x" operator. To wit:
Binary "x" is the repetition operator. In scalar context
or if the left operand is not enclosed in parentheses, it
returns a string consisting of the left operand repeated
the number of times specified by the right operand. In
list context, if the left operand is enclosed in parenthe
ses, it repeats the list.
Notably, that last phrase is probably a poor choice. Perhaps
something like:
Binary "x" is the repetition operator. In scalar context,
or if the left operand is not enclosed in parentheses, it
returns a string consisting of the left operand (evaluated
in scalar context) repeated the number of times specified
by the right operand (also in scalar context). In list
context, if the left operand is enclosed in parentheses,
then it is evaluated in list context and the result is re-
peated.
Some examples that seem to help to illustrate the significance of the
parens are:
my @list = @{[2,3]} x 5;
my @list = (@{[2,3]}) x 5;
my @list = @{[2,3]}[0,1] x 5;
my @list = (@{[2,3]}[0,1]) x 5;
my $scalar = (@{[2,3]}[0,1]) x 5;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Mon, 7 May 2001 10:31:08 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Help on optimization wanted
Message-Id: <3af6dbdc$1@news.microsoft.com>
"Michael Ströck" <michael@stroeck.com> wrote in message
news:3af482be$1@e-post.inode.at...
> Hi to all !
>
> One of our CS teachers at school told me to write a
> script that finds all primes from 1 - n.
>
> Writing that script was easy, but as I'm very new to
> Perl, I'd really appreciate any comments on how to
> make the following script run faster.
Instead of tweaking your script a little bit here and a little bit there you
may want to look into a more efficient algorithm altogether.
The Sieve of Eratosthenes is known to be pretty good.
I'm sure this topic has been studied in Theory of Algorithms quite a bit,
but surprisingly I can't find any algorithms in my standard books. Anyway, a
NG about algorithm design is probably the better place to ask (rather then
CLPM).
jue
------------------------------
Date: Mon, 7 May 2001 10:33:23 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Help on optimization wanted
Message-Id: <3af6dc63$1@news.microsoft.com>
"Michael Ströck" <michael@stroeck.com> wrote in message
news:3af5777e@e-post.inode.at...
> So I have no idea what sieves are :-) But if you could point me to some
> information ?
Check out the "Duden Rechnen und Mathematik", page 710, topic "Sieb des
Eratosthenes".
Your school library should have a copy.
jue
------------------------------
Date: Mon, 7 May 2001 21:59:27 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: Help on optimization wanted
Message-Id: <slrn9fdvku.u94.eins@www42.t-offline.de>
Michael Ströck <michael@stroeck.com> wrote:
> use strict;
Good.
> use warnings;
>
> my @primes;
> my $current_number=1;
> my $numbers_to_test=100000;
>
> push (@primes, 2);
>
> LOOP:
> while ($current_number <= $numbers_to_test) {
> $current_number+=2;
> foreach (@primes) {
> next LOOP if ($current_number % $_ == 0);
You can do a last when $_ * $_ > $current_number: then it must be a prime!
> }
> push (@primes, $current_number);
> }
>
> open (OUTPUT, ">primes.txt")
> or die "ERROR: Can't create output-file: $!";
> foreach (@primes) {
> print OUTPUT "$_\n";
> }
> close OUTPUT
> or die "ERROR: Can't close output-file; $!";
--
#!/usr/bin/perl -W -- WARNING: This copies a random file from
use strict;my$s;my$n=0;for # the current directory to your
(<*>){++$n;int rand$n or$s # signature file. Use at your
=$_};`cp $s ~/.signature`; # own risk! (c) 2001 Rudolf Polzer
------------------------------
Date: Mon, 07 May 2001 14:10:44 GMT
From: ryan@dcntet.net
Subject: Local Time
Message-Id: <E1yJ6.43555$FS3.481009@sjc-read.news.verio.net>
Hello,
I have just a quick question, I have been through the documentation
and I can't find what I am looking for. I want to assign the local time to
a variable in the following format. Wed May 2 09:56:48 2001. If anyone
could point me in the right direction as far as documentation or what
module to use, I would greatly appreciate it.
Thanks in advance.
Ryan
------------------------------
Date: Mon, 7 May 2001 16:19:04 +0200
From: "Peter Søgaard" <peter.sogaard@tjgroup.com>
Subject: Re: Local Time
Message-Id: <9d6atj$e79$1@tnews.inet.tele.dk>
$now_string = localtime;
<ryan@dcntet.net> wrote in message
news:E1yJ6.43555$FS3.481009@sjc-read.news.verio.net...
> Hello,
> I have just a quick question, I have been through the documentation
> and I can't find what I am looking for. I want to assign the local time
to
> a variable in the following format. Wed May 2 09:56:48 2001. If anyone
> could point me in the right direction as far as documentation or what
> module to use, I would greatly appreciate it.
>
> Thanks in advance.
> Ryan
------------------------------
Date: Mon, 07 May 2001 14:20:08 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Local Time
Message-Id: <8pbdftc8s5abbm16b4o3g7rdsbe4im5apd@4ax.com>
ryan@dcntet.net wrote:
> I have just a quick question, I have been through the documentation
>and I can't find what I am looking for. I want to assign the local time to
>a variable in the following format. Wed May 2 09:56:48 2001. If anyone
>could point me in the right direction as far as documentation or what
>module to use, I would greatly appreciate it.
print scalar localtime;
-->
Mon May 7 16:20:16 2001
That looks close enough to me.
perldoc -f localtime
and you may want to check out gmtime() as well.
--
Bart.
------------------------------
Date: Mon, 07 May 2001 15:42:18 GMT
From: ryan@dcntet.net
Subject: Re: Local Time
Message-Id: <unzJ6.43624$FS3.481272@sjc-read.news.verio.net>
>> I want to assign the local
>>time to a variable in the following format. Wed May 2 09:56:48 2001.
>>If anyone could point me in the right direction as far as documentation
>>or what module to use, I would greatly appreciate it.
>
> print scalar localtime;
>-->
> Mon May 7 16:20:16 2001
>
>That looks close enough to me.
>
> perldoc -f localtime
>
>and you may want to check out gmtime() as well.
>
That did the trick. Thanks all!
Ryan
------------------------------
Date: Mon, 7 May 2001 18:19:05 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Local Time
Message-Id: <Pine.LNX.4.30.0105071759230.30987-100000@lxplus003.cern.ch>
On Mon, 7 May 2001 ryan@dcntet.net wrote:
[comprehensive quote snipped]
> That did the trick. Thanks all!
Congratulations, you just succeeded in unleashing the entire power of
the world-wide Perl community on reading the documentation to you.
However, for some reason they didn't seem to answer your real problem,
which appears to be how to use the comprehensive documentation that
came as standard with your Perl installation.
You claimed to have consulted the documentation, but you didn't
mention how, so it's hard to know where you went wrong.
The documentation can be displayed using the perldoc command (or
alternative accesses may be available to you: ActiveState Perl for
example has a handy Web-ified access to the same documentation).
"perldoc perlfunc" displays, amongst other things, a handy list of
functions by categories. There's a category for "Time-related
functions". It isn't hard to find it.
"perldoc -f localtime" almost immediately displays an example of usage
which you would recognize as being the one you want.
"perldoc perldoc" of course tells more about how to use perldoc.
And don't miss those FAQs.
------------------------------
Date: Mon, 07 May 2001 18:00:51 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Local Time
Message-Id: <tfdomjq4hkuke2@corp.supernews.com>
ryan@dcntet.net wrote:
: I have just a quick question, I have been through the documentation
: and I can't find what I am looking for. I want to assign the local time to
: a variable in the following format. Wed May 2 09:56:48 2001. If anyone
: could point me in the right direction as far as documentation or what
: module to use, I would greatly appreciate it.
perldoc POSIX
look for strftime.
--
| Craig Berry - http://www.cinenet.net/~cberry/
--*-- "God becomes as we are that we may be as he is."
| - William Blake
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 847
**************************************