[19271] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1466 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 8 14:11:51 2001

Date: Wed, 8 Aug 2001 11:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997294214-v10-i1466@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 8 Aug 2001     Volume: 10 Number: 1466

Today's topics:
    Re: Line counting in a file (Yves Orton)
    Re: manipulating webpages? <andras@mortgagestats.com>
        mresolv2 and sockets on HP-UX 10.20 (Mike)
    Re: Not matching strings (Tad McClellan)
    Re: Pattern Matching: Which subpattern (rather than sub (Tad McClellan)
    Re: perldoc is like Greek to a beginner?? (Jon Bell)
    Re: perldoc is like Greek to a beginner?? <tsee@gmx.net>
    Re: perldoc is like Greek to a beginner?? (Tad McClellan)
    Re: perldoc is like Greek to a beginner?? <tsee@gmx.net>
    Re: perldoc is like Greek to a beginner?? <miscellaneousemail@yahoo.com>
    Re: perldoc is like Greek to a beginner?? (Tad McClellan)
    Re: perldoc is like Greek to a beginner?? <miscellaneousemail@yahoo.com>
        q: converting strings <ow22@nospam-cornell.edu>
    Re: q: converting strings (Malcolm Dew-Jones)
    Re: q: converting strings <jasper@guideguide.com>
    Re: RegEXP's (Tad McClellan)
    Re: String version of += assignment operator?? (Tad McClellan)
        Timed out if no input (Jim)
    Re: Timed out if no input (Rene Nyffenegger)
    Re: Timed out if no input <mjcarman@home.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 8 Aug 2001 09:56:28 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Line counting in a file
Message-Id: <74f348f7.0108080856.3cc6753d@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<9krj4f$gq6$1@mamenchi.zrz.TU-Berlin.DE>...
> According to Yves Orton <demerphq@hotmail.com>:
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> > news:<9kqrk4$pth$1@mamenchi.zrz.TU-Berlin.DE>...
> > > According to Yves Orton <demerphq@hotmail.com>:
> > > > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> > > > news:<9kos74$fjn$2@mamenchi.zrz.TU-Berlin.DE>...
> > > > > According to John Imrie  <john.imrie@pa.press.net>:

SNIP

> > > > while (<>) {}
> > > > print $.;

SNIP

> > It printed out the correct number of lines.  Is there a point there
> > anno? :-)
> 
> Yes.  It didn't print anything, most likely print failed.  If it could,
> it would print the total of lines in the files mentioned on the command
> line, or count lines from STDIN.  Unless FILE happens to be opened to
> one of these, the count printed has nothing to do with the number of
> lines in FILE.
> 
> Apparently you didn't try the code you posted.

Ahhh.  Finally the cobwebs clear.  You are in pedantic mode. :-)  I
should have said

while (<FILE>) {}

Oh, and if you do run the second bit of code I provided you will see
that the point is valid even if the first bit of code was slightly
inconsistent.

And you _knew_ what I meant anyway.

Yves
ps (And yes it DOES work from the command line.  If you pipe a file to
the script I provided before it works fine.)


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

Date: Wed, 08 Aug 2001 11:07:46 -0400
From: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: manipulating webpages?
Message-Id: <3B7155C2.32437019@mortgagestats.com>



Nathan Randle wrote:

> How do you get a script to perform diffferent actions depending on the links
> found on a webpage then follow certain links?

You should use the LWP module (available from CPAN, in case it's not installed
on your system). Read the documentation for LWP and read the lwpcook document
(the LWP Cookbook).




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

Date: 8 Aug 2001 10:47:39 -0700
From: junkeater12@yahoo.com (Mike)
Subject: mresolv2 and sockets on HP-UX 10.20
Message-Id: <43e24eb1.0108080947.6d7f843d@posting.google.com>

<originally posted in comp.lang.perl by mistake>

Hello all,

