[17683] in Perl-Users-Digest
Perl-Users Digest, Issue: 5103 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 13 18:05:47 2000
Date: Wed, 13 Dec 2000 15:05:16 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <976748716-v9-i5103@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 13 Dec 2000 Volume: 9 Number: 5103
Today's topics:
-KPIC, xdepend, x03 <mark.drummond@canada.sun.com>
<STDIN> vs. byte-by-byte editing <ayoungtechie@my-deja.com>
Re: <STDIN> vs. byte-by-byte editing <mothra@nowhereatall.com>
Debugging <eric.kort@vai.org>
Re: default method (Greg Bacon)
Re: Does comp.lang.perl exist? <edwardj@ameritech.perl.net>
Re: Eliminating unneeded whitespace... <bart.lateur@skynet.be>
Re: Eliminating unneeded whitespace... <bart.lateur@skynet.be>
Re: Eliminating unneeded whitespace... <ren.maddox@tivoli.com>
Re: Eliminating unneeded whitespace... <mischief@velma.motion.net>
Excluding a string from a RE <ASkwar@DigitalProjects.com>
Re: Faster than LWP (BUCK NAKED1)
Re: Faster than LWP <elijah@workspot.net>
Re: Faster than LWP (BUCK NAKED1)
FileSearch <lars_lars@home.se>
getting OS info gurusri@my-deja.com
Hopefully not to difficult a question. Please Help msalerno@my-deja.com
Re: Hopefully not to difficult a question. Please Help <jdhunter@nitace.bsd.uchicago.edu>
Re: Hopefully not to difficult a question. Please Help <bart.lateur@skynet.be>
Re: Ideas... <bart.lateur@skynet.be>
initialize array of identical elements <jdhunter@nitace.bsd.uchicago.edu>
Re: initialize array of identical elements <jeff@vpservices.com>
Re: initialize array of identical elements <jeff@vpservices.com>
Re: initialize array of identical elements (Gary E. Ansok)
Re: initialize array of identical elements <jeff@vpservices.com>
Re: initialize array of identical elements <aqumsieh@hyperchip.com>
Re: initialize array of identical elements <ren.maddox@tivoli.com>
Re: initialize array of identical elements <jeff@vpservices.com>
Re: Interpolating <aqumsieh@hyperchip.com>
Re: Interpolating <g.soper@soundhouse.co.uk>
Re: mime decoding (Adam)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 Dec 2000 14:51:54 -0500
From: Super-User <mark.drummond@canada.sun.com>
Subject: -KPIC, xdepend, x03
Message-Id: <3A37D35A.EF2DB68E@canada.sun.com>
Trying to build perldap, dbi and dbd-oracle under perl 5.005_03
(installed with the OS), gcc 2.95.2 (installed from sunfreeware.com
package), and solaris 8 10/00. `perl Makefile.PL` works fine (no
errors), but the resulting Makefile has three compiler/linker options in
it that gcc does not like:
CCCDLFLAGS = -KPIC
OPTIMIZE = -xO3 -xdepend
The compiler chokes on all of these. Also, all references to the
compiler are as `cc` ... is there anyway for me to have it automagically
use `gcc` ... I can just create a link but still. I tried putting
`CC=gcc` in front of the `perl Makefile.PL` but no joy.
Handraulically removing those options from the resulting Makefile allows
me to build the software properly, but that's a pain and there has to be
some way to correct it.
Thanks,
Mark
------------------------------
Date: Wed, 13 Dec 2000 19:05:21 GMT
From: A Young Techie <ayoungtechie@my-deja.com>
Subject: <STDIN> vs. byte-by-byte editing
Message-Id: <918h99$2c7$1@nnrp1.deja.com>
I'm having a little bit of trouble with a script I'm developing - the
user needs to input a password (this is just a PERL script, not CGI), I
can't find any other method of retrieving characters from the keyboard
than STDIN, but I need to blank each character as the user types it..
Any thoughts on how to do that?
--
nothing is ever too good to be true
- michael faraday
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 13 Dec 2000 11:31:39 -0800
From: mothra <mothra@nowhereatall.com>
Subject: Re: <STDIN> vs. byte-by-byte editing
Message-Id: <3A37CE9B.C9DD45EA@nowhereatall.com>
A Young Techie wrote:
> I'm having a little bit of trouble with a script I'm developing - the
> user needs to input a password (this is just a PERL script, not CGI), I
> can't find any other method of retrieving characters from the keyboard
> than STDIN, but I need to blank each character as the user types it..
> Any thoughts on how to do that?
>
> --
> nothing is ever too good to be true
> - michael faraday
>
> Sent via Deja.com
> http://www.deja.com/
type perldoc -q password
------------------------------
Date: Wed, 13 Dec 2000 15:20:37 -0500
From: "Eric" <eric.kort@vai.org>
Subject: Debugging
Message-Id: <918lde$2783$1@msunews.cl.msu.edu>
I'm having some terrible memory problems, so two basic questions:
1) How exactly to I go about recompiling the perl interpretter so I can use
the -d switch (which I can't under our current configuration).
2) How can I get the debugger (or anything else) to report the memory
allocated to any and all current variables?
Thanks,
Eric
------------------------------
Date: Wed, 13 Dec 2000 22:48:19 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: default method
Message-Id: <t3fv5jkp8ln10e@corp.supernews.com>
In article <3a37a73f.211b$2c9@news.op.net>,
Mark-Jason Dominus <mjd@plover.com> wrote:
: I can think of another way, but last time I mentioned it (at Boston.pm
: this summer) everyone made fun of me and then they took away my beer.
That sounds like juicily grievous heresy!
Greg
--
I have not finished with a woman until I have had her all three ways.
-- JFK
------------------------------
Date: Wed, 13 Dec 2000 16:32:04 -0600
From: Ed Jamison <edwardj@ameritech.perl.net>
Subject: Re: Does comp.lang.perl exist?
Message-Id: <3A37F8E4.3BCF2AF0@ameritech.perl.net>
Last I checked, what Randal says, is. Or so it works in theory. Kind of
like the info on Perl Programming, 3rd Edition. "We're not sure if this is
going to make it into the final printing..." Kind of funny coming from the
fellas that wrote it...
Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to Randal L. Schwartz
> <merlyn@stonehenge.com>],
> who wrote in article <m18zpywz83.fsf@halfdome.holdit.com>:
> > Jan> No - it does exist - check with your news-provider.
> >
> > No, it authoritatively DOES NOT EXIST.
>
> Do not think that your choice of verbs is authoritative enough.
> Existence of newsgroups is a very delicate subject: you view it from
> one side, and it exists, you view it from another one, and it does not.
>
> So "it should not exist" may be a better wording. Or "it has no right
> to exist". BTW, what percentage of US population "has no right to
> exist" in US? ;-)
>
> Ilya
--
Ed Jamison
yapn
No, there's not really an ameritech.perl.net, tho that'd be cool.
Remove the .perl from my e-mail address to reply.
------------------------------
Date: Wed, 13 Dec 2000 20:46:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Eliminating unneeded whitespace...
Message-Id: <32of3t8bvrgoq9c1civnia0836vut31oaq@4ax.com>
Nicholas C. Cheung wrote:
>I am trying to write some small program segment which converts the
>following:
>
>a) " This is very good." to "This is very good."
s/\s+/ /g;
s/^ //;
s/ $//;
--
Bart.
------------------------------
Date: Wed, 13 Dec 2000 20:48:01 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Eliminating unneeded whitespace...
Message-Id: <b4of3tkkbke29af4eu75lg9thboa5afjra@4ax.com>
mike_solomon@lineone.net wrote:
>#convert more than one space to one space
>$a =~ s/\s\s*/ /g;
/\s\s*/ is the same as /\s+/.
--
Bart.
------------------------------
Date: 13 Dec 2000 14:59:40 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Eliminating unneeded whitespace...
Message-Id: <m3k894f35v.fsf@dhcp11-177.support.tivoli.com>
"Nicholas C. Cheung" <ncheung@draper.com> writes:
> I am trying to write some small program segment which converts the
> following:
>
> a) " This is very good." to "This is very good."
> b) "This is very good" to "This is very good"
> c) "This is very good " to "This is very good"
> d) " This is very good " to "This is very good"
> e) " This is very good " to "This is very good"
>
> (OK, you get the idea by now.)
>
> How should I write this program segment such that it complies with all
> five situations outlined above?
#!/usr/local/bin/perl -lw
use strict;
while (<DATA>) {
print join ' ', split ' ';
}
__DATA__
This is very good.
This is very good
This is very good
This is very good
This is very good
__END__
My *very* limited benchmarking even has the join/split combo as faster
than the natural s/// solution. Note that this does remove the
newlines (thus the -l option).
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 13 Dec 2000 22:11:37 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Eliminating unneeded whitespace...
Message-Id: <t3ft0pfgs1in96@corp.supernews.com>
Mark Ferguson <mefergus@stanford.edu> wrote:
> Nicholas C. Cheung <ncheung@draper.com> writes:
>>I am trying to write some small program segment which converts the
>>following:
> [examples of squishing whitespace snipped]
> Well, it is a FAQ, but there is another approach
> (likely slower, but it's kind of cool, too).
Well, the results depend upon the implementation of the
substitutions from what I can tell.
Here's my perl version info:
This is perl, version 5.005_03 built for i386-linux
Here's my system info:
Pentium 166 with 128 megs of ram, c. 8megs free before and after
runnning the benchmarks, eide (non-udma) hard disks
> If the string is in $_:
> $_ = join ' ', split;
> If the string is in $x:
> $x = join ' ', split ' ', $x;
> Split on ' ' (or with no arguments when splitting
> $_) will "throw away" leading/trailing whitespace.
The below results show that, properly implemented,
the substitutions are faster.
It is faster to use separate substitutions than to use
alternated regex code. I expected the alternated regex
method to incur some overhead, but not the circa 200%
reported.
How much faster also depends upon the order of the
substitutions, probably since you don't need to use
variable-length matches for beginning and ending
whitespace if you do the space squashing first. I did
not realize how much time difference there could be
between fixed-length matches and variable-length ones.
It's clear that one is more complicated than the other,
but the amount of time is what threw me. An extra 33%
running time for three statements is a big difference,
especially when one of them is unchanged.
Take a look at these results:
###----- output from test: -----
Benchmark: timing 1000000 iterations of a, b1, b2, c1, c2...
a: 27 wallclock secs (27.03 usr + 0.00 sys = 27.03 CPU)
b1: 57 wallclock secs (56.49 usr + 0.00 sys = 56.49 CPU)
b2: 66 wallclock secs (64.27 usr + 0.01 sys = 64.28 CPU)
c1: 18 wallclock secs (17.59 usr + 0.00 sys = 17.59 CPU)
c2: 24 wallclock secs (22.93 usr + 0.00 sys = 22.93 CPU)
a : 'This should throw away unneeded spaces.'
b1: 'This should throw away unneeded spaces.'
b2: 'This should throw away unneeded spaces.'
c1: 'This should throw away unneeded spaces.'
c2: 'This should throw away unneeded spaces.'
###----- end of output -----
Okay, now, here's the code:
###----- code from test: -----
#!/usr/bin/perl
use Benchmark;
$x = ' This should throw away unneeded spaces. ';
$zz = $z = $y = $yy = $x;
timethese 1000000, {
a => q!$x = join ' ', split ' ', $x;!,
b1 => q!$yy =~ s/\s+/ /g; $yy =~ s/(?:^\s|\s$)//;!,
b2 => q!$y =~ s/(?:^\s+|\s+$)//; $y =~ s/\s+/ /g;!,
c1 => q!$z =~ s/\s+/ /g; $z =~ s/^\s//; $z =~ s/\s$//;!,
c2 => q!$zz =~ s/^\s+//; $zz =~ s/\s+$//; $zz =~ s/\s+/ /g;!
};
print "a : '$x'\n";
print "b1: '$yy'\n";
print "b2: '$y'\n";
print "c1: '$z'\n";
print "c2: '$zz'\n";
###----- end of code -----
> See:
> perldoc -f split
> perldoc -f join
Hope this helps put the split/join method in the right
light. I know after running this benchmark three or four
times that I'll look at replacing alternating regexen in
my substitutions with multiple simpler substitutions where
applicable.
Chris
--
Christopher E. Stith - mischief@velma.motion.net
------------------------------
Date: Wed, 13 Dec 2000 22:27:11 GMT
From: Alexander Skwar <ASkwar@DigitalProjects.com>
Subject: Excluding a string from a RE
Message-Id: <918t3m$dfj$1@nnrp1.deja.com>
Hello!
I've got the problem, that I want to extract the OS a user runs from the
HTTP_USER_AGENT string. For this, I want to distinguish between Windows
2000 and Windows NT 4.0.
Windows 2000 includes itself in the HTTP_USER_AGENT with:
Windows NT 5.0
E.g.:
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
Windows NT 4.0 is identified by this in HTTP_USER_AGENT:
Windows NT
E.g.:
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)
I want to write a regular expression that abides to this rule:
"Find NT followed by 0 or more whitespaces and after that not the string
5.0"
I wrote this non-functional RE:
"|NT[\s]*?[^5]|"
This matches the string for Windows NT 4.0, but for an unknown reason
(at least to me) also the string for Windows 2000. If I replace the "*"
(star) by a "+" (plus), it does not match Windows 2000 (understood), but
it also doesn't match Win NT 4.0 (why?).
Could anyone be so kind and explain to me what I did wrong and how to do
it right?
Thanks a lot!
Note: Crosspost to clp and clp.misc; Followup-To: set to
comp.lang.perl.misc
Alexander Skwar
--
Homepage: http://www.digitalprojects.com | http://www.iso-top.de
iso-top.de - Die guenstige Art an Linux Distributionen zu kommen
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 13 Dec 2000 13:25:58 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Faster than LWP
Message-Id: <11151-3A37CD46-6@storefull-247.iap.bryant.webtv.net>
[keeping fingers crossed that newsreader doesn't throw in garbage
characters or wrap]
Thanks Helgi,
Now maybe I'm getting somewhere. Yours is the first script that I've
been able to get to print out anything. At least, there are no BEGIN
errors showing up, so all the modules appear to be installed at @INC :)
I've modified it slightly below. It gives me a :404 NOT FOUND" error
though. We all know that the particular URL I'm trying to grab is a
valid one from CPAN.
In my script below, what is causing the 404 error?
------------------------------------------
#!/usr/local/bin/perl -w
print "Content-type: text/html\n\n";
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;
my $raw_url =
"http://cpan.org/modules/by-module/Alias/Alias-2.32.tar.gz" or die
"usage: $0 url\n";
my $url = URI::Heuristic::uf_urlstr($raw_url);
$| = 1;
printf "%s =>\n\t", $url;
my $ua = LWP::UserAgent->new();
$ua->proxy(['http', 'ftp'] => 'http://balder.prohosting.com/asner:80');
my $req = HTTP::Request->new(GET => $url);
my $response = $ua->request($req);
if ($response->is_error()) {
printf " %s\n", $response->status_line;
} else {
my $count;
my $bytes;
my $content = $response->content();
$bytes = length $content;
$count = ($content =~ tr/\n/\n/);
printf "%s (%d lines, %d bytes)\n", $response->content;
}
Thanks,
Dennis
------------------------------
Date: 13 Dec 2000 20:19:10 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Faster than LWP
Message-Id: <eli$0012131509@qz.little-neck.ny.us>
In comp.lang.perl.misc, Helgi Briem <helgi@NOSPAMdecode.is> wrote:
> This code, slightly modified from the Perl Cookbook works
> for me every day and is lightning fast for either ftp or
> http, substitute your own proxy server and port number.:
I modified it slighly and becnhmarked it against my code, both
requesting http://localhost/ 1000 times. It was ever so slightly
faster than mine. (Which suggests to me that I should optimize
mine better, to at least indistinguishable times. :^)
#!/usr/bin/perl -w
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
my $url = shift or die "usage: $0 url\n";
$| = 1;
my $ua = LWP::UserAgent->new();
timethis(1000, sub {
my $req = HTTP::Request->new(GET => $url);
my $response = $ua->request($req);
}
__END__
Benchmarking:
$ bget -t 1000 -B http://localhost/
timethis 1000: 53 wallclock secs (17.52 usr + 1.44 sys = 18.96 CPU) @ 52.74/s
(n=1000)
$ /tmp/lwp-bm http://localhost/
timethis 1000: 52 wallclock secs (14.66 usr + 1.77 sys = 16.43 CPU) @ 60.86/s
(n=1000)
$
Elijah
------
will profile his code now
------------------------------
Date: Wed, 13 Dec 2000 14:45:25 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Faster than LWP
Message-Id: <11149-3A37DFE5-39@storefull-247.iap.bryant.webtv.net>
Hi Helgi,
I finally got your script to work with another URL; but don't know why
it wouldn't take that tar.gz URL???
However, that script just seems to print the URL, doing the same thing
as print "Location:http://blah/blah".
Maybe I should've explained better what I was trying to accomplish. I
need to be able to grab a URL from either an http or an ftp address ...
AND... store it in a scalar. How would you suggest I do that? I cannot
get the following codes to work, though they previously worked on a
server that just 86'd me over nothing... and I digress...
These are the codes that worked on the other server, but won't work on
my new server. I'm also using CGI qw(:standard) in the script. FWIW,
I've narrowed the script down to the portion that's failing. It hangs
and sits there when it tries to grab and store the URL.
#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use LWP::Simple;
[NOTE: the URL is coming from form input where input name is url]
$URL = param('url');
$file = "temp/storage";
getstore($URL,$file);
--Dennis
PS Interesting benchmarks, Eli. Thanks.
------------------------------
Date: Wed, 13 Dec 2000 22:57:37 GMT
From: "Lars Svensson" <lars_lars@home.se>
Subject: FileSearch
Message-Id: <B9TZ5.463$wz.26977@nntp1.chello.se>
Hello.
I want to write a searchengine for a single computer with multiple disks.
Does anyone know which module to use?
Lars
------------------------------
Date: Wed, 13 Dec 2000 22:15:42 GMT
From: gurusri@my-deja.com
Subject: getting OS info
Message-Id: <918se9$cth$1@nnrp1.deja.com>
How to get the operating system information from a perl script. Ex: I
have to call a api which is dependent on OS, I have to first determine
the operating system where the script is running. How to do it?
Thanks
-Gururaj.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 13 Dec 2000 21:06:03 GMT
From: msalerno@my-deja.com
Subject: Hopefully not to difficult a question. Please Help
Message-Id: <918obk$96t$1@nnrp1.deja.com>
I need to modify the password field of the passwd file. Is there any
way that I can modify the file ? I don't want to have to rewrite the
passwd file. I don't want to have to make any system calls to sed or
some other utility. Please let me know how I can do this, or let me
know where I could get some sample script that I could pick apart. Any
info will be considered helpful.
Thanks,
Matt
I was looking at the perl faq's and I came accross this.
Those are operations of a text editor. Perl is not a text editor. Perl
is a programming language.
The general solution is to create a temporary copy of the text file with
the changes you want, then copy that over the original
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 13 Dec 2000 15:52:37 -0600
From: John Hunter <jdhunter@nitace.bsd.uchicago.edu>
Subject: Re: Hopefully not to difficult a question. Please Help
Message-Id: <1r4s082dlm.fsf@video.bsd.uchicago.edu>
>>>>> "msalerno" == msalerno <msalerno@my-deja.com> writes:
msalerno> I need to modify the password field of the passwd file.
msalerno> Is there any way that I can modify the file ? I don't
msalerno> want to have to rewrite the passwd file. I don't want
msalerno> to have to make any system calls to sed or some other
msalerno> utility. Please let me know how I can do this, or let
msalerno> me know where I could get some sample script that I
msalerno> could pick apart. Any info will be considered helpful.
I don't think you should be overly concerned about rewriting the
password file. This can be done easily and safely. You can
automatically generate backups within your perl script for extra
security.
You will be more likely to wreck your data file if you try to do the
editing in place. You will have to work at the binary level and I am
sure that this will be more error prone than working at the text
level.
What was wrong with the solution and detailed commentary that Chris
Fedde offered when you asked this question Monday?
John Hunter
------------------------------
Date: Wed, 13 Dec 2000 22:45:31 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Hopefully not to difficult a question. Please Help
Message-Id: <quuf3ts4c3vcvdgsicssk0shgvnqbod9ab@4ax.com>
msalerno@my-deja.com wrote:
>I need to modify the password field of the passwd file. Is there any
>way that I can modify the file ? I don't want to have to rewrite the
>passwd file.
Sorry, rewriting the file, or at least the part following your altered
text, is the only way to go, unless your replacement text is *exactly*
as long as the original. That's what text editors do, anyway.
Overwriting the old file, that is.
--
Bart.
------------------------------
Date: Wed, 13 Dec 2000 20:41:53 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Ideas...
Message-Id: <ppmf3t8dicd6pdd6calddt340dh4m40kgo@4ax.com>
iwjaph wrote:
> From my research it seems that this is the basic premise of SOAP
So it seems. Do you know there is a few SOAP modules for Perl? For
example, <http://search.cpan.org/search?dist=SOAP> and
<http://search.cpan.org/search?dist=SOAP-Lite>.
They're pretty new, and no, I haven't worked with any of them, yet. I've
only read about SOAP.
FWIW, yes, you can invent your own protocol pretty much like, but not
quite the same as HTTP. All you need to do is launch a server, for
example, through CGI, and you're ready to go. You can incorporate a
handshake mechanism with some form of password protection mechanism
(preferably digest) and provide encryption like for example with PGP.
There's no way an ordinary user can access it with a plain browser.
--
Bart.
------------------------------
Date: 13 Dec 2000 13:56:33 -0600
From: John Hunter <jdhunter@nitace.bsd.uchicago.edu>
Subject: initialize array of identical elements
Message-Id: <1rk8942iz2.fsf@video.bsd.uchicago.edu>
I want to initialize an array of constant size where all the elements
are the same. I know how to do this with a brute force approach:
use constant N => 6;
use constant VAL => 1;
my @a;
for (my $i=0; $i<N; ++$i) {
$a[$i] = VAL;
}
What is the cute, elegant, pithy perl way to do this?
Thanks,
John Hunter
------------------------------
Date: Wed, 13 Dec 2000 12:10:15 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: initialize array of identical elements
Message-Id: <3A37D7A7.5055F788@vpservices.com>
John Hunter wrote:
>
> I want to initialize an array of constant size where all the elements
> are the same. I know how to do this with a brute force approach:
>
> use constant N => 6;
> use constant VAL => 1;
> my @a;
> for (my $i=0; $i<N; ++$i) {
> $a[$i] = VAL;
> }
>
> What is the cute, elegant, pithy perl way to do this?
my @a = map{ $_ = VAL } (0..N-1);
--
Jeff
------------------------------
Date: Wed, 13 Dec 2000 12:15:46 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: initialize array of identical elements
Message-Id: <3A37D8F2.8F2B5CAF@vpservices.com>
Jeff Zucker wrote:
>
> my @a = map{ $_ = VAL } (0..N-1);
Or, duh, $jeff->{pithiness}--, forget the $_ and just use this:
my @a = map{ VAL } (0..N-1);
--
Jeff
------------------------------
Date: 13 Dec 2000 20:21:00 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: initialize array of identical elements
Message-Id: <918lnc$hr4@gap.cco.caltech.edu>
In article <3A37D7A7.5055F788@vpservices.com>,
Jeff Zucker <jeff@vpservices.com> wrote:
>John Hunter wrote:
>> I want to initialize an array of constant size where all the elements
>> are the same. I know how to do this with a brute force approach:
>>
>> use constant N => 6;
>> use constant VAL => 1;
>> my @a;
>> for (my $i=0; $i<N; ++$i) {
>> $a[$i] = VAL;
>> }
>>
>> What is the cute, elegant, pithy perl way to do this?
>
>my @a = map{ $_ = VAL } (0..N-1);
my @a = (VAL) x N;
-- Gary
------------------------------
Date: Wed, 13 Dec 2000 12:26:08 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: initialize array of identical elements
Message-Id: <3A37DB60.847254AF@vpservices.com>
Jeff Zucker wrote:
>
> my @a = map{ VAL } (0..N-1);
Or even:
my @a = split //, VAL x N;
--
Jeff
------------------------------
Date: Wed, 13 Dec 2000 21:04:52 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: initialize array of identical elements
Message-Id: <7a4s08av7w.fsf@merlin.hyperchip.com>
Jeff Zucker <jeff@vpservices.com> writes:
> Jeff Zucker wrote:
> >
> > my @a = map{ VAL } (0..N-1);
>
> Or even:
>
> my @a = split //, VAL x N;
why so complicated?
my @a = (VAL) x N;
--Ala
------------------------------
Date: 13 Dec 2000 14:45:07 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: initialize array of identical elements
Message-Id: <m3vgsof3u4.fsf@dhcp11-177.support.tivoli.com>
John Hunter <jdhunter@nitace.bsd.uchicago.edu> writes:
> I want to initialize an array of constant size where all the elements
> are the same. I know how to do this with a brute force approach:
>
> use constant N => 6;
> use constant VAL => 1;
> my @a;
> for (my $i=0; $i<N; ++$i) {
> $a[$i] = VAL;
> }
>
> What is the cute, elegant, pithy perl way to do this?
my @a = (VAL) x N;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Wed, 13 Dec 2000 14:21:33 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: initialize array of identical elements
Message-Id: <3A37F66D.F7AA4B18@vpservices.com>
Ala Qumsieh wrote:
>
> Jeff Zucker <jeff@vpservices.com> writes:
>
> > Jeff Zucker wrote:
> > >
> > > my @a = map{ VAL } (0..N-1);
> >
> > Or even:
> >
> > my @a = split //, VAL x N;
>
> why so complicated?
>
> my @a = (VAL) x N;
Now I remember why I don't play golf in public too often :-).
--
Jeff
------------------------------
Date: Wed, 13 Dec 2000 21:07:34 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Interpolating
Message-Id: <7a1yvcav3d.fsf@merlin.hyperchip.com>
Geoff Soper <g.soper@soundhouse.co.uk> writes:
> Currently I sue an expression such as :
^^^
^^^
Why? What did it do to you? ;-)
--Ala
------------------------------
Date: Wed, 13 Dec 2000 21:15:47 +0000 (GMT)
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Re: Interpolating
Message-Id: <4a2c6fa741g.soper@soundhouse.co.uk>
In article <m3vgsoi6ha.fsf@dhcp11-177.support.tivoli.com>,
Ren Maddox <ren.maddox@tivoli.com> wrote:
> Not sure why you have the comma at the end, so I've left it off.
Calling a function I'd written, it must have previously had more arguments!
--
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/
------------------------------
Date: Wed, 13 Dec 2000 21:18:41 GMT
From: adamf@box43.gnet.pl (Adam)
Subject: Re: mime decoding
Message-Id: <3a37e781.7440636@nntp.lucent.com>
On 13 Dec 2000 10:56:53 GMT, "Pascal HOARAU" <hoarau@cybercable.fr>
wrote:
>Hi,
>
>I am making a site to use newsgroups through html.
>You can see it at http://pascalboards.dyndns.org
>I would like to decode mime file (uu,base64 and multipart).
>I did that with system("munpack") or with the module convert::uu (decode only uu)
>But if someone could help me to do a better job (with mime or whatever on my site)
>:)
sure, the MIME:tools modul will help you ;)
--
Adam.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 5103
**************************************