[28098] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9462 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 13 14:05:39 2006

Date: Thu, 13 Jul 2006 11:05:05 -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           Thu, 13 Jul 2006     Volume: 10 Number: 9462

Today's topics:
    Re: "Learning Perl" book <tadmc@augustmail.com>
    Re: "Learning Perl" book <penryu@saiyix.ath.cx>
        [Way off-topic] Re: What is a type error? <david.nospam.hopwood@blueyonder.co.uk>
    Re: Bad protocol 'tcp' <benmorrow@tiscali.co.uk>
    Re: Bad protocol 'tcp' <mark.clementsREMOVETHIS@wanadoo.fr>
    Re: Find a line in an html file <starfrit@gmail.com>
    Re: Find a line in an html file <tadmc@augustmail.com>
    Re: finding perl info on google can be hard ilikesluts@gmail.com
        flock/fcntl xhoster@gmail.com
    Re: flock/fcntl <benmorrow@tiscali.co.uk>
    Re: Lama Vs. Camel, How Much Camel in Perl Docs? (Was:  <tadmc@augustmail.com>
    Re: problem with time stamp <DJStunks@gmail.com>
    Re: RegEx and AND anno4000@radom.zrz.tu-berlin.de
    Re: RegEx and AND <no@email.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 13 Jul 2006 08:33:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: "Learning Perl" book
Message-Id: <slrnebcitu.jgj.tadmc@magna.augustmail.com>

rajeev.networld@gmail.com <rajeev.networld@gmail.com> wrote:
> I would recommend you using "Programming Perl". That is real guide
> book.


The purpose of a reference book (Camel) and a tutorial book (Llama)
are so different that they cannot be meaningfully compared.


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


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

Date: Thu, 13 Jul 2006 15:22:52 GMT
From: Tim Hammerquist <penryu@saiyix.ath.cx>
Subject: Re: "Learning Perl" book
Message-Id: <slrnebcpac.vd6.penryu@ruri.saiyix>

it_says_BALLS_on_your forehead <simon.chao@fmr.com> wrote:
> Tim Hammerquist wrote:
> > rajeev.networld@gmail.com <rajeev.networld@gmail.com> wrote:
> > > I would recommend you using "Programming Perl". That is real
> > > guide book.
> >
> > I've had limited success using "Programming Perl" to teach (and/or
> > learn) Perl.  Though after a good grasp of the langauge is
> > acquired, it is invaluable.
>
> I agree with Tim. I'd recommend the Perl Cookbook for learning Perl. Of
> course, the choice of texts is dependent alot upon learning style. I
> happen to learn by example much more rapidly and thoroughly than by
> reading through an instructional text (although typically the authors
> of Perl instructional texts--that I'm familiar with--write with a
> certain verve that makes it less dry than other instructional texts).

I'm not sure I'd suggest learning from the Cookbook either.  The
cookbook is great at showing useful example code, but doesn't help the
user in assembling the base parts of the language from scratch to form
a complete solution.  This is the shortcoming of any cookbook
approach.

The Cookbook is a valuable tool, but I try to limit its use to cases
such as, "I can solve this problem, but I'm sure someone else has done
it before and possibly better."

I learned Perl from the llama book, using the camel as a reference,
and lurking here in clpm... and of course, by copious experimentation.

HTH,
Tim Hammerquist


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

Date: Thu, 13 Jul 2006 16:08:16 GMT
From: David Hopwood <david.nospam.hopwood@blueyonder.co.uk>
Subject: [Way off-topic] Re: What is a type error?
Message-Id: <Qdutg.91033$7Z6.15255@fe2.news.blueyonder.co.uk>

Joachim Durchholz wrote:
> A concrete example: the
> first thing that Windows does when accepting userland data structures
> is... to copy them; this were unnecessary if the structures were immutable.

It is necessary also because the userland structures are in a different
privilege domain, and the memory backing them is potentially mapped by
other processes, or accessible by other threads of this process, that can
be running in parallel while the current thread is in the kernel.

Also, it tends to be easier and more secure to treat userland structures
as if they were in a different address space (even if for a particular OS,
the kernel would be able to access user mode addresses directly). The
kernel cannot trust that pointers in userland structures are valid, for
instance.

