[21742] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3946 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 10 14:06:04 2002

Date: Thu, 10 Oct 2002 11:05:21 -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           Thu, 10 Oct 2002     Volume: 10 Number: 3946

Today's topics:
    Re: Anyone who uses Perl on VAX <jpagnew@vcu.edu>
        Bug or weird thing? <dd@4pro.net>
        Bug/Programmer Error? ForkTest w/ Manager/Client works  <mclay@cfdlab.ae.utexas.edu>
    Re: Bug/Programmer Error? ForkTest w/ Manager/Client wo <nobull@mail.com>
    Re: extract emails with corresponding URLs from whoisre news@roaima.freeserve.co.uk
        First meeting for Oslo.pm, 16. oct 2002 (Salve J. Nilsen)
        flock related issue <zoips@eesoft.org>
        Getting off the ground (more newbie than newbie) <judywellsnow@prodigy.net>
    Re: Getting off the ground (more newbie than newbie) <nobull@mail.com>
    Re: Getting off the ground (more newbie than newbie) <jurgenex@hotmail.com>
    Re: GMT Windows vs Linux <nospam@fakedomain.com>
    Re: How can I tell what version a module is? <du_bing@hotmail.com>
        How to test for blessedness? <heather710101@yahoo.com>
    Re: How to test for blessedness? <dd@4pro.net>
    Re: How to test for blessedness? <dd@4pro.net>
    Re: How to test for blessedness? <nobull@mail.com>
    Re: ithreads, perl 5.8 and shared objects <uri@stemsystems.com>
        join lines in @array <No_Mail_Address@cox.net>
    Re: join lines in @array <nobull@mail.com>
        Loops (Joe R)
    Re: Loops <nobull@mail.com>
        NDBM_File <usenet@variomedia.de>
    Re: newbie with datatype prob (Dan Jason)
    Re: newbie with datatype prob (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 10 Oct 2002 09:19:43 -0400
From: Jim Agnew <jpagnew@vcu.edu>
Subject: Re: Anyone who uses Perl on VAX
Message-Id: <3DA57E6F.E0CCC381@vcu.edu>

pkent wrote:
> 
> In article <32b689fe.0210091048.250d0c2f@posting.google.com>,
>  ph3arnot@hotmail.com (Ph3arnot) wrote:
> 
> > An interesting note, the version of perl that is running on our
> > VAX/Alpha cluster DOESN'T have a "chomp" command.  I haven't even
> 
> Gah! OpenVMS and an ancient version (or bizarrely patched) of perl.
> 
> What happens if you run 'perl -v' and 'perl -V' or whatever the
> equivalent is under the DCL shell? You should get information about the
> build of perl.
> Has your sysadmin installed several versions of perl, and you're
> accessing but one of them (apaprently perl 4 if its missing chomp()).
> 
> P
> 
> --
> pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
> Remove the tea to reply

that *is* old...

I do have chomp and v5, but a very old v5...  it's missing some debugger
commands..  If it bothers me enough, i'll upgrade one of these days...
;-)


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

Date: Thu, 10 Oct 2002 11:33:35 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Bug or weird thing?
Message-Id: <ao46lc$j0in6$1@ID-159100.news.dfncis.de>

Why the SCALAR slot of a symboltable is ALWAYS defined, while the ARRAY,
HASH and CODE slots are not?


Please try this:

======== CODE =========
$Defined = 'the Scalar';
@Defined = ('the', 'Array');
%Defined = ('the' => 'Hash');
sub Defined {}

print '$Defined is defined'."\n" if defined *Defined{SCALAR};
print '@Defined is defined'."\n" if defined *Defined{ARRAY};
print '%Defined is defined'."\n" if defined *Defined{HASH};
print '&Defined is defined'."\n" if defined *Defined{CODE};

print '$not_Defined is defined'."\n" if defined *not_Defined{SCALAR};
print '@not_Defined is defined'."\n" if defined *not_Defined{ARRAY};
print '%not_Defined is defined'."\n" if defined *not_Defined{HASH};
print '&not_Defined is defined'."\n" if defined *not_Defined{CODE};
======== END CODE =======

