[17442] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4862 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 10 00:10:36 2000

Date: Thu, 9 Nov 2000 21:10:15 -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: <973833015-v9-i4862@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 9 Nov 2000     Volume: 9 Number: 4862

Today's topics:
    Re: Perl Registry Entries hosed? <bwalton@rochester.rr.com>
    Re: Pushing a hash on to a stack... <hartleh1@westat.com>
        ref & regexp's don't mix in 5.6? <nb@no.where>
    Re: returning arrays from a subroutine (Tad McClellan)
    Re: returning arrays from a subroutine (Gwyn Judd)
    Re: returning arrays from a subroutine (Tad McClellan)
        Returning variable from PM spcman@my-deja.com
        Self-modifying code in Perl (Tarael200)
    Re: Self-modifying code in Perl (Jerome O'Neil)
    Re: Self-modifying code in Perl <jeff@vpservices.com>
    Re: Self-modifying code in Perl (Mark-Jason Dominus)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Fri, 10 Nov 2000 02:34:38 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Perl Registry Entries hosed?
Message-Id: <3A0B5F8E.9E921671@rochester.rr.com>

Morpheus wrote:
> 
> Hello all. I have Apache 1.3.14 running on a Win98SE machine and have
> been having problems getting cgi scripts to run through my browser.
> Basically it tells me that I don't have permission to run the script.
> I chalked it off to not being able to change the permissions and
> resolved myself to find a workaround.  Several hours later and still
> nothing in sight, I decided to check my registry entries for perl
> since I couldn't even run a script in DOS or a perl window.  The
> results I found here are disturbing to me, but since I am new to Perl,
> I thought I'd share this with the experts and get your opinion.
> 
> Sorry for the length of the second key, it really is that long.
<lengthy gibberish deleted>
 ...
> 
> Is this right or is my ActivePerl 5.6.0.620 installation hosed?  The ?
> in the path in the first key I'm sure is whacked, but then again, I am
> new to this.  There were other keys in the same folder as the second
> key, and they were similar in length, just a bunch of numbers, symbols
> and letters.  I tried setting the path using set
> path=%path%;c:\usr\bin but it returned an error about a backslash near
> usr\ or something like that.
> 
> Any help would be appreciated.  I am expecting to have to reinstall
> Perl, but want to verify before doing this again.
> 
> Thanks!
> James
Well, Perl works on my system, and it has similar registry key/value
pairs to yours. Actually, it seems to have four sets of them, probably
because I have installed four different versions of Perl since I started
with Perl 5.6.  Looks like Microsoft Installer collects garbage in one's
registry.  I doubt that these keys are used by anything but installer,
but that is just speculation on my part.  I have learned not to
experiment with removing stuff like that.
-- 
Bob Walton


------------------------------

Date: Thu, 09 Nov 2000 11:54:52 -0500
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: Pushing a hash on to a stack...
Message-Id: <3A0AD6DC.FFBF75E6@westat.com>

Christopher Burke wrote:
> 
> mgjv@tradingpost.com.au (Martien Verbruggen) wrote:
> >> You're ungrateful, and unreasonable. And very childish, too. But
> >> if you want to go off, and sulk in a corner, that's fine by me.
> >> Usenet can be hard on the ego, especially if you're of a stubborn
> >> nature.  Some people never get over that.
> 
> Having read your blurb I am not ungrateful, just more wary now of
> asking questions of people who I thought were superior in knowledge
> to me. I asked a few people at work who are long time perl users,
> none of them could answer - but neither were they critical of my
> question nor did they think it a silly question.
> 
> I made it clear from the start of this thread that I HAVE A SOLUTION
> and that I was clearly requesting an answer to a specific question.
> 

I first came to this newsgroup a few years ago as someone with only a
little Perl knowledge (but with a respectable amount of programming
experience).  I must admit I posted a question early on which I would
have been able to answer myself if I had only read the documentation
before asking.  I was properly chastised and now always try to find the
answer there (and by searching the archive of this and other newsgroups)
before posting any question.  People answer lots of questions here and
it's rare for me to come up with a question that hasn't been asked
before (and answered many times).  I've also learned that there are some
people here who really know what they are talking about and others that
do not.  Hang out a while and it becomes clear to whom you should
listen.

As with any fairly large group of people, there are people here with a
wide range of experience and expertise.  They also have a wide range of
patience, tact, eloquence, etc.  While some are terse or even rude, I've
found them on the whole to be quite patient and understanding.  There
are limits.  In particular, I've found Martien Verbruggen to be very
helpful, with "newbies" and experienced hackers alike.  He'd be the
first to admit that he's not always right and he seems willing to take
correction when his mistakes are pointed out.  I've never asked a
question myself that he happened to answer directly but he has answered
many questions I would have asked if they had not been already answered.

Some of the people here are actually the developers who have written the
internals of Perl.  It seems a bit presumptuous for us (unless we really
understand what we are doing and I for one am nowhere near this place)
to call into question their understanding of what is happening behind
the scenes.  Likewise, when one of these folks says that doing A is much
less efficient than doing B, it seems likely that they are not just
guessing (although that happens, it usually gets corrected if they guess
wrong).  If someone asks a question like "I want to use Perl for writing
a CGI script but I cannot use the CGI module" or "I want to find all the
files in a directory tree but I cannot use the File::Find module" the
typical response has some measure of derision.  Those are two fairly
common threads here and people, particularly those regulars who can
provide so much useful information, tend to tire of this sort of thing. 
There is a tendency to say things that to new folk may seem gruff or
even rude.  They aren't (necessarily) trying to be rude.  They *could*
have just ignored the question but people seem to get upset about that,
too.

This happens most often when someone asks a FAQ and is told to RTFM. 
Often they are even told what specific part of which FM they should R. 
These newbies then get all upset that they were not given the answer and
attempt to start a flame war.  Those are more common that the sort of
question we are discussing here but the process is basically the same. 
Someone asks the question.  They get a few fairly terse answers asking
why they would want to do that.  Instead of responding to that question,
they say they have their reasons and start to get defensive.  Since this
has happened before, killfiles start to get updated.  Then the original
poster wonders out loud why none of the "so called gurus" can answer
such a simple question.  This doesn't exactly endear the OP to the
people on the list and they are killfiled by even more locals.  This
basically ensures they won't get help to legitimate questions in the
future.

If, instead of getting upset, the OP explains their reason for their
otherwise silly requirement they will usually get the help they are
seeking.  That assumes their reason is even slightly valid.  Reasons
such as, "just 'cause!" or "I have my reasons," don't get you very far.  

In this case, Martien has been very courteous and helpful and has even
given you code to do what you ask (or at least what he understood to be
what you ask).  You continue to respond as above without even seeming to
read all that he says.  The reason he's one of only a few to respond to
your posts is that many of the others here aren't seeing them any more. 
He has given you a fair share of his time and seems willing to help all
he can.  But instead of being helped, you refuse to share your reason
for not wanting to use references.  "Just 'cause!"  Then, you complain
that the people here must not be smart enough to answer your question. 
There are people here whose code I am unworthy to untie.  You'll have to
take my word for it that these folk are smart enough to do pretty much
anything that can be done.  They are also smart enough to know when
there is a better way to do something or when something doesn't make
sense.

With all due respect to the Perl programmers at your place of
employment, perhaps the reason they didn't see anything odd about your
requirements is that they don't understand the situation well enough. 
There are people here who do.  Learn from them.


> I will not be sulking in a corner, but I now know that like one
> or two other newsgroups I have seen that this is one to be wary of.

It doesn't matter much.  Once Martien and the one or two other
knowledgeable people here killfile you, you'll be effectively in a
corner anyway.  But you've done it to yourself.

--
Henry Hartley
Westat
Rockville, Maryland, USA


------------------------------

Date: Thu, 09 Nov 2000 20:52:03 -0800
From: Noboday at Lucasfilm <nb@no.where>
Subject: ref & regexp's don't mix in 5.6?
Message-Id: <3A0B7EF2.FD16F51F@no.where>

I know the proper way of finding the type of a reference is to use "ref"

Saying that, I came across some code that worked in 5.004_04 but not in
5.6.0- can someone explain to me what's going on here?

thanks,
-y

#!/usr/bin/perl
my $a = 'abc';
my $b = \$a;
print "b is: $b\n";  # Prints SCALARetc

$b=~/.*/;
print "what matched: $&\n"; # Prints SCALARetc
my $c = $b =~ /^SCALAR/;
print "what is c: $c\n";  # $c==1 in 5.004, but is undef in 5.6.0





------------------------------

Date: Thu, 9 Nov 2000 21:59:33 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: returning arrays from a subroutine
Message-Id: <slrn90mp4l.d2a.tadmc@magna.metronet.com>

On 10 Nov 2000 11:51:43 +1100, Kiel Stirling <taboo@comcen.com.au> wrote:
>
>Hi all, I want to return two array's from a subroutine. Can u do this??


No.

You can't even return one array from a subroutine.

You can return a list from a subroutine.

A list is not an array.


>maybe something like,


A lot like that. You are nearly there.


>        return ($buffer1,$buffer2);
                 ^        ^
                 ^        ^
I assume you meant @ there, else it won't even compile.


>}