I've been using Perl for a few years, but never sockets (in any
language) until now.  I'm trying to get a script given to me working
under HP-UX 10.20 and Perl 5.005_02 (our current in-house production
version - upgrading is not an option right now unless really needed)
which was based on mresolv2 1.3 (http://www.fuhr.org/~mfuhr/perldns/).
 When the script runs, the socket bind fails with an "Invalid
argument".  So, I thought, since the script is based on mresolv2, let
me try the original, unchanged mresolv 1.3.  I did, and I get the same
thing, an "Invalid argument", specifically:

can't bind socket: Invalid argument at mresolv2.pl line 58.

After hunting in the newsgroup archives at groups.google.com, I tried
changing the source address to a specific interface's address (instead
of 0.0.0.0), and the source port to a specific non-priv port (instead
of 0), but this did not change the result.

I know general (non-IO) socket support is correctly installed because
I tried the simple UDP example in the perlipc manpage and it returns
what I think is the proper result (time difference between local
machine and each host on the network which I supply on the command
line).

What (probably obvious) thing am I missing?  I suspect it's something
obvious because if I really knew socket programming I think it would
jump out at me.

Thanks!


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

Date: Wed, 8 Aug 2001 11:48:44 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Not matching strings
Message-Id: <slrn9n2nqs.mpm.tadmc@tadmc26.august.net>

Grunge Man <grunge12345@hotmail.com> wrote:

>Is there a way of doing:
>
>if ($string !~ /^PAT$/) {
>   print "hi\n";
>}
>
>but using =~ instead of !~


Sure:

   if ( ! $string =~ /^PAT$/) {
      print "hi\n";
   }

or

   unless ( $string =~ /^PAT$/) {
      print "hi\n";
   }