So, in order to avoid a copy when accepting a userland structure:

 - when servicing a kernel call for a given process, the OS must use
   kernel-mode page table mappings that are a superset of the user-mode
   mappings for that process at the point of the call.

 - the memory backing the structure must be immutable in all processes
   that could map it, and the kernel must trust the means by which it is
   made immutable.

-- 
David Hopwood <david.nospam.hopwood@blueyonder.co.uk>


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

Date: Thu, 13 Jul 2006 03:20:43 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: Bad protocol 'tcp'
Message-Id: <r8ngo3-scb.ln1@osiris.mauzo.dyndns.org>

[quoting fixed. please learn to quote properly]

Quoth "Garrett" <garrett.hennessey@gmail.com>:
> Mark Clements wrote:
> > garrett.hennessey@gmail.com wrote:
> > >
> > > This supports my belief that for whatever reason, my 'protocol' file is
> > > never being used. Any ideas why this may happen?
> >
> > Pass. What does
> >
> > use strict;
> > use warnings;
> >
> > my $protocolFilePath = q(C:\Windows\System32\Drivers\Etc\Protocol);
> > my $protocolFH;
> >
> > open ( $protocolFH, "<", $protocolFilePath )
> > 	or die "could not open $protocolFilePath for read: $!";
> >
> > give you?
> >
> > Beyond that, I have a few leads in mind but I'm no Windows expert and so
> >   they're little more than conjecture. There are people in here with
> > vastly more experience than me, although this appears to be more of a
> > Windows question than Perl.
> 
> You're example code (assuming I change the path to c:\winnt\... from
> c:\windows\...) works fine. It prints nothing (as it should).

Right... good. Does your c:\windows\system32\drivers\etc\protocol have a
line like

tcp     6   tcp     # Transmission control protocol

? If not, it should have.

> I don't see how this a windows problem. The other programming languages
> I use (c++, java, etc) don't have this problem. And I can use the
> network with email, web, ftp, telnet, ssh, nfs, etc fine with other
> programs. Perl is the only one who complains.

It's possible that other programs don't request the TCP protocol by
name, but either hardcode the number (in practice it's always 6) or use
the default protocol (which, again in practice, is always TCP for
AF_INET/SOCK_STREAM sockets). This doesn't mean Perl is in the wrong:
it's just following the specs to potentially cope with odd systems where
things aren't the way they usually are.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ benmorrow@tiscali.co.uk ~            Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Thu, 13 Jul 2006 17:44:51 +0200
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: Bad protocol 'tcp'
Message-Id: <44b66a6e$0$851$ba4acef3@news.orange.fr>

Garrett wrote:
> Mark -
> 
> You're example code (assuming I change the path to c:\winnt\... from
> c:\windows\...) works fine. It prints nothing (as it should).
OK.


> I don't see how this a windows problem. The other programming languages
> I use (c++, java, etc) don't have this problem. And I can use the
> network with email, web, ftp, telnet, ssh, nfs, etc fine with other
> programs. Perl is the only one who complains.
> 
What does a small C program calling getprotobyname give you?
(NB: my C is pretty weak. Do not use this as an example of how to write 
C. Have probably made a host of security and stylistic errors).


#include <stdio.h>
#include <netdb.h>

#define MAXPROTOLENGTH 82

int main(int argc, char* argv[]){
	char* protocolName;
     struct protoent* protocol;

     protocolName =(char*)malloc(MAXPROTOLENGTH);

     if(argc != 2){
         printf("Usage: %s protocol\n",argv[0]);
         return 1;
     }
	sscanf(argv[1],"%s",protocolName);

	printf("lookup protocol: %s\n",protocolName);

     protocol = getprotobyname( protocolName );

     if(protocol == NULL ){
         printf("could not find protocol\n");
     }else{
         printf("name: %s number: %d\n",protocol->p_name, 
protocol->p_proto);
     }

	return 0;
}

Mark


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

Date: 13 Jul 2006 08:30:42 -0700
From: "starfrit" <starfrit@gmail.com>
Subject: Re: Find a line in an html file
Message-Id: <1152804642.525692.107920@b28g2000cwb.googlegroups.com>


