[26245] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8430 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 18 14:05:26 2005

Date: Sun, 18 Sep 2005 11:05:04 -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           Sun, 18 Sep 2005     Volume: 10 Number: 8430

Today's topics:
        Comparing Arays <7sumari@mail.goo.ne.jp>
    Re: Comparing Arays <matthew.garrish@sympatico.ca>
    Re: Comparing Arays <john@castleamber.com>
    Re: Comparing Arays <jgibson@mail.arc.nasa.gov>
    Re: convert $array[0] into $new-array[0,0] <jgibson@mail.arc.nasa.gov>
        http://search.cpan.org/ getting 502 Bad Gateway error <jkeen_via_google@yahoo.com>
    Re: http://search.cpan.org/ getting 502 Bad Gateway err <matthew.garrish@sympatico.ca>
        i havent got a clue can sombody help with this line of  <darren_linda@ingall.me.uk>
    Re: i havent got a clue can sombody help with this line <tintin@invalid.invalid>
        Perl Threads Tutorial <alt_test.3.boerni@spamgourmet.com>
    Re: What is "$^O" on Cygwin? <joe@inwap.com>
    Re: What is "$^O" on Cygwin? <sisyphus1@nomail.afraid.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 18 Sep 2005 13:03:28 -0400
From: Taxi Driver <7sumari@mail.goo.ne.jp>
Subject: Comparing Arays
Message-Id: <nd7ri1lv7k4fkasccp44gr6mvtm86gpjp0@4ax.com>

Hi Everyone -
Can I get your help with this, it is driving me crazy.
I have 2 arrays listed below:
@req[0][0]=75
@req[1][0]=76
@req[2][0]=77
@req[2][0]=78
---
@bid[0][0]=75
@bid[1][0]=76
@bid[2][0]=80

I need to find all cases where a number in @req is NOT in @bid. In
this example 77 and 78.

Thank you


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

Date: Sun, 18 Sep 2005 13:27:45 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: Comparing Arays
Message-Id: <ishXe.235$0u2.128077@news20.bellglobal.com>


"Taxi Driver" <7sumari@mail.goo.ne.jp> wrote in message 
news:nd7ri1lv7k4fkasccp44gr6mvtm86gpjp0@4ax.com...
> Hi Everyone -
> Can I get your help with this, it is driving me crazy.
> I have 2 arrays listed below:
> @req[0][0]=75

What are these things? Did you mean to write $req[0][0]? If so, please bear 
in mind that you should always post real code.

> @req[1][0]=76
> @req[2][0]=77
> @req[2][0]=78

Why are you using multi-dimensional arrays when there is only one entry for 
each? Or are there more entries? It's hard to give you useful help if you 
don't present the problem clearly (like why you repeated @req[2][0], for 
example).

> ---
> @bid[0][0]=75
> @bid[1][0]=76
> @bid[2][0]=80
>
> I need to find all cases where a number in @req is NOT in @bid. In
> this example 77 and 78.
>

Hashes are your friend in situations like this. Assuming you have a real 
mutlidimensional array (and all the entries in @bid and @req contain 
references to arrays):

my %chk;

for my $x (0..$#bid) {
   for my $y (0..$#{$bid[$x]}) {
      $chk{$bid[$x][$y]} = 1;
   }
}

for my $i (0..$#req) {
   for my $j (0..$#{$req[$i]}) {
      print "Not found: $req[$i][$j]\n" unless $chk{$req[$i][$j]};
   }
}


Matt




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

Date: 18 Sep 2005 17:55:22 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Comparing Arays
Message-Id: <Xns96D58340C6D90castleamber@130.133.1.4>

Taxi Driver <7sumari@mail.goo.ne.jp> wrote:

> Hi Everyone -
> Can I get your help with this, it is driving me crazy.
> I have 2 arrays listed below:
> @req[0][0]=75
> @req[1][0]=76
> @req[2][0]=77
> @req[2][0]=78
> ---
> @bid[0][0]=75
> @bid[1][0]=76
> @bid[2][0]=80

Uhm...

You mean:

use strict;
use warnings;

my @req = ( 75 .. 78 );
my @bid = ( 75, 76, 80 );

> I need to find all cases where a number in @req is NOT in @bid. In
> this example 77 and 78.

my %test;
@test{ @bid } = ();

my @not_in;
exists $test{ $_ } or push @not_in, $_ for @req;

print join( ', ', @not_in ), "\n";

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: Sun, 18 Sep 2005 10:57:55 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Comparing Arays
Message-Id: <180920051057554440%jgibson@mail.arc.nasa.gov>

In article <nd7ri1lv7k4fkasccp44gr6mvtm86gpjp0@4ax.com>, Taxi Driver
<7sumari@mail.goo.ne.jp> wrote:

