[8461] in Perl-Users-Digest
Perl-Users Digest, Issue: 2078 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 11 20:07:35 1998
Date: Wed, 11 Mar 98 17:00:23 -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 Wed, 11 Mar 1998 Volume: 8 Number: 2078
Today's topics:
Attaching File to perl / sendmail script <Nick1pub@worldnet.att.net>
Re: Calculating DOW <mwilliam@duncan.cs.utk.edu>
Can't find "from" and "subject" <kenvogt@sni.net>
Re: Can't find "from" and "subject" <kenvogt@sni.net>
embedding Perl modules into the interpreter <josh@removethis.spies.com>
Re: How do I rename a file using perl (Mike Stok)
Medium regex question <chris@surewould.com>
Re: Multiple Variable Reference (Mike Stok)
Need Help from PERL GURU'S afaleti@dllr.state.md.us
Re: Need help with PERL script <mishra.aditya@emeryworld.com>
Need perl program written, would like to hire someones <bridea@ix.gen.com>
Re: Need perl program written, would like to hire someo <jdf@pobox.com>
Re: Perl & Cookies: How do I delete once a person leave (Michael J Gebis)
Re: Problem with "goto" in Perl <zenin@best.com>
Re: Problem with "goto" in Perl <zenin@best.com>
Re: Problem with "goto" in Perl (Ilya Zakharevich)
Q about FAQ answer - Random line from file (David Wall)
Re: Spitting out MIME types (Michael Fuhr)
Re: splice -- useful uses? (Abigail)
Re: splice -- useful uses? (Michael W Peterson)
splitting by one or more spaces <oosterom@e-mark.nl>
Re: splitting by one or more spaces (jay)
Re: splitting by one or more spaces <scotts@ptp.hp.com>
Way of testing whether a variable is blessed <achoy@us.oracle.com>
Re: What is PERL? Learn JAVA instead? (Michael J Gebis)
Re: Where can I find perlman for perl/tk ? <mishra.aditya@emeryworld.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Mar 1998 19:28:43 -0500
From: Nick Nottleman <Nick1pub@worldnet.att.net>
Subject: Attaching File to perl / sendmail script
Message-Id: <6e7a1j$m18@bgtnsc02.worldnet.att.net>
Is there a way to attach a file to an e-mail with perl?
------------------------------
Date: 11 Mar 1998 18:47:40 -0500
From: Myles Barrett Williams <mwilliam@duncan.cs.utk.edu>
Subject: Re: Calculating DOW
Message-Id: <lcafawkcwz.fsf@duncan.cs.utk.edu>
"Phil Heinz" <heinz@platinum.com> writes:
> I'm trying to determine a day of week for a particular date that is read in
> via any date format by my program. I'm assuming I'll have to convert their
> format into a gmtime type to do the localtime function? How can I accomplish
> this task?
To calculate the DOW, you take the stock prices of Bethlehem Steel,
3M, International Paper -- Huh? oh, never mind.
Myles Williams
------------------------------
Date: Wed, 11 Mar 1998 17:25:49 -0700
From: Kenneth Vogt <kenvogt@sni.net>
Subject: Can't find "from" and "subject"
Message-Id: <35072B8C.BDABD922@sni.net>
I have a perl script I am trying to use to send mail to a mailing list.
When I send mail, sendmail leaves 'subject' blank and it does not use
the 'from' address I specify. I cut the script down to the following
bare essentials as a test. This script correctly fills the 'from'
address and 'subject'. So something else in the script is messing me up.
Can anyone suggest what I might look for?
#!/usr/local/bin/perl
$mail_program = '/usr/lib/sendmail';
$to = 'kenvogt@sni.net';
$from = 'test\@modernshopping.com';
$subject = 'test subject';
$body = 'test body';
open (MAIL, "|$mail_program -t -n");
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$body\n\n";
close MAIL;
--
Kenneth Vogt
KenVogt@sni.net
http://ModernShopping.com
Buy Tupperware(r) products right on the WWW!
------------------------------
Date: Wed, 11 Mar 1998 17:41:31 -0700
From: Kenneth Vogt <kenvogt@sni.net>
Subject: Re: Can't find "from" and "subject"
Message-Id: <35072F3B.2B08A6D@sni.net>
It dawned on me you might think that I am just failing to set $from and
$subject correctly. What happens is the malfunctioning script produces a
message BODY that looks like the following:
To: kenvogt@sni.net
From: test@modernshopping.com
Subject: test subject
test body
--
Kenneth Vogt
KenVogt@sni.net
http://ModernShopping.com
Buy Tupperware(r) products right on the WWW!
------------------------------
Date: Wed, 11 Mar 1998 15:57:27 -0800
From: Josh Carter <josh@removethis.spies.com>
Subject: embedding Perl modules into the interpreter
Message-Id: <350724E7.46EBB2B8@removethis.spies.com>
Fellow Perl hackers,
Here's my situation: I have a fairly large Perl script which is used for
synchronizing a bunch of data on a Win32 client machine with a remote
server. While the script works just great, it requires that all client
machines have Perl installed on them, and the typical Windows user
doesn't have Perl or know anything about installing it. To ease customer
hassle, I'd like to wrap the script up into a single .exe (or .exe and a
.dll or two; whatever).
I already know how to embed the interpreter into a C program, but the C
program still needs a full Perl install on the machine. To quote the
perlembed doc: "you can't use Perl from your C program unless Perl has
been compiled on your machine, or installed properly." I've looked at
the "perl2exe" program at www.demobuilder.com, but it has a few
problems: first, it only works with the ActiveState Perl, and the .exe
it produces chokes with my script (gets a "parse error", whereas the
standard GNU Perl works fine). Second, it's commercial, and I'm already
catching heat for using Perl in the first place, so it would be tough to
convince my manager to buy perl2exe even if it did work.
Is there any decent way to make a "shrink-wrapped", distributable
Perl-based application on Win32 which doesn't require the full Perl
install? How about non-decent ways? :) I've read perlembed and the FAQs,
but they don't seem to address this issue (please let me know if I
missed something). If all else fails, I suppose I can hack ".\" into the
module include path and stick the required .pm's in the same directory
as the custom interpreter.
Thanks in advance for any help.
Best regards,
Josh
------------------------------
Date: 11 Mar 1998 23:51:57 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: How do I rename a file using perl
Message-Id: <6e782t$47r@news-central.tiac.net>
In article <35070A23.B3F63B75@yahoo.com>,
Dave Bushong <spamfree@yahoo.com> wrote:
>[biteme!dbushong 377] perldoc rename
>No documentation found for 'rename'
>
>Great tip. Except I didn't even get a dinosaur.
You're probably using an older perl, many people active in the perl
community get used to the latest & greatest features, the -f flag to
perldoc being relatively new. It allows you to get a chunk of a perl
manual page, e.g.
[mike@stok mike]$ perldoc -f rename
=item rename OLDNAME,NEWNAME
Changes the name of a file. Returns 1 for success, 0 otherwise. Will
not work across file system boundaries.
is a little easier to type than remembering the right man page (perlfunc)
and saying
[mike@stok mike]$ perldoc perlfunc
and searching for rename with the pager to get
rename OLDNAME,NEWNAME
Changes the name of a file. Returns 1 for
success, 0 otherwise. Will not work across file
system boundaries.
The File::Copy module might be more generally useful, its documentation
says:
NAME
File::Copy - Copy files or filehandles
SYNOPSIS
use File::Copy;
copy("file1","file2");
copy("Copy.pm",\*STDOUT);'
move("/dev1/fileA","/dev2/fileB");
[...]
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@colltech.com | Collective Technologies (work)
------------------------------
Date: Wed, 11 Mar 1998 19:45:26 -0500
From: Chris <chris@surewould.com>
Subject: Medium regex question
Message-Id: <35073026.2D3EAA7B@surewould.com>
I'm having a problem finding how to match a semi-complicated bunch of
strings. I want to match strings like these (yep, it's html):
<pre> (this isn't part of the string - it's just to foil HTML-enabled
newsreaders, I think.)
<td></td>
<td><font size=2>+</font></td>
<td><font size=1>-</font></td>
</pre>
In other words, I want an empty <td></td> element, or a <td></td>
element that has either a + or - in it, which is modified by a font tag.
Also, I'd like to be able to catch the + or - in a back reference.
My best stab is
<td>(<font.*>([+|-])</font>)?</td>
However, if I try to match
<td><font size=2>-</font></td>
with it, it matches, but $1 is equal to "<font size=2>-</font>", not
just "-" as desired. I've tried a bunch of combos of parens and ? but
nothing else even matches.
Any ideas?
Thanks,
Chris
------------------------------
Date: 11 Mar 1998 23:57:22 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Multiple Variable Reference
Message-Id: <6e78d2$47r@news-central.tiac.net>
In article <6e71hq$4q5$1@nnrp1.dejanews.com>, <slafran@ibm.net> wrote:
>This is my problem:
>
>$TEMP00=1;
>$TEMP01=2;
>$TEMP02=3;
>$TEMP10=4;
>$TEMP11=5;
>$TEMP12=6;
>$TEMP20=7;
>$TEMP21=8;
>$TEMP22=9;
If you're using a recent perl then it has soft (or symbolic) references
which can be used to access variables (except those declared using my)
like this:
foreach $i (0 .. 2) {
foreach $j (0 .. 2) {
print qq(TEMP$i$j = ${"TEMP$i$j"}\n);
}
}
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@colltech.com | Collective Technologies (work)
------------------------------
Date: Wed, 11 Mar 1998 17:27:08 -0600
From: afaleti@dllr.state.md.us
Subject: Need Help from PERL GURU'S
Message-Id: <6e76hn$8ps$1@nnrp1.dejanews.com>
I am just learning perl and would need the help of the Big guys.
I do have a Perl code to convert a simple text file into a
Netscape LDIF format file.
I did modify the code but do not get the desired result with the
variable assignment.
Please help
afaleti@dllr.state.md.us
CODE: ascii2ldif.pl
#!/usr/local/bin/perl
#Here it checks if there are 2 command line arguments.
if (scalar(@ARGV) < 2)
#Next print the usage if the command line arguments are < 2
{
print
"Usage: ascii2ldif.pl {asciifile} {Organization} \r\n";
print
"Example: ascii2ldif.pl list2 \"Md. Dllr\" \r\n";
print
"\r\nThis will create a ldif file with the same name of the
asciifile\r\n";
print
"The organization, will be the organization name.\r\n";
print
"\r\nAll left-over information will be found in the .left file.\r\n";
print
"\r\nFormat of entries: Lastname Firstname emailaddress.\r\n";
print
exit 1;
}
#This is the variable for the 1st command line arg. (filename of asciifile)
$list2 = shift (@ARGV);
#This is the variable for creating the .ldif file
$ldiflist = ">".$list2.".ldif";
#This is the variable for creating the .left file
$leftover = ">".$list2.".left";
#This is the variable for the 2nd command line arg. (Organization name)
$organization = shift (@ARGV);
sub print_header {
#This prints the top of the tree of format:
#dn: o=Md. Dllr,c=US
#o: Md. Dllr
#objectClass: top
#objectclass: organization
print OUT "dn: o=".$organization.", c=US\n";
print OUT "o: ".$organization."\n";
print OUT "objectClass: top\n";
print OUT "objectclass: organization\n\n";
}
sub print_entry {
local($s, $g, $e) = @_;
# This creates an entry of format:
#
#dn: cn=Faleti Ade, o=Md. Dllr, c=US
#cn: Faleti Ade
#sn: Faleti
#givenName: Ade
#email: afaleti@dllr.state.md.us
#objectclass: top
#objectclass: person
#objectclass: organizationalPerson
#objectclass: inetOrgPerson
#
if ( $s ne "" ) {
$cn = $s." ".$g;
} else {
$cn = $g." ".$s;
}
#
print OUT "dn: cn=$cn, o=".$organization.", c=US\n";
print OUT "cn: $cn\n";
print OUT "sn: $s\n";
print OUT "givenName: $g\n";
print OUT "emailaddress: $e\n";
print OUT "objectClass: top\n";
print OUT "objectClass: person\n";
print OUT "objectClass: organizationalPerson\n";
print OUT "objectClass: inetOrgPerson\n\n";
}
local($surname, $given, $email);
$surname = $given = $email = "";
open(ENTRY, $list2);
open(OUT, $ldiflist);
open(LEFTOVER, $leftover);
&print_header;
while (<ENTRY>) {
if ( $_ =~ /^\s*$/ ) {
next; #ignore blank lines
}
s/=09//g;
s/=ED/'/g;
s/\306/'/g;
#
# Check this out
#
&print_entry($surname, $given, $email);
$surname = $given = $email = "";
next;
}
#
# Check this out
#101
if ( $surname eq "" ) { # Get names seperated by spaces
/([A-Z][\w\-.']*)\s+([A-Z][\w\-.']*)\s+( * )\n/
&& ($surname = $1, $given=$2, $email=$3);
}
if ( $surname eq "" ) { # Get names seperated by tabs
/([A-Z][\w\-.']*)\t+([A-Z][\w\-.']*)\t+( * )\n/
&& ($surname = $1, $given=$2, $email=$3);
}
if ( $surname eq "" ) {
print LEFTOVER $_;
}
if ( $surname ne "" ) { # maybe lastone leftover
&print_entry($surname, $given, $email);
}
#112
close(ENTRY);
close(OUT);
close(LEFTOVER);
exit; # successful exit
_____________________________________________________________________
INPUT FILE: list2
Baczynski Sue sbaczynski@state.md.us
Baier Paul pbaier@state.md.us
Bailey Anita abailey@state.md.us
Baker Agnes abaker@state.md.us
Baker Beth bbaker@state.md.us
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 11 Mar 1998 15:54:25 -0800
From: "Mishra, Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: Need help with PERL script
Message-Id: <6e762h$g1m@news.cnf.com>
use mailtools bundle on CPAN
------------------------------
Date: Thu, 12 Mar 1998 09:39:08 +1000
From: "Rohan Wyllie" <bridea@ix.gen.com>
Subject: Need perl program written, would like to hire someones services.
Message-Id: <889659535.185998@subsonic.fan.net.au>
Hello all,
I hope this post is appropriate, please accept my apologies if it is not.
My name is Rohan Wyllie, I require the services of a talented Perl
programmer,
I am willing to pay whatever the industry standard is for having this work
performed.
Please e-mail me at bridea@ozemail.com.au(no spam filter, please remove)
if you would like to look over the requirements of the script etc..
Sincerely,
Rohan Wyllie.
------------------------------
Date: 11 Mar 1998 19:44:47 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Need perl program written, would like to hire someones services.
Message-Id: <ra48vitc.fsf@news.concentric.net>
"Rohan Wyllie" <bridea@ix.gen.com> writes:
> I hope this post is appropriate, please accept my apologies if it is
> not. My name is Rohan Wyllie, I require the services of a talented
> Perl programmer, I am willing to pay whatever the industry standard is
> for having this work performed.
> Rohan Wyllie.
Oh sure, you'll get a good contract from this guy, but watch out for
the contract riders. The riders of Rohan are known for their guile.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: 12 Mar 1998 00:16:43 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: Perl & Cookies: How do I delete once a person leaves my site?
Message-Id: <6e79hb$piq@mozo.cc.purdue.edu>
Keywords: from just another new york perl hacker
comdog@computerdog.com (brian d foy) writes:
}In article <3506A98B.14CA@disconova.com>, webmaster@disconova.com posted:
}>Chocolate wrote:
Mmm, chocolate cookies.
}>
}>> Is it possible to delete a cookie once a person leaves my domain? If so
}>> how?
}>
}>It would propably be a good idea for you to read about cookies from
}>somewhere.
}>a) Nope, it is not possible in the traditional way(*
}yes it is. the Netscape cookie FAQ even tells you how. see the
}CGI Meta FAQ for details.
This sounds like a good reason for asking web-related questions in
web-related newsgroups, instead of in the perl newsgroup.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: 11 Mar 1998 23:36:03 GMT
From: Zenin <zenin@best.com>
Subject: Re: Problem with "goto" in Perl
Message-Id: <889659741.71194@thrush.omix.com>
Steve Linberg <linberg@literacy.upenn.edu> wrote:
: It could be done with nested conditionals, but after about 4 layers deep
: the code becomes unreadable. Which is cleaner?
>snip<
: goto exit1 if (!cond1)
: blah
: blah
: goto exit1 if (!cond2)
: blahblah
: goto exit1 if (!cond3)
: blahblahblah # etc.
:
: exit1:
:
: clean up
: return
And this is different then:
return exit1 if (!cond1);
blah
blah
return exit1 if (!cond1);
blah
return exit1 if (!cond1);
blah
sub exit1 {
clean ('up');
return;
}
How, exactly? Except that you avoid name collisions, and have the
option of passing arguments to exit1() so it might have a better
idea of what exactly to clean up and/or how to clean it up. Error
checking is also greatly improved (see below).
: Where there is a multi-step, linear process where each step depends on the
: successful completion of the last, and especially where there is work to
: do at the end (like closing files or databases), I find it much easier to
: read, write and maintain code using goto.
I highly disagree with this use of goto as effort to write better
code. It's not. It also allows for bugs that can only be detected
at runtime because strict can't (or at least doesn't) check for valid
labels. If you misspell one of those goto labels, you're out of
luck until you hit that condition at which time you're program comes
to a vary ungraceful end with only the message,
"Can't find label exi1 at foo line 3"
However, using strict and a statement of "return exi1 if (!cond1)"
would have thrown a "bare word" error for the "exi1" typo at compile
time.
--
-Zenin
zenin@best.com
------------------------------
Date: 11 Mar 1998 23:44:08 GMT
From: Zenin <zenin@best.com>
Subject: Re: Problem with "goto" in Perl
Message-Id: <889660225.816059@thrush.omix.com>
Uri Guttman <uri@sysarch.com> wrote:
: because goto was invented by uncle bill, lord of the evil empire :-)
>snip<
Goto is pretty much an ASM JMP (in use, not implementation). Bill
didn't invent it. Intel "invented" it, if anyone did. Bill has
never invented anything that I can remember, DOS included (it was
bought from another company).
Bill is a business man, not an inventer.
--
-Zenin
zenin@best.com
------------------------------
Date: 11 Mar 1998 23:48:29 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Problem with "goto" in Perl
Message-Id: <6e77sd$gc6$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to
<schwern@starmedia.net>],
who wrote in article <6e3p9k$mif$1@nnrp1.dejanews.com>:
> there are other possiblities. He could have wrapped the program in a labeled
> block and done a next LABEL or redo LABEL (wait... can you do that in a
> non-loop block?), but would that really have been any different from the
> goto? No.
Wrong. Interested parties may look in the implementation of pp_goto
for an insight.
Ilya
------------------------------
Date: Wed, 11 Mar 1998 23:32:19 GMT
From: dkw0@cdc.gov (David Wall)
Subject: Q about FAQ answer - Random line from file
Message-Id: <6e777n$2nc2@cdc4.cdc.gov>
I was reading the FAQ, not looking for anything in particular, just ideas
to add to my "toolbox", and ran across a code fragment to grab a random
line from a file:
srand;
rand($.) < 1 && ($line = $_) while <FILE>;
Pretty neat, I thought, so I tried it with a text file, and unsurprisingly,
it works. :-) But, even though I understand all the pieces (I hope), I
don't understand how the whole statement works. Surely there's another way
to rewrite this in smaller chunks so that it's obvious to a neophyte what
it's doing?
(The FAQ says it's from the Camel, but I've not been able to find it in
there, despite flipping through every section that looked relevant.)
Despite not needing this for anything useful, I've still been puzzling over
it off and on for several days, trying to rewrite it, but without success.
Any hints?
(My ramblings about what I think might be happening deleted on rereading)
David Wall
# Perl is designed to give you several ways to do anything, so
# consider picking the most readable one.
# -- Larry Wall in the perl man page
------------------------------
Date: 11 Mar 1998 17:22:03 -0700
From: mfuhr@dimensional.com (Michael Fuhr)
Subject: Re: Spitting out MIME types
Message-Id: <6e79rb$adl@flatland.dimensional.com>
Jeff Stewart <object01@cc.gatech.edu> writes:
> Since I can't find a newsgroup dedicated to CGI programming (and if you
> feel like declaring where this post belongs, feel free)...
comp.infosystems.www.authoring.cgi
> I'm writing a script in Perl that allows users to both upload and
> download from a server. It's a modified version of another script that
> spits out x-unknown as the mime type for any file the user tries to
> download. How would I modify the code to have Perl let the -server-
> handle the MIME declaration?
One way might be to have your script send a redirect to the user's
browser so the HTTP daemon could serve the file itself. This assumes,
of course, that the file is under a directory that the HTTP server is
configured to serve. If that's not what you're looking for, post more
details to the CGI newsgroup mentioned above.
--
Michael Fuhr
http://www.dimensional.com/~mfuhr/
------------------------------
Date: 12 Mar 1998 00:07:03 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: splice -- useful uses?
Message-Id: <6e78v7$ngb$1@client3.news.psi.net>
Andrew M. Langmead (aml@world.std.com) wrote on 1653 September 1993 in
<URL: news:EpoF38.IBH@world.std.com>:
++ klassa@aursgh.aur.alcatel.com (John Klassa) writes:
++
++ >Either way, what do people use splice for?
++
++ The first edition of programming perl showed something like this in
++ the "common taks with perl" section. It randomizes an array.
++
++ push @random, splice @orig, rand @orig, 1 while @orig;
I hate to see a quadratic algorithm being used a an example
for what people use splice for if there's a linear algorithm
doing the same.
Knuth's algorithm:
for ($i = @arr; $i; $r = rand $i --, @arr [$r, $i] = @arr [$i, $r]) {}
Abigail
--
perl -weprint\<\<EOT\; -eJust -eanother -ePerl -eHacker -eEOT
------------------------------
Date: 12 Mar 1998 00:42:04 GMT
From: michael@flash.net (Michael W Peterson)
Subject: Re: splice -- useful uses?
Message-Id: <6e7b0s$qol$1@excalibur.flash.net>
On 12 Mar 1998 00:07:03 GMT, <abigail@fnx.com> wrote:
>Andrew M. Langmead (aml@world.std.com) wrote on 1653 September 1993 in
><URL: news:EpoF38.IBH@world.std.com>:
>++ klassa@aursgh.aur.alcatel.com (John Klassa) writes:
>++
>++ >Either way, what do people use splice for?
>++
>++ The first edition of programming perl showed something like this in
>++ the "common taks with perl" section. It randomizes an array.
>++
>++ push @random, splice @orig, rand @orig, 1 while @orig;
>
>I hate to see a quadratic algorithm being used a an example
>for what people use splice for if there's a linear algorithm
>doing the same.
>
>Knuth's algorithm:
>for ($i = @arr; $i; $r = rand $i --, @arr [$r, $i] = @arr [$i, $r]) {}
Interestingly, the quadratic algorithm is faster (at least on my box):
Benchmark: timing 100000 iterations of c, perl...
c: 50 secs (50.74 usr 0.01 sys = 50.75 cpu)
perl: 37 secs (36.13 usr 1.88 sys = 38.01 cpu)
#!/usr/local/bin/perl
use Benchmark;
timethese(100000, {
perl => '
@a = (0,1,2,3,4,5,6,7,8,9);
push @b, splice @a, rand @a, 1 while @a;
',
c => '
@a = (0,1,2,3,4,5,6,7,8,9);
for ($i = @a; $i; $r = rand $i--, @a[$r,$i] = @a[$i,$r]) {};
'
});
__END__
--
Michael W Peterson <http://www.flash.net/~michael/>
Chief System Administrator FlashNet Communications
Unix: more than enough rope...
------------------------------
Date: 11 Mar 1998 22:49:42 GMT
From: "Oosterom" <oosterom@e-mark.nl>
Subject: splitting by one or more spaces
Message-Id: <01bd4d3f$bf439e40$0781f1c3@thijs>
Hi,
I am trying to extract the date from the localtime value. I have to split
this value, but if the daynumber is smaller than 10, there are two spaces
before this number in the localtime value. This means I have to split by
one or more spaces. The codes below don't work:
($day, $month, $daynr, $time, $year) = split (/*\s/, localtime);
Any suggestions anyone? Thanks.
Thijs.
------------------------------
Date: Thu, 12 Mar 1998 00:40:19 GMT
From: mocat@spamtrap.best.com (jay)
Subject: Re: splitting by one or more spaces
Message-Id: <35072ebf.83635898@nntp.best.com>
On 11 Mar 1998 22:49:42 GMT, "Oosterom" <oosterom@e-mark.nl> wrote:
>Hi,
>
>I am trying to extract the date from the localtime value. I have to split
>this value, but if the daynumber is smaller than 10, there are two spaces
>before this number in the localtime value. This means I have to split by
>one or more spaces. The codes below don't work:
>
>($day, $month, $daynr, $time, $year) = split (/*\s/, localtime);
($day, $month, $daynr, $time, $year) = split(/\s+/, localtime);
that worked for me.
-j
:mocat@best.com/www.best.com/~mocat:
------------------------------
Date: Wed, 11 Mar 1998 16:49:31 -0800
From: Scott Starks <scotts@ptp.hp.com>
Subject: Re: splitting by one or more spaces
Message-Id: <3507311B.6F422067@ptp.hp.com>
Oosterom wrote:
> Hi,
>
> I am trying to extract the date from the localtime value. I have to split
> this value, but if the daynumber is smaller than 10, there are two spaces
> before this number in the localtime value. This means I have to split by
> one or more spaces. The codes below don't work:
>
> ($day, $month, $daynr, $time, $year) = split (/*\s/, localtime);
>
> Any suggestions anyone? Thanks.
>
> Thijs.
Try
($day, $month, $daynr, $time, $year) = split (/\s+/, localtime);
Scott Starks
------------------------------
Date: Wed, 11 Mar 1998 15:51:06 -0800
From: Allen Choy <achoy@us.oracle.com>
Subject: Way of testing whether a variable is blessed
Message-Id: <3507236A.4F4A5632@us.oracle.com>
Is there a standard way of testing whether a variable is blessed or not?
The only way I can think of is testing whether a reference has an '='
sign.
--Allen
------------------------------
Date: 11 Mar 1998 23:58:45 GMT
From: gebis@albrecht.ecn.purdue.edu (Michael J Gebis)
Subject: Re: What is PERL? Learn JAVA instead?
Message-Id: <6e78fl$mvv@mozo.cc.purdue.edu>
Markku Uttula <webmaster@disconova.com> writes:
}Robert F. Harrison wrote:
}>> Perl 4.036, way back in the early 70's[1]. Unfortunately, "Ja
}>> Va" means "Yes Go" in Swedish/Spanish (per word) so the name
}I'm propably out of line with this comment, but as swedish being my 2nd
}native language, I'd like to inform everybody that :
}1) "Ja" really means "Yes" in swedish, but
}2) "Va" means nothing... if it instead was "Vad" then it'd be "What"
Per word. As in: "Ja Va" => "Yes (using swedish) Go (using spanish)"
I'm surprised none of the other English/Swedish/Spanish trilingual
readers of this group said anything.
--
Mike Gebis gebis@ecn.purdue.edu mgebis@eternal.net
------------------------------
Date: Wed, 11 Mar 1998 17:08:00 -0800
From: "Mishra, Aditya" <mishra.aditya@emeryworld.com>
Subject: Re: Where can I find perlman for perl/tk ?
Message-Id: <6e7ace$fgm@news.cnf.com>
http://www.perl.com/CPAN-local/authors/by-authors/johan_vromans
Also read FAQ
Adi
------------------------------
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 2078
**************************************