it will print:

$Defined is defined
@Defined is defined
%Defined is defined
&Defined is defined
$not_Defined is defined

--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...






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

Date: Thu, 10 Oct 2002 15:24:31 GMT
From: rtm <mclay@cfdlab.ae.utexas.edu>
Subject: Bug/Programmer Error? ForkTest w/ Manager/Client works linux fails on Windows
Message-Id: <PYgp9.99022$Fw2.3253468@twister.austin.rr.com>

I am writing client/server code in perl to manage a list of regression
tests.  I have taken the real code and simplified it to be an example.

This code forks off 2 clients.  Then each connects through a socket
call to the server.  Once connected each clients asks for the next
test. In this example code it is just calls sleep for so many seconds.
In the real code it fires off a regression test.  The real code needs
to work for both unix platforms as well as windows NT.

It seems to work reliably under Linux, Solaris but has occasionally
hung under SGI/IRIX.  This is all with perl 5.6.0 and 5.6.1.

This example code always gets stuck when run under windows.  I am
running perl 5.6.1 from activestate and the cygwin version as well.
Under Windows ME it gets stuck at the select call.  Under NT it does 
not terminate correctly.

So the question is: What am I doing wrong?  It is probably unlikely
that I have found a bug in perl 5.6.1.  This is probably a race
condition.  I have tried with the number of forks to be 1 and 2 under
Windows and it gets farther with 1 but it always hangs.

Can anyone help this client/server newbie?  Changing $Debug to 1 will
turn on more print statements.


Thanks

------------------------------------------------------------------------
#!/usr/local/bin/perl -w

use strict;
use English;
use IO::File;
use IO::Socket;
########################################################################
# Global Variables.
use vars qw/$Port/;               # Port Number.
use vars qw/$NumForks/;           # number of forks.
use vars qw/$Debug/;              # Debug printing flag
use vars qw/$NumberGrpTsts/;      # number of entries in %GrpTestHsh
use vars qw/%GrpTestHsh/;         # Hash Table of Tests.
use vars qw/$DoneName/;           # Done name

$DoneName = "%*%__DONE__%*%";
$Debug    =    0;
$Port     = 6411;
$NumForks = 2;


########################################################################
# Subroutines
########################################################################
sub askServer($$$)
{
  my ($server,$logFH,$tag) = @_;
  my $answer = "NoAnswer\n";
  my $icount;
  print $logFH "#*# activeTests: Asking for $tag\n" if $Debug;
  print $server "$tag\n";
  $answer = <$server>;
  return $answer;
}

