[26246] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8431 Volume: 10

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

Date: Sun, 18 Sep 2005 18: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: 8431

Today's topics:
        ActivePerl perlscript output inconsistencies <news@lawshouse.org>
    Re: ActivePerl perlscript output inconsistencies xhoster@gmail.com
    Re: Comparing Arays <7sumari@mail.goo.ne.jp>
    Re: Comparing Arays <7sumari@mail.goo.ne.jp>
    Re: Comparing Arays <john@castleamber.com>
    Re: Comparing Arays <jgibson@mail.arc.nasa.gov>
    Re: Perl Threads Tutorial xhoster@gmail.com
    Re: sorting data - hash vs. list <Fred@fred.net>
    Re: sorting data - hash vs. list <matthew.garrish@sympatico.ca>
    Re: Space (\s) count problem <do-not-use@invalid.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 18 Sep 2005 23:18:44 +0100
From: Henry Law <news@lawshouse.org>
Subject: ActivePerl perlscript output inconsistencies
Message-Id: <1127081924.22199.0@eunomia.uk.clara.net>

Running ActivePerl under Win XP; I'm trying to work out how to make 
Perlscript do what Perl does (why doesn't it ... answers on a postcard). 
Here's a sample script:

<Job ID="tryit">
<script language=PerlScript>

	use strict;
	use warnings;
	use vars('$WScript');	# Avoid "strict" warnings
	
	my $arg = $WScript->{Arguments};

	my $countArgs = $arg->{Count};

	open OUTPUT,">>tryit.log";

	for(my $i=0; $i<$countArgs; $i++) {
		$WScript->Echo($arg->Item($i));
		#print OUTPUT "$arg->Item($i)\n";
	}
</script>
</job>

Call it "tryit.wsf" and run it with "tryit.wsf one two three" and it 
puts up messages boxes with "one", "two" and "three" in them, as desired.

Now comment out the $WScript->Echo line and remove the comment on the 
line below it; I expect this to write "one", "two" and "three" to the 
log file.  Instead when I run "tryit.wsf one two three" I get the 
following log file:

Win32::OLE=HASH(0x179cea0)->Item(0)
Win32::OLE=HASH(0x179cea0)->Item(1)
Win32::OLE=HASH(0x179cea0)->Item(2)

Can anyone help me find out why replacing this "Echo" thing with a print 
statement apparently changes the data printed?  I'm mystified.


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

Date: 18 Sep 2005 22:36:25 GMT
From: xhoster@gmail.com
Subject: Re: ActivePerl perlscript output inconsistencies
Message-Id: <20050918183625.761$65@newsreader.com>

Henry Law <news@lawshouse.org> wrote:

>                 $WScript->Echo($arg->Item($i));
>                 #print OUTPUT "$arg->Item($i)\n";
 ...
>
> Now comment out the $WScript->Echo line and remove the comment on the
> line below it; I expect this to write "one", "two" and "three" to the
> log file.  Instead when I run "tryit.wsf one two three" I get the
> following log file:
>
> Win32::OLE=HASH(0x179cea0)->Item(0)
> Win32::OLE=HASH(0x179cea0)->Item(1)
> Win32::OLE=HASH(0x179cea0)->Item(2)
>
> Can anyone help me find out why replacing this "Echo" thing with a print
> statement apparently changes the data printed?  I'm mystified.

It is not because you changed print to Echo, it is because in the
process you changed  (...) to "..." in the process.

print OUTPUT $arg->Item($i), "\n";

Xho

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


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

Date: Sun, 18 Sep 2005 14:35:25 -0400
From: Taxi Driver <7sumari@mail.goo.ne.jp>
Subject: Re: Comparing Arays
Message-Id: <gocri1989egee2mkq2oddt0ngj88ng9bj5@4ax.com>

Thank you.  That is exactly what I was looking for.  
I apologize for not posting code.

TD

Matt Garrish:
  "Matt Garrish" <matthew.garrish@sympatico.ca>  a écrit dans le
message :
>
>"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: Sun, 18 Sep 2005 15:06:02 -0400
From: Taxi Driver <7sumari@mail.goo.ne.jp>
Subject: Re: Comparing Arays
Message-Id: <c5eri1lqel3594kso5m63b87ms7pl1hj6v@4ax.com>

It all works great until I added a second variable (ts) to the first
MYSQL Select statement. Then I get multiple valuse for ts instead of
one.
--------------- 
#!/usr/bin/perl
use DBI;
#Declare arrays to hold results
my @data; 
my @data2; 
my (@requests) = ();
my (@bids) = ();

# Database information
 $db="X";
 $host="X";
 $port="X";
 $userid="X";
 $passwd="X";
 $connectionInfo="DBI:mysql:database=$db;$host:$port";
 
# Make connection to database
 $dbh = DBI->connect($connectionInfo,$userid,$passwd) or die "Couldn't
connect to db. " . $sth->errstr;
 
# Prepare and execute query
 $query = "SELECT id, ts FROM insrequest WHERE status=0 ORDER BY id";
 $sth = $dbh->prepare($query);
 $sth->execute()or die "Couldn't execute statement. " . $sth->errstr;
 
# Read the matching records and print them out. 
 while (@data = $sth->fetchrow_array()) { 
 my $id = $data[0]; 
 push(@requests, [@data]);
 # print "Row: @data\n";
 }

 if ($sth->rows == 0) { 
 print "No jobs found.\n\n"; 
 } 

# Second query
 $query2 = "SELECT DISTINCT jobnum FROM insbid1 ORDER BY jobnum";
 $sth = $dbh->prepare($query2);
 $sth->execute()or die "Couldn't execute statement. " . $sth->errstr;
 
# Read the matching records and print them out. 
 while (@data2 = $sth->fetchrow_array()) { 
 my $jobnum = $data2[0]; 
 push(@bids, [@data2]);
 } 

 if ($sth->rows == 0) { 
 print "No bids found insbid1.\n\n"; 
 } 

 $sth->finish();
         
# Disconnect from database
 $dbh->disconnect;

# Comparison
 print "Not found:\n";
 my %chk;

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

 for my $i (0..$#requests) {
        for my $j (0..$#{$requests[$i]}) {
        print "\t$requests[$i][$j]\n" unless $chk{$requests[$i][$j]};
        }
 }
----------
Matt Garrish:
  "Matt Garrish" <matthew.garrish@sympatico.ca>  a écrit dans le
message :
>
>"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 19:44:38 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: Comparing Arays
Message-Id: <Xns96D595C6D7FB8castleamber@130.133.1.4>

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

> It all works great until I added a second variable (ts) to the first
> MYSQL Select statement. Then I get multiple valuse for ts instead of
> one.
> --------------- 
> #!/usr/bin/perl
> use DBI;

most people stop looking now, because you forgot use strict; and use 
warnings;

Also, it looks like you are attempting to program a join in Perl, instead 
of using the database to do this. Try to give an exact description of your 
problem based on the database table(s), I am sure it can be done in SQL.

Finally, *don't* top post.

-- 
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 12:50:18 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Comparing Arays
Message-Id: <180920051250180612%jgibson@mail.arc.nasa.gov>

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

Please stop posting to comp.lang.perl. That newsgroup is defunct.

Note: it is customary to place your responses below that to which you
are responding. 

Your program would benefit from some indenting of loops.

> It all works great until I added a second variable (ts) to the first
> MYSQL Select statement. Then I get multiple valuse for ts instead of
> one.
> --------------- 
> #!/usr/bin/perl
> use DBI;
> #Declare arrays to hold results
> my @data; 
> my @data2; 
> my (@requests) = ();
> my (@bids) = ();
> 
> # Database information
>  $db="X";
>  $host="X";
>  $port="X";
>  $userid="X";
>  $passwd="X";
>  $connectionInfo="DBI:mysql:database=$db;$host:$port";
>  
> # Make connection to database
>  $dbh = DBI->connect($connectionInfo,$userid,$passwd) or die "Couldn't
> connect to db. " . $sth->errstr;
>  
> # Prepare and execute query
>  $query = "SELECT id, ts FROM insrequest WHERE status=0 ORDER BY id";
>  $sth = $dbh->prepare($query);
>  $sth->execute()or die "Couldn't execute statement. " . $sth->errstr;
>  
> # Read the matching records and print them out. 
>  while (@data = $sth->fetchrow_array()) { 
>  my $id = $data[0]; 
>  push(@requests, [@data]);

You are complicating your task by saving references to arrays with two
elements, but you seem only interested in the first. Why don't you
simplify by just saving the first element? Like this:

   push( @requests, $id );

>  # print "Row: @data\n";
>  }
> 
>  if ($sth->rows == 0) { 
>  print "No jobs found.\n\n"; 
>  } 
> 
> # Second query
>  $query2 = "SELECT DISTINCT jobnum FROM insbid1 ORDER BY jobnum";
>  $sth = $dbh->prepare($query2);
>  $sth->execute()or die "Couldn't execute statement. " . $sth->errstr;
>  
> # Read the matching records and print them out. 
>  while (@data2 = $sth->fetchrow_array()) { 
>  my $jobnum = $data2[0]; 
>  push(@bids, [@data2]);

Here your arrays contain only one element. Why not just save that
element, rather than saving a reference to an array holding just that
one element:

   push( @bids, $jobnum );

>  } 
> 
>  if ($sth->rows == 0) { 
>  print "No bids found insbid1.\n\n"; 
>  } 
> 
>  $sth->finish();
>          
> # Disconnect from database
>  $dbh->disconnect;
> 
> # Comparison
>  print "Not found:\n";
>  my %chk;
> 
>  for my $x (0..$#bids) {
>         for my $y (0..$#{$bids[$x]}) {
>         $chk{$bids[$x][$y]} = 1;
>         }
>   }
> 
>  for my $i (0..$#requests) {
>         for my $j (0..$#{$requests[$i]}) {
>         print "\t$requests[$i][$j]\n" unless $chk{$requests[$i][$j]};
>         }
>  }

Now these loops may be simplified (untested):

   my %chk;
   $chk{$_} = 1 for @bids;

   for( @requests ) {
      print "$_\n" unless $chk{$_};
   }

or even something like (really untested):

   my @nobid = grep { ! $chk{$_} } @requests;
   print "No bids: @nobid\n";

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


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

Date: 18 Sep 2005 23:22:52 GMT
From: xhoster@gmail.com
Subject: Re: Perl Threads Tutorial
Message-Id: <20050918192252.706$gl@newsreader.com>

"Boerni" <alt_test.3.boerni@spamgourmet.com> wrote:
> 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.


When stress-testing Perl under Windows, I've also found 120 to be about
the limit on the number of simultaneous threads.

> Can someone explain this and maybe has a workaround?

A workaround would probably depend on why you want to have more than 120
threads around in the first place.  I think that just wanting to run the
cutesy but impractical code from the tutorial is not a very good enough
reason.

Also, you should check that the creation of new threads succeeds.  That
would have removed some of the mystery from the failure.

> my $kid    = new threads(\&check_num, $stream, 2)

or die $!;

Xho

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


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

Date: Sun, 18 Sep 2005 17:46:45 -0500
From: "Fred@fred.net" <Fred@fred.net>
Subject: Re: sorting data - hash vs. list
Message-Id: <d4rri1dvgn5n2mmrpv8su1ic8kip5urel2@4ax.com>

On Sat, 17 Sep 2005 19:21:00 -0400, "Matt Garrish" <matthew.garrish@sympatico.ca> wrote:

>
><Fred@fred.net> wrote in message 
>news:ip5pi1lsk2od557qdi6p8iart5n6t7e5v9@4ax.com...
>> On Fri, 16 Sep 2005 20:31:42 -0500, Tad McClellan <tadmc@augustmail.com> 
>> wrote:
>>>
>>>You should abandon Perl and its community of Nazis immediately
>>>and use Ruby for all of your future programming.
>>
>> Well, thanks for the advice, but I like perl, and as indicated,
>> I seldom post here, mostly just search it.
>>
>
>Tad may have broken Godwin's Law, but you just confirmed in that one 
>sentence what most regulars already suspected: you want free advice, but you 
>aren't interested in helping out yourself. Worse, you want free advice, and 
>you expect people to give it to you the way you want it. That isn't usenet. 
>Until you shell out money you're getting what you pay for.
>
>Matt 
>


>> Well, thanks for the advice, but I like perl, and as indicated,
>> I seldom post here, mostly just search it.

Free advice, yes that is what I want. And the honest reason I don't ever
respond to posts here is because:
(1. They are too old!!)
And if not that then just a general caution that I don't like
being crictized, it's an uncomfortable expereince. I get flamed and 
I have replied and it became tedious, honestly so I went anonymous
and rarely post. I'd try and help someone and some other
SOB would jump my ass for it and I got to where, I said.....
WITFP. What is the piont.
So I quit "hanging out"
becuase each and every time I do, I get flamed for it.
No matter what I say.
Case in point.
Fred


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

Date: Sun, 18 Sep 2005 19:42:28 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: sorting data - hash vs. list
Message-Id: <BXmXe.643$0u2.249226@news20.bellglobal.com>


<Fred@fred.net> wrote in message 
news:d4rri1dvgn5n2mmrpv8su1ic8kip5urel2@4ax.com...
> On Sat, 17 Sep 2005 19:21:00 -0400, "Matt Garrish" 
> <matthew.garrish@sympatico.ca> wrote:
>
> Free advice, yes that is what I want. And the honest reason I don't ever
> respond to posts here is because:
> (1. They are too old!!)
> And if not that then just a general caution that I don't like
> being crictized, it's an uncomfortable expereince.

You're taking usenet too seriously, then. Everyone gets corrected from time 
to time. It's part of the learning process. If someone corrects your code 
it's usually because there is a better way (and if it's not, someone will 
correct them). If you take offense at being corrected you're losing out on 
what the group has to offer.