Xicheng Jia wrote:
> starfrit@gmail.com wrote:
> > I'm trying to addapt a perl script with another version of my hockey
> > simulator, because the file name structure as changed.  It is an IF
> > that looks for a link into an html file
> >
> > Before, the link was
> > <A HREF=AHSQ79.html> and the perl  line was if (m/^<A
> > HREF.(\w*.\w+)>.(\d+).*/)
> >
> > Now, the link is  <a href="AHSQ2006-79.html">
> >
> > Thanks for any help
>
>     if (/^<a href="([^"]*)">.(\d+)/i) { ... }
> 
> Xicheng

It works, thanks



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

Date: Thu, 13 Jul 2006 10:53:53 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Find a line in an html file
Message-Id: <slrnebcr4h.jnd.tadmc@magna.augustmail.com>

starfrit@gmail.com <starfrit@gmail.com> wrote:

> I'm trying to addapt a perl script


You forgot to post the adaptations that you have tried.

If you show us your broken attempt, we can probably help you fix it.


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


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

Date: 13 Jul 2006 09:34:24 -0700
From: ilikesluts@gmail.com
Subject: Re: finding perl info on google can be hard
Message-Id: <1152808463.990122.94010@h48g2000cwc.googlegroups.com>

Hi J=FCrgen Exner,

LOL!  You must have a bad short term memory :)
If you look at my first post you'll see the answer.

J=FCrgen Exner wrote:
> ilikesluts@gmail.com wrote:
> Ok, well, fine, whatever.
> In which way are the limitation or non-limitations of Google related to
> Perl?
>=20
> juye



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

Date: 13 Jul 2006 16:58:10 GMT
From: xhoster@gmail.com
Subject: flock/fcntl
Message-Id: <20060713130217.363$bV@newsreader.com>

from perldoc -f flock:

               Note also that some versions of "flock" cannot lock things
               over the network; you would need to use the more
               system-specific "fcntl" for that.  If you like you can force
               Perl to ignore your system's flock(2) function, and so
               provide its own fcntl(2)-based emulation, by passing the
               switch "-Ud_flock" to the Configure program when you
               configure perl.

Is there an easy way (a pragma or switch or something) to obtain the fcntl
based emulation *without* needing to recompile perl?  Also, since flock
seems to be Perl's first choice over fcntl, I wonder why that is.  What
disadvantages does building Perl with -Ud_flock have, other than this one:

               Note that the fcntl(2) emulation of flock(3) requires that
               FILEHANDLE be open with read intent to use LOCK_SH and
               requires that it be open with write intent to use LOCK_EX.

Thanks,

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 13 Jul 2006 18:26:42 +0100
From: Ben Morrow <benmorrow@tiscali.co.uk>
Subject: Re: flock/fcntl
Message-Id: <ibcio3-2kf.ln1@osiris.mauzo.dyndns.org>


Quoth xhoster@gmail.com:
> from perldoc -f flock:
> 
>                Note also that some versions of "flock" cannot lock things
>                over the network; you would need to use the more
>                system-specific "fcntl" for that.  If you like you can force
>                Perl to ignore your system's flock(2) function, and so
>                provide its own fcntl(2)-based emulation, by passing the
>                switch "-Ud_flock" to the Configure program when you
>                configure perl.
> 
> Is there an easy way (a pragma or switch or something) to obtain the fcntl
> based emulation *without* needing to recompile perl?

Not that I know of, but it would be trivial to write a replacement
yourself which calls fcntl.

> Also, since flock
> seems to be Perl's first choice over fcntl, I wonder why that is.  What
> disadvantages does building Perl with -Ud_flock have, other than this one:
> 
>                Note that the fcntl(2) emulation of flock(3) requires that
>                FILEHANDLE be open with read intent to use LOCK_SH and
>                requires that it be open with write intent to use LOCK_EX.

fcntl locks

    - can lead to unavoidable deadlocks (which the kernel ought to
      detect for you). 

    - are often slower. 
    
    - aren't inherited across forks.
    
It's important to realize that the semantics are different:

    flock $FH, LOCK_SH;
    flock $FH, LOCK_EX;