But I expect you were really trying to ask some question
(I couldn't figure out what, exactly...) other than the one
asked above...?


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


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

Date: Wed, 8 Aug 2001 11:51:02 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Pattern Matching: Which subpattern (rather than substring) was   matched?
Message-Id: <slrn9n2nv6.mpm.tadmc@tadmc26.august.net>

Jasper McCrea <jasper@guideguide.com> wrote:
>Martien Verbruggen wrote:
>> On Wed, 08 Aug 2001 03:01:18 +0100,
>>         Simon Best <barsticus@earthling.net> wrote:
>> > "John W. Krahn" wrote:
>> >>
>> >> print "Matched pattern number $#-\n"
>> >> # OR
>> >> print "Matched pattern number $#+\n"
>> >
>> > Thanks, but @- and @+ don't seem to exist!  Perhaps it's 'cause I'm
>> > using Perl 5.005_03?
>> 
>> Indeed.
>> 
>
>Is this also the reason I can't find an 'any' key?


You use the keys() function for finding keys.

heh.


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


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

Date: Wed, 8 Aug 2001 14:42:22 GMT
From: jtbell@presby.edu (Jon Bell)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <GHr7IM.43I@presby.edu>

In article <MPG.15da6ff931aa281d989716@news.edmonton.telusplanet.net>,
Carlos C. Gonzalez  <miscellaneousemail@yahoo.com> wrote:
>
>A lot of the perldoc documentation is very thorough and people have 
>graciously put a lot of time into it.  For this I am grateful but a lot 
>of it for someone like me who is a beginner is like Greek.  

Perldoc is a _reference_, not a textbook or a tutorial.  Using perldoc as 
your primary source for learning Perl is like using a dictionary and a 
grammar as primary references for learning English.

You should look for something that was written specifically as a textbook,
and use that as your initial guide.  If you're a beginner to programming
in general, you need a book that not only teaches Perl, but also teaches
general programming concepts.  (Many Perl books assume that the reader
already has some programming background in some other language.)  Perhaps
you'll even need _two_ books, one for programming (in some other language)
and one for Perl.  And you may need yet another book for CGI if that's
what you really want to do.

Then, as you're learning, also scan through the various sections of 
perldoc occasionally.  You'll pick up new things just by doing that, but 
more important, you'll become familiar with its layout, so that when you 
do want to look up something that isn't in your textbook, or something 
that you've just learned but want more details about, you'll have some 
idea where to look.

-- 
Jon Bell <jtbell@presby.edu>                        Presbyterian College
Dept. of Physics and Computer Science        Clinton, South Carolina USA


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

Date: Wed, 8 Aug 2001 17:06:58 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <9krkdl$kas$00$1@news.t-online.com>

"Carlos C. Gonzalez" <miscellaneousemail@yahoo.com> schrieb im Newsbeitrag
news:MPG.15da6ff931aa281d989716@news.edmonton.telusplanet.net...
> Hi everyone,
>
> A lot of the perldoc documentation is very thorough and people have
> graciously put a lot of time into it.  For this I am grateful but a lot
> of it for someone like me who is a beginner is like Greek.
> Interpolation, unary operator, lexical scope, expected semantics, extent
> of a string...  These are just some of the "Greek" terms in perldoc
> perlop that I saw.  Now I have some idea of what some of these are but
> the point I am making is that it seems to me that another version of the
> documentation needs to be rewritten in common English.  Without so much
> computereese in it.  Especially for us new beginners.
>
> It is very frustrating sometimes to be told to go read this or that perl
> documentation only to go to the documentation and to find myself reading
> something that has a bunch of terms that I don't even understand.  I need
> a simple answer to a simple and pointed question and I end up being
> confronted with a volume of information which ends up throwing terms at
> me that are even more confusing.
>
> Please don't get me wrong.  It's good to read through the documentation
> and I appreciate every tid bit and insight that is given me on this
> newsgroup and every suggestion as to which docomentation I should read.
> I truly do.  But I guess I am just wondering if it might not be good to
> have a new perldoc added devoted to giving the common meaning to as many
> computereese terms as can be found?
>
> I don't mean to step on anyone's toes.  I am just expressing my
> frustrations as a beginner to Perl for what they are worth and welcome
> any feedback on any of this.

You don't step on anybody's toes, but what you are demanding is that
somebody who *does* understand the docs paraphrases them in simpler terms.
First, it is hard to draw the line: How simple does the text have to be?
Second, that is a lot of work. Why should anybody paraphrase 1000 pages
worth of text if it's not of *any* use to him or her?
Third, you cannot simplify the docs without either losing a lot of their
content and meaning. If you do retain all of their content, you basically
just add an explanation of every IT term. I say *just* because it's easy to
describe the task that way. It's not *just* a little bit of work - that'd
bloat the docs to something trice their size.
Fourth, the docs are a reference and supposed to document all features.
Nobody ever said that you can understand them without any background.
Fifth, there are the FAQs. They are pretty easy to understand and answer *a
lot* of newbie questions. If you read through them, you'll come across a lot
of weird terms, too, but in the simpler context, you might be able to
understand them more easily. That way, when you encounter them in the rest
of the docs, you might have some grasp of their meaning already.
Sixth and most importantly, there are a lot of Perl tutorials on the web. A
few pretty good ones, too! Reading those will - just like the FAQs - help
you understand the more exotic terms.
Seventh, it would be a lot of work to keep the non-techie docs up to date.
The docs change quite a bit and one'd have to amend the paraphrased texts
accordingly. Anybody want to do that?

Steffen Müller





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

Date: Wed, 8 Aug 2001 09:50:11 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <slrn9n2gsj.mbp.tadmc@tadmc26.august.net>

Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>Carlos C. Gonzalez wrote:
>
>> A lot of the perldoc documentation is very thorough and people have 
>> graciously put a lot of time into it.  For this I am grateful but a lot 
>> of it for someone like me who is a beginner is like Greek.  
                                 ^^^^^^^^^^^^^

This thread will descend into confusion if we are not clear
on what we are speaking of.

Above, Carlos seems to be thinking "beginner with Perl".


>> Interpolation, unary operator, lexical scope, expected semantics, extent 
>> of a string...  These are just some of the "Greek" terms in perldoc 
>> perlop that I saw.  


Each of those terms (except perhaps interpolation) will be familiar
to anyone who has the fundamentals of programming in general.


>> Now I have some idea of what some of these are but 
>> the point I am making is that it seems to me that another version of the 
>> documentation needs to be rewritten in common English.  Without so much 
>> computereese in it.  Especially for us new beginners. 
                                          ^^^^^^^^^^^^^

Now those with programming training (or self learning) are
thinking "new to programming", not "new to Perl", as those are
not Perl-specific terms.

As Eric has mentioned, the Perl docs should document Perl. Other
docs should document programming fundamentals.


Learning programming AND Perl at the same time will be much much
harder than learning either one by itself.

(and many folks are also trying to learn Unix, Usenet and CGI
 programming all at the same time too! Hopeless to sort it all 
 out...
)


>Just note that no one is frowning upon people not yet fully 
>understanding the perl documentations. Just disregarding them at all is 
>considered a major sin in this newsgroup. ;-)


