[24887] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7139 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 14 14:27:50 2004

Date: Tue, 14 Sep 2004 11:25:23 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 14 Sep 2004     Volume: 10 Number: 7139

Today's topics:
    Re: $| (undocumented) magic? (krakle)
    Re: hv_iterinit has side effects - who cares about PL t <tassilo.von.parseval@rwth-aachen.de>
    Re: newbie question (krakle)
    Re: Newbie, how di I change variables for mysite??? (krakle)
    Re: Perl CBT? (ft4bredn)
    Re: Perl CBT? <zebee@zip.com.au>
    Re: Problem with global text search using Regular Expre <josef.moellers@fujitsu-siemens.com>
    Re: use CGI qw(:standard) ??? <sbryce@scottbryce.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 13 Sep 2004 21:16:37 -0700
From: krakle@visto.com (krakle)
Subject: Re: $| (undocumented) magic?
Message-Id: <237aaff8.0409132016.28517a5a@posting.google.com>

Michele Dondi <bik.mido@tiscalinet.it> wrote in message news:<udb1k01b574opq7l9pv82501se3m0ef308@4ax.com>...
> While trying my hand at a new japh[*], 

Why why and why?
Do something productive...useful...


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

Date: Tue, 14 Sep 2004 06:35:11 +0200
From: "Tassilo v. Parseval" <tassilo.von.parseval@rwth-aachen.de>
Subject: Re: hv_iterinit has side effects - who cares about PL theory
Message-Id: <2qnao1F105i7rU1@uni-berlin.de>

Also sprach Ozgun Erdogan:

>> Clearly, this will end in an infinite recursion. But is this a bug in
>> perl? One has to keep track of the references to make sure that circular
>> ones are detected correctly.
>> 
> 
> I think another example will make it clear why I think Perl's
> hv_iterinit()/hv_iternext() functions are not implemented as expected.
> Technically, these functions are doing reads. Say, you have two
> threads:
> 
> T1
> ----
> grab_read_lock(hash1);
> hv_iterinit(hash1);
> while (not_endof_hash(hash1));
> {
>   hv_iternext(hash1);
>   print(value(hash1));
> }
> release_read_lock(hash1);
> 
> T2
> ----
> grab_read_lock(hash1);
> hv_iterinit(hash1);
> while (not_endof_hash(hash1));
> {
>   hv_iternext(hash1);
>   print(value(hash1));
> }
> release_read_lock(hash1);
> 
> Technically, independent of scheduling, you should see each of hash1's
> elements printed twice. This is because hv_iterinit()/hv_iternext()
> are supposed to do reads. Honestly, I haven't tried this, but am
> pretty sure it'll mess up in Perl. 

I haven't tried. However, perl is thread-safe and hashes are used with
threads. So far I haven't yet heard any complains about this particular
aspect.

>> You aren't modifying a hash's values when iterating over it. You are
>> however modifying the internal state of the iterator. There is no other
>> way to do it in any language.
> 
> No, the problem is, the value of the iterator is in the hash structure
> itself. And yes, you can easily do it in any other language, C++ STL
> libraries provide you a data structure (like <vector>) and an iterator
> that's independent of the data structure. Try the above example with
> STL, and it'll give you what you want (or what I expect).

That's because you create each iterator object manually. If you do:
    
    void function (map<int,int>::iterator i) {
	cout << i->first << i->second;
    }
    
    map<int,int> m;
    m[1] = 1;
    m[2] = 2;
    map<int,int>::iterator i = m.begin();
    cout << i->first << i->second;
    function(++i);

that is equivalent to Perl's:

    sub function { print each %{$_[0]} }
    %hash = (1=>1, 2=>2);
    print each %hash;
    function(\%hash);

The latter's even more powerful as values can be added to the hash in
function(). In C++ you'd additionally have to pass the map to the
function.

>> So the bug is in the module and not in perl. You should report this to
>> its author.
> 
> No, that depends on your perspective. I'm aware that implementing
> hashes in a different way would break Perl's lazy deletion idea.
> However, implementing it this way breaks one of the fundamental rules
> of programming language theory: A read is supposed to do a read.

