[19674] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1869 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 4 06:10:25 2001

Date: Thu, 4 Oct 2001 03:10:09 -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: <1002190209-v10-i1869@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 4 Oct 2001     Volume: 10 Number: 1869

Today's topics:
        parallel http-requests with LWP::Parallel <mr.thanquol@gmx.de>
    Re: pattern matching between range (Anno Siegel)
    Re: remove some pattern at the end of a file (Anno Siegel)
        Skipping following lines if the same (Laird)
    Re: Skipping following lines if the same <Rainer.Klier@erl.sbs.de>
    Re: socket robustness (perl misk)
    Re: Something wrong with this? (Anno Siegel)
    Re: Template-Toolkit (Randal L. Schwartz)
    Re: What does POSIX-compliant mean ? <ilya@martynov.org>
    Re: Whither Palm Perl? (Anno Siegel)
        Why does if statement not work ? <nick.blake@qr.com.au>
    Re: Why does if statement not work ? benhopkins@mindspring.com
    Re: Why does if statement not work ? <nick.blake@qr.com.au>
    Re: Why does if statement not work ? <ilya@martynov.org>
    Re: Why does if statement not work ? nobull@mail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 4 Oct 2001 11:33:25 +0200
From: felix <mr.thanquol@gmx.de>
Subject: parallel http-requests with LWP::Parallel
Message-Id: <9phb1m$j6c$1@crusher.de.colt.net>

Hi,