The above point seems to be often missed, so I'll leave it in
even though I don't have anything to add to it  :-)


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


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

Date: Wed, 8 Aug 2001 18:14:17 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <9krob4$l0r$07$1@news.t-online.com>

"Tad McClellan" <tadmc@augustmail.com> schrieb im Newsbeitrag
news:slrn9n2gsj.mbp.tadmc@tadmc26.august.net...
> Learning programming AND Perl at the same time will be much much
> harder than learning either one by itself.
>
> (and many folks are also trying to learn Unix, Usenet and CGI
>  programming all at the same time too! Hopeless to sort it all
>  out...
> )

If anybody considers what I do programming and not horrible
piecing-together, I'd say I did sort it all out at the same time.
Umm, well... I used basic before, but you aren't going to be good at squash
if you used to work as an indoor jojo professional, do you?

Steffen




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

Date: Wed, 08 Aug 2001 17:20:15 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <MPG.15db22897ad499d2989718@news.edmonton.telusplanet.net>

In article <slrn9n2gsj.mbp.tadmc@tadmc26.august.net>, Tad McClellan at 
tadmc@augustmail.com says...

> >> Interpolation, unary operator, lexical scope, expected semantics, extent 
> >> of a string...  These are just some of the "Greek" terms in perldoc 
> >> perlop that I saw.  
> 
> 
> Each of those terms (except perhaps interpolation) will be familiar
> to anyone who has the fundamentals of programming in general.
> 

Hi Tad and everyone else.  Thanks for all your input.  I am not sure I 
agree with the statement that the "terms will be..." above.  I started 
programming in DBase III+, moved on to C, derivatives of DBase III+, 
Visual Basic, and Delphi.  Although I would call myself a programmer many 
terms in Perl are new to me though to be sure *some* of the ones above 
are not.  I was just pointing out how some of these terms if not 
understood can confuse the rest of the documentation which builds on it.  
Making it a very frustrating experience to read. 

Programmers like me who come from high level languages (except for C - 
and my experience in that was the least in all of them) will have a 
tougher time than those who come from all out computer science 
backgrounds I am sure. 

> As Eric has mentioned, the Perl docs should document Perl. Other
> docs should document programming fundamentals.

If by programming fundamentals you mean control structures, compiling 
verses interpretation, structure programming verses objection oriented 
programming, using control structures like while and if statements, I 
completely agree. 

As another example of the kind of confusion that Perl can be for a 
beginning Perl programming take regular expressions.  I have never in my 
life had to deal with the confusions of Perl regular expressions.  C came 
close but even in C they were logical and from what I remember the 
characters used were consistent.  They did not change much with the 
context.  One character did not mean one thing until it was put inside 
brackets to mean something else type of thing.  And C's regular 
expressions did not have the incredibly rich set of possibilities that 
Perl's does IMHO.  

Perl's regular expressions seem to be so much more powerful and this is a 
very good thing.  But all the symbols and their combined uses takes a bit 
to get used to.  Even for someone like me who has done programming 
(albeit using high level languages).  Try writing Perl like regular 
expression in Delphi or Visual Basic?  You'll have to bend all over the 
place if you can even do it.  More than likely you will have to use a 
bunch of if statements to accomplish the same thing that can be done in 
Perl with one line.  I certainly wouldn't call regular expressions 
something that is a programming fundamental.  At least in how Perl does 
it.  Perl regular expressions are a skill all on it's own IMHO.  

Sure an assignment operation such as $string = "some value" is a 
programming fundamental.  

But not something like: $pattern =~ s/(\W)/\\$1/g;.  This is Perl 
peculiar. At least from my background.  I've never had to deal with this 
kind of confusing string until arriving at Perl.  

> Learning programming AND Perl at the same time will be much much
> harder than learning either one by itself.