will unlock the shared lock before applying the exclusive with flock(2),
but not with fcntl(2) emulation. This is the cause of the potential
deadlock, and the need to do deadlock detection is why locks can't be
inherited.

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit.|benmorrow@tiscali.co.uk
Musica vel ipsas arbores et horridas movet feras.     |


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

Date: Thu, 13 Jul 2006 10:50:06 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Lama Vs. Camel, How Much Camel in Perl Docs? (Was: "Learning Perl" book)
Message-Id: <slrnebcqte.jnd.tadmc@magna.augustmail.com>

Veli-Pekka Tätilä <vtatila@mail.student.oulu.fi> wrote:
> rajeev.networld@gmail.com wrote:


>> I would recommend you using "Programming Perl". That is real guide
>> book.


The "real guide book" for Perl are the docs that come with
the perl distribution. Every other source of Perl information
is a _secondary_ resource.


> As to what style appeals to me, personally I like to start with the very 
> practical the style in many Sams books comes to mind, though I do realize it 
> is not for everyone. After having gotten the basics right,


Whether or not you have gotten the basics right is likely dependent 
on what "time frame" appears in the Sam's title.   :-)

"24 hours" should be good, Clinton is a Real Perl Programmer.

"21 days" was widely ridiculed in its 1st edition, I dunno about
the 2nd edition, but I doubt it is improved enough.


> All this reminds me of an observation I've made:
> In reading some Perl docs followed by Programming Perl's take on the 
> subject, there are sentences that are very close to each other, as though 


The pink Camel (1st edition) matched the std docs a whole lot. The
correspondence has weakened with each new edition though.


> the Perl docs were influenced by the Camel rather heavily.


I think it went in the other direction, the Perl docs where used
as a starting point for large sections of the Camel book.


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


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

Date: 13 Jul 2006 08:41:49 -0700
From: "DJ Stunks" <DJStunks@gmail.com>
Subject: Re: problem with time stamp
Message-Id: <1152805309.777687.213370@35g2000cwc.googlegroups.com>


Tony Curtis wrote:
> >> On 13 Jul 2006 07:08:07 -0700,
> >> davide.papagno@gmail.com said:
>
> > Yeah Tony, it seems is great $now = strftime "%a %b %d",
> > gmtime; print "$now\n";
>
> > But I have to get the time stamp of a file $file.  I
> > don't know how to match strftime and stat function
>
> Ah well, couldn't give it all away, could I? :-)
>
>     localtime()

or use Date::Format instead of POSIX...

  C:\tmp>perl -MDate::Format -e "print time2str '%a %b %d', (stat
'tmp.txt')[9]"
  Tue Jul 11

-jp



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

Date: 13 Jul 2006 15:18:44 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: RegEx and AND
Message-Id: <4hn6ikFc8rfU1@news.dfncis.de>

Xicheng Jia <xicheng@gmail.com> wrote in comp.lang.perl.misc:
> tinu wrote:
> > Hi All
> >
> > I need to do a simple RegEx expression for and AND. I dont know how to
> > do this.
> > I have the following string:
> > "The tree is taller then the flower".
> >
> > I would like to search for "tree" AND "flower". How Do I do this?
> >
> > Thanks for your help
> 
>   if ($line =~ /^(?=.*tree)(?=.*flower)/) { ... }

Why do you anchor the regex?  It doesn't change what it matches.

This is the one-regex solution the OP asked for, but in a practical
program I'd always prefer two and-connected matches.

   $line =~ /tree/ and $line =~ /flower/;

has been suggested.  It is much easier to read and substantially
faster too.

Anno


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

Date: Thu, 13 Jul 2006 16:35:55 +0100
From: Brian Wakem <no@email.com>
Subject: Re: RegEx and AND
Message-Id: <4hn7irFd7e1U1@individual.net>

tinu wrote:

> Hi All
> 
> I need to do a simple RegEx expression for and AND. I dont know how to
> do this.
> I have the following string:
> "The tree is taller then the flower".
> 
> I would like to search for "tree" AND "flower". How Do I do this?
> 
> Thanks for your help


No need to use a regex. index is much more suited and faster.


if ( (index($string,'tree') != -1) and (index($string,'flower') != -1) ) {
 ..
}


-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

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 9462
***************************************


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