I'm trying to make some parallel request to my website. This is not the 
problem, but I think If go a logical problem and I am actually not able to 
see it... :-((  . I am reading the URL's out of my database and want to 
call 5 of them parallel with this part of my code



foreach my $categoryid (@CategoryValues){
        my $StoreUrl = $StoreCatalogUrl . $sid . $categoryid;
        my $StoreRequest = HTTP::Request->new('GET', $StoreUrl);
        push (@RequestCount, $StoreRequest);

        if (scalar @RequestCount eq $MaxRequestCount){
           foreach my $requests (@RequestCount){ 
               # Create $MaxRequestPerTime http-requests
               print "Registering '" . $requests->url . "'\n"
                   if (my $res = $ua->register ($requests));
           }

           my $entries = $ua->wait();
           foreach (keys %$entries){
               my $response = $entries->{$_}->response;
               print "Answer for '", $response->request->url, "' \n";}
              @RequestCount = ();
              print "Scalar of REQEUSTCOUNTER = ". scalar @RequestCount . 
"\n";} 
        else { print "not enough url's yet";}
    }

this calls first 5 than 10 than 15 ... urls. but I what i need is that it 
always calls 5 urls....

thx 
fe


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

Date: 4 Oct 2001 08:20:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: pattern matching between range
Message-Id: <9ph653$6id$1@mamenchi.zrz.TU-Berlin.DE>

According to jzh <jzh@earthlink.net>:
> I need to match between a range in a file.
> 
> File:
> 
> Hpppppppp
> S01010101
> D.................
> Dxxxxxxxxx
> Dvvvvvvvvv
> Hqqqqqqqq
> S33333333
> Drrrrrrrrrrrrr
> Dpppppppp
> Hqqqqqqqq
> S01010101
> Dlllllllllllllllllllll
> Dpppppppp
> 
> I need to match based on the pattern found in lines starting with S
> then I need to return the values between H (the line before the match until
> next occurance of H)
> The Pattern starting with S may not be unique in the input file.
> 
> Example output:
> 
> based on matching on S01010101
> 
> Hpppppppp
> S01010101
> D.................
> Dxxxxxxxxx
> Dvvvvvvvvv
> Hqqqqqqqq

There would be another line "Hqqqqqqqq" here, following your description.

> S01010101
> Dlllllllllllllllllllll
> Dpppppppp
> 
> I used the range operator in regex to print between but it does not return
> the proper values
> 
> My code:
> #!/usr/bin/perl
> @keys=qw/S01010101 S33333333/;
> @file=<>;
> sub print_records {
>   foreach $key (@keys) {
>     for (@file) {
>       if (/^$key/ ... /^H/) {print}
>     }
>   }
> }

Using the range operator is fine, but making a pass over the whole
file for each key is inefficient[1].  Also, there are no provisions
in your code to print the line *before* the match, so how did you
expect it to produce the desired output?

    my $key_re = qr/S01010101|S33333333/;
    
    my $h_line;
    while ( <> ) {
        $h_line = $_ if /^H/;       # keep it in case we need it
        print $h_line if /$key_re/; # print the last H-line
        print if /$key_re/ .. /^H/; # print rest of block
    }

Anno

[1] Cardinal Slurphammer remarks that it also leads to unnecessary
    file slurping.


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

Date: 4 Oct 2001 09:22:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: remove some pattern at the end of a file
Message-Id: <9ph9ol$6id$4@mamenchi.zrz.TU-Berlin.DE>

According to hwchui <hwc33@hotmail.com>:
> I created a function to remove pattern <<CNF>> appearing at the end of
>  a file.
> 
> sub removeCode {
>  my ($filename) = @_;
> 
>  local(*FH);
>  open(FH, "+< $filename") || die "Can\'t open file $filename: $!\n";
> 
>  $out = '';
> 
>  while(<FH>) {
>   s/<<CNF>>//g;
>   $out .= $_;
>  }
> 
>  seek(FH, 0, 0)   || die "Can't seek to start of $filename\n";
>  print FH $out   || die "Can't print to $filename\n";
>  truncate(FH, tell(FH))  || die "Can't truncate $filename\n";
>  close(FH);
> }
> 
> 
> 
> Is there a way which only goes to the last line of a file and remove a given
> pattern?  so that it more efficient that reading the whole file. As I know
> the
> given pattern only appears at the end of the file.

Well for one, there is no need to re-write the file if you want
to truncate a few bytes.

As for positioning to the last line, Uri's module File::ReadBackwards
(does he really use that many capital letters? :) should do that.

If you know the length of the pattern (or a reasonable upper bound),
you could also seek to that many byes before EOF and then check
if the pattern appears.  If it does, truncate as above.

Anno


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

Date: 4 Oct 2001 02:12:56 -0700
From: kenlaird@yahoo.com (Laird)
Subject: Skipping following lines if the same
Message-Id: <94a02505.0110040112.3dd9557d@posting.google.com>

Hi everyone,

I've got this array

aaa
aaa
bbbbb
cccc
cccc
c
ddd
ddd
fff
fff
fff
ffff
ffff


and would like to transform it into this


aaa
bbbbb
cccc
c
ddd
fff
ffff


skipping following lines if the same.
But only following lines.

I tried this but it doesn't work.

#!/usr/bin/perl
     open (IN,data);
     @a=<IN>;
     for (@a){
     $i++;
     chomp $a[$i];
     print "$a[$i]\n" if /$a[$i]/ ne /$a[$i+1]/
     }




Cordially 
Ken


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

Date: Thu, 04 Oct 2001 10:42:49 -0100
From: Rainer Klier <Rainer.Klier@erl.sbs.de>
Subject: Re: Skipping following lines if the same
Message-Id: <3BBC4B39.6E546570@erl.sbs.de>

Laird wrote:
> 
> Hi everyone,
> 
> I've got this array
> 
> aaa
> aaa
> bbbbb
> cccc
> cccc
> c
> ddd
> ddd
> fff
> fff
> fff
> ffff
> ffff
> 
> and would like to transform it into this
> 
> aaa
> bbbbb
> cccc
> c
> ddd
> fff
> ffff
> 

Try this: perldoc -q duplicate

Bye, Rainer


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

Date: 4 Oct 2001 01:59:11 -0700
From: perlmisk@yahoo.co.uk (perl misk)
Subject: Re: socket robustness
Message-Id: <7fe42fcd.0110040059.2b34213@posting.google.com>

Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3BBB911C.74468C1B@earthlink.net>...
> perl misk wrote:
> > 
> > within a socket server, if one uses:
> 
> First, I'm going to assume that you mean by "socket server":
> A server which has used accept() to get connections from clients, and
> has one socket to each client.
> 
> >     104     while (defined (my $reply = <$sock>)) {
> >     105
> >     106         print "$reply\n";
> >     107
> >     108     }
> > 
> > is this a potential bug?
> 
> Yes.  You should use select and sysread, not <>.

oh.

From the APP book:

12.3 Handling Multiple Clients

<snip>

1.Create multiple threads of control (processes or threads) and have
each call block in its own thread.

2.Make these calls only when you are absolutely sure they won't block.
We'll call this the "select" approach, because we use the select call
to ensure that a socket has something to offer.

3.Make these calls nonblocking using fcntl or ioctl. 

I have gone down the route of [1.] - even though the book says not -
for some strange reason I thought I new best ;)

The reason I did this was, when I tried RPC.pm which calls Msg.pm,
select appeared to only service 1 client's request at any one time,
instead of timeslicing.

ie. server.pl
sub pause30 {
    print shift . " start\n";
    sleep(30);
    print shift . " finished\n";
}

clientA.pl
RPC->pause30(A);		# sorry, I forget the syntax

clientB.pl
RPC->pause30(B);

both clients are executed from the cmd line at almost the same time.
result in:

A start
<gap>
A finished
B start
<gap>
B finished

as opposed to what I was hoping for:

A start
B start
<gap> * 2
A (or B) finished
B (or A) finished

So is select the preferred method even though it doesn't offer
'apparent' multiple access?


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

Date: 4 Oct 2001 08:58:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Something wrong with this?
Message-Id: <9ph8c1$6id$3@mamenchi.zrz.TU-Berlin.DE>

According to Joe Schaefer  <joe+usenet@sunstarsys.com>:

> -- 
> Joe Schaefer                 "Language is the dress of thought."
>                                                -- Samuel Johnson
> 

Does that make an autist a cognitive nudist?

Anno


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

Date: 04 Oct 2001 02:50:42 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Template-Toolkit
Message-Id: <m1lmirybrh.fsf@halfdome.holdit.com>

[comp.lang.perl is an unapproved group.  removed from list]

>>>>> "Evil" == Evil Overlord <webmaster@thedarkcitadel.com> writes:

Evil> Anybody use this? Is it any good?

Ever heard of citysearch.com or ticketmaster.com ?
Or etoys.com before that?

Perhaps you can visit tt2.org (the website for Template) and see for
yourself.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: 04 Oct 2001 13:14:32 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: What does POSIX-compliant mean ?
Message-Id: <87eloj4vif.fsf@abra.ru>

>>>>> On Thu, 4 Oct 2001 15:36:29 +1000, "Gregory Toomey" <nobody@nowhere.com> said:

GT> It was an attempt to define a set of common system calls, so that all
GT> flavours of Unix would be compatible. Windows NT is also supposed to be
GT> Posix compliant, so Perl should run OK there as well.

AFAIK there are exist several POSIX standarts. WinNT supports only
some of them. For example it is possible to create hardlink on WinNT
but it is impossible to make symlink. Another example: WinNT doesn't
have fork. WinNT doesn't have all POSIX syscalls which are required
for full support of Perl (remember fork - it is emulated using threads
in Win32 port of Perl).

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 4 Oct 2001 08:47:11 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Whither Palm Perl?
Message-Id: <9ph7mf$6id$2@mamenchi.zrz.TU-Berlin.DE>

According to DrDebug <DrDebug@att.net>:
> Is there some reason why Perl has not been ported to the PalmOS?
> 
> Sure it's big, but couldn't something be done?
> 
> Is there other reasons why not?

Not only is Perl big, Perl programs are not exactly parsimonious of
system resources.  Experiences with other interpreters that have been
ported to PalmOS (LispMe) are not too encouraging.

Anno


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

Date: Thu, 4 Oct 2001 17:42:37 +1000
From: "Nick Blake" <nick.blake@qr.com.au>
Subject: Why does if statement not work ?
Message-Id: <9ph3tg$bbm1@inetbws1.citec.com.au>


while ( <> ){

($path, $who, $acl) = split(/,/, $_);
chomp $acl;

 $length = length( $path );

$newpath = substr($path, -1, $length);

if ( $newpath = '\'){

(print "yes it is\n") }
}




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

Date: Thu, 4 Oct 2001 00:54:11 -0700
From: benhopkins@mindspring.com
Subject: Re: Why does if statement not work ?
Message-Id: <3j4hp9.193.ln@127.0.0.1>

Nick Blake <nick.blake@qr.com.au> wrote:

> while ( <> ){

> ($path, $who, $acl) = split(/,/, $_);
> chomp $acl;

>  $length = length( $path );

> $newpath = substr($path, -1, $length);

> if ( $newpath = '\'){
  if ( $newpath eq '\'){       # '=' is an assignment operator, 'eq' or '=='
							   #   tests for equality
> (print "yes it is\n") }
> }




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

Date: Thu, 4 Oct 2001 19:07:40 +1000
From: "Nick Blake" <nick.blake@qr.com.au>
Subject: Re: Why does if statement not work ?
Message-Id: <9ph8sv$bli1@inetbws1.citec.com.au>

I tried but still receiving a error.

Can't find string terminator "'" anywhere before EOF at roky.pl line 10.

while ( <> ){

($path, $who, $acl) = split(/,/, $_);
chomp $acl;

 $length = length( $path );

$newpath = substr($path, -1, $length);

if ( $newpath eq '\'){ print "yes it is\n" }
}



<benhopkins@mindspring.com> wrote in message news:3j4hp9.193.ln@127.0.0.1...
> Nick Blake <nick.blake@qr.com.au> wrote:
>
> > while ( <> ){
>
> > ($path, $who, $acl) = split(/,/, $_);
> > chomp $acl;
>
> >  $length = length( $path );
>
> > $newpath = substr($path, -1, $length);
>
> > if ( $newpath = '\'){
>   if ( $newpath eq '\'){       # '=' is an assignment operator, 'eq' or
'=='
>    #   tests for equality
> > (print "yes it is\n") }
> > }
>
>




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

Date: 04 Oct 2001 13:20:28 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Why does if statement not work ?
Message-Id: <87adz74v8j.fsf@abra.ru>

>>>>> On Thu, 4 Oct 2001 00:54:11 -0700, benhopkins@mindspring.com said:

b> Nick Blake <nick.blake@qr.com.au> wrote:
>> while ( <> ){

>> ($path, $who, $acl) = split(/,/, $_);
>> chomp $acl;

>> $length = length( $path );

>> $newpath = substr($path, -1, $length);

>> if ( $newpath = '\'){
b>   if ( $newpath eq '\'){       # '=' is an assignment operator, 'eq' or '=='
b> 							   #   tests for equality
>> (print "yes it is\n") }
>> }

And advice: always run with warnings turned on. Perl will warn you
about sich mistakes.

If you are using perl < 5.6.0 add in shebang lang of your scripts '-w'

    #!/usr/bin/perl -w

If you are using perl >= 5.6.0 and don't care about compatibility with
older versions add this line into your scripts

    use warnings;

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 04 Oct 2001 08:58:21 +0100
From: nobull@mail.com
Subject: Re: Why does if statement not work ?
Message-Id: <u98zerzrqv.fsf@wcl-l.bham.ac.uk>

"Nick Blake" <nick.blake@qr.com.au> writes:

> Subject: Why does if statement not work ?

Enable warnings and Perl will tell you.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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


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