You cannot return 2 arrays, but you can return 2 references
to arrays (in the returned list):

---------------------------------
#!/usr/bin/perl -w
use strict;

my($ref1, $ref2) = returnsub();       # get the array refs
my @array1 = @{$ref1};                # deref the array
my @array2 = @{$ref2};

print foreach @array1;
print foreach @array2;

sub returnsub {
        my (@buffer1, @buffer2);
        $buffer1[0] = "blar1";
        $buffer2[0] = "blar2";
        return (\@buffer1, \@buffer2);  # 2 references to arrays
}
---------------------------------


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 10 Nov 2000 04:18:59 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: returning arrays from a subroutine
Message-Id: <slrn90mtpe.769.tjla@thislove.dyndns.org>

I was shocked! How could Kiel Stirling <taboo@comcen.com.au>
say such a terrible thing:
>
>I see the prob, sorry !
>
>return ($buffer1,$buffer2);
>
>should be 
>
>return (@buffer1,@buffer2);

No it shouldn't. This question was asked just yesterday under a
different topic.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
If you think education is expensive, try ignorance.
		-- Derek Bok, president of Harvard


------------------------------

Date: Thu, 9 Nov 2000 22:22:00 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: returning arrays from a subroutine
Message-Id: <slrn90mqeo.d8a.tadmc@magna.metronet.com>

