[17991] in Perl-Users-Digest
Perl-Users Digest, Issue: 151 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jan 26 14:21:16 2001
Date: Fri, 26 Jan 2001 11:10:22 -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: <980536222-v10-i151@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 26 Jan 2001 Volume: 10 Number: 151
Today's topics:
Re: Perl Style Guide - uncuddled elses <monty@primenet.com>
POST method problem in a request <junior_s@sympatico.ca>
Re: POST method problem in a request <jdf@pobox.com>
Re: POST method problem in a request nobull@mail.com
Re: Precision? (was: Perl is bad at (very) simple math! <occitan@esperanto.org>
Re: Precision? (was: Perl is bad at (very) simple math! (Mark Jason Dominus)
Re: Precision? (was: Perl is bad at (very) simple math! <joe+usenet@sunstarsys.com>
Re: Precision? <dan@tuatha.sidhe.org>
Regular expression question <g9karkav@cdf.toronto.edu>
Re: Regular expression question <barmar@genuity.net>
Re: Script to "rotate" the chars in a string. <julien.quint@imag.fr>
Re: Script to "rotate" the chars in a string. <uri@sysarch.com>
sed and Perl <a58289@yahoo.com>
Re: sed and Perl <jdf@pobox.com>
Re: sed and Perl <monty@primenet.com>
Sending email using a socket prpr1685@my-deja.com
Re: Sending email using a socket <dan@tuatha.sidhe.org>
Re: Sending email using a socket nobull@mail.com
setting environment variables <dlecky@home.com>
Re: setting environment variables (Rafael Garcia-Suarez)
Re: setting environment variables (Nick Condon)
Simple perl question, please help -- khanh215@my-deja.com
Re: Simple perl question, please help -- (Greg Bacon)
Re: Simple perl question, please help -- egwong@netcom.com
Re: Split string into two arrays <ren.maddox@tivoli.com>
Re: Split string into two arrays <h.camp@scm.de>
Re: stability of threads + interpreter performance <uri@sysarch.com>
tied variables and access speed <joe+usenet@sunstarsys.com>
Re: tied variables and access speed <joe+usenet@sunstarsys.com>
Re: Time / Date Format <sorinvc@utdallas.edu>
Re: Time / Date Format <jdf@pobox.com>
using dbmmanage in a perl script <dpalmeNOSPAM@unitedtraffic.com>
Re: wincvs.org offline? <aussie_roamer1@yahoo.com.au>
Re: wincvs.org offline? <randy.galbraith@pegs.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 26 Jan 2001 19:01:06 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: Perl Style Guide - uncuddled elses
Message-Id: <94shhi$6ok$1@nnrp2.phx.gblx.net>
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
> Bart Lateur <bart.lateur@skynet.be> wrote:
> > Bleh. I prefer cuddled elses any time.
>
> I don't. But that's just another religious war.
[*snip* lengthy discourse on cuddled elses v. uncuddled elses]
> Let's not get into one of these [religious wars] again.
Ok. Good suggestion.
(Oh, by the way: cuddles braces RULE! Now let's have no more
senseless discussion about this topic, please. ;-)
--
Jim Monty
monty@primenet.com
Tempe, Arizona USA
------------------------------
Date: Fri, 26 Jan 2001 17:14:06 GMT
From: "junior" <junior_s@sympatico.ca>
Subject: POST method problem in a request
Message-Id: <yfic6.125081$JT5.4558309@news20.bellglobal.com>
Hi,
I want to make a request via the POST method and I'm lost...
It's easy doing a request with the GET method using the UserAgent 'request'
method or the HTTP::Request but when it comes to do a POST request then
every thing seems complicated...
what I've so far is one request GET like this one:
# builds the object HTTP::Request
$oRequest = HTTP::Request->new(GET => $$refSite);
# opens a tmp file for writing the page requested
open(OUT, ">$fhTemp") || warn "cant open file: $fhTemp.\n" ;
# oUA object created earlier calling the request method and calling a sub,
printing the page requested
$oUA->request($oRequest, \&print_file, 4096);
this is simple...
Now when I'm calling a page with the POST, I KNOW that the process isn't the
same.
there's content that i'm send to the server in the header but it doesn't
work.
is there an example that i can view somewhere other than the manpages or the
documentaion coming with the packages.
thanks
jr
------------------------------
Date: 26 Jan 2001 13:08:23 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: POST method problem in a request
Message-Id: <snm6qj8o.fsf@pobox.com>
"junior" <junior_s@sympatico.ca> writes:
> I want to make a request via the POST method and I'm lost...
> is there an example that i can view somewhere other than the
> manpages or the documentaion coming with the packages.
Did you read the lwpcook man page? It has a fairly simple example of
negotiating a POST.
perldoc lwpcook
If you've already read that, and you still have questions, please do,
ahem, *post* here again.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 26 Jan 2001 17:54:32 +0000
From: nobull@mail.com
Subject: Re: POST method problem in a request
Message-Id: <u9y9vyfbbh.fsf@wcl-l.bham.ac.uk>
"junior" <junior_s@sympatico.ca> writes:
> Newsgroups: comp.lang.perl,comp.lang.perl.misc,comp.lang.perl.modules
comp.lang.perl does not exist.
> I want to make a request via the POST method and I'm lost...
Then at least show us where you are so we can get you unlost.
> # builds the object HTTP::Request
> $oRequest = HTTP::Request->new(GET => $$refSite);
> Now when I'm calling a page with the POST, I KNOW that the process isn't the
> same.
If there's no content the process is identical.
> there's content that i'm send to the server in the header but it doesn't
> work.
Eh? An HTTP message consists of headers and a content. The content is
not _in_ the header. There's a content-type header that says what
type the content is.
Anyhow could you be a bit more precice about what you want in the
content how you are building the content, how you are building the
HTTP::Request object and how it is failing?
Note: if you want content that looks like a form submission then have
you looked at HTTP::Request::Common?
> is there an example that i can view somewhere other than the manpages or the
> documentaion coming with the packages.
Why don't you like the working examples that come with the packages?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 26 Jan 2001 16:33:19 GMT
From: Daniel Pfeiffer <occitan@esperanto.org>
Subject: Re: Precision? (was: Perl is bad at (very) simple math!)
Message-Id: <94s8sg$ugo$1@nnrp1.deja.com>
In article <3a713757.2de2$209@news.op.net>,
mjd@plover.com (Mark Jason Dominus) wrote:
> In article <94qd71$di5$1@nnrp1.deja.com>,
> Daniel Pfeiffer <occitan@esperanto.org> wrote:
>> $ perl -e 'print 1e9|1,"\n", 1e10|1,"\n", 1e15-1,"\n", 1e15+1,"\n"'
>> 1000000001
>> 4294967295
>> 999999999999999
>> 1e+15
>> which seems to suggest that 1e9 is the biggest power-of-ten-integer
>> while 1e15 seems to be the biggest integrally precise
>> power-of-ten-float.
> That makes sense. You have 32-bit integers, so the largest
> representable integer is 2^32-1 = 4294967295 and the largest
> representable integer power of 10 is 1000000000.
> Your floating point numbers are 64 bits, most likely represented in
> the IEEE format. A 64-bit IEEE floating-point number has a sign bit,
> an 11-bit exponent, and a 52-bit mantissa. The largest number
> representable has a mantissa of
> 1.1111111111111111111111111111111111111111111111111111
> (that is, 2 - 2**(-52) = 1.99999999999999977796; the inital "1." is
> implicit) and an exponent of 2047, ...
> OK, let's give that a whirl:
> # Only use 'reverse' if your computer is little-endian
> $d = unpack "d", pack "C*", reverse (68, 128, 240, 207, 6, 77, 213,
146);
> printf "%.20f\n", $d;
> and our program prints the largest exactly representable power of 10:
> 10000000000000000000000.00000000000000000000.
> Wah-lah, and rather bigger than what you suggested.
> Why's that? Because your test was looking for something else: Where
> does the floating-point format precision become coarser than 1? It
> occurs for when the least significant bit in the mantissa has a value
> greater than 1; since the mantissa is 52 bits wide, this occurs when
> the exponent exceeds 52. (In the example above, we were able to
> represent 10^22 all right, but the next larger number after that is
> 10000000000000002097152 because the large exponent (70) makes the
> least significant bit of the mantissa worth 2097152 instead of only
1.)
I expressed myself badly, this was in fact what I wanted.
> Putting together a number with an exponent of 52 and a mantissa of all
> 1's yields:
> $d = unpack "d", pack "C*", reverse (67, 63, 255, 255, 255, 255,
255, 255);
> printf "%.2f\n%.2f\n%.2f\n%.2f\n", $d-1, $d, $d+1, $d+2;
> 9007199254740990.00
> 9007199254740991.00
> 9007199254740992.00
> 9007199254740992.00
> $d+1 works correctly, but that's the end of the line. After that, the
> LSB is worth 2 instead of 1, so ($d+1)+1 loses the extra 1 to
> round-off error.
What a pity, so close to one digit more!
> The largest power of 10 less than this amount is 1000000000000000 =
> 10**15, as you discovered. But you got lucky. Your program, like
many
> that involve floating-point numbers, has committed a round-off
> error---Perl uses a default format of '%15g' when printing
> floating-point numbers. Even if your computer could have represented
> 10**16 without loss of precision, your program might not have found
> out, since it was formatting the numbers with scientific notation once
> they got longer than 16 digits.
> Now, why does Perl use a default format of %15g? Because your C
> compiler defines a macro called DBL_DIG to be 15. Why does it define
> it to be 15? Because 10**15 is the largest power of 10 that your
> computer can represent without loss of precision.
>> But is this universally true, or does it depend on the underlying
>> architecture and/or C compiler?
> Certainly on the architecture, and possibly on the compiler. Nothing
> stops the compiler from implementing its own floating-point arithmetic
> routines in software to any precision it desires.
>> And if so, what is the best way to find out?
> Your way looks a lot easier than mine, but easier still is to look up
> DBL_DIG in <float.h>. DBL_DIG might conceivably lie, but if it does
> your method won't work anyway. (Mine is even less robust, since it
> depends on the internal details of the floating-point format. On the
> other hand, you can be absolutely sure of the results, if you have
> enough understanding.)
What does work, then, is looking for nines in:
$ perl -e 'printf "%.0f\n%.0f\n", 1e15-1, 1e16-1'
999999999999999
10000000000000000
Thanks for an extremely complete and helpful answer!
Daniel
--
Bring text-docs to life! Erwecke Textdokumente zum Leben!
http://beam.to/iPerl/
Vivigu tekstodokumentojn!
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 16:58:19 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Precision? (was: Perl is bad at (very) simple math!)
Message-Id: <3a71acaa.3c7b$24@news.op.net>
Keywords: gravel, sector, veil, vile
In article <94s8sg$ugo$1@nnrp1.deja.com>,
Daniel Pfeiffer <occitan@esperanto.org> wrote:
>I expressed myself badly, this was in fact what I wanted.
Not at all. Your code was perfectly clear. But I got interested in
the other thing.
>> 9007199254740990.00
>
>What a pity, so close to one digit more!
I had the same reaction.
Still, you can't have everything. We're lucky enough to have 2**10 = 10**3.
(I wonder if I could believe that to be evidence of a benevolent God?)
>What does work, then, is looking for nines in:
I think %.0f is the key thing here. You need to tell Perl not to
round off the result when it is printed.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 26 Jan 2001 12:27:34 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Precision? (was: Perl is bad at (very) simple math!)
Message-Id: <m3k87inrzt.fsf@mumonkan.sunstarsys.com>
mjd@plover.com (Mark Jason Dominus) writes:
> Still, you can't have everything. We're lucky enough to have 2**10 = 10**3.
> (I wonder if I could believe that to be evidence of a benevolent God?)
Far better evidence of a benevolent god is the fact that
log 3 / log 2 = 3 / 2
See http://www.math.niu.edu/~rusin/papers/uses-math/music/12 for details.
--
Joe Schaefer
------------------------------
Date: Fri, 26 Jan 2001 17:14:23 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Precision?
Message-Id: <Pfic6.156754$P82.19024135@news1.rdc1.ct.home.com>
Daniel Pfeiffer <occitan@esperanto.org> wrote:
> In article <t70pai1fh08r2b@corp.supernews.com>,
> Chris Stith <mischief@velma.motion.net> wrote:
>> philhibbs@my-deja.com wrote:
>>> In article <t6ui3ecdn4pn39@corp.supernews.com>,
>>> Chris Stith <mischief@velma.motion.net> wrote:
>>>> I wouldn't call that failing. Figure out for yourself how to
>>>> represent 0.1 in binary.
>>> Well, I'd use one of the x87 BCD floating point formats, if I was
>>> doing it on an Intel CPU.
>> I might do the same if I was going to run _only_ on Intel
>> x86 CPU-based machines. One of Perl's greatest strengths
>> is its portability. I the core had a different math engine
>> for every platform...
> This brings me to the question about precision that can be expected from
> Perl.
It's reasonably platform specific (and with perl 5.6.0, depends on your
settings when you built perl) but generally most platforms use standard
IEEE floats. In perl that means the largest integer you can represent
accurately is 53 bits long. (About 17.5 decimal digits IIRC, which I
might not) Integer math is signed and gets you 31 bits, or about 9.25
decimal digits.
If you enable 64-bit integers (or they're your native int size) you'll
get 63 bits of integer precision (though perl's tendency to do everything
in floating point means you'll get 53 bits anyway, and if you enable
long doubles you'll get more. How much more's a bit up in the air,
and platform dependent.
You can, of course, always use the bigint or bigfloat modules for
longer numbers, but you'll pay a rather hefty performance penalty.
Dan
------------------------------
Date: Fri, 26 Jan 2001 18:03:34 GMT
From: Kauser Ali Karim <g9karkav@cdf.toronto.edu>
Subject: Regular expression question
Message-Id: <Pine.GSO.4.30.0101261251540.4890-100000@koala.cdf>
Hi,
I need to get rid of the first fifteen charcters
(which are uppercase letters and numbers) of a line. How
would I do this using regular expressions.
I know that something like this would work,
but would only get rid of the first character.
s/[^A-Z0-9]//
Any help would be appreciated
Thanks.
Kauser
------
------------------------------
Date: Fri, 26 Jan 2001 18:46:04 GMT
From: Barry Margolin <barmar@genuity.net>
Subject: Re: Regular expression question
Message-Id: <MBjc6.60$b_3.129@burlma1-snr2>
In article <Pine.GSO.4.30.0101261251540.4890-100000@koala.cdf>,
Kauser Ali Karim <g9karkav@cdf.toronto.edu> wrote:
>I need to get rid of the first fifteen charcters
>(which are uppercase letters and numbers) of a line. How
>would I do this using regular expressions.
>
>I know that something like this would work,
>but would only get rid of the first character.
>
>s/[^A-Z0-9]//
s/^.\{15\}//
--
Barry Margolin, barmar@genuity.net
Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
------------------------------
Date: 26 Jan 2001 16:04:22 +0100
From: Julien Quint <julien.quint@imag.fr>
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <khvhf2mbbih.fsf@imag.fr>
Jerome Abela <Jerome.Abela@free.fr> writes:
> A one liner is always a contest. Here is shorter variation (no need to chop):
> perl -le'$:=reverse$;=pop;map{map{print}/(?=(.{${\length$;}}).)/g}$;x2,$:x2'
>
> I tried to avoid a map, but it's not shorter:
> perl -le'$:=reverse$;=pop;map{print}"$;$;\n$:$:"=~/(?=(.{${\length$;}}).)/g'
What about:
perl -le"$:=reverse$;=pop;for($;,$:){print$&.$'.$\`while/./g}"
Seems shorter, and I had to use some \ because of the shell.
--
Julien
------------------------------
Date: Fri, 26 Jan 2001 18:59:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Script to "rotate" the chars in a string.
Message-Id: <x7k87iuokt.fsf@home.sysarch.com>
>>>>> "MV" == Martien Verbruggen <mgjv@tradingpost.com.au> writes:
MV> $r = reverse $s = shift;
MV> print $s and $s .= substr $s, 0, 1, "" for 1 .. length $s;
MV> print $r and $r .= substr $r, 0, 1, "" for 1 .. length $r;
perl -le '$_ = shift ; print and substr( $_, 0, 0, chop ) while $i++ <
length' qwert
just trying a little golf. anyone else?
so the rules are one liner and the token is in @ARGV
perl -le'$_=pop;print,substr($_,0,0,chop)while$i++<length' qwert
qwert
tqwer
rtqwe
ertqw
wertq
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Fri, 26 Jan 2001 17:45:04 GMT
From: Aitor Garcia <a58289@yahoo.com>
Subject: sed and Perl
Message-Id: <94sd2s$2mj$1@nnrp1.deja.com>
Hello everybody,
I have a problem with a Perl script with a sed
command
in it.
When I execute the following sed command from the
shell:
sed '/^[0-9][0-9]*\(
0\.00000000000000000000e+00\)\{2048\}/d' file_in >
file.out.
and works.
But when I write this command inside a Perl script
and try
to execute it using backtick operator, does not
work. I have tried exec command for it neither works.
Any help will be greatly appreciated.
Best Regards,
Aitor
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 26 Jan 2001 13:21:49 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: sed and Perl
Message-Id: <hf2mqima.fsf@pobox.com>
Aitor Garcia <a58289@yahoo.com> writes:
> sed '/^[0-9][0-9]*\(> 0\.00000000000000000000e+00\)\{2048\}/d' file_in >> file.out.
> But when I write this command inside a Perl script and try to
> execute it using backtick operator, does not work.
Why are you using Perl when the sed command works just fine?
If you want to use Perl, why not just have Perl do what sed was doing?
perl -ne 'print unless /^\d+(> 0\.0+e\+00){2048}/' \
file_in >> file.out
(Warning: I'm guessing at the meaning of that sed program!)
What do you mean when you say it doesn't work? One problem I'd
anticipate is that backticks interpolate their argument, so that some
of those backwhacks within the sed program disappear.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: 26 Jan 2001 19:11:56 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: sed and Perl
Message-Id: <94si5s$6ok$2@nnrp2.phx.gblx.net>
Aitor Garcia <a58289@yahoo.com> wrote:
> I have a problem with a Perl script with a sed command in it.
> When I execute the following sed command from the shell:
> sed '/^[0-9][0-9]*\( 0\.00000000000000000000e+00\)\{2048\}/d' file_in
> > file.out. and works. But when I write this command inside a
> Perl script and try to execute it using backtick operator, does
> not work. I have tried exec command for it neither works.
Folk wisdom suggests "Never say never," but I'm gonna go way out
on a limb here and state categorically and unequivocally that
there is NEVER a good reason to run a sed command from within
a Perl script!
Why would you do that? The (much improved) s command of sed is
built into Perl.
perldoc perlop
--
Jim Monty
monty@primenet.com
Tempe, Arizona USA
------------------------------
Date: Fri, 26 Jan 2001 16:17:24 GMT
From: prpr1685@my-deja.com
Subject: Sending email using a socket
Message-Id: <94s7u9$tno$1@nnrp1.deja.com>
I am attempting to write Perl code to open a socket and send a message
to a mail server (without using the Perl SMTP module). Here is the code:
use strict;
use IO::Socket;
my $from = "prpr1685\@deja.com";
my $to = "pr1\@excite.com";
my $rcpt = $from;
my $data = "Hello world from $from!";
my $host = shift || 'mail.deja.com';
my $port = shift || '25'; # email
my $msg_out = "mail from: $from\nrcpt to: $to\ndata\n$data\n";
my $socket = IO::Socket::INET->new("$host:$port") or die $@;
print $socket $msg_out;
#my $msg_in = <$socket>;
#print $msg_in;
$socket->close or warn $@;
print "Done!\n";
================================
This code does not work. What is missing?
Many thanks.
Philippe de Rochambeau
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 17:19:20 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Sending email using a socket
Message-Id: <skic6.156755$P82.19024615@news1.rdc1.ct.home.com>
prpr1685@my-deja.com wrote:
> I am attempting to write Perl code to open a socket and send a message
> to a mail server (without using the Perl SMTP module). Here is the code:
Urk. You probably don't want to do that. Use one of the SMTP modules.
Libnet has a nice one.
> ================================
> This code does not work. What is missing?
Rather a lot, which is a good sign you ought not be doing this by hand.
If you absolutely must, go read RFC 821 and 822 first. They've got
everything you need in them to do this. (Well, you only really
need 821, but they go hand in hand)
Dan
------------------------------
Date: 26 Jan 2001 17:43:41 +0000
From: nobull@mail.com
Subject: Re: Sending email using a socket
Message-Id: <u93de6gqeq.fsf@wcl-l.bham.ac.uk>
prpr1685@my-deja.com writes:
> I am attempting to write Perl code to open a socket and send a
> message to a mail server (without using the Perl SMTP module).
Why!?
> This code does not work. What is missing?
The message headers and the final line containing a dot, not to
mention response code ckecking.
Note: you are off-topic, your question is about SMTP not Perl.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 26 Jan 2001 15:59:40 GMT
From: "Duane" <dlecky@home.com>
Subject: setting environment variables
Message-Id: <M9hc6.87234$3j.5672195@news1.gvcl1.bc.home.com>
I am sharing data around several Perl scripts in a ksh environment. The
decision of my group was that this is best done using environment variables.
No one, including me, knows how to set them though, and I am supposed to be
the Perl expert. Here is what I have tried:
1. system(+ACI-export var+AF8-name+AD0-value+ACI-)+ADs-
2. +AGA-export var+AF8-name+AD0-value+AGAAOw-
3. +ACQ-ENV+AHsAIg-var+AF8-name+ACIAfQA9ACQ-value+ADs- +ACM- +ACQ-value was properly initialized before
4. system(+ACI-set+AF8-env+AF8-vars.ksh+ACI-)+ADs-
5. system(+ACI-. set+AF8-env+AF8-vars.ksh+ACI-)+ADs-
In attempt numbers 4 and 5, set+AF8-env+AF8-vars.ksh is a ksh script that contains
six lines of export var+AF8-name+AD0-value
At least with attempt number 3, when I printed out +ACU-ENV my value appeared,
but it did not appear to other scripts or when I typed env at the command
line.
Does anyone out there know how to set environment variables that can be seen
outside the running script? Am I wasting my time?
Duane
dlecky+AEA-home.com
------------------------------
Date: Fri, 26 Jan 2001 16:08:36 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: setting environment variables
Message-Id: <slrn973894.l6d.rgarciasuarez@rafael.kazibao.net>
Duane wrote in comp.lang.perl.misc:
>
> I am sharing data around several Perl scripts in a ksh environment. The
> decision of my group was that this is best done using environment variables.
> No one, including me, knows how to set them though, and I am supposed to be
> the Perl expert. Here is what I have tried:
>
> 1. system(+ACI-export var+AF8-name+AD0-value+ACI-)+ADs-
> 2. +AGA-export var+AF8-name+AD0-value+AGAAOw-
> 3. +ACQ-ENV+AHsAIg-var+AF8-name+ACIAfQA9ACQ-value+ADs- +ACM- +ACQ-value was properly initialized before
> 4. system(+ACI-set+AF8-env+AF8-vars.ksh+ACI-)+ADs-
> 5. system(+ACI-. set+AF8-env+AF8-vars.ksh+ACI-)+ADs-
Strange syntax. Perl cannot parse this.
> Content-Type: text/plain; charset="utf-7"
> Content-Transfer-Encoding: 7bit
> X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
Oh, I understand what mangles your post.
BTW, your question is answered in the FAQ :
$ perldoc -q environment
I {changed directory, modified my environment} in a perl
script. How come the change disappeared when I exited the
script? How do I get my changes to be visible?
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: 26 Jan 2001 16:51:14 GMT
From: nickco3@yahoo.co.uk (Nick Condon)
Subject: Re: setting environment variables
Message-Id: <9035A2B64NickCondon@132.146.16.23>
dlecky@home.com (Duane) wrote in
<M9hc6.87234$3j.5672195@news1.gvcl1.bc.home.com>:
>I am sharing data around several Perl scripts in a ksh environment. The
>decision of my group was that this is best done using environment
>variables. No one, including me, knows how to set them though, and I am
>supposed to be the Perl expert.
And what what was the basis for this excellent decision?
You can't do this in Unix (without using nasty eval type messiness). The
script executes as a child process to the shell, and processes can't modify
each other's environment, only pass changes on to their children.
I suggest you go back to the group and get them to reconsider. Why don't
you get IPC::Shareable from CPAN? It allows processes on the same machine
to share data structures of any complexity.
--
Nick
------------------------------
Date: Fri, 26 Jan 2001 18:22:19 GMT
From: khanh215@my-deja.com
Subject: Simple perl question, please help --
Message-Id: <94sf8g$4sh$1@nnrp1.deja.com>
hello all
I am trying to learn perl. I have a very simple question for you all.
I would like to change a column of numbers to row using perl.
For example, I have a txt file with this
1 10
2 20
3 30
4 40
I would like to change it to
1 2 3 4
10 20 30 40
I can't seem to do that with one simple perl program. Can you help.
Thanks
-Khanh
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Fri, 26 Jan 2001 18:56:53 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Simple perl question, please help --
Message-Id: <t73i3lja57clf8@corp.supernews.com>
In article <94sf8g$4sh$1@nnrp1.deja.com>,
<khanh215@yahoo.com> wrote:
: I am trying to learn perl. I have a very simple question for you all.
: I would like to change a column of numbers to row using perl.
:
: For example, I have a txt file with this
:
: 1 10
: 2 20
: 3 30
: 4 40
:
: I would like to change it to
: 1 2 3 4
: 10 20 30 40
#! /usr/local/bin/perl -w
use strict;
my @rows;
$_ = <DATA>;
push @rows, [ $_ ] for split;
my $cols = @rows;
my @tmp;
while (<DATA>) {
@tmp = split;
if (@tmp != $cols) {
my $n = @tmp;
my $fields = $n == 1 ? "field" : "fields";
warn "line $.: saw $n $fields; expected $cols\n";
}
push @$_ => shift @tmp for @rows;
}
print "@$_\n" for @rows;
__DATA__
1 10
2 20
3 30
4 40 2
Enjoy,
Greg
--
Using an old wooden chair leg, I beat the crap out of the guy until he
promised not to disregard my medical instructions again.
-- Ragnar Benson
------------------------------
Date: Fri, 26 Jan 2001 18:59:54 GMT
From: egwong@netcom.com
Subject: Re: Simple perl question, please help --
Message-Id: <KOjc6.1639$467.48221@news.flash.net>
khanh215@my-deja.com wrote:
> hello all
> I am trying to learn perl. I have a very simple question for you all.
> I would like to change a column of numbers to row using perl.
> For example, I have a txt file with this
> 1 10
> 2 20
> 3 30
> 4 40
> I would like to change it to
> 1 2 3 4
> 10 20 30 40
> I can't seem to do that with one simple perl program. Can you help.
% perl -lane 'push(@a, $F[0]); push(@b, $F[1]); END { print "@a\n@b"; }' filename
See the perlrun manpage for details, but essentially the command line
options are:
l: autochomp
a: autosplit
n: loop for every line
e: execute
The END block is done last (just as a BEGIN block would have been
done first, if specified (see perlmod))
------------------------------
Date: 25 Jan 2001 22:46:50 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Split string into two arrays
Message-Id: <m3puhaj4xx.fsf@dhcp11-177.support.tivoli.com>
scottpa@my-deja.com writes:
> I wonder if anyone could check my code and see if it could be more
> compact. I need to break the following string up into two arrays @parm
> and @type and I wondered if there was a tidier way of doing it?
>
> $_='charparm string dateparm datetime intparm number';
Here are a couple of methods I haven't seen posted yet...
@words = split;
@params = @words[map $_*2, 0..$#words/2];
@types = @words[map $_*2+1, 0..$#words/2];
push @{($i=1-$i) ? \@params : \@types}, $_ for split;
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 26 Jan 2001 18:05:46 +0100
From: H. Camphausen <h.camp@scm.de>
Subject: Re: Split string into two arrays
Message-Id: <94saho$g8n$1@surz18.uni-marburg.de>
[F'up zu Ren Maddox's Posting vom 25 Jan 2001 22:46:50 -0600]
> scottpa@my-deja.com writes:
>
> > I wonder if anyone could check my code and see if it could be more
> > compact. I need to break the following string up into two arrays @parm
> > and @type and I wondered if there was a tidier way of doing it?
> >
> > $_='charparm string dateparm datetime intparm number';
>
> Here are a couple of methods I haven't seen posted yet...
>
>
# "LONG":
> @words = split;
> @params = @words[map $_*2, 0..$#words/2];
> @types = @words[map $_*2+1, 0..$#words/2];
# "PUSH":
> push @{($i=1-$i) ? \@params : \@types}, $_ for split;
Yet another one:
# "SHORT":
my %h = split;
my @types = @h{my @parms = keys (%h)};
Let's do some testing:
Benchmark: timing 50000 iterations of LONG, PUSH, SHORT...
LONG: 7 wallclock secs ( 6.70 usr + 0.00 sys = 6.70 CPU)
PUSH: 5 wallclock secs ( 4.83 usr + 0.00 sys = 4.83 CPU)
SHORT: 4 wallclock secs ( 3.84 usr + 0.00 sys = 3.84 CPU)
mfg, Hartmut
--
CREAGEN Computerkram Fon: 06422/850527
Hartmut Camphausen Fax: 06422/850528
Am kleinen Born 1 E-Mail: h.camp@creagen.de
35287 Amöneburg WWW: http://www.creagen.de
------------------------------
Date: Fri, 26 Jan 2001 18:35:07 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: stability of threads + interpreter performance
Message-Id: <x7n1ceupph.fsf@home.sysarch.com>
>>>>> "KB" == Koen Bossaert <not@defined.com> writes:
KB> Uh, I'm sorry, I should have read the manpage better.
KB> So if I want to solve this with Event.pm I guess it should look like :
KB> ...
KB> my $watcher = Event->timer(interval => $seconds, cb => \&call_back_timer);
KB> my $watcher2 = Event->idle(cb => \&call_back_idle);
KB> loop();
KB> sub call_back_timer {
KB> do_poll();
KB> # no unloop
KB> }
KB> sub call_back_idle {
KB> my $client = $socket->accept(); # no infinite while
KB> process_request(...);
KB> ...
KB> # no unloop
KB> }
KB> Is this the right way to do it?
nope. you would first create a listen socket with IO::Socket (or roll
your own which is a waste of time). then you create an read event on
that listen socket. when it gets called back, you can do an accept and
it won't block. that is a new client connection.
i don't know your data polling needs so i can't tell if a simple timer
loop is what you want. it may work. if it suffices, then your code for
that is what you have there. the no unloop comments are meaningless. you
never unloop and this is effectively a daemon and runs forever. you
could daemonize yourself (a module can do that for you) if you really
want that.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: 26 Jan 2001 11:13:28 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: tied variables and access speed
Message-Id: <m31ytqp9zr.fsf@mumonkan.sunstarsys.com>
I stumbled across a performance issue with tied variable
access that I don't quite understand. Basically, I observed
that after something like this
$obj = tie %hash => "Package";
$hash{one} = 1;
it is considerably faster to access the "one" attribute via
$obj->FETCH("one")
or
$ref(%hash)->FETCH("one")
versus
$hash{one} .
It seems to be the case for tied scalars and arrays as well.
I've read through section 9.1.1 in OOP for an explanation,
but was unsatisfied with the answer there.
Can anyone explain this better? Here's some code for tied
scalars; output for perl 5.6 on linux follows.
% cat try.pl
#!/usr/local/bin/perl -w
use Benchmark;
package Foo;
sub FETCH { ${ $_[0] } }
sub STORE { ${ $_[0] } = $_[1] }
sub TIESCALAR { bless \( my $obj ), $_[0] }
package main;
$ref = tie $var => 'Foo';
$var = 1;
print join '=', ( $var, $ref->FETCH(), Foo::FETCH($ref),
tied($var)->FETCH() . "\n");
timethese 500_000, {
ACCESS => q/$_ = $var/,
FETCH => q/$_ = $ref->FETCH()/,
FQ => q/$_ = Foo::FETCH($ref)/,
TIED => q/$_ = tied($var)->FETCH()/,
};
__END__
% try.pl
1=1=1=1
Benchmark: timing 500000 iterations of ACCESS, FETCH, FQ, TIED...
ACCESS: 12 wallclock secs (12.11 usr + 0.00 sys = 12.11 CPU)
FETCH: 3 wallclock secs ( 4.03 usr + 0.00 sys = 4.03 CPU)
FQ: 4 wallclock secs ( 3.86 usr + 0.00 sys = 3.86 CPU)
TIED: 6 wallclock secs ( 5.42 usr + 0.00 sys = 5.42 CPU)
%
TIA.
--
Joe Schaefer
------------------------------
Date: 26 Jan 2001 12:01:01 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: tied variables and access speed
Message-Id: <m3snm6nt82.fsf@mumonkan.sunstarsys.com>
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
> I stumbled across a performance issue with tied variable
> access that I don't quite understand. Basically, I observed
> that after something like this
>
> $obj = tie %hash => "Package";
> $hash{one} = 1;
>
> it is considerably faster to access the "one" attribute via
>
> $obj->FETCH("one")
> or
> $ref(%hash)->FETCH("one")
^^^^
tied
Sorry about the gibberish there. The code I posted should
be to the point, though.
>
> versus
> $hash{one} .
>
--
Joe Schaefer
------------------------------
Date: Fri, 26 Jan 2001 11:46:42 -0600
From: Sorin Voicu-Comendant <sorinvc@utdallas.edu>
Subject: Re: Time / Date Format
Message-Id: <Pine.GSO.4.21.0101261145410.5053-100000@apache.utdallas.edu>
"sprintf" should do the trick.
***SOLI DEO GLORIA***
On Wed, 24 Jan 2001, PaAnWa wrote:
#($sec,$min,$hour,$mday,$mon,$year) =(localtime)[0..5];
#printf("the currect day and time is %04d/%02d/%02d %02d:%02d:%02d\n",
#$year+1900, $mon+1, $mday, $hour, $min, $sec);
#
#Is there a way to place this into a string variable?
#
#
#
------------------------------
Date: 26 Jan 2001 13:25:00 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: Time / Date Format
Message-Id: <d7daqigz.fsf@pobox.com>
"PaAnWa" <paul_wasilkoff@ucg.org> writes:
> ($sec,$min,$hour,$mday,$mon,$year) =(localtime)[0..5];
> printf("the currect day and time is %04d/%02d/%02d %02d:%02d:%02d\n",
> $year+1900, $mon+1, $mday, $hour, $min, $sec);
>
> Is there a way to place this into a string variable?
Another post answered your question directly; I'd also look into using
the strftime function, which resides in the POSIX module.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf
------------------------------
Date: Fri, 26 Jan 2001 12:03:41 -0600
From: "D.W." <dpalmeNOSPAM@unitedtraffic.com>
Subject: using dbmmanage in a perl script
Message-Id: <94se7e$hb4$1@slb6.atl.mindspring.net>
I'm trying to structure a perl script to add user names and passwords to a
dbm file.
I know that I can call the dbmmanage with the following line:
system("dbmmanage /home/dbm/mydbm adduser $newuser");
Which works fine, only it still prompts me for the new password, which is
where my problem lies.
How do I give it the password and then the re-enter password?
Douglas
------------------------------
Date: Fri, 26 Jan 2001 17:30:10 -0000
From: Chris Spry <aussie_roamer1@yahoo.com.au>
Subject: Re: wincvs.org offline?
Message-Id: <t73d122kmkdif2@corp.supernews.com>
Randy Galbraith wrote:
>
>
> All,
>
> Does anyone here[1] know of the fate of wincvs.org? For the past couple
of
> days I've been unable to access it.
>
> - Randy Galbraith
>
> [1] I know this isn't a perl specific question, alas, my internal news
> server as a limited number of groups.
>
>
G'Day
I have found the following site which lists sites from which wincvs can be
downloaded
http://mirror.openspace.ch/maccvs
don't be put off by the maccvs
Oo'roo
Chris Spry
--
Posted via CNET Help.com
http://www.help.com/
------------------------------
Date: Fri, 26 Jan 2001 11:32:59 -0700
From: "Randy Galbraith" <randy.galbraith@pegs.com>
Subject: Re: wincvs.org offline?
Message-Id: <94sfsh$116l$1@freepress.anasazi.com>
Chris,
Thank you kind sir, that did the trick!
- Randy Galbraith
Chris Spry wrote in message ...
<snip>
>I have found the following site which lists sites from which wincvs can be
>downloaded
> http://mirror.openspace.ch/maccvs
<snip>
------------------------------
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 V10 Issue 151
**************************************