[9840] in Perl-Users-Digest
Perl-Users Digest, Issue: 3433 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 12 21:07:18 1998
Date: Wed, 12 Aug 98 18:00:24 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 12 Aug 1998 Volume: 8 Number: 3433
Today's topics:
Re: A Regexp problem (Abigail)
Announcing Perl User Group in Madison, WI (John Cotter)
Re: Calling closure syntax (Craig Berry)
Re: CGI on Browser <dmckeown@istar.ca>
Re: CGI on Browser (Bob Trieger)
Challenge: Socksified FTP and Perl (sam ansari)
Re: dates in excess of 2037 (A Problem???) <ljz@asfast.com>
Re: dates in excess of 2037 (A Problem???) <jdf@pobox.com>
Re: exit code of pipe <rootbeer@teleport.com>
Re: File updating question <ketanp@NOSPAMxwebdesign.com>
Re: File updating question <REPLY_TO_lastronin@earthlink.net>
flock on NT (The Seeker)
how to <ritter@lfc.edu>
Match '$a' in regexp--can't do it (Chris Sherman)
Re: Match '$a' in regexp--can't do it (Craig Berry)
Re: need help making WBT system <rootbeer@teleport.com>
Re: Opening a file as "+>>file" (Craig Berry)
Re: Opening a file as "+>>file" <tchrist@mox.perl.com>
Re: passing a hash to a method <rra@stanford.edu>
Re: Perl 5.005.1 core dumps under Irix 6.2 <scotth@sgi.com>
Re: Perl Docs.. forget the original post <metcher@spider.herston.uq.edu.au>
Perl script interaction with external application (Marco Goncalves)
Re: print() acting strangely on Win32 <briant@packeteer.com>
Re: print() acting strangely on Win32 (Craig Berry)
Re: Q: How to read a file piece by piece <rootbeer@teleport.com>
Re: Q: How to read a file piece by piece (Abigail)
Re: RE engine vs. Perl <rootbeer@teleport.com>
recommended value for $d_lstat <jthompso@writeme.com>
Re: trying to execute a perl script using server side i <rootbeer@teleport.com>
Re: use strict problem with indirect file variables ? (Phil Taylor)
Re: Using PERL5 with NT4 Peer Web Services <rootbeer@teleport.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Aug 1998 00:16:52 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: A Regexp problem
Message-Id: <6qtb9k$1nv$1@client3.news.psi.net>
Greg Smolyn (smolyn@cs.ubc.ca) wrote on MDCCCVII September MCMXCIII in
<URL: news:35D1DAF4.E1FC130D@cs.ubc.ca>:
++
++ Is there a way to force /$OPENTAG/ or /$CLOSETAG/ to treat the contents
++ as literal and not regexp special characters?
Any reason you can't be bothered to read the manual or the faq?
BTW, 'regex' is much easier to pronounce than 'regexp'.
Abigail
--
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
print+Just (), another (), Perl (), Hacker ();'
------------------------------
Date: 12 Aug 1998 17:48:15 -0500
From: jdcotter@earth.execpc.com (John Cotter)
Subject: Announcing Perl User Group in Madison, WI
Message-Id: <6qt63g$5l6@newsops.execpc.com>
Announcing a Perl Mongers group for the Madison, WI area.
If you live or work in Dane county and are interested
getting together to discuss all things Perl. Send an email
to jdcotter@execpc.com
Our first get together is scheduled for the Monday 8/17.
More specific information will be posted at http://www.pm.org
soon.
- John D. Cotter
==
I hear and I forget. I see and I believe. I do and I understand.
- Confucius (551-479 BC)
------------------------------
Date: 12 Aug 1998 22:55:51 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Calling closure syntax
Message-Id: <6qt6hn$8so$3@marina.cinenet.net>
Jonathan Feinberg (jdf@pobox.com) wrote:
: hex@voicenet.com (Matt Knecht) writes:
: > In my current quest to try and grok OO programming, I'm at an annoying
: > point with closures.
:
: I'm not sure how closures are related to objects, but I might still be
: of some help.
A lexical closure can be used as a primitive 'object' of sorts, with
encapsulated state coupled to function instances. A Lisp-loving friend of
mine is fond of saying "Classes are a poor man's closures." :)
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 13 Aug 1998 00:28:04 GMT
From: Dave Mckeown <dmckeown@istar.ca>
Subject: Re: CGI on Browser
Message-Id: <35D23420.6CF78F39@istar.ca>
Lawrence Han wrote:
> [..............]
Get microsoft personal web server....
It is free for download at microsoft.com
--
Icq# 14056739
mailto:dmckeown@istar.ca
------------------------------
Date: Thu, 13 Aug 1998 00:32:51 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: CGI on Browser
Message-Id: <6qtcd3$7tp$1@strato.ultra.net>
Dave Mckeown <dmckeown@istar.ca> wrote:
-> Lawrence Han wrote:
->
-> > [..............]
->
-> Get microsoft personal web server....
->
-> It is free for download at microsoft.com
Get CGI.pm, it's free at your local CPAN (if you don't already have it)
Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-400-1972
Ext: 1949 and let the jerk that answers know
that his toll free number was sent as spam. "
------------------------------
Date: Wed, 12 Aug 1998 23:07:02 GMT
From: sam_ansari@hp.com (sam ansari)
Subject: Challenge: Socksified FTP and Perl
Message-Id: <35d2156f.24549900@rosenews.rose.hp.com>
Hello folks,
I'm trying to create a Perl script that attempts to ftp to a remote
server and deposit some files. If the first server is busy, it uses
the second. If the second is busy it uses the third.
The ftp has to go through a fire wall to do that.
We currently have a socksified ftp directory:
/opt/socks/bin/
which contains the proper wrappers and security to ftp files outside
the fire wall.
The script works as long as I'm inside the firewall. I thought if I
redirected it to launch from /opt/socks/bin/ I would be able to use
the socksified FTP by running the script from there but to no avail.
The script uses ftplib.pl.
Does anyone there know how to set this up so it uses the socksified
FTP or allow for the use of a socksified server.
Many thanks,
Sam.
Here is the script below:
------------------------------------------------------------------------------------------------------------------------------
#!/usr/local/bin/perl
#
######################################################
# This is the beginning of the "easily edited" hard #
# coded defaults. You can change any of these items #
# relatively easily, without needing to make changes #
# anywhere else in the program. #
######################################################
$version='ftp2AGS0.0';
#AGS Location
$manager="server1.company.com";
$manager2="server2.company.com";# Default First location
$manager3="server3.company.com"; #Third Location
# The *effective* UID of the process $user="HP";
$user="user1";
$user3="user2";
$user2="user3";
$passwd="pass1";
$passwd3="pass2";
$passwd2="pass3";
# the ftplib.pl file should be in the same directory as we are, so
# we need to include that in @INC...
if ($0 =~ m|^(.*)/([^/]+)$|) {
# The command looks like /a/b/c/d
$command_path=$1;
$command=$2;
}
else {
# The command looks like d.
$command_path=`pwd`;
chop($command_path);
$command=$0;
}
unshift(@INC, $command_path); # put the path of the source
code in
# the front of the list of
suspect
# locations to check for
ftplib
require 'ftplib.pl' || # go get ftplib...
die("Can not fund ftplib.pl.");
# if we don't start with a /,
#Fully qualify docroot.
#$old_pwd=`pwd`;
#chop($old_pwd);
#$docroot="/home/sansari/" ;
#Read the contents of the directory into an array
@lslist = `ls /home/sansari/ags/`;
# $quiet=pop@lslist;
# print $quiet;
#printing the values inside @lslist
print " This is a printout of the @lslist\n";
chdir "/opt/socks/bin/";
### Now FTP the globs...
$Erroropen=&ftp'open( $manager, $user, $passwd);
$Errortype=&ftp'type("i"); # || &killftp Binary baby!
print "This is the first FTP open error code $Erroropen\n";
print "This is the first ftptype error $Errortype\n";
if ($Erroropen < 1 )
{
print "Printing Error code $Erroropen if any after first open\n";
print "Standard Perl Return code $!\n " ;
print "Attempted $manager$user$passwd\n";
print "Now attempting logon to second server\n";
print "Now Attempting $manager2$user2$passwd2\n";
$manager=$manager2;
$user=$user2;
$passwd=$passwd2;
$Erroropen=&ftp'open( $manager, $user, $passwd);
print "Second Erroropen Print $Erroropen";
$Errortype=&ftp'type("i");
if ($Erroropen < 1)
{
print "Attempted $manager$user$passwd\n";
print "Now attempting third server";
print "Now Attempting $manager3$user3$passwd3 \n";
$manager = $manager3;
$user= $user3;
$passwd= $passwd3;
$Erroropen="";
$Errortype="";
$Erroropen=&ftp'open( $manager, $user, $passwd) || &killftp;
$Errortype=&ftp'type("i") || &killftp;
}
else
{
print $manager2;
print "Access was successful ";
}
}
else
{
print "Successfully opened $manager $user $passwd\n";
}
print "Successfully opened server $manager \n";
print "Ready to perform ftp type\n";
print "Error Code before ftptype $Errortype\n";
$Errortype=&ftp'type("i") || &killftp ; # Binary baby!
print "putting file in destination directory\n";
print "Printing the whole list @lslist\n";
#Loop through array and discard empty line.
foreach $filename(@lslist)
{
print $filename;
chop $filename;
if ($filename ne " ")
{
&ftp'put("$filename" ,"$filename") || &killftp ;
}
}
&ftp'close;
# system("mv /home/sansari/ags/*.* /home/sansari/backup/");
print "1Proccess completed successfully. Your file(s) have been
deposited on the
AGS machine.";
# Get rid of the traces...
# unlink("$tmp$homepagekey.tix");
# unlink("$tmp$homepagekey.pkg");
exit;
sub killftp
{
$error = &ftp'error;
print $manager;
print $docroot;
&ftp'close;
&cleandie("FTP failed: $error");
}
sub cleandie {
local($msg)=shift;
print "$msg\n";
# unlink("$tmp$homepagekey.tix");
# unlink("$tmp$homepagekey.pkg");
exit 1;
}
sub usage {
print STDERR "USAGE:";
}
------------------------------
Date: 12 Aug 1998 20:08:47 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: dates in excess of 2037 (A Problem???)
Message-Id: <ltww8d3fqo.fsf@asfast.com>
martin@RADIOGAGA.HARZ.DE (Martin Vorlaender) writes:
> Dan Nguyen (nguyend7@egr.msu.edu) wrote:
> : Okay so the designers of UNIX weren't thinking. Its nothing new look
> : at the Y2K problem. But the solution for it is simple. Newer
> : computers will be using a 64-bit long int rather than a 32-bit long
> : int.
>
> Might I point out that VMS had a 64-bit time representation right from
> v1.0 (though storing 100 nanosecond units since 17-NOV-1858, this will
> be enough until year 30000+)? Now that's what I call foresight...
Just out of curiosity, do you know their rationale for choosing
17-nov-1858 as the beginning of the epoch?
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: 12 Aug 1998 20:25:02 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: Lloyd Zusman <ljz@asfast.com>
Subject: Re: dates in excess of 2037 (A Problem???)
Message-Id: <90ktr7v5.fsf@mailhost.panix.com>
Lloyd Zusman <ljz@asfast.com> writes:
> Just out of curiosity, do you know their rationale for choosing
> 17-nov-1858 as the beginning of the epoch?
http://www.slac.stanford.edu/~rkj/crazytime.txt
> perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
> $t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
> $x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
LOL.
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
http://pobox.com/~jdf/
------------------------------
Date: Thu, 13 Aug 1998 00:20:16 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: exit code of pipe
Message-Id: <Pine.GSO.4.02.9808121716450.10161-100000@user2.teleport.com>
On Wed, 12 Aug 1998, Bruce Mohler wrote:
> I'm trying to capture the exit code of a pipe. I've checked the Blue
> Camel and Perl FAQ without finding an answer yet.
It's the return value from close() on the pipe. Of course, that's usually
going to be the exit code of the shell which started the sub-process, so
that's another ball of wax. It may be that you'll want to use code like
that which I posted earlier today under the subject line, "Re: How to test
for failed command open useing FileHandle".
news:Pine.GSO.4.02.9808120833000.10161-100000@user2.teleport.com
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 12 Aug 1998 19:51:49 -0400
From: Ketan Patel <ketanp@NOSPAMxwebdesign.com>
Subject: Re: File updating question
Message-Id: <35D22A95.8307D860@NOSPAMxwebdesign.com>
>
> > open(DATA, ">$datapath")
> > || print ("Son, it's not my fault.");
> > flock(DATA, 2);
>
> That's not a good way to cooperate with other processes. If another
> process were writing that file, you just clobbered it!
>
Can you further explain this statement? How would this ruin the file if
every other call to open the file also has an exclusive lock?
------------------------------
Date: Wed, 12 Aug 1998 20:47:49 -0400
From: "Ha" <REPLY_TO_lastronin@earthlink.net>
Subject: Re: File updating question
Message-Id: <6qtcf8$qla$1@holly.prod.itd.earthlink.net>
Ketan Patel wrote in message <35D0EB06.F7457814@NOSPAMxwebdesign.com>...
>Tom Phoenix wrote:
>
>>
>> > @databaseArray = <DATA>;
>> > close(DATA);
>>
>> Uh oh. If you meant to keep that lock, this isn't going to work!
>>
>
>This is part of my problem... As you can see in the original code, I
>read in the whole file (as an array), go to each line (~100), split it
>into another array (of 12 elements) and modify it. Then, I write the
>whole modified array back to the file (overwriting the previous data).
>What is a more efficient way of doing this? Doing it the way I am now
>(open input,read data,close input ---> modify data ---> open
>output,write data,close output)?
use your judgment. use the Benchmark module to time how long the 2 different
methods took. do a number of tests. IMHO, you should try both methods and
learn the new one for future use on larger files. if you feel the time
difference is negligible, go with slurping.
Or should I leave the file open the
>entire time (open input,read data,modify data,write data,close input)?
leave the file open. it's not hurting anyone. remember, the stuff is already
compiled upon execution (oh, i guess that's why they call it compiled!). the
same datafile can be opened a billion times simultaneously if it's a simple
read.
>If the second method is recommended, I'm not quite sure how to go line
>by line (as recommended earlier) and make changes without reading in the
>whole array in the beginning...
didn't i post something to the effect? or is the clock on my computer
forboding an easter egg disaster?
ouch!
ha
mailto:info@r-go.com
------------------------------
Date: Wed, 12 Aug 1998 19:42:05 -0500
From: seekersm@flash.net (The Seeker)
Subject: flock on NT
Message-Id: <MPG.103bf253c96d1f89989680@news.flash.net>
Can any one tell me how to do an flock on an NT server?
------------------------------
Date: Wed, 12 Aug 1998 19:49:56 -0500
From: Nicholas Ritter <ritter@lfc.edu>
Subject: how to
Message-Id: <35D23831.EB869767@lfc.edu>
I am have an array element that contians a 12 digit, alphanumeric,
case-insentive string (to be more specific, it is an ethernet address,
but without the colons).
I am new to perl, and I can't seem to figure out a way to get perl to
take the array element, and insert a colon every two characters.
Here is an example of what I have, and what I want perl to do with it:
someArray[1] = 008894fg7t44
I want perl to change it to:
someArray[1] = 00:88:94:fg:7t:44
Is Perl capable of doing this? And if so, can somebody demonstrate it to
me? I have approx. 1500 Ethernet addresses that must be converted. If I
can't get it done with Perl, I will have to rewrite everything in Java
('cause I know Java can do it).
Also, how can I take an array element and flip it arround. For instance:
someArray[1] = 2.1
And convert it to:
someArray[1] = 1.2
Thanx in advance for any help that anyone can give me.
Sincerely,
Nick
------------------------------
Date: Wed, 12 Aug 1998 23:03:35 GMT
From: sherman@unx.sas.com (Chris Sherman)
Subject: Match '$a' in regexp--can't do it
Message-Id: <ExLMpz.EvC@unx.sas.com>
I can't find a way to match the pattern '$a' (in a regular
expression and replace it with something else.
In the following example, I'm trying to replace '$a' with 'b'.
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
#!/usr/local/bin/perl5
$line1=$line2=$line3=$line4 = '$a';
$a="abc"; # make $a something other than a blank, which changes
# the output of the following lines
$line1 =~ s/$a/b/;
print "slashes : $line1\n";
$line2 =~ s'$a'b';
print "single quotes : $line2\n";
$line3 =~ s/\Q$a\E/b/;
print "\\Q \\E w/ slashes : $line3\n";
$line4 =~ s'\Q$a\E'b';
print "\\Q \\E w/ single quotes : $line4\n";
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The output is:
slashes : $a
single quotes : $a
\Q \E w/ slashes : $a
\Q \E w/ single quotes : $a
None of these got converted to a 'b'.
Of course, doing something like this works:
$line =~ s/\$a/b/;
But that isn't the point. :-) According to the docs, the \Q \E trick, or
using single quotes (or both maybe) should have worked, but they didn't.
Anyone know what I'm missing? Pointers to the FAQ or any of the docs are
much appriciated. However, I found "How can I quote a variable to use in a
regexp?", but I covered that answer above (right?) and it didn't work.
Side note: To make things interesting, replace the $a="abc" with $a='$a'
(that is, make it so that $a is replaced with $a and then evaluated. Then
"\Q \E w/ slashes" converts $a to b. Too weird--why doesn't this trick
with with regular "slashes".
Thanx for any help.
--
____/ / / __ / _ _/ ____/
/ / / / / / / Chris Sherman
/ ___ / _/ / /
_____/ __/ __/ __/ _\ _____/ _____/ sherman@unx.sas.com
------------------------------
Date: 12 Aug 1998 23:49:04 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Match '$a' in regexp--can't do it
Message-Id: <6qt9lg$8so$6@marina.cinenet.net>
Chris Sherman (sherman@unx.sas.com) wrote:
: I can't find a way to match the pattern '$a' (in a regular
: expression and replace it with something else.
Do you mean to replace the value contained in $a with something else, or
to replace the literal string '$a'?
Replace value: $line =~ /\Q$a/b/;
Replace literal: $line =~ /\$a/b/;
: In the following example, I'm trying to replace '$a' with 'b'.
:
: vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
: #!/usr/local/bin/perl5
No -w ?
: $line1=$line2=$line3=$line4 = '$a';
: $a="abc"; # make $a something other than a blank, which changes
: # the output of the following lines
:
: $line1 =~ s/$a/b/;
: print "slashes : $line1\n";
That says 'substitute in the value of $a in the match part, and replace
the result with b. The value of $a is 'abc'. The value of $line1 is
'$a', so it doesn't match 'abc'. Hence, no change. Using s/\$a/b/ would
work.
: $line2 =~ s'$a'b';
: print "single quotes : $line2\n";
This is a tricky one. The single-quotes make $a be used literally as the
pattern, but notice that $ is a regex metacharacter. So instead of
matching dollar-sign-then-a, this matches end-of-line-then-b. Using
s'\$a'b' would work.
: $line3 =~ s/\Q$a\E/b/;
: print "\\Q \\E w/ slashes : $line3\n";
That substitutes in the value of $a ('abc'), then does quotemeta on that
value (a no-op in this case). Thus, it acts the same as the $line1
version.
: $line4 =~ s'\Q$a\E'b';
: print "\\Q \\E w/ single quotes : $line4\n";
\Q doesn't work in a single-quotish context, which this is.
: The output is:
: slashes : $a
: single quotes : $a
: \Q \E w/ slashes : $a
: \Q \E w/ single quotes : $a
:
: None of these got converted to a 'b'.
Well, glad to see Perl behaves as documented. :)
: Of course, doing something like this works:
: $line =~ s/\$a/b/;
Ah, didn't see you'd already found this when I started answering above.
: But that isn't the point. :-) According to the docs, the \Q \E trick, or
: using single quotes (or both maybe) should have worked, but they didn't.
Hope my explanations above have shown you why this isn't so.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 13 Aug 1998 00:15:55 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: need help making WBT system
Message-Id: <Pine.GSO.4.02.9808121715090.10161-100000@user2.teleport.com>
On Wed, 12 Aug 1998, J Nicholas Tolson wrote:
> I have been put in charge of making a web-based training system for my
> company.
Cool. The docs, FAQs, and newsgroups about the web and related issues
should be of some help to you. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Aug 1998 23:02:30 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Opening a file as "+>>file"
Message-Id: <6qt6u6$8so$5@marina.cinenet.net>
Phil Taylor (phil@ackltd.demon.co.uk) wrote:
: I read somewhere that if you open a file as follows:-
:
: open HANDLE, "+>>file1" || do something on fail
You either need parens around the open args, or to use 'or' rather than
'||'.
Can't comment on the other part, however.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: 12 Aug 1998 23:16:15 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Opening a file as "+>>file"
Message-Id: <6qt7nv$g02$1@csnews.cs.colorado.edu>
[courtesy cc of this posting sent to cited author via email]
In comp.lang.perl.misc,
phil@ackltd.demon.co.uk (Phil Taylor) writes:
:I read somewhere that if you open a file as follows:-
:
:open HANDLE, "+>>file1" || do something on fail
:
:the length of the record written back to the file MUST be the same
:length as the original record length.
No, if you open a file that way, you are probably doing the wrong thing.
Why do you want to be able to read at any point in the file, but then
to slam your seek pointer through the end every time you write to it?
Nobody understands I/O. Grr...
--tom
--
"The young think they are immortal, and are determined to prove otherwise."
--Larry Wall
------------------------------
Date: 12 Aug 1998 16:25:05 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: passing a hash to a method
Message-Id: <m3k94du6jy.fsf@windlord.Stanford.EDU>
Brian <hochgurt@fsl.noaa.gov> writes:
> I'm trying to pass a hash to a method in an OO perl program I am
> writing. Once I pass the hash to the method, the $key and the
> $Tokens{$key} values appear to be switched (so that the $key var has the
> actual value of what $Tokens{$key} should have). I can't seem to figure
> out why, but I suspect that it has to do with an object in PERL being a
> hash as well.
It's because you made an incorrect assumption about what arguments are
actually getting passed to your sub.
> I have tried to pass by reference without much luck.
That would be the better way to do it.
> $atmos->printout(%SubTokens);
Okay, the printout sub is going to get as its arguments a reference to its
object (the first argument to a method is *always* a reference to its
object), and then, as a list, the keys and values of the hash in the form
'key1', 'value1', 'key2', 'value2', etc.
> sub printout {
> local(%Tokens) = @_; #tried my as well
So you just associated the stringification of the object reference with
the first key in your hash as the first key value pair in your local
%Tokens hash, which is definitely not what you want. And the rest of your
associations will have an off-by-one error.
What you wanted was this:
my ($self, %tokens) = @_;
which would do what you want. But what you *really* want to do is this:
$atmos->printout (\%subtokens);
and then:
sub printout {
my ($self, $tokens) = @_;
for $key (keys %$tokens) {
print "Key:$key $$tokens{$key} <br>\n";
}
}
and then you don't make a needless copy of your hash. See man perlref for
more details on how references work.
--
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print
------------------------------
Date: 12 Aug 1998 16:48:49 -0700
From: Scott Henry <scotth@sgi.com>
Subject: Re: Perl 5.005.1 core dumps under Irix 6.2
Message-Id: <yd8r9ylhice.fsf@hoshi.engr.sgi.com>
>>>>> "G" == Greg Bacon <gbacon@cs.uah.edu> writes:
>>>>> "O" == Oliver Laumann <net@informatik.uni-bremen.de> writes:
O> Has anybody managed to successfully compile Perl 5.005.1 under Irix
O> 6.2 using cc -n32 (on an IP-22 machine)?
G> In article <yd8emumi32o.fsf@hoshi.engr.sgi.com>,
G> Scott Henry <scotth@sgi.com> writes:
:
: Most definitely. What compiler version are you using? Perl found
: some optimizer bugs in pre-7.2.1 compilers, one of them during the
: 5.005 alphas. The fix made it into the 7.2.1 compilers.. As long as
: you didn't override the hints file, which reduces optimization for
: the cases which were tested...
G> I wonder whether the optimization level shouldn't be turned down for
G> toke.c too. cc -n32 -O3 toke.c ends up sucking in about 40 Mb
G> (according to gmemusage) and takes forever (v7.1 compiler, BTW).
G> Does this problem show up with later versions?
You can compile all objects -O3 with the 7.2.1 compilers for all of
perl5.005, 5.005_01 and 5.005_02. I know that you have to reduce the
optimization on some objects for older compilers, but it's been a
long time since I ran them myself... The space used by `be` for
optimizing is ~ independent of the compiler rev. Higher optimization
just uses more and bigger data structures, and toke.c has some BIG
functions. "-OPT:Olimit=0" tells the optimizer to optimize a
function no matter how big it is.
--
Scott Henry <scotth@sgi.com> / Help! My disclaimer is missing!
IRIX MTS, / GIGO *really* means: Garbage in, Gospel Out
Silicon Graphics, Inc / http://reality.sgi.com/scotth/
------------------------------
Date: Thu, 13 Aug 1998 10:25:51 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Perl Docs.. forget the original post
Message-Id: <35D2328F.93902A44@spider.herston.uq.edu.au>
Bart Lateur wrote:
>
> Jaime Metcher wrote:
>
> >I've seen people on this ng get annoyed when people ask a
> >question about something that is already explained in (for example):
^^^^^^^^^^^
<snip>
> The first doc I always look at is perlfunc. You seem to have forgotten
> about that one.
>
> perlre is for regular expressions, perlop is for operators, perlfunc is
> for functions. Not every problem in Perl is a regular expression
> problem!
>
--
Jaime Metcher
------------------------------
Date: Wed, 12 Aug 1998 23:52:23 GMT
From: marco@infnet.com.br (Marco Goncalves)
Subject: Perl script interaction with external application
Message-Id: <35d22a6c.2602523@cnews.newsguy.com>
Hello all,
I have a question that I would really appreciate some help:
Is it possible for a Perl script to interact directly (not using
something like a telnet/socket) with an external application (like a
Cobol program running on a Dos/Netware environment)?
The Perl script would call the app and interact with it like a user
would do it. A user that calls the application interacts with it
making numbered choices. Example: the user would press 1, then press
3, input some info and then the application would return some data.
The goal is for the perl script act as a user and return the returned
data (by the app) for the browser that is accessing the Perl script.
Is there some way of doing this only using plain Perl or there is
some module that does it? This Perl script is supposed to run on
Windows NT.
If someone can help me clarify this subject I would be very thankful.
(Please send answer with a copy to my address)
Regards,
Marco Goncalves
marco@infnet.com.br
------------------------------
Date: Wed, 12 Aug 1998 15:59:51 -0700
From: Brian Tiemann <briant@packeteer.com>
Subject: Re: print() acting strangely on Win32
Message-Id: <35D21E67.317DC115@packeteer.com>
Brian Tiemann wrote:
> Unix: 0a0d0d0d
> Windows: 0d0a0d0d0d
Er, excuse me. Make that:
Unix: 0a0d0d
Windows: 0d0a0d0d
I can count. Really. :)
Brian
------------------------------
Date: 12 Aug 1998 22:57:26 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: print() acting strangely on Win32
Message-Id: <6qt6km$8so$4@marina.cinenet.net>
Brian Tiemann (briant@packeteer.com) wrote:
[snip]
: The problem: print() works just fine on Unix, printing out each
: character as it comes in, without translation. However, on Win32, it
: converts all the line-feed characters (0a) to CR/LF combinations (0d0a).
: I don't want it to do that-- this is binary data that gets screwed up
: easily. :)
[snip]
perldoc -f binmode
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Thu, 13 Aug 1998 00:01:52 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Q: How to read a file piece by piece
Message-Id: <Pine.GSO.4.02.9808121656070.10161-100000@user2.teleport.com>
On Wed, 12 Aug 1998, TeXaS wrote:
> sub Send_As_tgz {
> system("$TAR -C $Rwhere -czf /tmp/tar-em.pl.$pid.tgz $who");
It may not make any difference, but it's possibly better to call system
with a list of args, so that there won't be any chance of shell
metacharacters being (mis)interpreted.
> open (TEMPFILE, "/tmp/tar-em.pl.$pid.tgz");
Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.
> unlink ("/tmp/tar-em.pl.$pid.tgz");
Rather than use the same (long) filename in many places, store it into a
variable. That's not just more efficient; it's more reliable if you ever
have to switch to /var/tmp, for example, or change its name for any other
reason.
> print "Content-Type: application/zip\n";
> print "Content-Disposition: attachment; filename=\"$file_name.tgz\"\n\n";
> print <TEMPFILE>;
Instead of gulping the whole thing and printing it, you could read() it in
blocks of, say, 8192 bytes at a time. (Also, you could let tar and your
program run in parallel, by using a pipe. That would eliminate the need
for creating and destroying the temp file, as an extra bonus.)
> close (TEMPFILE);
> }
Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 13 Aug 1998 00:29:50 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Q: How to read a file piece by piece
Message-Id: <6qtc1u$1nv$2@client3.news.psi.net>
TeXaS (pswaters@eos.ncsu.edu) wrote on MDCCCVII September MCMXCIII in
<URL: news:Pine.SOL.3.96.980812150809.29406A-100000@cc02du.unity.ncsu.edu>:
++ I have setup a Perl script that will allow someone to download a directory
++ or few via HTTP as a tgz or zip file. One problem that I have hit is that
++ I don't know of a way to load the tgz or zip file piece by piece as it is
++ being delivered to keep the entire file from being loaded into memory
++ all at once. I have included this section of code so anyone can make
++ suggestions on what to do. Thanks
The fine manual tells you about that. Grep for 'read' in the manual.
But why bother? Any decent implementation of tar happily writes to STDOUT.
sub Send_As_tgz {
print "Content-Type: application/zip\n";
print "Content-Disposition: attachment; filename=\"$file_name.tgz\"\n\n";
system $TAR, '-C', $Rwhere, 'czf', '-', $who;
}
Abigail
--
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
${qq$\x5F$} = q 97265646f9 and s g..g;
qq e\x63\x68\x72\x20\x30\x78$&eggee;
{eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'
------------------------------
Date: Thu, 13 Aug 1998 00:12:55 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: RE engine vs. Perl
Message-Id: <Pine.GSO.4.02.9808121708140.10161-100000@user2.teleport.com>
On 12 Aug 1998, Ilya Zakharevich wrote:
> [A complimentary Cc of this posting was sent to Tom Phoenix
> <rootbeer@teleport.com>],
> who wrote in article <Pine.GSO.4.02.9808121309170.10161-100000@user2.teleport.com>:
> > I have a hard time believing that the difference will be enough to notice
> > on any real-world program, but you're welcome to prove me wrong! :-)
>
> My conjecture would be that for moving the logic from Perl to the RE
> engine the speedup up to a couple of orders of magnitude may be
> expected.
Of course, that's a different "difference" than I was talking about. I was
talking about the difference between one non-matching pattern and another.
IMHO, if you've got a pattern which will never match anything (say,
/\b\B/) in a real-world program, replacing that pattern with another
pattern which will never match anything (say, /(?!)/) is going to be just
about as fast. (The exception would, of course, be pathological
"million-year" patterns, of course.)
That is, if the program takes three days to run with one, it'll take three
days with the other, give or take a few minutes.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 12 Aug 1998 23:53:26 GMT
From: Jeremy Thompson <jthompso@writeme.com>
Subject: recommended value for $d_lstat
Message-Id: <35D22AF5.2A81E162@writeme.com>
When I was running "Configure" to build 5.005_51 on my i686-linux box
(glibc6, egcs-2.90.29), I got the following message?
*** WHOA THERE!!! ***
The recommended value for $d_lstat on this machine was "define"!
Keep the recommended value? [y]
what the heck do I say?
Please e-mail or post replies.
--
"We have to move fast to do something about
these monkeys because the people here are
scared to death," -- a Japanese official
commenting on an incident where a pack of
wild monkeys swooped down and attacked
passers-by in a Japanese seaside town,
injuring 26 people, January 27, 1998.
--
Jeremy Thompson
mailto:jthompso@writeme.com
------------------------------
Date: Thu, 13 Aug 1998 00:03:38 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: trying to execute a perl script using server side include - help!
Message-Id: <Pine.GSO.4.02.9808121702400.10161-100000@user2.teleport.com>
On Wed, 12 Aug 1998 st6hu@jetson.uh.edu wrote:
> I'm trying to execute a perl script through a server-side include.
You do it the same way you execute a FORTRAN program through a server-side
include. The docs, FAQs, and newsgroups about servers should be able to
help you with this. Good luck!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 12 Aug 1998 23:01:17 GMT
From: phil@ackltd.demon.co.uk (Phil Taylor)
Subject: Re: use strict problem with indirect file variables ?
Message-Id: <35d21e9d.926055@news.demon.co.uk>
On Wed, 12 Aug 1998 00:41:43 -0400, rjk@coos.dartmouth.edu (Ronald J
Kimball) wrote:
>Phil Taylor <phil@ackltd.demon.co.uk> wrote:
>
>> I bet you don't fully understand how your car works, but you still use
>> it.
>
>Let's consider the difference between driving a car and building a car.
>
>Now let's consider the difference between using a Perl program and
>writing a Perl program...
>
Let's Not!
------------------------------
Date: Thu, 13 Aug 1998 00:07:46 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Using PERL5 with NT4 Peer Web Services
Message-Id: <Pine.GSO.4.02.9808121705590.10161-100000@user2.teleport.com>
On Wed, 12 Aug 1998, Dan S. Levine wrote:
> When my link uses a .pl or .cgi script from the client to the
> server i get the .pl file returned to me in NOTEPAD instead of
> processing on the server and returning to me the scripts output.
That's because your browser isn't running the script. That's to be
expected; it's used to a _server_ running the script. The docs, FAQs, and
newsgroups about browsers, servers, and related issues should be able to
help you with this.
Of course, if you wrote the program in Perl, and if you used the CGI.pm
module (or a similar one), it's probably easy to test your script from the
command line, no server needed. Hope this helps!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3433
**************************************