Agreed.  But again I wonder if learning programming is the issue here.  
Take any top notch Delphi object oriented programmer and throw him or her 
into Perl and see what happens.  Some might not even survive.  Visual 
Basic programmers would even fare worse I think.  Yet I wouldn't say that 
such people are in need of learning the fundamental basics of 
programming.  Maybe their programming is not what a top notch Assembly 
programmer's experience is but it is programming nevertheless.  Maybe 
their background is not a four year degree in computer science but I 
would still call them programmers though not neccessarily computer 
scientists.  At least IMHO.  

> >Just note that no one is frowning upon people not yet fully 
> >understanding the perl documentations. Just disregarding them at all is 
> >considered a major sin in this newsgroup. ;-)

I've sort of discovered that already.  A few times in this newsgroup I 
have been led to believe that if I had only read the documentation I 
would not have needed to ask a question (even though I have spent on 
average of about an hour searching and reading through stuff or trying 
code for every question I ask).  At least that was the implication in 
some of the responses.  To be sure most responses have been absolutely 
wonderful but a few of them have led me to be very careful in asking 
questions on this newsgroup.  Sometimes I feel like I am talking to 
programmers who have lost touch with the realities of first coming into 
Perl.  If everything was so second nature to me I certainly wouldn't feel 
a need to ask my questions.  

Please don't take any of this to mean that I do not respect the responses 
or anyone in particular.  I am very appreciative of the help I have been 
given here but I would definitely tell newbie Perl programmers (from 
whatever background) to tread lightly here and to make sure that they 
have done some homework.  Which is a good thing I guess.  

Again my honest opinions for what they are worth. 

-- 
Carlos 
www.internetsuccess.ca


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

Date: Wed, 8 Aug 2001 11:41:53 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <slrn9n2ne1.mpm.tadmc@tadmc26.august.net>

I myself <tadmc@augustmail.com> wrote:
>Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote:
>>Carlos C. Gonzalez wrote:

>>> Now I have some idea of what some of these are but 
>>> the point I am making is that it seems to me that another version of the 
>>> documentation needs to be rewritten in common English.  Without so much 
>>> computereese in it.  Especially for us new beginners. 


I should point out that I have many times thought that the Perl
_FAQs_ could be made easier to understand for the untrained.

The thought occurred to me so many times that I seem to remember
starting to work on a swFAQ (Small Words), but my interest waned...


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


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

Date: Wed, 08 Aug 2001 17:36:35 GMT
From: Carlos C. Gonzalez <miscellaneousemail@yahoo.com>
Subject: Re: perldoc is like Greek to a beginner??
Message-Id: <MPG.15db2624813ad68989719@news.edmonton.telusplanet.net>

In article <GHr7IM.43I@presby.edu>, Jon Bell at jtbell@presby.edu says...

> Perldoc is a _reference_, not a textbook or a tutorial.  Using perldoc as 
> your primary source for learning Perl is like using a dictionary and a 
> grammar as primary references for learning English.

I agree.  I guess it's tough when I am directed to a reference work as 
such when I need to be tutored in how to do something that would best be 
discovered in a tutorial or textbook.  

Some on this newsgroup refer me to a part of the reference as the 
solution when what I need is a bit of tutoring.  Along with an 
encouragment to check out the reference.  

Some of the responses have been no more than just....

"Check out perldoc perlsomething."  

This is very tough for a beginning Perl programmer like me.  And 
frustrating.  I go to the reference work and find myself having to read 
through a mountain of material to find the answer that I need. 

Fortunately with the help of many on this and other newsgroups and some 
tutorial texts like "Learning Perl" I am getting there but it's slow 
going. 

Thanks.  

---
Carlos 
www.internetsuccess.ca


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

Date: Wed, 8 Aug 2001 09:52:54 -0700
From: "Oliver" <ow22@nospam-cornell.edu>
Subject: q: converting strings
Message-Id: <9krqpl$jv7$1@news01.cit.cornell.edu>

how do i convert a string to an int? thanks




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

Date: 8 Aug 2001 10:16:21 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: q: converting strings
Message-Id: <3b7173e5@news.victoria.tc.ca>