It still is a read. The fact that you do not have to create iterators
yourself in Perl is a feature, and a good one IMO.

The fact that that's the way Perl hashes behave is well known. The
module of this particular module appears to neglect it if his module
falls into infinite recursion. In order to avoid it he has to save the
iterators value somewhere and restore it later when he wants to continue
where he left off.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 13 Sep 2004 21:08:26 -0700
From: krakle@visto.com (krakle)
Subject: Re: newbie question
Message-Id: <237aaff8.0409132008.2f48a3bb@posting.google.com>

"NDS Ltd" <nds@none.com> wrote in message news:<ncV0d.1328$_67.1149@newsfe2-win.ntli.net>...
> hi,
> 
> at the prompt on my linux box if i type
> 
> perl test.pl
> 
> i gets the message 'perl is working'
> 
> but if i view the same file through my browser (it is in cgi-bin) i get
> Internal Server Error
> The server encountered an internal error or misconfiguration and was unable
> to complete your request. bla bla bla..
> 
> 
> in the logs it says...
> 
> [Sun Sep 12 10:51:31 2004] [error] (8)Exec format error: exec of
> /home/e-smith/files/ibays/networkdata/cgi-bin/test.pl failed
> [Sun Sep 12 10:51:31 2004] [error] [client 192.168.1.4] Premature end of
> script headers: /home/e-smith/files/ibays/networkdata/cgi-bin/test.pl
> 
> 
> Any help appreciated...

To run as CGI you must include a content header

so while the Perl script:

#!/usr/bin/perl -w
print "Perl works\n";

prints "Perl works" from the command line if you requested it from a
browser you would receive a "Premature end of script headers" error.
You'd have to define mime content header since the output of a CGI
script can be anything from text to images to anything. So try this:

#!/usr/bin/perl -w
print "Content-type: text/html\n\n";
print "Perl works\n";

From the browser it prints:

Perl works

From the terminal it prints:

Content-type: text/html

Perl works

:)


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

Date: 13 Sep 2004 21:14:32 -0700
From: krakle@visto.com (krakle)
Subject: Re: Newbie, how di I change variables for mysite???
Message-Id: <237aaff8.0409132014.946752e@posting.google.com>

tigermott@yahoo.com (javatiger) wrote in message news:<962e2a34.0409111516.11eec137@posting.google.com>...
> I have downloaded a few scripts and I'm not sure about how to change
> them to suit my site.

Refer to the README files or the authors site for help...

> 
> Below is part of a perl script I have downloaded, now I need to
> personlize them for my site.

Refer to the README file...

> On my server we use the public_html folder only and not the www folder
> I have created a new folder in the public_html called perltest and
> uploaded the htm files into hear, I have put the perl script in my
> cgi_bin.
> 
> Can someone post a reply editing the script below to suit my site.
> 
> Also I see /usr/ in alot of scripts what does it mean?

"usr" is a directory... So... when a script asks for a full path to a
file it may begin with a "/usr" depending on your server and setup...

> --------------------------------------------------------------------------------
> #*******Variables that need to be personalized***********
>         $answerFile = "/usr/www/users/mhughes/perltest/answers.txt";
>         $logFile = "/usr/www/users/mhughes/perltest/testlog.htm";
>         $logFileUrl =
> "http://www.flashlightbrown.com/perltest/testlog.htm";
>         $testUrl = "http://www.flashlightbrown.com/perltest/test.htm";
>         $graphFile = "/usr/www/users/mhughes/perltest/graphlog.htm";
>         $graphFileUrl =
> "http://www.flashlightbrown.com/perltest/graphlog.htm";
> ---------------------------------------------------------------------------------

Yea... We don't know where you put the files... Nor do we know your
full path on your server... Refer to the authors site... Or a newbies
guide on CGI scripts...

This is offtopic here...


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