> Hi Everyone -
> Can I get your help with this, it is driving me crazy.
> I have 2 arrays listed below:
> @req[0][0]=75
> @req[1][0]=76
> @req[2][0]=77
> @req[2][0]=78
> ---
> @bid[0][0]=75
> @bid[1][0]=76
> @bid[2][0]=80
> 
> I need to find all cases where a number in @req is NOT in @bid. In
> this example 77 and 78.

perldoc -q "How do I compute the difference of two arrays"

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Sun, 18 Sep 2005 10:48:43 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: convert $array[0] into $new-array[0,0]
Message-Id: <180920051048431314%jgibson@mail.arc.nasa.gov>

In article <555Xe.13500$_84.11603@newsread1.news.atl.earthlink.net>,
William Hymen <t18_pilot@hotmail.spam.com> wrote:

> Thanks Jim.
> 
> Would the syntax for the split remian
> the same? I need to split using the pipe char
> as a separator, and I'm not sure what
> to place between [] in your example.
> 
> My split _was_ split(/\|/ , $entry);

Yes, sorry. I overlooked that bit. Here it is modified, with a chomp
added, since you probably don't want the newline in the last field:

my @entry_parts;
while(<INFILE>) {
  chomp;
  push( @entry_parts, [ split(/\|/) ]);
}

The default string for split, like many Perl functions, is $_, which is
where <INFILE> puts the line read. You can also use an explicit scalar
variable, if you need to do any more processing on the input data:

my @entry_parts;
while(my $entry = <INFILE>) {
  chomp($entry);
  push( @entry_parts, [ split(/\|/,$entry) ]);
}

Hope I got it right that time.

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: Sun, 18 Sep 2005 13:50:15 GMT
From: James E Keenan <jkeen_via_google@yahoo.com>
Subject: http://search.cpan.org/ getting 502 Bad Gateway error
Message-Id: <rgeXe.3165$LV5.1663@trndny02>

While attempting to reach search.cpan.org, I am getting a 502 Bad 
Gateway error:

Bad Gateway

The proxy server received an invalid response from an upstream server.

Does anyone know what's happening?

Thanks.

jimk


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

Date: Sun, 18 Sep 2005 10:29:20 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: http://search.cpan.org/ getting 502 Bad Gateway error
Message-Id: <2ReXe.101$0u2.75081@news20.bellglobal.com>


"James E Keenan" <jkeen_via_google@yahoo.com> wrote in message 
news:rgeXe.3165$LV5.1663@trndny02...
> While attempting to reach search.cpan.org, I am getting a 502 Bad Gateway 
> error:
>
> Bad Gateway
>
> The proxy server received an invalid response from an upstream server.
>
> Does anyone know what's happening?
>

Sounds like technical difficulties. It happens.

You should read the cpan faq before posting, you know... : )

<quote>
I'm having trouble with search.cpan.org, whom do I need to contact?
If you are experiencing difficulty using search.cpan.org due to network or 
server errors, you need to contact webmaster@search.cpan.org.
</quote>

Matt 




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

Date: Sun, 18 Sep 2005 08:58:57 +0100
From: "Darren & Linda Ingall" <darren_linda@ingall.me.uk>
Subject: i havent got a clue can sombody help with this line of code
Message-Id: <432d1e42$0$22938$ed2619ec@ptn-nntp-reader01.plus.net>


if($ENV{'HTTP_REFERER'} !~ /$ENV{'SERVER_NAME'}/ && $RemoteAccess eq "0") 
{ &invalid_referer; }

I purchased a website off the shelf.
the website assumes cgi-bin is in the htdocks .... with my isp cgi-bin is on 
a different server
when a form is submitted this line of code stops the form with an invalid 
referer error
so I want to redo this line of code to say