Oliver (ow22@nospam-cornell.edu) wrote:
: how do i convert a string to an int? thanks



In perl, if the string looks like a number then it is a number.

	e.g.
		$one = " 1 ";
		$two = " 2 ";
		$three = $one + $two ;
		print $three;

(Does that help?)

In a slightly different vein, there's a function called "int"  (see
perldoc perlfunc) and the pod for int mentions some other useful functions
along this same line. 





--
Want to access the command line of your CGI account?  Need to debug your
installed CGI scripts?  Transfer and edit files right from your browser? 

What you need is "ispy.cgi" - visit http://nisoftware.com/ispy.cgi


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

Date: Wed, 08 Aug 2001 18:45:20 +0100
From: Jasper McCrea <jasper@guideguide.com>
Subject: Re: q: converting strings
Message-Id: <3B717AB0.BB0C1DBA@guideguide.com>

Malcolm Dew-Jones wrote:
> 
> Oliver (ow22@nospam-cornell.edu) wrote:
> : how do i convert a string to an int? thanks
> 
> In perl, if the string looks like a number then it is a number.
> 

This is a little misleading.

$one = "twelve";
$two = "12";

both are strings, and look like numbers to me.

It is when perl comes to interpret a string as a number that it does
some fancy stuff. If you int(), even indirectly, a string that has no
leading number characters, it'll give you zero, and work with that.

print "twelve" + "thirteen", "\n"; # gives 0
print "this12" + "that13", "\n";   # gives 0
print "12this" + "13that", "\n";   # gives 25

more obviously

print "12" + "13", "\n";           # gives 25, too

and we get onto string and number comparisons...

print "same string\n" if "13this" eq "13that"; # doesn't print
print "same number\n" if "13this" == "13that"; # does print

Jasper
-- 
      split//,'019617511192'.
      '17011111610114101114'.
      '21011141011840799901'.
            '17101174';
            foreach(0..
            $#_){$_[$_
            ++]^=$_[$_
            --]^=$_[$_
]^=$_[++    $_]if!($_%
2)}$g.=$_  ,chr($g)=~
 /(\w)/&&($o.=$1and
   $g='')foreach@_;
      print"$o\n"


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

Date: Wed, 8 Aug 2001 12:39:46 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: RegEXP's
Message-Id: <slrn9n2qqi.mpm.tadmc@tadmc26.august.net>

Adrian Immler <newsgroup@12mm.de> wrote:
>let's say i've got a string like this:
>
>$string = 'this is my great <b>string</b> with lots of <a
>href="http://www.foo-bar.com/index.php?action=listall&user=foo">links</a> in
>it to some place on the net.';


That sure doesn't look like merely "a string".

That looks like HTML. If it really is HTML, then a general-purpose
robust solution becomes Much Harder. In that case, you should use
a module that understands HTML for processing HTML.


>is it possible to create an array with RegEXP's that looks like this? :
>
>$array[0] = 'this';
>$array[1] = 'is';
>$array[2] = 'my';
[snip]
>...
>$array[n] = '<a
>href="http://www.foo-bar.com/index.php?action=listall&user=foo">';


Newlines within HTML tags are not significant. Yet another reason
to know if we are dealing with "HTML" or with "a string"...


>$array[n] = 'links';
        ^
        ^ n+1 surely...


First, let us get the correct way done:

---------------------------------------------
#!/usr/bin/perl -w
use strict;
use HTML::TokeParser;

my $string = 'this is my great <b>string</b> with lots of <a
href="http://www.foo-bar.com/index.php?action=listall&user=foo">links</a> in
it to some place on the net.';

my $p = HTML::TokeParser->new( \$string) || die "parsing problem... $!";

my @array;
while ( my $token_ref = $p->get_token() ) {
   my $tokentype = $token_ref->[0];

   if ( $tokentype eq 'T' ) {  # Text (#PCDATA)
      push @array, split(' ', $token_ref->[1])
   }
   elsif ( $tokentype eq 'E' ) {  # End tag
      push @array, "</$token_ref->[1]>";
   }
   elsif ( $tokentype eq 'S' ) {  # Start tag
      my( undef, $gi, $attr, $attrseq, $text) = @$token_ref;

      my $tag = "<$gi";
      foreach my $attrname ( @$attrseq ) {
         $tag .= qq( $attrname="$attr->{$attrname}");
      }
      $tag .= '>';
      push @array, $tag;
   }

}