On 10 Nov 2000 11:59:50 +1100, Kiel Stirling <taboo@comcen.com.au> wrote:
>
>I see the prob, sorry !


No you don't!


>return ($buffer1,$buffer2);
>
>should be 
>
>return (@buffer1,@buffer2);


That does not fix the problem.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 10 Nov 2000 03:51:21 GMT
From: spcman@my-deja.com
Subject: Returning variable from PM
Message-Id: <8ufrbn$3m1$1@nnrp1.deja.com>

Hey guys, i have a question.  I want to send variables to a perl
module, have the perl module run some code then return a value back to
the main cgi program.  Im relativly new to cgi learning by cut/paste
and tearing code apart.  I cannot figure out the correct way to return
a value.

Heres some basic code...

 uses template
 $RunTemplate = New template;
 $RunTemplate -> SetVariables(\%VarValues);
 $RunTemplate -> ProcessTemplate(\$FileName);

I want the template.pm to return a value to the program.
Example...  $RunTemplate = ReturnValue();

Any help appreciated. - Al


Sent via Deja.com http://www.deja.com/
Before you buy.


------------------------------

Date: 10 Nov 2000 02:17:38 GMT
From: tarael200@aol.com (Tarael200)
Subject: Self-modifying code in Perl
Message-Id: <20001109211738.02983.00000009@ng-bj1.aol.com>

Yes, this is very rudimentary. It can not be considered a quine because it
'cheats' by reading it's code off of the disk..

Hey, I'm 14. Cut me some slack:-)

----------------------------------------------------------
#!/usr/bin/perl

$Gen = 241;
print $Gen . "\n";

&modify_code;
exec("perl selfmod.pl");