sub doServer($$)
{
  my (@fd, @fp, $msg, $rout, $t);
  my ($pidArray,$server) = @_;
  my $numClients = scalar(@$pidArray);
  my $closed     = 0;
  print "I'm the server, waiting for connections from $numClients clients\n";
  ########################################################################
  # Wait for clients to register
  my $client;
  my $count = 0;
  my $answer;
  while ($client = $server->accept()) # wait for connection
    {
      my $info  = <$client>;          # from no on use the new port
                                      # from $client
      my $idx   = substr($info, 4);   # Remove "clnt" from "clnt1", etc
      if ($idx >= $numClients)
        {
          print $client "service refused!\n";
          close($client);
          next;
        }
      $fd[$idx] = fileno($client);
      $fp[$idx] = $client;
      $count++;
      print $client "start\n";
      last if ($count == $numClients);
    }
  close($server);

  my @testNames = (sort keys %GrpTestHsh);
  my $testCount = 0;

  while(1)
    {
      ########################################################################
      # Fill read bit mask
      my $rin = '';
      for (0 .. $numClients-1)
        { vec($rin, $fd[$_], 1) = 1; }

      print "### doServer: before select\n" if $Debug;
      select($rout=$rin, undef, undef, undef);
      print "### doServer: after select\n"  if $Debug;
      for my $iclient (0 .. $numClients-1)
        {
          if ($fd[$iclient] && vec($rout, $fd[$iclient], 1))
            {
              $client = $fp[$iclient];
              $msg    = <$client>;
              chomp($msg);
              $t      = time;
              print "### doServer: $t: received from client"
                   ." $iclient: $msg\n" if $Debug;
              if ($msg eq "NeedPrinter")
                {
                  #############################################################
                  # Pass Printer Token to Client>>=
                  $t      = time;
                  print "### doServer: $t: Giving Print Token to"
                       ." client: $iclient\n" if $Debug;
                  print $client "startPrinting\n";
                  $answer = <$client>;
                  $t      = time;
                  print "### doServer: $t: Receiving Print Token from "
                       ."client: $iclient\n" if $Debug;
                }

              elsif ($msg eq "NextTest")
                {
                  ##############################################################
                  # Send next test
                  my $name;
                  if ($testCount < $NumberGrpTsts)
                    {
                      $name        = $testNames[$testCount++];
                      my $testTime = scalar localtime(time);
                      my $c        = $testCount;
                      my $n        = $NumberGrpTsts;
                      print "\nRunning Group Test: $name\n"
                             ."Group Test Number:  $c/$n on client: "
                             ."$iclient/$NumForks, started at $testTime\n";

                    }
                  else
                    { $name = $DoneName; }
                  $t      = time;
                  $name   = "$testCount:$name";
                  print "### doServer: $t: Sending client "
                       ."$iclient test: $name\n" if $Debug;
                  print $client "$name\n";
                  $t      = time;
                  print "### doServer: $t: Sent    client "
                       ."$iclient test: $name\n" if $Debug;
                }

              elsif ($msg eq "Terminate")
                {
                  ######################################################
                  # Terminate client
                  print "### doServer: Trying to terminate client "
                       ."$iclient\n" if $Debug;
                  close($client);
                  $closed++;
                  $fd[$iclient] = 0;
                  print "### doServer: Terminated client "
                       ."$iclient\n" if $Debug;
                }

            }
        }
      last if ($closed == $numClients);
    }

  for (@$pidArray)
    { waitpid($_,0); }
  print "I'm the server, DONE!\n";
}

sub doClient($$)
{
  my ($iclient, $log) = @_;
  my ($grpKey,$testCount);
  my $logFH = $log->[$iclient];
 
  ########################################################################
  # Register with server
  my $lh     = "127.0.0.1";
  my $server = IO::Socket::INET->new(PeerAddr => $lh,
                                     PeerPort => $Port,
                                     Proto    => "tcp",
                                     Type     => SOCK_STREAM)
    or die "couldn't connect to master host: $lh:$Port :$!\n";
  print $server "clnt$iclient\n";
  my $answer = <$server>;
  print "I am client $iclient, server sent me $answer" if $Debug;


  while (1)
    {
      #################################################################
      # Ask for next test name:
      my $icount = 0;

      $grpKey = askServer($server,$logFH,"NextTest");
      chomp($grpKey);
      print $logFH "#*# Got NextTest from Server: $grpKey\n" if $Debug;
      $grpKey    =~ /([0-9]+):(.*)/;
      $testCount = $1;
      $grpKey    = $2;
      last if ($grpKey eq $DoneName);
      ########################################################################
      # do work
      my $sleepTime = $GrpTestHsh{$grpKey};
      sleep($sleepTime);

      ########################################################################
      # Ask for printer control
      print $logFH  "#*# Server: Need Print Token\n" if $Debug;
      $answer = askServer($server,$logFH,"NeedPrinter");
      print $logFH  "#*# Server: Got Print Token\n"  if $Debug;

      ########################################################################
      # Print output to [[$logFH]]>>=
      print         "Client $iclient done with test: $grpKey\n";
      print $logFH  "Client $iclient done with test: $grpKey\n";

      ########################################################################
      # Return printer control
      print $logFH  "#*# Server: Returning Print Token\n" if $Debug;
      print $server "DonePrinter\n";

    }
  ########################################################################
  # Ask to die
  print $server "Terminate\n";
  <$server>; # Wait until eof;

  print "Client $iclient will terminate\n";
  exit(0);
}


