[8278] in Perl-Users-Digest
Perl-Users Digest, Issue: 1895 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 13 23:08:20 1998
Date: Fri, 13 Feb 98 20:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 13 Feb 1998 Volume: 8 Number: 1895
Today's topics:
Re: auto responder script <rra@stanford.edu>
Re: Basic File Manipulation <cybersky@generation.net_no_spam>
Re: Basic File Manipulation <cybersky@generation.net_no_spam>
Re: Beauty <dformosa@st.nepean.uws.edu.au>
Re: Clearing all variables (Jonathan Feinberg)
exec() || spawn() ? to multithread on NT <peter@uhu.com>
Re: FAQless Forgays <dformosa@st.nepean.uws.edu.au>
Re: foreach and my() [GUTS; LONG] <dgoddard@us.oracle.com>
formating a text file (hard returns)? (John Davidson Highfill)
Re: Help: "use strict" & passing variables to subroutin <zenin@best.com>
Re: help: Question on hash ref <beans@bedford.net>
Re: Killfile Triage (Nicholas Carey)
Re: on reading FAQs and gurus answering questions <merlyn@stonehenge.com>
Re: perl pointer puzzle <chris@ixlabs.com>
Re: Printing $query->param in a here-doc? <tom@moertel.com>
Problems with Comm.pl on OSF1 <asehbai@osf1.gmu.edu>
Re: Quickie: regexp for valid e-mail addresses <merlyn@stonehenge.com>
Re: Syntax question <beans@bedford.net>
Re: Testing integer <beans@bedford.net>
Re: The Young Man and the Beach (Mark Kramer)
Re: The Young Man and the Beach (Mark Kramer)
Truncate <dan@dmf.net>
Re: Using flock? <merlyn@stonehenge.com>
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Feb 1998 18:16:57 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: auto responder script
Message-Id: <m367mjx752.fsf@windlord.Stanford.EDU>
Shimpei Yamashita writes:
> man procmail
> man procmailex
> It could be done with a perl script, but don't bother reinventing the
> wheel.
I recommend *against* using the autoresponder example in procmailex for
the following reasons:
(a) formail's reply code is broken. It should follow RFC 822 and look
solely at Reply-To and then From to determine what address to
respond to. It doesn't. It applies a bunch of heuristics to look
for "right-looking" addresses and can potentially reply to Sender
(which is *totally* wrong).
(b) The given example is nowhere *close* to sufficient to prevent mail
looping. X-Loop headers are sufficient to keep you from responding
to yourself, but they're not sufficient to prevent more complex
loops.
There was some discussion of this recently on the qmail mailing list, and
the general list of things one wants to do with an autoresponder are:
* Ensure that the reply address on the mail that you send points to
something *other* than the autoresponder address. *Every reply must
be escalated towards a system that takes no automatic action.* That's
the key to keep in mind when writing automated response systems to
prevent looping.
* Fix your envelope sender so that if the reply bounces or generates
automatic replies to the envelope sender, those replies don't cause
looping. One way to do that is to give autoreplies a null envelope
sender (<>), which causes them to be treated like bounces but which
may result in postmaster seeing double-bounces. Another way is to
set the envelope sender to a user who silently discards all mail, such
as the quasi-standard nobody user.
* Don't reply to obvious bad addresses (majordomo, listproc, listserv,
and possibly /^owner-.*/ and /.*-owner$/).
* Even given all of that, it's probably still worthwhile to implement at
least some form of simple throttling, probably along the lines of
keeping track of who one has sent mail to and not repeating.
This is not to say that procmail can't be used. It might be a good tool.
This is just to say that the example given in the man pages is dangerously
inadequate.
--
#!/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: Sat, 14 Feb 1998 09:17:20 +0000
From: Amine <cybersky@generation.net_no_spam>
Subject: Re: Basic File Manipulation
Message-Id: <34E56120.4908@generation.net_no_spam>
Hello ,
I have faced the same problem two days ago and here is what i wrote
if you are using Unix delete a line (see my code) .
Note that i have send some question to Chritiansen to see if there is
any way to speedup this code,cause for 10Mo+ it will be too slow to
generate the index.txt file :(
My next idea is to write the index generation in C this will speed
up the things,note also that this code is still in an alpha stage so
i am still changing it .
here it is,and if there is any suggestion feel free to send me an
email.
Thank you
Amine Moulay Ramdane
#<=== Begin===>
################################################
# 1997-1998 #
# Code(Alpha): AccessIt.pl version 0.1 #
# Name: Amine Moulay Ramdane #
# Compagny: CyberNT Communications #
# Email: aminer@generation.net #
# Phone:(514)4856659 #
################################################
# Note: try to test it first with a file of 1Mo
# you will notice that for a file more than 10M+ it
# will be too slow to generation the index.txt
# hope someone will tell me how to speedup the generation
# of the index.txt without rewritting some parts in C .
# Thank you.
sub ArrayIndexSize #Return the size of the index file
{
$Separator = $/;
$/ = ' ';
local($File) = @_;
local (@list);
open(Index,$File) || die "\nCouldn't open $FILE : $!\n";
local(@list) = <Index>;
$c = scalar(@list);
close(Index) ;
$/ = $Separator;
return($c);
}
sub AccessLine #Access the line of the index file
{
local($LineNumber,$Index,$File,$ArrayAddress) = @_;
$a = scalar(@$ArrayAddress);
open(FILE,$File) || die "\nCouldn't open $$FILE : $!\n";
seek(FILE,$$ArrayAddress[$LineNumber],0);
$/ = $Separator;
$line = <FILE>;
chop($line);
return($line);
close(FILE);
close(Index);
}
sub RecordIndexLines # Record the indexes on a file
{
local($File,$List) = @_;
splice(@$List,$size-1,1);
open(MGRFILE,">$File") || die "\nCouldn't open $$FILE : $!\n";
$RecordList = join(' ',@$List);
print MGRFILE $RecordList;
print qq(\n$File has been generated.\n);
print qq(Please run again the script Thank you...\n);
close(MGRFILE);
}
sub IndexLines # Index the lines of the file
{
local($FILE) = @_;
local(@list);
$i = 0;
$a = '';
open(MGRFILE,"$$FILE") || die "\nCouldn't open $$FILE : $!\n";
push(@list,$i);
while (!eof(MGRFILE))
{
seek(MGRFILE,$i,0);
read(MGRFILE,$a,1);
if ($a eq "\n")
{
$i++; #<==== Delete this for Unix
push(@list,$i+1);
}
$i++;
}
return @list;
}
$filename = 'amine' ; # Put here the name of your file
$IndexFile = 'index.txt'; # Our index.txt file
if (-e "index.txt")
{
$Separator = $/;
$/ = ' ';
open(Index,"index.txt") || die "\nCouldn't open $$FILE : $!\n";
@list = <Index>;
$/ = $Separator;
$a = scalar(@list);
#$a = &ArrayIndexSize($IndexFile);
#print qq($a\n);
srand(time() ^ ($$ + ($$ << 15)));
$iterations=$i=100; #<=== 100 Iterations set it to what you want
while($i--)
{
$RandomLine = (int(rand($a-1))+1);#<=== This is for a demonstration
$l = AccessLine($RandomLine,$IndexFile,$filename,\@list);
print "Line $RandomLine:$l\n";
sleep(1); #<=== For demonstration
}
}
else
{
print qq(\nPlease wait while generating the indexes...\n);
@list = &IndexLines(\$filename);
RecordIndexLines($IndexFile,\@list);
}
close(MGRFILE);
close(Index);
<====End===>
KHeise wrote:
>
> I am a new Perl user with some prior programming knowledge, and so far I just
> love it. There are a couple of questions I have about manipulating and
> outputting I have.
>
> Background: I am dealing with very large, fixed length data files (500M+ -
> 1,000,000+ records (lines)).
>
> Question 1: Luckily our company appends a CRLF (carriage-return line-feed) at
> the end of each record (line) even though we don't really need it, so it has
> been easy for me to isolate records (lines), but there are times when I wont
> want to use the CRLF as a record delimiter. I will want to define the records
> according to x number of bytes (i.e.record1 = byte 0 - 199, record2 = 200-399,
> etc.). It seems like an easy problem, but I can't figure out a clean,
> efficient, and **fast** to deal with a file in this manner.
>
> Question 2: I want to reverse the lines in a large file.
> (i.e. File = "AA""AB""AC""AD"- Reversed File = "AD""AC""AB""AA"). Is there an
> easy way to do this? Remember, these files are pretty huge, so I can't simply
> reverse the contents of a list(I think).
>
> Question 3: How do you return the number of bytes in a file?
>
> Any comments, code, advice, etc. would be greatly appreciated. I'm really
> exited about Perl and I could use all the help I can get to improve my
> programming skills.
>
> Jay
>
> e-mail addr - kheise@pgicompanies.com
------------------------------
Date: Sat, 14 Feb 1998 09:24:00 +0000
From: Amine <cybersky@generation.net_no_spam>
Subject: Re: Basic File Manipulation
Message-Id: <34E562B0.2064@generation.net_no_spam>
ello ,
I have faced the same problem two days ago and here is what i wrote
if you are using Unix delete a line (see my code) .
Note that i have send some question to Chritiansen to see if there is
any way to speedup this code(still waiting),cause for 10Mo+ it will be
too slow to generate the index.txt file :(
My next idea is to write the index generation in C this will speed
up the things,note also that this code is still in an alpha stage so
i am still changing it .
here it is,and if there is any suggestion feel free to send me an
email.
Thank you
Amine Moulay Ramdane
#<=== Begin===>
################################################
# 1998-1999 #
# Code(Alpha): AccessIt.pl version 0.1 #
# Name: Amine Moulay Ramdane #
# Compagny: CyberNT Communications #
# Email: aminer@generation.net #
# Phone:(514)4856659 #
################################################
# Note: try to test it first with a file of 1Mo
# you will notice that for a file more than 10M+ it
# will be too slow to generation the index.txt
# hope someone will tell me how to speedup the generation
# of the index.txt without rewritting some parts in C .
# Thank you.
sub ArrayIndexSize #Return the size of the index file
{
$Separator = $/;
$/ = ' ';
local($File) = @_;
local (@list);
open(Index,$File) || die "\nCouldn't open $FILE : $!\n";
local(@list) = <Index>;
$c = scalar(@list);
close(Index) ;
$/ = $Separator;
return($c);
}
sub AccessLine #Access the line of the index file
{
local($LineNumber,$Index,$File,$ArrayAddress) = @_;
$a = scalar(@$ArrayAddress);
open(FILE,$File) || die "\nCouldn't open $$FILE : $!\n";
seek(FILE,$$ArrayAddress[$LineNumber],0);
$/ = $Separator;
$line = <FILE>;
chop($line);
return($line);
close(FILE);
close(Index);
}
sub RecordIndexLines # Record the indexes on a file
{
local($File,$List) = @_;
splice(@$List,$size-1,1);
open(MGRFILE,">$File") || die "\nCouldn't open $$FILE : $!\n";
$RecordList = join(' ',@$List);
print MGRFILE $RecordList;
print qq(\n$File has been generated.\n);
print qq(Please run again the script Thank you...\n);
close(MGRFILE);
}
sub IndexLines # Index the lines of the file
{
local($FILE) = @_;
local(@list);
$i = 0;
$a = '';
open(MGRFILE,"$$FILE") || die "\nCouldn't open $$FILE : $!\n";
push(@list,$i);
while (!eof(MGRFILE))
{
seek(MGRFILE,$i,0);
read(MGRFILE,$a,1);
if ($a eq "\n")
{
$i++; #<==== Delete this for Unix
push(@list,$i+1);
}
$i++;
}
return @list;
}
$filename = 'amine' ; # Put here the name of your file
$IndexFile = 'index.txt'; # Our index.txt file
if (-e "index.txt")
{
$Separator = $/;
$/ = ' ';
open(Index,"index.txt") || die "\nCouldn't open $$FILE : $!\n";
@list = <Index>;
$/ = $Separator;
$a = scalar(@list);
#$a = &ArrayIndexSize($IndexFile);
#print qq($a\n);
srand(time() ^ ($$ + ($$ << 15)));
$iterations=$i=100; #<=== 100 Iterations set it to what you want
while($i--)
{
$RandomLine = (int(rand($a-1))+1);#<=== This is for a demonstration
$l = AccessLine($RandomLine,$IndexFile,$filename,\@list);
print "Line $RandomLine:$l\n";
sleep(1); #<=== For demonstration
}
}
else
{
print qq(\nPlease wait while generating the indexes...\n);
@list = &IndexLines(\$filename);
RecordIndexLines($IndexFile,\@list);
}
close(MGRFILE);
close(Index);
<====End===>
KHeise wrote:
>
> I am a new Perl user with some prior programming knowledge, and so far I just
> love it. There are a couple of questions I have about manipulating and
> outputting I have.
>
> Background: I am dealing with very large, fixed length data files (500M+ -
> 1,000,000+ records (lines)).
>
> Question 1: Luckily our company appends a CRLF (carriage-return line-feed) at
> the end of each record (line) even though we don't really need it, so it has
> been easy for me to isolate records (lines), but there are times when I wont
> want to use the CRLF as a record delimiter. I will want to define the records
> according to x number of bytes (i.e.record1 = byte 0 - 199, record2 = 200-399,
> etc.). It seems like an easy problem, but I can't figure out a clean,
> efficient, and **fast** to deal with a file in this manner.
>
> Question 2: I want to reverse the lines in a large file.
> (i.e. File = "AA""AB""AC""AD"- Reversed File = "AD""AC""AB""AA"). Is there an
> easy way to do this? Remember, these files are pretty huge, so I can't simply
> reverse the contents of a list(I think).
>
> Question 3: How do you return the number of bytes in a file?
>
> Any comments, code, advice, etc. would be greatly appreciated. I'm really
> exited about Perl and I could use all the help I can get to improve my
> programming skills.
>
> Jay
>
> e-mail addr - kheise@pgicompanies.com
------------------------------
Date: 14 Feb 1998 02:41:04 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Beauty
Message-Id: <887424023.245829@cabal>
In <34e4ec3a.361799583@nntp.usit.net> jnorman2@usit.net writes:
[...]
>Please post your opinions, especially if you have an opinion that is
>contrary to either of the above choices.
When we are talkig about beauty in programing we must first pay attention
to its context. A YAPH script has a diffrent estactic intnet then
anouther script.
In general however the baeuty of programing dervies somewhat from the
baeuty of mathmatics. So I would have to aggry with Mr Wall.
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep.
Support NoCeM http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Fri, 13 Feb 1998 18:42:11 -0500
From: jdf@pobox.com (Jonathan Feinberg)
Subject: Re: Clearing all variables
Message-Id: <MPG.f4ea461e079d7709896c3@news.concentric.net>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
Martien said...
> >Then you are NOT calling it as a seperate process. You would need
> >system, exec, backticks or qx// for that.
> >
> >perldoc -f require
> >
> >Please read.
> >Martien
elaine@lainer.com said...
>Why are some people so damned rude to others in here?
> Someone else was KIND enough to point me in the right direction politely and
> I have subsequently learned a great deal from his willingness to help.
Lainer - I can't parse Martien's reply as "rude." It's certainly
"terse," "brief," and "efficient." You said "I'm calling such-and-such
as a separate process using require" which is self-contradictory, and
Martien pointed that out, with several solutions and a reference to the
appropriate documentation.
"People, why are we fighting?" -- Mick Jagger
--
Jonathan Feinberg jdf@pobox.com Sunny Brooklyn, NY
------------------------------
Date: Thu, 12 Feb 1998 23:29:39 -0500
From: Peter Tapolyai <peter@uhu.com>
Subject: exec() || spawn() ? to multithread on NT
Message-Id: <34E3CC33.3903@uhu.com>
When I first developed my cgis I thought that the programwill work nice.
Wehn the next day I checekd the server, it was really slow with wuite a
few Perl processes running in an infinite loop.
Then I looked into multithreaded coding. So the question is:
is exec() correct on NT like this ?
exec(&shor_sub);
sub short_sub{
buncha_calls;
more calls;
&buncha_subs;
&adios;
}
This seemed to solve the problem of multiple users calling the same Perl
cgi at
the same time. After all exec() quites after the executed command, and
that is exactly
what I needed.
Appreciate some enlightement on this.
------------------------------
Date: 14 Feb 1998 02:55:33 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: FAQless Forgays
Message-Id: <887424892.743189@cabal>
In <6c1uth$mfv$1@cyprus.atlantic.net> chip@mail.atlantic.net (Chip Salzenberg) writes:
>According to Russ Allbery <rra@stanford.edu>:
>>I think people who use Usenet had better start getting used to the idea
>>that good posters are not necessarily a renewable resource ...
>>>quotes
>Where is Linus Torvalds? Where is Larry Wall?
Where is knuth? The 'net itself is a massive time sink, perhaps its not
the falt of this newsgroup, but of all the networks both internet and
usenet.
--
Please excuse my spelling as I suffer from agraphia see the url in my header.
Never trust a country with more peaple then sheep.
Support NoCeM http://www.cm.org/
I'm sorry but I just don't consider 'because its yucky' a convincing argument
------------------------------
Date: Fri, 13 Feb 1998 18:32:39 -0800
From: Denis Goddard <dgoddard@us.oracle.com>
Subject: Re: foreach and my() [GUTS; LONG]
Message-Id: <34E50247.C0D0C53D@us.oracle.com>
Chris Schoenfeld wrote:
>
> If you want to make your global variables a little safer you could put
> them in an object and only access them by methods like GetStatus and
> SetStatus.
So let's see...
put a variable in a package in a module...
make the variable part of a data structure...
bless a reference to that structure...
and only access it via get/set methods....
Translated to Perl (and pretty much right from FAQs and Panther):
package myobj;
$global_variable = 42;
sub new { return bless { attribute => \$global_variable } };
sub get { my $obj=$_[0]; return ${$obj->{'attribute'}} };
sub set { my $obj=$_[0]; my $val=$_[1];
return ${$obj->{'attribute'}}=$val; }
package main;
my $obj = new myobj;
my $foo = get $obj;
print "new foo: $foo\n";
set $obj 666;
$foo = get $obj;
print "set foo: $foo\n";
$myobj::global_variable="plugh"; # HA!!
$foo = get $obj;
print "Munged it globally: $foo\n";
Er, yes, that's much easier
-Denis
--
__ __ _ __ __
~~~~(__)|-< /-\(__ |__(-_ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Denis Goddard, Senior Member, Tech. Staff |"I see the heads of men arise
email: dgoddard@us.oracle.com |with hungry minds and open eyes!"
ourworld.compuserve.com/homepages/d_goddard| -Rush, from 2112: _The Oracle_
------------------------------
Date: 14 Feb 1998 03:22:03 GMT
From: davidson@unity.ncsu.edu (John Davidson Highfill)
Subject: formating a text file (hard returns)?
Message-Id: <6c32kr$bmr$2@uni00nw.unity.ncsu.edu>
Sorry for the vauge subject but i was wondering about formating text
files that are too wide. I have been trying to make up a perl script
(I am VERY new to perl, and programing in general)(If it makes a diff
i am using linux slackware) that would atuomatically format a text file
so that is is say 70 char long bout would not cut off words (rather hard
return and put them on the next line). thank you very much.
-Davidson
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
NAME: Davidson Highfill POSITION: Student Extrodinare
E-MAIL: davidson@unity.ncsu.edu or nature_boy@earthling.net
"The last bug isn't fixed until the last user is dead..."
When mailing me don't forget to take the 1st "n" out of my email address
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
------------------------------
Date: 14 Feb 1998 03:28:49 GMT
From: Zenin <zenin@best.com>
Subject: Re: Help: "use strict" & passing variables to subroutine
Message-Id: <887427190.678574@thrush.omix.com>
Tommy <tkho@technologist.com> wrote:
: Correct me if I am wrong. To do a variable passing between main and
: subroutine, the structure for Perl 4 is something like this:
>snip<
my() the %Q. Oh, and use a name longer then one char please. :-)
: my %Q= @_;
Yep, like that. Cool, thanks. :-)
: my $A= "TEST";
Hmm... $A is now a string
: $A->{FIRST}= 1; # equals to $$A{FIRST}= 1; I guess
You just nuked the string "TEST" out of $A and have made
$A a hash reference with a single key "FIRST" that has the
value 1.
: # equals to $$A{FIRST}= 1; I guess
Hmm, I'd have to test this as I feel the $$symble short cut should
be banded so I don't bother remembering what the precedence is. I
think however, that this is incorrect in that it would be (if memory
serves me) the same as ${ $A{FIRST} } = 1; which is dereferencing a
member of a hash %A, that does not exist.
: $A->{SECOND}= 2;
You're still a hash ref, but this is ok.
: # equals to *A= "TEST";
Forget type globs. Forget they exist. This is incorrect anyway,
and type globs will just confuse the issue.
: $A{SECOND}= 2; I guess
Nope, this is again the hash %A, that doesn't exist. $A does not
relate in anyway to %A or @A or A or A(). They are all different
symbols.
: $A= "TEST2";
Now you've nuked your hash reference (and therefor nuked it's data)
and have set the scalar $A to the string "TEST2".
: $A->{WHITE}= "FFFFFF";
: $A->{BLACK}= "000000";
Same as last time. You've nuked the string, and created yet another
new hash reference with two key/value pairs.
: $A= $Q{ARRAY};
And now you've nuked the hash ref and assigined the scalar value of
the key 'ARRAY' of the hash %Q to the scalar $A.
: return $$A{$Q{POS}};
Blah... And this is meant to meen what, exactly?
: sub RetVal4 {
: # for Perl 4
: my %Q= @_;
Can't be perl 4 and use a my(). :^)
: my $A= "TEST";
: $$A= ( FIRST => 1, SECOND => 2);
You're assigning a list to a dereferenced scalar that was a simple
string a moment ago. Maybe a quick read though perldsc and perllol
would help.
: $A= "TEST2";
You've nuked all the above.
: $$A= ( WHITE => "FFFFFF", BLACK => "000000");
Same as last time.
: $A= $Q{ARRAY};
You've nuked all of the above avain.
: return $$A{$Q{POS}};
This isn't doing what I think you think it's meant to do. But what
exactly it's meant to do I don't know either...
--
-Zenin
zenin@best.com
------------------------------
Date: 14 Feb 98 03:16:19 GMT
From: "TomH" <beans@bedford.net>
Subject: Re: help: Question on hash ref
Message-Id: <01bd38aa$80ac1940$129163ce@beans.bedford.net>
my %TEST= ...
"my" makes the variable %TEST out of scope inside the RetVal subroutine.
Tommy <tkho@technologist.com> wrote in article
<34E4F848.8E7BC70F@technologist.com>...
> I have a question on hash ref. For some reasons, the first script works
> but the second one.
<first script cut>
>
> #!/usr/local/bin/perl
> # This script does not work
> my %TEST= ( "FIRST" => 1, "SECOND" => 2 );
> my %TEST2= ( "WHITE" => "FFFFFF", "BLACK" => "000000" );
> my $VAL= &RetVal( ARRAY => "TEST", POS => "FIRST" );
> print $VAL; # exactly equal to print $TEST{FIRST};
>
> sub RetVal {
> my %Q= @_;
> $A= $Q{ARRAY};
> return $$A{$Q{POS}};
> }
>
> I really appreciate if some can help.
> --
>
> Tommy Ho
> ---------------------------------------------------------------
> Email: tkho@technologist.com
>
>
>
------------------------------
Date: Sat, 14 Feb 1998 02:00:39 GMT
From: a-bnc@microsoft.com (Nicholas Carey)
Subject: Re: Killfile Triage
Message-Id: <34e4f579.27781921@newsvr>
Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org> and Richard
Caley <spt@cstr.ed.ac.uk> both whined, about the same rule in a
killfile:
Shmuel> In <6bnv7o$n1g$1@csnews.cs.colorado.edu>, on 02/09/1998
Shmuel> at 10:16 PM, Tom Christiansen <tchrist@mox.perl.com> said:
Shmuel>
Shmuel> > Such "From" lines are not just a pain in the butt;
Shmuel> > they are also not legal, and I zap illegal messages.
Shmuel>
Shmuel> Sigh! Good advice costs nothing and it's worth the price. The
Shmuel> presence of "nospam" in an address does not mean that it is
Shmuel> munged, that it is illegal or even that it is undeliverable.
Shmuel> Anyone with half a clue would recognize that this filter will
Shmuel> hit valid addresses as well as the invalid ones.
[exceedingly long .sig pruned]
Shmuel> I mangled my E-mail address to foil automated spammers;
Shmuel> reply to domain>acm dot org user shmuel to contact me.
Shmuel> Do not reply to spamtrap@library.lspace.org
Richard> So, people who put requests not to be spammed in their
Richard> headers should be killed but people like me who have
Richard> applied some spamproofing should not. I'm not clear on the
Richard> logic here.
Richard>
Richard> --
Richard> Mail me as rjc not spt@cstr.ed.ac.uk
[sigh] Once more, preaching to the deaf...
RFC 1036, "Standard for Interchange of USENET Messages",
specifies the format of USENET messages. Its section 2, "Message
Format", states that
"all USENET news messages must be formatted as valid
Internet mail messages, according to the Internet
standard RFC-822."
That standard, RFC 822, "Standard For The Format Of ARPA Internet Text
Messages", states in its section 4.4.1, that the FROM: field should
"be a single, authenticated machine address, indicating
the AGENT (person, system or process) entering the message.
If this is not done, the "Sender" field MUST be present."
Hmmm...I wonder what RFC 822 says about the "Sender:" field. Let's
see, shall we?
Here we go, RFC 822, section 4.4.2, states that the "Sender:" field
"contains the authenticated identity of the AGENT (person,
system or process) that sends the message."
Please note the explicit, non-ambigous use of "authenticated" in
describing the contents of both the "from:" and "sender:" fields.
To authenticate is to certify as authentic. "Authentic" is an
adjective whose meaning, according to my dictionary, is:
3. not false or imitation: real, actual.
When return addresses, such as those in your posts, are doctored so as
to be non-mailable, it ceases to be authentic. Ergo, such messages are
illegal according to both RFC 1036 and RFC 822, and belong in a
killfile.
Maybe your dictionary defines "authentic" differently. But I doubt it.
N.
--
"Hey Rocky, watch me pull some intelligence out of the Internet."
"Not again, Bullwinkle. That trick *never* works."
"This time for sure!"
------------------------------
Date: 13 Feb 1998 19:59:03 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: on reading FAQs and gurus answering questions
Message-Id: <8cn2fu6geg.fsf@gadget.cscaper.com>
>>>>> "Cameron" == Cameron Dorey <camerond@mail.uca.edu> writes:
Cameron> At the end of each message to
Cameron> comp.infosystems.www.authoring.cgi, there is a little
Cameron> disclaimer message. I have no idea how that is done
Cameron> (actually, I have some idea, but it is rudimentary). Perhaps
Cameron> a sentence or two at the end of every post here can be set,
Cameron> directing new readers to Nathan's NG FAQ, particularly if it
Cameron> could be archived at perl.com or another suitable
Cameron> place. Nathan's FAQ, even though it is posted 2x week, gets
Cameron> drowned in the noise just like every other useful post.
ciwac is moderated, and thus you can do that, since all postings come
through the robo-moderator script. You can't retrofit clpm as
moderated very easily. Hence the proposal for clp.moderated or
something like that.
And the day clp.moderated comes along, I am *abandoning* clp.misc.
Seriously.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 199 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Fri, 13 Feb 1998 18:37:30 -0800
From: "Chris Schoenfeld" <chris@ixlabs.com>
Subject: Re: perl pointer puzzle
Message-Id: <6c30fb$ep8$1@ultra.sonic.net>
Damian,
OK, you are shooting for 'symbolic references', which are special - if you
do $$var, perl will do different things depending on whether $var is a real
reference or a string.
If it is a string like "variable", this is called a symbolic reference and
Perl will go to the symbol table and see what's in $variable.
> $temp{'var'} = "variable";
> $variable = "output_1";
> $reference = \$$temp{'var'}; #supposed to place the string "$variable"
>in $reference
> print $$reference . "\n"; #should print string "output_1"
Ok this didn't work because \$$temp{'var'} does not return "$variable" (the
easiest way to debug this is to print out each variable as you assign them -
that's what I did!)
You expected \$ to escape the dollar sign and return it as a string, then
concatenate it with the string returned by $temp{'var'} - you need
double-quotes for this interpolation:
"\$$temp{'var'}"
personally I would prefer
'$' . $temp{'var'}
because I am easily confused :)
What you got was a reference to an undefined variable.
But you don't want "$variable", you want just plain old "variable", so that
$$reference will be interpreted as
$"variable"
Is the correct syntax for a symbolic reference, not
$"$variable"
> $temp = "variable_2";
> $variable_2 = "output_2";
> $reference_2 = \$$temp;
> print $$reference_2 . "\n"; #prints the string "output_2"
In this case, because you were working with a scalar and not a hash element,
\$$temp "happened" to return what you wanted by accident. You really simply
wanted $temp.
Hope this helps - BTW I'm a 'use strict' guy all the way and never do any of
this, I just felt like figuring it out, but I think this is correct. See
Advanced Perl Programming pp16-17
-Chris
>The first block of code does not de-reference, whereas the second one
>does. My assumption is that the line $reference = \$$temp{'var'} does
>not actually replace $temp{'var'} with the characters 'variable' so that
>'$variable' can get stored in $reference. Why is this, and how do I
>correct it?
>The array %temp{} is necessary in the actual program for which I would
>like to implement this.
>
>Thanks
>Damian Berger
>dberger@uwyo.edu
>
>
------------------------------
Date: Fri, 13 Feb 1998 21:22:48 -0500
From: Tom Moertel <tom@moertel.com>
To: Mark666769 <mark666769@aol.com>
Subject: Re: Printing $query->param in a here-doc?
Message-Id: <34E4FFF8.E34BAE36@moertel.com>
Mark666769 wrote:
>
> [...]
> Is it possible to print the results of [evaluating
> an expression] in a here-doc [without first assigning
> the results to a scalar]?
Yup.
Here are two ways:
print <<EOF;
1st: Here's the WHO value @{[$query->param("WHO")]}.
2nd: And again: ${\($query->param("WHO"))}
EOF
An explanation for the magic can be found in the perlref(1) man page:
Anywhere you'd put an identifier (or chain of
identifiers) as part of a variable or subroutine name,
you can replace the identifier with a BLOCK returning
a reference of the correct type.
or in the perlfaq, the 4th section, to be precise:
How do I expand function calls in a string?
This is documented in the perlref manpage. In general,
this is fraught with quoting and readability problems, but
it is possible. To interpolate a subroutine call (in a
list context) into a string:
print "My sub returned @{[mysub(1,2,3)]} that time.\n";
If you prefer scalar context, similar chicanery is also
useful for arbitrary expressions:
print "That yields ${\($n + 5)} widgets\n";
See also "How can I expand variables in text strings?" in
this section of the FAQ.
In general, checking the perlfaq is the quickest and easiest way to
answer your Perl questions. It's well organized, not to mention clear,
crisp, and fun to read. If you don't have a local copy, point your
browser at an on-line copy and *do* bookmark it:
http://www.perl.com/CPAN-local/doc/manual/html/pod/perlfaq.html
Happy hacking!
Cheers,
Tom
------------------------------
Date: Fri, 13 Feb 1998 21:49:30 -0500
From: Aamir Sehbai <asehbai@osf1.gmu.edu>
Subject: Problems with Comm.pl on OSF1
Message-Id: <Pine.OSF.3.96.980213214651.28753B-100000@osf1.gmu.edu>
Hello,
I have been trying to get Comm.pl to run on my school account which runs
the OSF1 Operating System (uname -a gives "OSF1 osf1.gmu.edu V4.0 564
alpha"). When I try to run the example telnet expect script frm Comm.pl
(at end of message), I consistently get the following error :
"could not open slave, /dev/pts/XXX, errno=Device busy at Comm.pl line 1342."
Where the number XXX in /dev/pts/XXX keeps changing.
I have run the exact same script successfully on two other accounts I have
which are SunOS machines.
Please direct me to any help with this problem. I would say I am at
the intermediate level in Perl programming concepts ( Anything from
"Learning Perl", I know it), so I guess I could play around with the
Comm.pl source code if need be.
Any help will be appreciated.
Thanks,
Aamir.
The script :
#-------------------- Example telnet expect, short version ---------------------
#
# This will give an idea of the usage, without becoming overwhelming. See
# the next example for better error checking and more interesting operations.
eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
& eval 'exec perl -S $0 $argv:q'
if 0;
require "Comm.pl";
&Comm'init( 1.8 );
$Host = "osf1.gmu.edu";
$User = "asehbai";
$Password = "(mypassword)";
#$PS1 = '(\$|\%|#|Z\|) $'; # shell prompt, Z| is my weird prompt
$PS1 = '([$%#|>]) $'; # shell prompt pattern
$|=1;
$proc_handle = &open_proc( "telnet $Host" ) || die "open_proc failed";
( $match, $err, $before ) = &expect( $proc_handle, 3, 'login:' );
die "failed looking for login: err($err), before($before)" unless $match;
print $proc_handle "$User\n";
&expect( $proc_handle, 3, 'word:' ) || die "Didn't get a password prompt";
print $proc_handle "$Password\n";
&expect( $proc_handle, 10, $PS1 ) || die "no shell prompt";
print $proc_handle "finger asehbai\n"; # do something, anything
{
# Now, show the results of the above command:
( $match, $err, $before, $after ) = &expect( $proc_handle, 5, $PS1 );
redo unless $match;
print $before;
die "err=$err, quitting\n" if ( $err eq "EOF" );
}
print $proc_handle "\n"; # give us another shell prompt, please
&stty_raw(STDIN);
&interact( $proc_handle );
print "\nExited interact()\n";
&stty_sane(STDIN);
&close_it( $proc_handle );
------------------------------
Date: 13 Feb 1998 20:12:11 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Dennis Whitney <dennis@ironlight.com>
Subject: Re: Quickie: regexp for valid e-mail addresses
Message-Id: <8chg626fsk.fsf@gadget.cscaper.com>
>>>>> "Dennis" == Dennis Whitney <dennis@ironlight.com> writes:
Dennis> The check I currently use looks something like:
Dennis> if (($email =~ /\w+@[\w\.]+(com|gov|net|edu|mil|us|org|int)$/)&&
Dennis> ($email !~ /(!#$%^&*\(\))+/)) {
Dennis> ... Your code here ...
Dennis> }
Completely wrong. It rejects the perfectly valid functioning
<fred&barney@stonehenge.com> address (it's an autoresponder... try it!).
Get your head out of the dark place and over to RFC822, which
basically says that *any* character can appear on both the left and
right side of the @.
And this has been said OVER and OVER and OVER in this newsgroup,
which a moment's research on dejanews would have shown.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 199 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 14 Feb 98 02:19:12 GMT
From: "TomH" <beans@bedford.net>
Subject: Re: Syntax question
Message-Id: <01bd38a2$891edac0$129163ce@beans.bedford.net>
According to perlfunc, the exit function "Evaluates EXPR and exits
immediately with that value."
Believe it when it says immediately. It's my understanding that you don't
return from the exit function; print was never called since the interpreter
called the exit function while putting together the list of values to be
printed.
This sort of illustrates what happened:
#===============================
print STDERR ("Hello "), &hello;
sub hello {
return "World";
}
Helmut Jarausch <jarausch@numa1.igpm.rwth-aachen.de> wrote in article
<6c1e4g$p97$1@nets3.rz.RWTH-Aachen.DE>...
> Hi,
> can anybody explain what is going on if I say
>
> print STDERR ("something went wrong\n"), exit if 2 > 1;
>
> Here I don't see anything printed. Exit seems to be so fast,
> that some buffers (although STDERR isn't buffered) are lost.
> ...
------------------------------
Date: 14 Feb 98 02:46:39 GMT
From: "TomH" <beans@bedford.net>
Subject: Re: Testing integer
Message-Id: <01bd38a6$5dfc8a00$129163ce@beans.bedford.net>
Perhaps not. Use a regular expression /^-?[0-9]+$/
You might want to strip off or allow leading/trailing whitespace.
Using == with strings is asking for trouble.
#######################################
$\ = "\n";
$xyz = "xyz";
&nogood ($xyz);
®exp ($xyz);
$xyz = "-0";
&nogood ($xyz);
®exp ($xyz);
$xyz = "abc 123";
&nogood ($xyz);
®exp ($xyz);
sub nogood {
my ($x) = @_;
if (int($x) == $x) {
print "$x - nogood";
}
}
sub regexp {
my ($x) = @_;
if ( $x =~ /^-?[0-9]+?/ ) {
print "$x - regexp";
}
}
Joseph N. Hall <joseph@5sigma.com> wrote in article
<34E43A97.18A03C71@5sigma.com>...
> int($a) == $a, perhaps
>
> -joseph
>
> Andy Brezing wrote:
> >
> > Hi
> >
> > I'm a Perl beginner and need some some help in the distinction of data
> > types.
> >
> > Question: How can I test a variable whether it's an integer or not,
> > the variable value could be any data-type (string,number,list ...)
>
> --
> Joseph N. Hall, prop., 5 Sigma Productions mailto:joseph@5sigma.com
> Author, Effective Perl Programming . . . . . http://www.effectiveperl.com
> Perl Training . . . . . . . . . . . . . . . http://www.perltraining.com
>
------------------------------
Date: Sat, 14 Feb 1998 01:52:16 GMT
From: c28f62@world.std.com (Mark Kramer)
Subject: Re: The Young Man and the Beach
Message-Id: <EoCIJ4.EvJ@world.std.com>
In article <34E45CDC.D6B5D299@ti.com>, Graham Barr <gbarr@ti.com> wrote:
>Mark Kramer wrote:
><ungrateful gibberish deleted>
Ok, Mr. Barr. You tell me, exactly, what I was supposed to be grateful
for in the fable Tom posted. Was I supposed to be grateful that he
compared all of us to dirty beggars and shoeless children? Was I
supposed to be grateful for his reference to all the human debris on
"his beach"? No, you don't get to exclude yourself from his fable,
since he did not find any of his old friends on the beach, just the
rabble.
Or maybe what I was supposed to be grateful for was the way he was
jumping down people's throats for picking the wrong newsreader to post
to his group?
You tell me, Mr. Barr. Which is it?
>It is posts like these that are likely to alienate the people on
>this list who soul purpose for being here is to help.
Telling people that they are scum who are using scurilous software
isn't going to help them. It will alienate them. And posts like this
"Young Man on the Beach" will alienate everyone else. I found it
offensive to be lumped with the detritus that beg for scraps when I
have not once begged Mr. Christiansen for anything, and when Mr.
Christiansen is creating a good deal of the noise about which he
complains, and when he seems unable to simply walk past the beggars as
I have been doing for years.
How dare I infest his beach? How dare I indeed.
As for his "soul" purpose being to "help", well, I can state without
hesitation that his vendettas helped nobody. It increased the noise
and drew attention to himself, that's all.
>Sure
>we might get a little short with people at times but believe
>me this newsgroup would be almost useless if all these
>"good samaritans" left to help others who appreciated their
>input.
Please explain to me how one cannot appreciate VALUABLE CONTRIBUTIONS
to a group while opposing flames. You can't explain it, because you can
appreciate contributions while pointing out flames.
Nobody is talking about the contributions that Tom makes, except those
who think it excuses his OS flaming. There are some of us here who
think his vendetta against properly formatted articles from certain
newsreaders does nothing but hurt his reputation and make him look
petty and vain. If he doesn't care, then that's fine, but he ought to
know.
------------------------------
Date: Sat, 14 Feb 1998 01:54:42 GMT
From: c28f62@world.std.com (Mark Kramer)
Subject: Re: The Young Man and the Beach
Message-Id: <EoCIn6.FzJ@world.std.com>
In article <6c2hdq$347@abattoir.cc.ndsu.nodak.edu>,
Nem W Schlecht <nem@abattoir.cc.ndsu.nodak.edu> wrote:
>Unfortunately, many of us have left.
And many of us haven't.
>Keep up the good work, Tom. You know you still have a lot of grateful
>people behind you.
Yes, by all means, keep up the good work. Nobody has said he should
stop that. Just drop the OS flaming and fables.
------------------------------
Date: Fri, 13 Feb 1998 22:11:17 -0500
From: Daniel Fox <dan@dmf.net>
Subject: Truncate
Message-Id: <34E50B54.DD54A3F@dmf.net>
I wrote a function to open a file and lock it:
sub open_for_write {
($fp, $file) = @_;
open ($fp, ">> $file");
flock ($fp, 2);
truncate($fp, 0);
}
I then call it with something like this:
open_for_write(\*SOMEFILE, "/path/to/somefile");
This works fine on Linux 2.0 with perl 5.004, but the
truncate() call doesn't work on SunOS 5.5 with
perl 5.003.
I know I could just open($fp, "> $file") and forget about
the truncate(), but then if someone else opened the file for
read in between the open() and flock(), they'd get an empty
file.
So, how do I get truncate to work with the variable $fp?
Thanks.
------------------------------
Date: 13 Feb 1998 20:15:29 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: Russ Allbery <rra@stanford.edu>
Subject: Re: Using flock?
Message-Id: <8cd8gq6fn2.fsf@gadget.cscaper.com>
>>>>> "Russ" == Russ Allbery <rra@stanford.edu> writes:
Russ> If you're using a recent (5.004 or newer) version of Perl, you
Russ> should be able to use flock FILE,8 without too many
Russ> difficulties, as it now automatically flushes the stdio buffers.
Russ> However, for compatibility with previous versions of Perl, you
Russ> shouldn't rely on that, and that's the main gotcha with flock.
Russ> You *have* to make sure that all your buffered output is flushed
Russ> *before* you release your lock, or you may end up writing to the
Russ> file without it being locked, which is just asking for problems.
Wrong... The workaround was only for people that commonly do:
flock HANDLE, 8;
close HANDLE;
It does *not* help with:
flock HANDLE, 8;
... wait ...
flock HANDLE, 2;
$foo = <HANDLE>;
because the buffer for HANDLE is now out of sync. You must seek() to
force a refresh.
In other words, this fixed only the case where people were clearly doing
it wrong, but doesn't fix *all other* cases. You must *think* about
buffering when you are doing flocks.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 199 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 1895
**************************************