sub modify_code {
        open CODE, "<$0" or die "Can't open for reading: $!";
        @filetext = <CODE>;
        close CODE;

        $_ = join("", @filetext);

        ($ext) = /\$Gen = (\d+)/;
        $ext++;
        s/\$Gen = \d+/\$Gen = $ext/;

        open OUTP, ">$0" or die "Can't open for writing: $!";
        print OUTP $_;
        close OUTP;
}
---------------------------------------------------------

Comments? And don't tell me to use -w and use strict. I know that already.
I'm just lazy ;-)



------------------------------

Date: Fri, 10 Nov 2000 02:35:57 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Self-modifying code in Perl
Message-Id: <haJO5.3400$te1.337994@news.uswest.net>

tarael200@aol.com (Tarael200) elucidates:

> Comments? And don't tell me to use -w and use strict. I know that already.
> I'm just lazy ;-)

If you were Lazy rather than lazy, you'd know that -w and strict are
your Lazy friends. 

-- 
"Civilization rests on two things: the discovery that fermentation 
produces alcohol, and the voluntary ability to inhibit defecation.  
And I put it to you, where would this splendid civilization be without 
both?" --Robertson Davies "The Rebel Angels" 


------------------------------

Date: Thu, 09 Nov 2000 18:52:30 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Self-modifying code in Perl
Message-Id: <3A0B62EE.4165A9CC@vpservices.com>

Tarael200 wrote:
> 
> Comments? And don't tell me to use -w and use strict. I know that already.
> I'm just lazy ;-)

I'm lazy also.  Too lazy to answer questions to posts from people who
brag about how they don't follow advice given on this list.  If they
aren't likely to follow my advice, not much point in giving it is
there?  But you do get a consolation prize:

http://www.nyx.net/~gthompso/quine.htm.

-- 
Jeff


------------------------------

Date: Fri, 10 Nov 2000 04:57:26 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Self-modifying code in Perl
Message-Id: <3a0b8035.a7a$51@news.op.net>
Keywords: raft, seedling, shimmy, singsong

In article <20001109211738.02983.00000009@ng-bj1.aol.com>,
Tarael200 <tarael200@aol.com> wrote:
>        @filetext = <CODE>;
>        $_ = join("", @filetext);

This is a classic mistake.  Perl goes to all the trouble of breaking
the file into lines for you, and then you join them back together
again.  It's more efficient to use:

        { local $/ = undef;
          $_ = <CODE>;
        }

which reads the entire file as fast as it can be read.  Of course, in
this case it probably doesn't matter much, because the file is small.
But uf you still want to use the 'join' approach, why not just

        $_ = join "", <CODE>;

??

>$Gen = 241;
>        s/\$Gen = \d+/\$Gen = $ext/;

This seems a little risky to me.  I would have felt more comfortable
if the editable line were explicitly marked:

        $Gen = 241;     # EDIT ME
        s/\d+(?=;\s+\# EDIT ME)/$ext/;

But finally, you might find a different approach amusing.  You need
the following utility module.  Put the this code into the file
Devel/Dumpcode.pm:

        package Devel::Dumpcode;

        sub DB::DB { }    # Do nothing special
        
        sub main::source_of_function {
          my $package = caller;
          $function = $package . '::' . shift();
          my ($file, $start, $end) =
            $DB::sub{$function} =~ /(.*):(\d+)-(\d+)/;
          @{"::_<$file"}[$start..$end];
        }

        1;


Then put the following into tryme.pl:

        #!/usr/bin/perl

        for (;;) {
          print "Gen = ", Gen_val(), "\n";
          my @code = source_of_function('Gen_val');
          for (@code) {
            last if s{(\d+)(?=;\s+\# EDIT ME)}
                     {(($1 * 1103515245 + 12345) / 65536) % 32768}e;
          }
          eval join '', @code;
        }

        sub Gen_val {
          1;     # EDIT ME
        }

           
Now use

        perl -d:Dumpcode tryme.pl

>Comments? 

Now it doesn't have to open the source code file.  I hope you're entertained!

The nice thing about this is that although it is a genuinely useful
and effective technique, it's also extremely bizarre.  

> And don't tell me to use -w and use strict. 

'strict' is for cowards and weaklings.  

-- 
@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: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4862
**************************************


home help back first fref pref prev next nref lref last post