if lastpage = 'http://mywebsite.com' do nothing otherwise give me the 
invalid referer error.     (i've never done perl !)

thx for any help Darren 




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

Date: Sun, 18 Sep 2005 20:52:43 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: i havent got a clue can sombody help with this line of code
Message-Id: <wV9Xe.12720$iM2.1080942@news.xtra.co.nz>


"Darren & Linda Ingall" <darren_linda@ingall.me.uk> wrote in message 
news:432d1e42$0$22938$ed2619ec@ptn-nntp-reader01.plus.net...
>
> if($ENV{'HTTP_REFERER'} !~ /$ENV{'SERVER_NAME'}/ && $RemoteAccess eq "0") 
> { &invalid_referer; }
>
> I purchased a website off the shelf.
> the website assumes cgi-bin is in the htdocks .... with my isp cgi-bin is 
> on a different server
> when a form is submitted this line of code stops the form with an invalid 
> referer error
> so I want to redo this line of code to say
>
> if lastpage = 'http://mywebsite.com' do nothing otherwise give me the 
> invalid referer error.     (i've never done perl !)

Best just to delete it as relying on the HTTP_REFERER is next to useless. 




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

Date: Sun, 18 Sep 2005 12:22:51 +0200
From: "Boerni" <alt_test.3.boerni@spamgourmet.com>
Subject: Perl Threads Tutorial
Message-Id: <432d3ff0$0$1154$5402220f@news.sunrise.ch>

Hi all

I tried to run the sample script from the "tutoriol on threads in perl" that
should list prime numbers between 1 and 1000.

The Problem is, the script always ends with this errormessage "A thread
exited while 2 threads were running."
The last Prime it finds is 661.
After adding some prints, it looks like if no more threads are started once
120 threads are running.
The thread to check for 661 is created, but never starts.

I use ActiveState Perl 5.8.2 on WinXP.
The script runs fine on Linux (... yeah I know... but I want to use threads
on Win32 boxes :)

Can someone explain this and maybe has a workaround?

I hope this question hasn't been answered before... I googled but couldn't
find the answer for this problem.

Thanx in advance
Boerni

This is the script i try to run:

----- Start Code --------
#!/usr/bin/perl -w
# prime-pthread, courtesy of Tom Christiansen

use strict;

use threads;
use threads::shared;
use Thread::Queue;

$| = 1;

my %running_threads : shared;

my $stream = new Thread::Queue;
my $kid    = new threads(\&check_num, $stream, 2);

for my $i ( 3 .. 1000 ) {
    $stream->enqueue($i);
}

$stream->enqueue(undef);
$kid->join;

my @running = keys %running_threads;
print "\nStill checking for @running\n";


sub check_num {
    my ($upstream, $cur_prime) = @_;
    my $kid;
    my $downstream = new Thread::Queue;
    my $num_to_join;

   $running_threads{$cur_prime}++;
   print "Thread checking $cur_prime has started\n";

    while (my $num = $upstream->dequeue) {
        next unless $num % $cur_prime;
        if ($kid) {
           #print "Thread checking $cur_prime is adding $num to
downstream\n";
           $downstream->enqueue($num);
        } else {
           print "Found prime $num\n";
           $kid = new threads(\&check_num, $downstream, $num);

           $num_to_join = $num;
           print "Thread checking $cur_prime initialized a new thread to
check $num. ThreadID: ".$kid->tid."\n";
           #print "Still checking for ". keys( %running_threads)." other
primes\n";

        }
    }
    $downstream->enqueue(undef) if $kid;
    $kid->join if $kid;
    print "$num_to_join joined by thread checking $cur_prime\n";
    delete $running_threads{$cur_prime};
    print "Thread checking $cur_prime ended\n";
}
----- End Code --------

----- Some Output -----
 ....
 ....
Thread checking 647 initialized a new thread to check 653. ThreadID: 119
Thread checking 653 has started
Found prime 659
Thread checking 653 initialized a new thread to check 659. ThreadID: 120
Thread checking 659 has started
Found prime 661
Thread checking 659 initialized a new thread to check 661. ThreadID: 121
661 joined by thread checking 659
Thread checking 659 ended
659 joined by thread checking 653
Thread checking 653 ended
653 joined by thread checking 647
Thread checking 647 ended
 ....
 ....
5 joined by thread checking 3
Thread checking 3 ended
3 joined by thread checking 2
Thread checking 2 ended

Still checking for 661
A thread exited while 2 threads were running.




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

Date: Sun, 18 Sep 2005 01:25:11 -0700
From: Joe Smith <joe@inwap.com>
Subject: Re: What is "$^O" on Cygwin?
Message-Id: <Sdidncl9iKPuubDeRVn-tA@comcast.com>

Randy Harris wrote:
> "James E Keenan" <jkeen_via_google@yahoo.com> wrote in message
> news:Iu2Xe.5345$iv5.79@trndny03...
> 
>>Can anyone running Cygwin tell me what the value for $^O is?
>>
>>     perl -e 'print "$^O\n";'
>>
>>MSWin32? Cygwin?  Something else?
>>
>>Thanks in advance.
>>
>>jimk
> 
> 
> $ perl -e 'print "$^O\n";'
> MSWin32

That's the wrong perl.  You need to readjust your $PATH.

bash-2.05b$ /usr/bin/perl -le 'print $^O'
cygwin
bash-2.05b$ /cygdrive/c/perl/bin/perl -le 'print $^O'
MSWin32
bash-2.05b$

		-Joe


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

Date: Sun, 18 Sep 2005 20:35:38 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: What is "$^O" on Cygwin?
Message-Id: <432d4342$0$31290$afc38c87@news.optusnet.com.au>


"James E Keenan" <jkeen_via_google@yahoo.com> wrote in message
news:Iu2Xe.5345$iv5.79@trndny03...
> Can anyone running Cygwin tell me what the value for $^O is?
>
>      perl -e 'print "$^O\n";'
>
> MSWin32? Cygwin?  Something else?
>

You will find that '/mswin/i' will always match $^O on Microsoft Windows and
*never* match $^O on Cygwin - and that '/cygwin/i' will always match $^O on
Cygwin and *never* match $^O on Microsoft Windows. (But that answers a
different question :-)

Cheers,
Rob




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

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


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