print "$_: $array[$_]\n" for  0..$#array;
---------------------------------------------

The above does not preserve newlines within tags though.

(And it shouldn't.)


>i've got the problems with that it should not break it up at spaces within
><>.


Yes, you can do that for the string you show above. This will not
work on arbitrary HTML though:

   my @array = $string =~ /(<[^>]+>|[^\s<]+)/g;


>question1: how is the performance 


Performance of what? I don't see a program here. If I did, I
would use the Benchmark module to find out which alternative
is faster.

Premature optimization is a bad idea.

Carefully choose a good algorithm, then code it up.

Only _after_ it has proven to have a problem do you turn your
attention to solving the problem. It may be "fast enough" on
your first try, and you can avoid concerning yourself with it
altogether...


>question2: can someone tell me that regexp?


See above, but tremble in fear if you use it on arbitrary HTML.


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


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

Date: Wed, 8 Aug 2001 09:01:27 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: String version of += assignment operator??
Message-Id: <slrn9n2e17.mbp.tadmc@tadmc26.august.net>

Brent Dax <brentdax1@earthlink.net> wrote:
>
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrn9n0qpo.kas.tadmc@tadmc26.august.net...
>...
>>    perl -ne "print if /^=/" perlfaq[1-9].pod >faq.heads
>
>Not on Windows.  For some odd reason, DOS leaves the globbing to the
>program, 


But we know how to write Perl, so we write Perl to overcome
that deficiency too:

   perl -ne "BEGIN {@ARGV = glob 'perlfaq[1-9].pod'} print if /^=/"


Perl is even more important than normal if you must work in
a silly environment. You use it to write the tools that you need.

:-)


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


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

Date: Wed, 08 Aug 2001 14:50:08 GMT
From: test@test.com (Jim)
Subject: Timed out if no input
Message-Id: <3b7150da.23742565@newscore.theplanet.net>

Hi,
I guess this is simple to do but I'm not having much luck.
I want to wait 5 seconds for a Y/N ans to a question
"Do you want to continue? "
If I get a Y within 5 seconds I print "Continuing" if I
get a N or nothing the script exits.

Anyone any thoughts?
Jim


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

Date: 8 Aug 2001 17:02:06 GMT
From: rene.nyffenegger@gmx.ch (Rene Nyffenegger)
Subject: Re: Timed out if no input
Message-Id: <Xns90F749AACAFDAgnuegischgnueg@130.133.1.4>


>Hi,
>I guess this is simple to do but I'm not having much luck.
>I want to wait 5 seconds for a Y/N ans to a question
>"Do you want to continue? "
>If I get a Y within 5 seconds I print "Continuing" if I
>get a N or nothing the script exits.


Are you running the script under Unix? Then an alarm should do:

print "Yes or No:";
eval{
    local $SIG{ALRM} = sub { die };
    alarm 5;
    $yn = <STDIN>;
    print "You typed yn\n";
    alarm 0;
    1;
} or print "you're late!\n";

However, alarm is not implemented under windows. 


-- 
Recherchen im Schweizerischen Handelsamtsblatt:
http://www.adp-gmbh.ch/SwissCompanies/Search.php3


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

Date: Wed, 08 Aug 2001 11:18:42 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Timed out if no input
Message-Id: <3B716662.1EC08A4F@home.com>

Jim wrote:
> 
> I guess this is simple to do but I'm not having much luck.
> I want to wait 5 seconds for a Y/N ans to a question
> "Do you want to continue? "

You want the alarm() function.

eval {
    local $SIG{ALRM} = sub {die "timeout\n"};
    alarm(5);
    print "Do you want to continue?\n";
    chomp($response = <STDIN>);
};
if ($@) {
    print "Too late!\n";
    exit;
}

unless ($response =~ /^y/i) {
    print "Goodbye.\n";
    exit;
}

-mjc


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

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.  

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


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