########################################################################
# Main
########################################################################
package main;
my $VN = 'forkTest: $Revision$'."\n";
print STDERR $VN;

%GrpTestHsh = (
               Test01 =>  1,
               Test02 => 10,
               Test03 =>  1,
               Test04 =>  1,
               Test05 =>  2,
               Test06 =>  3,
               Test07 =>  4,
               Test08 =>  1,
               Test09 =>  2,
               Test10 => 10,
               Test11 =>  1,
               Test12 =>  2,
               );

$NumberGrpTsts = scalar(keys(%GrpTestHsh));  # get size of the array
#########################################################################
# Start up server>>=
my ($pid, @pidA);
my $count = 0;
my $server;
while (!($server = IO::Socket::INET->new(LocalPort => $Port,
                                         Type      => SOCK_STREAM,
                                         Reuse     => 1,
                                         Listen    => 10)))
  {
    $Port++;
    $count++;
    die "server failed: $!\n" if ($count > 500);
  }


########################################################################
# Open a log file for each client
my @log;
my $rtlbase = 'forkTest';
my $iclient;
for $iclient (0 .. $NumForks-1)
  {
    my $log                 = "${rtlbase}-${iclient}.log";
    my $fh = $log[$iclient] = new IO::File(">$log")
           || die "Can't open $log: $!\n";
    autoflush $fh 1;
  }

########################################################################
# Fork $NumFork clients
for $iclient (0 .. $NumForks-1)
  {
    if ( ! ($pid = fork) )
      { doClient($iclient, \@log);  exit(0);}
    $pidA[$iclient] = $pid;
  }

########################################################################
#  have server manage clients.
doServer(\@pidA, $server);


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

Date: 10 Oct 2002 18:16:53 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Bug/Programmer Error? ForkTest w/ Manager/Client works linux fails on Windows
Message-Id: <u9it0aw6wq.fsf@wcl-l.bham.ac.uk>

rtm <mclay@cfdlab.ae.utexas.edu> writes:

> This code forks...

> This example code always gets stuck when run under windows.

AFAIK fork is not fully implemented under Windows.

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


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

Date: Thu, 10 Oct 2002 14:35:14 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: extract emails with corresponding URLs from whoisreport.com list
Message-Id: <imv3oa.m02.ln@moldev.cmagroup.co.uk>

Nat <wynethlia@cox.net> wrote:
> I need to find a script or application that can run through the long
> lists of URLs that come up at whoisreport.com, extract the admin
> emails from the WHOIS info pages and parse these out along with the
> corresponding URL into a CSV file for use in an Access database.
> Anyone heard of such a beast or know where I can get one created?

This sounds suspiciously like you want us to help you write a tool to
generate a mailing list for SPAM.

No thanks.
Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: 10 Oct 2002 16:59:47 +0200
From: sjn+njus@pvv.org (Salve J. Nilsen)
Subject: First meeting for Oslo.pm, 16. oct 2002
Message-Id: <m3ofa2qqzg.fsf@benzen.eiendomsnett.no>

Hi!

After some discussion at YAPC::Europe::2002::Munich and on the
Norwegian Perl newsgroup, we've decided that an Oslo.pm ("Oslo Perl
Mongers") should be created.

I've therefore taken upon me the joy of inviting all who are
interested in the Perl programming language, to


    Oslo.pm (Oslo Perl Mongers) first meeting
    October 16th, 2002, at 19:00
    at "Pastiz", Tordenskiolds gate 10 (next to the city hall)


We'll start off with a social event where we'll try to decide what to
do with the users group.

Everyone is welcome! :)


Regards,

- Salve J. Nilsen, on behalf of the Oslo-members of the
                   no.it.programmering.perl newsgroup :)

-- 
 "Don't worry about what anybody else is going to do... The best way
  to predict the future is to invent it." -- Alan Kay, 1971


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

Date: Thu, 10 Oct 2002 18:04:14 GMT
From: Matt Eberts <zoips@eesoft.org>
Subject: flock related issue
Message-Id: <yijp9.20123$lV3.1948513@newsread1.prod.itd.earthlink.net>