As for being flamed, just remember that if you play with fire you're going 
to get burned.

That said, I won't deny you that there are some offensive posters here. Tad 
isn't one of them, though. And it's pointless to tell someone their tone is 
offensive; they'll just come back at you in a more offensive tone. That's 
why you're being called a troll. You want to make an argument of something 
that can never be resolved, but just makes for a lot of flame-bait. You may 
not feel you started it, but trust me, it's pointless to pursue it.

> I get flamed and
> I have replied and it became tedious, honestly so I went anonymous
> and rarely post. I'd try and help someone and some other
> SOB would jump my ass for it and I got to where, I said.....
> WITFP. What is the piont.
> So I quit "hanging out"
> becuase each and every time I do, I get flamed for it.
> No matter what I say.
> Case in point.

It's too bad you feel that way. There is a lot that can be learned from the 
people here.

Matt 




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

Date: 12 Sep 2005 14:52:04 +0200
From: Arndt Jonasson <do-not-use@invalid.net>
Subject: Re: Space (\s) count problem
Message-Id: <yzdfysa4fez.fsf@invalid.net>


Huub <"h.v.niekerk at hccnet.nl"> writes:
> Joe Smith wrote:
> > Huub wrote:
> >
> >>     $spatie++ if m/\s/m
> >>
> >> The line to be read is: dit is een test voor TIRCIN
> > You used the /m option instead of /g.
> > You did not include any code to repeat matches.
> >   $spatie++ while m/\s/g;
> > It is recommended to use tr/// for counting characters.
> >     -Joe
> 
> I can't find tr///.

When I search for "tr///" in the Perl documentation, I get a lot of
matches.

The command "perldoc -f tr" also says helpful things.


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

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


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