[23418] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5636 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 8 18:10:38 2003

Date: Wed, 8 Oct 2003 15:10:12 -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           Wed, 8 Oct 2003     Volume: 10 Number: 5636

Today's topics:
    Re: rotate items in log file <robertw@nospam.acm.org>
    Re: Send two documents to browser? - repost <mbudash@sonic.net>
    Re: Simple Regex Problem (James E Keenan)
    Re: Simple Regex Problem (Roy Johnson)
    Re: Sockets question <krahnj@acm.org>
    Re: TCP Listener on Windows XP <ThomasKratz@REMOVEwebCAPS.de>
    Re: Teach me how to fish, regexp <henryn@zzzspacebbs.com>
    Re:  <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 08 Oct 2003 11:51:33 -0400
From: Robert Wallace <robertw@nospam.acm.org>
Subject: Re: rotate items in log file
Message-Id: <3F843285.BC33EACA@nospam.acm.org>

thanks folks. here's what I did:

Tad McClellan wrote:
> 
> Robert Wallace <robertw@nospam.acm.org> wrote:
> 
> > in my code i'm trying to keep a log file of say 10 lines.
 ....

> 
> That does NOT get the size of the @logFile array, that gets the
> 1st element, same as:
> 
>    my($size) = $logFile[0];
> 
> You need the name of the array in _scalar_ context if you want
> to get the size:
> 
>    my $size = @logFile;
> 
> >     if ($size > 10){
> 
got rid of the $size thing.


> Here you already have a scalar context, so you don't even need the $size
> temporary variable:
> 
>    if (@logFile > 10) {
> 
> >     my($logFileWrite)=join "\n", @logFile;
> 
> Why did you chomp() them above only to put the newlines back in?
> 
> (and why no newline on the last element?)
> 
done.

> I don't see any file locking going on. Is logging going on while
> you are rotating the log?
> 
> > is there a way perhaps to move 10 items from one array to another
> 
I thought I keep it simple.
you think it'll be a problem without locking?


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

Date: Wed, 08 Oct 2003 15:21:28 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Send two documents to browser? - repost
Message-Id: <mbudash-5A1355.08212908102003@typhoon.sonic.net>

In article <45j7ovkt9uhjjpbs676sjr0s2suuqlg5g5@4ax.com>,
 Mark <REMOVEXtwoheadsX@tiscaliX.co.uk> wrote:

> > Hi All, 
> > 
> > I have a commercial website search script which is slow in returning
> > its results. The consequence is that for a short period the screen is
> > white until the results are returned. 
> > 
> > Is there a simple way to make the script return a temporary document
> > to the browser which is then replaced by the search results? 
> > 
> 
> Yes, there are simple ways to do this. However, they are no more 
> Perl-specific than they are Cobol-specific. Rather than give you a
> whole 
> solution here (and encourage more non-Perl-specific questions,
> drowning 
> out those with Perl questions), I'll mention "interstitial pages", 
> "browser redirects", and point you toward Google and the 
> comp.infosystems.www.authoring.cgi newsgroup.

http://www.stonehenge.com/merlyn/WebTechniques/col20.html

hth-

-- 
Michael Budash


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

Date: 8 Oct 2003 09:14:37 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: Simple Regex Problem
Message-Id: <b955da04.0310080814.e554641@posting.google.com>

Robert <rob@nospam.here> wrote in message news:<ibp7ov0qcuq7quoq6jtugamd177tdhgvdh@4ax.com>...
> I am struggling with the following (simple) problem.
> Given a list of vehicles I need to capitalise the first letter of the
> make and model and change the spec to uppercase.
> 
> eg.
> ford mondeo 2.0 glx
> Ford Mondeo 2.0 GLX
> 
> The closest I can get is this but it capitalises every word.
> 
> $model =~ s/(\w+)/\u\L$1/g;
> 
> Any pointers would be appreciated.

Have you consulted this item in the docs?

    perldoc -f ucfirst


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

Date: 8 Oct 2003 11:58:41 -0700
From: rjohnson@shell.com (Roy Johnson)
Subject: Re: Simple Regex Problem
Message-Id: <3ee08638.0310081058.58bc5a0b@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbo82hb.lcb.tadmc@magna.augustmail.com>...
> Robert <rob@nospam.here> wrote:
> > $model =~ s/(\w+)/\u\L$1/g;
>    $model =~ s/(\w+)$/\U$1/g;  # uc "the spec"

Just for fun, one that does it all:

    s/\b(\w(\w*$)?)/\U$1/g;


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

Date: Wed, 08 Oct 2003 17:07:14 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Sockets question
Message-Id: <3F84443F.C065556F@acm.org>

John wrote:
> 
> One of the exercises in front of me is:
> "Write a server in perl that will send the client a sleepy string of
> "ZZZZZZZZZ" whenever it connects using port 54321 from the same host using a
> socket in the UNIX domain."
> 
> Can someone possibly re-phrase the question? I have no idea about sockets -
> just found a chapter on it in Prog. Perl but have not read it yet :(.
> Any links out there I can get ideas/learn from?

perldoc perlipc


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 08 Oct 2003 19:18:19 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: TCP Listener on Windows XP
Message-Id: <3f84476e.0@juno.wiesbaden.netsurf.de>

Colin Robbins wrote:

> I have a network application that works fine on Linux, and I want to run it
> on on a Windows XP machine.   For some reason I cannot get the TCP listener
> to respond.
> 
> I have cut the code down to the bare minimum to try and debug...
> 
>         use IO::Socket;
>         use Net::hostent;
>         $PORT = 2345;
>         $server = IO::Socket::INET->new( Proto     => 'tcp',
>                                   LocalPort => $PORT,
>                                   Listen    => SOMAXCONN,
>                                   Reuse     => 1);
>                   die "can't setup server" unless $server;
>        print "[Server $0 accepting clients]\n";
>        while ($client = $server->accept()) {
>                $hostinfo = gethostbyaddr($client->peeraddr);
>                printf "Connect from %s\n", $hostinfo->name ||
> $client->peerhost;
>                $line = <$client>;
>                print "Got:  $line \n";
>                close $client;
>         }
> 
> When I run this, and connect a client, I get as far as the "Connect from..."
> message, but the $line=<$client> never returns anything.
> 
> Any ideas why this will not work on XP?
> 
> I am using ActivState perl 5.8.0.

I copied and pasted the code to an XP machine and did a 'telnet 
localhost 2345'. Worked like a charm. Didn't have a Unix machine to 
test it from there.

I think mooseshoes is right in assuming that the client doesn't send a 
valid line ending.

Thomas



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

Date: Wed, 08 Oct 2003 19:21:02 GMT
From: Henry <henryn@zzzspacebbs.com>
Subject: Re: Teach me how to fish, regexp
Message-Id: <BBA9B1AC.1569F%henryn@zzzspacebbs.com>

Martien:

Thanks for your response on this thread:

in article slrnbo6sk1.pv1.mgjv@verbruggen.comdyn.com.au, Martien Verbruggen
at mgjv@tradingpost.com.au wrote on 10/7/03 7:12 PM:

<snip> <snip>
> 
>>>> Seems the best way to deal with this is to slurp, and use "split"
>>>> with the appropriate regexp.  Wrinkle: I need to retain the
>>>> section numbers in the return strings.
>>>> 
>>> I would probably set the input record separator ($/, see perlvar)
>>> to "", which will treat two or more consecutive newlines as the
>>> record separator. Then each record starts with the number you're
>>> interested in.
> 
>> Right, that's what I finally did, in effect. (I did something
>> similar at the "split".)  But this  isn't very robust, I think: it
>> depends on some typist somewhere _always_ following the rules.
>> 
>> I think you are saying that slurp mode may not be the best choice.
>> 
>> As far as your setting
>> 
>>    $/ = "";
>> 
>> This is not exactly intuitive from the point of view of a newcomer.
>> Sorry, could you help me understand  (or give me a blind rule of
>> thumb) how what looks like setting a variable to an empty string
>> implies "two or more successive newlines"?
> 
> The perlvar documentation explains what $/ (the input record
> separator) does, and that it has a "special" setting of the empty
> string, which makes it reads "paragraphs", i.e. blocks of text
> separated by two or more newlines.

Right.  You are too polite, so I'll say it: I need to RTFM.

That said, I have to say I find the man pages the last place I want to look
in terms of convenience.  I'll have to find a web based... Done!

Ah, much easier.  Here's a relevant extract.

 ...Setting to "" will treat two or more consecutive empty lines as a single
empty line. Setting to "\n\n" will blindly assume that the next input
character belongs to the next paragraph, even if it's a newline. (Mnemonic:
/ delimits line boundaries when quoting poetry.)

Quoting _poetry_?

The choice of "" as a special is clearly a choice of convenience on the part
the people doing the internals-- and has no particular mnemonic or symbolic
values.  I'm glad that's clear.

This gives me a clue to the magnitude of my task of learning perl to do
useful work.

<snip> 
>> 
>>>   (           # start capture
>> 
>> Capture?  I guess you mean the mysterious "save the stuff you match"
>> mechanisms I've found in some perl references.  The explanations
>> I've found are very short and not very useful.   Also:  I find it
>> hard to discriminate between parens used for operation grouping and
>> this use.
> 
> Yes. Capturing parentheses "save" whatever is matched between them,
> and return it as a result of the operation, as well as in the named
> variables $1, $2, etc.. At the same time they group multiple
> characters together to form a single subpattern.

(I have the books "Perl by Example" and "Learning Perl" and what I've
finding is those aren't particularly good references when it comes to
details like this.)

Right, now I'm getting the idea.  Parens capture the matched stuff.

Thanks for coming out and saying this so directly.

Apparently only specially-marked parens do NOT capture stuff, right. Also, I
see by reading further that capturing is expensive in terms of processing
time, so you might want to limit its use.
> 
> There is more information about this in the perlre documentation,

Aha: in a Warning, I find

         ...(stuff)...

Captures stuff, but

     ...(?:stuff)...

doesn't.  Cute.

> well as in the perlop documentation under the entry for
> "m/PATTERN/cgimosx".

Hmmm, yet another man page.  How _many_ are there?  Over 100?  Hmmmm...

Yes, that's the best treatment of many issues that I could not understand by
consulting other references. Thanks!

I'm still trying to figure out the best way of referring to what are here
called "flags" in this context, but seem to have other names elsewhere:  the
"cgimosx" items.   Am I confused, or is this confusing?
> 
>>>     (?:       # start grouping, but no capturing
>> 
>> Sorry, could you speak more fully about this?  Again, I haven't
>> found a good reference for this stuff.
> 
> If you only want to group some stuff together in a subpattern, but you
> don't want that match of that subpattern returned as one of the digit
> variables, or in the return list, you use (?:PATTERN). Again, see the
> perlre documentation for a full explanation.
> 
>>>   .\ \        # literal . followed by two spaces
>> 
>> Sorry, I don't get that.  Could you explain more fully?  I think that I
>> understand that a period, unescaped, matches any character, so I would
>> expect that you'd have to escape before the period to match a literal
>> period/decimal point.
> 
> You're right. my mistake in transcribing the regular expression. there
> should be a backslash in front of the dot.

Sound effect:  <Long sigh of relief>.   (I'm not a total dipstick.)
> 
>>>   (.*)        # capture the rest of the record
>> 
>> I think I understand that
>> 
>>    .*
>> 
>> means "any character, repeated 0 or more times", but I don't get how the
>> parens lead to capture (and not operation grouping, as above) and eventual
>> appearance of the captured data somewhere.
> 
> It does both. They group, and as a side effect, the matched subpattern
> gets captured and returned (in this case as the second element of the
> returned list, as well as in $2).

Aha!  

It seems to me that you can use parens to affect operation grouping, if you
are sufficiently qualified (or ambitious);  that's story #2.   Depending on
which documentation you use, you may discover Story #2,  which describes who
parens _also_ store data, how to access that data, and how and why avoid
unnecessary use of this feature.

What I did not find --part of why I'm here-- is a reference that tells both
stories.   
> 
>>> The first capturing set of parentheses returns the paragraph
>>> number, including the sub-number, if present, and the second
>>> capturing parentheses set returns the "Blah, blah.." bit up to the
>>> end of the record.
>> 
>> Right, as I said above, I can't figure out how this aspect works.
>> This may seem obvious to you but looks like a hidden (or magical)
>> side-effect to me.
> 
> The fact that those grouped subpattern matches get returned (and saved
> in $1, $2...) is more an effect of the m// operator (documented in
> perlop) than of regular expressions themselves. However, they do get
> captured in regular expressions, and you can refer back to them (with
> \1, \2...) inside of the same regular expression.

I'm sorry you said _that_, because now I have uncertainty about the scope of
this "side effect" in different contexts.  I guess your purpose is to alert
me to the fact that parens in regexps anyplace do save data, but the
accessibility of the data varies from context to context. Right?
\
> 
<snip>
<snip>
> 
<snip> 

> There are also a perlrequick and a perlretut manual page, which are
> more gentle introductions to regular expressions than the perlre
> reference documentation. You should probably have a bit of a read of
> those.
> 
In my spare time, I'll concatenate all the perlxxxx man pages and see how
the contents compare to a moderate sized book.

That's a lot of stuff, and in a reference format.  Fortunately, the examples
are generally quite good, but this isn't exactly the most friendly
environment.    
> 
> Furthermore: Don't worry too much that some of this stuff looks
> magical. It is. Perl is full of things that you just have to learn
> about by immersion, and by repeated visits to the same documentation.
> it can take a while before some of this stuff becomes automatic.

Perl doesn't seem to be anything one can pick up quickly, that's for sure.

Thanks,

Henry

henryn@zzzspacebbs.com    remove 'zzz'
> 
> 
> Martien



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

Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: 
Message-Id: <3F18A600.3040306@rochester.rr.com>

Ron wrote:

> Tried this code get a server 500 error.
> 
> Anyone know what's wrong with it?
> 
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {

(---^


>     dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
 ...
> Ron

 ...
-- 
Bob Walton



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

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


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