Date: Tue, 14 Sep 2004 05:55:33 GMT
From: none@anytime.net (ft4bredn)
Subject: Re: Perl CBT?
Message-Id: <pJv1d.89190$yh.86557@fed1read05>

WOW.. That is what I meant by the books being way over my head.. it 
is ironic though, the first edition's free chapter is on file 
handles and I/O.... the chapter I am stuck on. Anyway, thanks for 
the input, I will look at the book more when I goto the book-
store..
Thanks!

----------------------------------------------
Posted with NewsLeecher v1.0 beta 26
 * Binary Usenet Leeching Made Easy
 * http://www.newsleecher.com/?usenet
----------------------------------------------



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

Date: Tue, 14 Sep 2004 06:23:48 GMT
From: Zebee Johnstone <zebee@zip.com.au>
Subject: Re: Perl CBT?
Message-Id: <slrnckd38b.1uu.zebee@zeus.zipworld.com.au>

In comp.lang.perl.misc on Tue, 14 Sep 2004 05:55:33 GMT
ft4bredn <none@anytime.net> wrote:
> WOW.. That is what I meant by the books being way over my head.. it 
> is ironic though, the first edition's free chapter is on file 
> handles and I/O.... the chapter I am stuck on. Anyway, thanks for 
> the input, I will look at the book more when I goto the book-
> store..


For more course oriented stuff, see the old netizen materials which 
are mostly at http://zoic.org/training/

Zebee


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

Date: Tue, 14 Sep 2004 08:50:32 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: Problem with global text search using Regular Expressions
Message-Id: <ci647h$dnn$2@nntp.fujitsu-siemens.com>

Matt Garrish wrote:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message=20
> news:Xns9563C31CA8619asu1cornelledu@132.236.56.8...
>=20
>>jayalmehta@hotmail.com (Jayal) wrote in news:e3932667.0409131452.6b9044=
a1
>>@posting.google.com:
>>
>>
>>>Hi
>>>I am trying to perform a global search in a string using regular
>>>expressions.
>>>
>>>consider the string
>>>
>>>"attgccgccgccatt"
>>>If I wish to search for the string "ccgcc" within it, if I use the
>>>operation given below, I would get only one find
>>>
>>>$a =3D~ /ccgcc/g;
>>>$location =3D pos......
>>>
>>>which would be the find match.
>>>What do I do if I want to get both occurances?
>>
>>You'll need to read up on your Perl regexes. There 'ccgcc' occurs only
>>once in the string above. Once a match is made, the search for a next o=
ne
>>does starts at the third 'g' in the source string.
>>
>>That is,
>>
>>my $s =3D 'attgccgccgccatt';
>>
>>while( $s =3D~ /ccgcc/g ) {
>>   print 'Position: ', pos $s, "\n";
>>}
>>
>>will only print 9.
>>
>>I remember seeing something to deal with this kind of a situation in th=
e
>>Cookbook, but I cannot remember how it is done.
>>
>=20
>=20
> You can reset pos after the match. In this case, you'd set it back two =

> characters

I'd suggest length('ccgcc') - 1
then e.g. a search for 'cccc' in 'cccccc' would produce the "expected" 3 =

matches.
Agreed, it wouldn't produce any more matches in the original case and=20
would take slightly longer, but for the sake of genericity ...

> to match the next ccgcc:


--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: Mon, 13 Sep 2004 22:28:05 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: use CGI qw(:standard) ???
Message-Id: <10kcsqk75jk2qe5@corp.supernews.com>

krakle wrote:

> Actually... His question wasn't a CGI question at all.

Neither Gunnar nor I said that it was.

> It was a
> question pertaining to a line of Perl code. Which just happened to be
> a call to the _Perl_ module CGI.pm.

It was a question about the Perl installation on his web host's server. 
We can make an assumption that CGI.pm is probably there, but we cannot 
install it for him if it isn't. OTOH, as Gunnar pointed out, we can 
answer the "where can I get it" part of his question.



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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

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

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


------------------------------
End of Perl-Users Digest V10 Issue 7139
***************************************


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