I'm trying to figure out if this is a bug in ActiveState Perl, or if 
it's because on Linux Perl is ignoring the file lock.

Here is the simplest test case. On Win2k running ActiveState Perl 5.6.1, 
the script will die attempting to copy test.xml.temp back over test.xml. 
However, on Linux, Perl version 5.6.1, it copies the file over just fine.

#!/usr/bin/perl

use Fcntl qw(:DEFAULT :flock);
use File::Copy;

sysopen(FILE, "test.xml", O_RDWR) or die("Unable to open test.xml");
flock(FILE, LOCK_EX);

copy("test.xml", "test.xml.temp") or die("Unable to copy test.xml to 
test.xml.temp");
copy("test.xml.temp","test.xml") or die("Unable to copy test.xml.temp to 
test.xml");

close(FILE);

Am I misunderstanding some basic concept of how flock works, or is this 
really a bug in ActiveState's Perl implementation?

Thanks.



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

Date: Thu, 10 Oct 2002 13:37:27 GMT
From: "judywellsnow" <judywellsnow@prodigy.net>
Subject: Getting off the ground (more newbie than newbie)
Message-Id: <rofp9.469$KU7.27799809@newssvr17.news.prodigy.com>


Is it necessary to be connected to or create a server to test scripts or can
this be done locally w/o server software?  I'm trying to activate scripts
via a web brower, using the client to send data to the scripts.  I can run
basic scripts that don't communicate with the client (I'm using the current
Activatestate release in Win98).


tia




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

Date: 10 Oct 2002 18:00:55 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Getting off the ground (more newbie than newbie)
Message-Id: <u9ptuiw7nc.fsf@wcl-l.bham.ac.uk>

"judywellsnow" <judywellsnow@prodigy.net> writes:

> Is it necessary to be connected to or create a server to test scripts or can
> this be done locally w/o server software?

If you are testing scripts that are intended to be run by a web server
then some testing can be done at the command line (redirect STDOUT to
a file then displat the file in a browser) but you really need
a web server to test them fully.

Free web servers are available for all popular operating systems.

This, of course, has very little to do with Perl.

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


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

Date: Thu, 10 Oct 2002 10:16:00 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Getting off the ground (more newbie than newbie)
Message-Id: <3da5b5d0$1@news.microsoft.com>

judywellsnow wrote:
> Is it necessary to be connected to or create a server to test scripts
> or can this be done locally w/o server software?

Because we are in a Perl NG I guess you are talking about Perl scripts.
Perl is an interpreted programming language just like any other and you
don't need any 'server' or 'server software' whatsoever to execute Perl
scripts.

> I'm trying to
> activate scripts via a web brower, using the client to send data to
> the scripts.

Now you are talking about CGI scripts, which have nothing to do with Perl
per se. They can be written in any language (although Perl is a common
choice).

> I can run basic scripts that don't communicate with the
> client (I'm using the current Activatestate release in Win98).

So your real question is: "How can I test CGI scripts written in Perl
without using a web server?" rather then "Getting off the ground(more newbie
than newbie)".

You may want to check the FAQ "perldoc -q CGI". It contains some hints.
And then of course there is the documentation for the CGI module
("perldoc -q CGI"), which contains quite some advise about e.g. passing
parameters to a CGI script from the command line.

jue




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

Date: Thu, 10 Oct 2002 10:21:21 -0500
From: "J. Dawson" <nospam@fakedomain.com>
Subject: Re: GMT Windows vs Linux
Message-Id: <3da59b02$0$1419$272ea4a1@news.execpc.com>


[snip] These threads do get unwieldly sometimes.

I appreciate everyone's input.   You convinced that the Linux machine is OK.
So upon closer inspection of the Windows machine (which is a separate
machine, miles [a few km] apart), the correct time zone was indeed
incorrect.  I checked it again and again, finally seeing the mistake.  I
know, operator error is usually to blame and I hope you forgive me for not
being more careful.   Time differences can be a lysdexic thing to some.

I posted here in the perl group because the problem was noticed while using
perl and wanted some confirmation from the group.

Thanks




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

Date: Thu, 10 Oct 2002 10:20:41 -0500
From: user <du_bing@hotmail.com>
Subject: Re: How can I tell what version a module is?
Message-Id: <3DA59AC9.47AE55F5@hotmail.com>

I'm aware of that command.  It works for many modules we have but not
IO::Socket::SSL.  I looked the SSL.pm directly and found
$IO::Socket::SSL::VERSION = '0.81'.

Bing

"Andrew V. Tkachenko" wrote:

> user wrote:
> > Specifically, I need to know what IO::Socket::SSL version we have.
> > Reading its manpage did not give me any clue.  It does not have a
> > version method.
> >
> > Thanks for any hints,
> >
> > Bing
> >
>
> try to run it from command line:
>
> perl -MIO::Socket::SSL -e 'print  $IO::Socket::SSL::VERSION'



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

Date: Thu, 10 Oct 2002 14:15:09 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: How to test for blessedness?
Message-Id: <ao421d$cgr$1@reader1.panix.com>



I'm sure this is much simpler than I'm making it, but I can't see
it...  Is there a better (i.e. more direct) way to test for
blessedness than something like

sub is_blessed { eval { (shift)->isa(0) }; !$@ }

??

Thanks,

h


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

Date: Thu, 10 Oct 2002 10:21:29 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Re: How to test for blessedness?
Message-Id: <ao42e7$irg4i$1@ID-159100.news.dfncis.de>

perldoc -f ref

--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...


"Da Witch" <heather710101@yahoo.com> wrote in message
news:ao421d$cgr$1@reader1.panix.com...
>
>
> I'm sure this is much simpler than I'm making it, but I can't see
> it...  Is there a better (i.e. more direct) way to test for
> blessedness than something like
>
> sub is_blessed { eval { (shift)->isa(0) }; !$@ }
>
> ??
>
> Thanks,
>
> h




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

Date: Thu, 10 Oct 2002 10:25:32 -0400
From: "Domizio Demichelis" <dd@4pro.net>
Subject: Re: How to test for blessedness?
Message-Id: <ao42lp$j2b8e$1@ID-159100.news.dfncis.de>

perldoc UNIVERSAL

use UNIVERSAL;

UNIVERSAL::isa($ref, "class"); #return true if $ref is a blessed ref of
class "class"

--
-.. --- -- .. --.. .. ---
-.. . -- .. -.-. .... . .-.. .. ...


"Da Witch" <heather710101@yahoo.com> wrote in message
news:ao421d$cgr$1@reader1.panix.com...
>
>
> I'm sure this is much simpler than I'm making it, but I can't see
> it...  Is there a better (i.e. more direct) way to test for
> blessedness than something like
>
> sub is_blessed { eval { (shift)->isa(0) }; !$@ }
>
> ??
>
> Thanks,
>
> h




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

Date: 10 Oct 2002 17:48:30 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to test for blessedness?
Message-Id: <u9y996w881.fsf@wcl-l.bham.ac.uk>

Da Witch <heather710101@yahoo.com> writes:

> I'm sure this is much simpler than I'm making it, but I can't see
> it...

use Scalar::Util 'blessed';

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


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

Date: Mon, 07 Oct 2002 18:13:51 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: ithreads, perl 5.8 and shared objects
Message-Id: <x7vg4e15ia.fsf@mail.sysarch.com>

>>>>> "DT" == Derek Thomson <derek@wedgetail.com> writes:

  DT> This is a very important question, as if we cannot share objects
  DT> between threads in Perl, then threading in Perl is, for everything
  DT> except toy examples, broken and I will have to be advising people
  DT> considering Perl for multithreaded applications that Perl is still
  DT> *not* thread capable.

i irc'ed with the threads guru and i think i have figured out your
sharing problem.

  DT> Can't call method "id" on unblessed reference at s.pl line 23.

  DT> our %Assoc : shared;

that is shared but its elements may not be shared. you have to explicitly
share the hash elements if they are complex items like objects.

  DT> %Assoc=();

  DT> MAIN:
  DT> {
  DT> 	for (my $i=0;$i<10;$i++) {
  DT> 		my $f=new Foo($i);
  DT> 		share($f);

this is the problem. you are sharing the reference and not the
referent. the referent is the actual object (the hash). $f is only a
reference to it. you bless referents through a reference, the
reference itself is not blessed.

  DT> 	sub new {
  DT> 		my $proto=shift;
  DT> 		my $id=shift;

  DT> 		my $class=ref($proto) || $proto;

  DT> 		my $self = {
  DT> 					ID => $id,
  DT> 				   };

  DT> 		bless($self,$class);

try this: <untested>

	my %self = (
		ID => $id 
	) ;

	share %self ;

 	bless(\$self,$class);

	return \$self;

also he mentioned that the DESTROY method will be called in EACH thread
when this object goes out of scope. so you have to be careful with
managing shared objects. one idea i proposed and he seconded was to keep
a hash of al shared objects (you are doing that) so you can globally
manage the object's scope and control when you want to destroy it.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 10 Oct 2002 14:31:26 GMT
From: Fred <No_Mail_Address@cox.net>
Subject: join lines in @array
Message-Id: <3DA58F68.B2037EF@cox.net>


I want to join some lines from mail-headers into one value of an
array, like:
From: somebody == Date: somedate == X-Mailer: Mozilla 4.04 [en]
(Win95; I) ==

But I always end up with a separate value for every header line:

 if (s/^(From:.+|Date:.+|X-Mailer:.+)/$1 == /i ) {
	chomp;
	push (@bigarray, $_) ;
 }

--
Fred


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

Date: 10 Oct 2002 17:56:48 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: join lines in @array
Message-Id: <u9smzew7u7.fsf@wcl-l.bham.ac.uk>

Fred <No_Mail_Address@cox.net> writes:

> I want to join some lines from mail-headers into one value of an
> array, like:
>
> From: somebody == Date: somedate == X-Mailer: Mozilla 4.04 [en]
> (Win95; I) ==
> 
> But I always end up with a separate value for every header line:

Simply wanting to do something is not enough.  You have to actually do
it.  To join the elements of a list into a single string you can use the
join() function.  Alternatively use the .= operator.

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


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

Date: 10 Oct 2002 08:57:42 -0700
From: jruffino@nslsilus.org (Joe R)
Subject: Loops
Message-Id: <18758cc6.0210100757.1e3ac547@posting.google.com>

Hi,

I'm working on a perl program to compare 2 tables.  I read open each
file, and the loop thru comparing certain feilds.  My problem is when
I loop thru completely on the second file, it stops only after
comparing the first record form the first file.  Here is my code:

#!/user/bin/perl -w

$dynix="dynixte.txt";
$elgin="gailtes.txt";

open (DYNIXDBF, "$dynix");
open (ELGINDBF, "$elgin");
while (<DYNIXDBF>) {
      chomp;
      ($dlast,$daddy,$dphone) = split(/:/);
      while (<ELGINDBF>) {
            chomp;
            ($elast,$eaddy,$ephone) = split(/:/);
            if ($dlast eq $elast) {
               if ($daddy eq $eaddy) {
                  print "Dynix LastName: $dlast Gail Addy: $eaddy Gail
Phone: $ephone\n";
               }
            }
      }
}
close(ELGINDBF);
close(DYNIXDBF);

Dynix is the first file and elgin is the second file, it will loop
thru elgin, comparing the first record of Dynix, but it then stops.  I
think I'm forgetting something, but I don't know what.

Can someone help me please?

Joe Ruffino
Automated Systems Assistant
Gail Borden Public Library District
jruffino@nsls.info


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

Date: 10 Oct 2002 18:14:47 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Loops
Message-Id: <u9lm56w708.fsf@wcl-l.bham.ac.uk>

jruffino@nslsilus.org (Joe R) writes:

> Hi,
> 
> I'm working on a perl program 

use strict;

(Without that you are 'dabbling' or 'toying' not 'working').

> to compare 2 tables.  I read open each
> file, and the loop thru comparing certain feilds.  My problem is when
> I loop thru completely on the second file, it stops only after
> comparing the first record form the first file.

>  Here is my code:

Without even looking I can guess you forgot to reset the file pointer
in the second file back to the beginning inside the outer loop.
 
> #!/user/bin/perl -w

-w has now been superceded by the warnings pragma.

> $dynix="dynixte.txt";
> $elgin="gailtes.txt";
> 
> open (DYNIXDBF, "$dynix");
> open (ELGINDBF, "$elgin");

Always check success of open().  At the very least "or die $!".

See also FAQ: What's wrong with always quoting "$vars"?

> while (<DYNIXDBF>) {
>       chomp;
>       ($dlast,$daddy,$dphone) = split(/:/);

Here is where you should have put the seek().

>       while (<ELGINDBF>) {
>             chomp;
>             ($elast,$eaddy,$ephone) = split(/:/);
>             if ($dlast eq $elast) {
>                if ($daddy eq $eaddy) {
>                   print "Dynix LastName: $dlast Gail Addy: $eaddy Gail
> Phone: $ephone\n";
>                }
>             }
>       }
> }
> close(ELGINDBF);
> close(DYNIXDBF);

Rather than nested iteration you probably should read the smaller file
into a hash keyed on the first column and then interate through the
larger file and select the matching record from the hash.

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


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

Date: Thu, 10 Oct 2002 19:02:15 +0200
From: Marten Lehmann <usenet@variomedia.de>
Subject: NDBM_File
Message-Id: <ao4bqn$ip3qo$3@ID-13266.news.dfncis.de>

Hello,

I have to use the NDBM-module to store values in a file in the 
NDBM-format. Unfortunatly I can't download the module NDBM_File any 
longer at CPAN, because it seems to be included in Perl 5.8 by now. But 
I'm still working with Perl 5.6 and I don't want to change this, so how 
can I download this module? Or how else can I tie a ash to a file in 
NDBM-format?

Regards
Marten Lehmann



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

Date: 10 Oct 2002 07:44:23 -0700
From: d4nj450n@yahoo.com (Dan Jason)
Subject: Re: newbie with datatype prob
Message-Id: <bef1395e.0210100644.69fcec0a@posting.google.com>

> so can I just confirm that there's no problem for $CustomerID to
> contain eight digits, starting with a zero, and be tested against
> seven digit numbers. Perl's pretty smart, isn't it, in knowing they're
> both normal integers (not octo)?
> 
Perl's smart, but it needs some sort of context.  Numbers starting
with a zero are suposed to be treated as octal...  I think this is
your problem
> 
> yep :( I've done what everyone's suggested but am still really unsure
> what I'm doing wrong. I thought using >= might be messing things up
> abit. Should it be ge instead, maybe?
> 

You tried this right? right?  Make sure you quote your fixed numbers.

dan


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

Date: Thu, 10 Oct 2002 11:45:43 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie with datatype prob
Message-Id: <slrnaqbbln.3ff.tadmc@magna.augustmail.com>

Dan Jason <d4nj450n@yahoo.com> wrote:
>> so can I just confirm that there's no problem for $CustomerID to
>> contain eight digits, starting with a zero, and be tested against
>> seven digit numbers. Perl's pretty smart, isn't it, in knowing they're
>> both normal integers (not octo)?


They are not integers they are strings since they come from form input.
Perl converts the strings to numbers when you use them with an
operator that wants numbers rather than strings.

Strings are data, not code.

A leading zero means "octal" only in code.

A leading zero in data might mean octal or decimal or anything
that the creator of the data deems for it to mean.


> Perl's smart, but it needs some sort of context.  


Yes, perl is smart, but this is not much of an example of its 
smartness since nearly every programming language makes a
distinction between code and data.


> Numbers starting
> with a zero are suposed to be treated as octal...  


When in code, but not when in data.


> I think this is
> your problem


I don't (unless he _wanted_ a leading zero in data to mean octal).


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


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

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


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