[17919] in Perl-Users-Digest
Perl-Users Digest, Issue: 79 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 17 11:05:32 2001
Date: Wed, 17 Jan 2001 08:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979747507-v10-i79@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 17 Jan 2001 Volume: 10 Number: 79
Today's topics:
Re: Re: OT: .htpasswd on Win32 build try@try.com
Re: $foo{$bar}={x=>$x,y=>$y} v. $foo{$bar}{x}=$x etc? <visstmbl@reading.ac.uk>
Re: $foo{$bar}={x=>$x,y=>$y} v. $foo{$bar}{x}=$x etc? (Abigail)
(Beginner) ?<! question <garry@heaton6.freeserve.co.uk>
ANNOUNCE: Archive-Zip version 0.11 on CPAN <ned@camano.net>
Another stupid regex question (Stan Brown)
Re: converting Internet Explorer 'favorites' to Netscap <bowman@montana.com>
File::Find wont traverse CDROM !? <rfoskett@my-deja.com>
Re: Fork lots of children <tad@cyberconceptscorp.com>
Forwarding NT Event Log to Syslog <jack.haberle@bigfoot.com>
help on a (maybe trivial?) upgrade from 5.005 -> 5.6 qu <fulchetr@drink.bt.co.uk>
HELP!! : Bi-Directional TCP Perl Sockets <dfortin@eftia.com>
How do you detect modem rings in Perl (if possible)? <noemail@nospam.org>
How to turn 'die' in 'warn' on the fly <Martin.Jost@icn.siemens.de>
Re: How to turn 'die' in 'warn' on the fly <bart.lateur@skynet.be>
Re: Newbie question: hash tables and dbm files; what am <brosson@my-deja.com>
Re: Perl and AOL. How is this possible? (Tad McClellan)
Quick Problem contact@stevencoutts.org.uk
Re: Random Numbers with a Twist <joe+usenet@sunstarsys.com>
Re: Random text script, got one?:-) (Tad McClellan)
Re: Random text script, got one?:-) <bart.lateur@skynet.be>
Re: techniques for finding slow code? dtbaker_dejanews@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 17 Jan 2001 15:02:00 GMT
From: try@try.com
Subject: Re: Re: OT: .htpasswd on Win32 build
Message-Id: <Iti96.134741$47.2069863@news.bc.tac.net>
> In article <3A5E221F.710E5A3@torontonian.com>,
>
> > I was wondering what can I do to make cyript or .htpasswd files to
> work
> > in win32 environment?
> ----------------------------
>
> I dont think you can... I am not aware of any win32 webserver that
> recognizes the .htaccess construct. It is ignored on win32 machines. If
> you have code in place that checks for REMOTE_USER, one thing you can do
> is check the OS, and step around it if you are running on win32.
>
> D
>
>
> Sent via Deja.com
> http://www.deja.com/
==================================
Posted via http://nodevice.com
Linux Programmer's Site
------------------------------
Date: Wed, 17 Jan 2001 14:10:37 +0000
From: John Stumbles <visstmbl@reading.ac.uk>
To: Abigail <abigail@foad.org>
Subject: Re: $foo{$bar}={x=>$x,y=>$y} v. $foo{$bar}{x}=$x etc?
Message-Id: <Pine.WNT.4.30.0101171332230.163-100000@supc16.rdg.ac.uk>
On 17 Jan 2001, Abigail wrote:
> John Stumbles (visstmbl@reading.ac.uk) wrote on MMDCXCVI September
> MCMXCIII in <URL:news:Pine.WNT.4.30.0101171245330.163-100000@supc16.rdg.ac.uk>:
> ^^ I had this:
> ^^ (a)
> ^^ $ifTable{$ifIndex} = {
> ^^ Name => $Name,
> ^^ Speed => $Speed,
> ^^ ...etc...
> ^^ } ;
> ^^ (b)
> ^^ $ifTable{$ifIndex}{dot1d}{$MAC} = {
> ^^ mtime => $MAC_mtime,
> ^^ nMACs => $nMACs,
> ^^ ...etc...
> ^^ } ;
> ^^
> ^^ and I thought I should have a table of mtime, nMACs etc for each $MAC, but
> ^^ I only get the record for the last $MAC I assign.
>
> What do you mean "each $MAC"? There's no loop in the code.
>
> ^^ If I change (a) to this:
> ^^ $ifTable{$ifIndex}{Name} = $Name ;
> ^^ $ifTable{$ifIndex}{Speed} = $Speed ;
> ^^ ...etc...
> ^^
> ^^ I get what I expect: a table for each $MAC.
> ^^ In each case I get the table of Name, Speed etc for each $ifIndex.
>
> Show more code.
Yes I do have a loop: I'm querying a mySQL database using the DBI:
while ($sth->fetch)
{
# $ifTable{$ifIndex} = {
# Name => $Name,
# Speed => $Speed,
# } ;
$ifTable{$ifIndex}{Name} = $Name ;
$ifTable{$ifIndex}{Speed} = $Speed ;
if (defined $nMACs) # anything seen on this port in dot1d table?
{
$ifTable{$ifIndex}{dot1d}{$MAC} = { # record for each MAC seen on port: latest time returned last so eventual record will be most recent
mtime => $MAC_mtime,
nMACs => $nMACs,
} ;
$username and $ifTable{$ifIndex}{dot1d}{$MAC}{users}{$username} = $user_mtime ; # get a record for each username seen, with latest time seen
$username and $ifTable{$ifIndex}{dot1d}{$MAC}{last_user} = $username ; # get a record for each username seen, with latest time seen
}
}
I also find that the 'username' bit is suffering the same effect:
I should have several usernames for some values of $ifIndex and
corresponding $MAC, but I am only getting one value in:
$ifTable{$ifIndex}{dot1d}{$MAC}{users}
i.e. scalar keys (%{$ifTable{$ifIndex}{dot1d}{$MAC}{users}}) == 0 or 1,
never > 1.
Again, if I change (b) to
$ifTable{$ifIndex}{dot1d}{$MAC}{mtime} = $MAC_mtime ;
$ifTable{$ifIndex}{dot1d}{$MAC}{nMACs} = $nMACs ;
the 'users' bit of the data structure works as expected.
regards,
--
John Stumbles j.d.stumbles@reading.ac.uk
I.T. Services Centre, University of Reading http://www.rdg.ac.uk/~visstmbl
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
never generalise
------------------------------
Date: 17 Jan 2001 14:52:51 GMT
From: abigail@foad.org (Abigail)
Subject: Re: $foo{$bar}={x=>$x,y=>$y} v. $foo{$bar}{x}=$x etc?
Message-Id: <slrn96bce3.9j6.abigail@tsathoggua.rlyeh.net>
John Stumbles (visstmbl@reading.ac.uk) wrote on MMDCXCVI September
MCMXCIII in <URL:news:Pine.WNT.4.30.0101171332230.163-100000@supc16.rdg.ac.uk>:
:} On 17 Jan 2001, Abigail wrote:
:}
:} > Show more code.
:}
:} Yes I do have a loop: I'm querying a mySQL database using the DBI:
:}
:} while ($sth->fetch)
:} {
:} # $ifTable{$ifIndex} = {
:} # Name => $Name,
:} # Speed => $Speed,
:} # } ;
:} $ifTable{$ifIndex}{Name} = $Name ;
:} $ifTable{$ifIndex}{Speed} = $Speed ;
:}
:} if (defined $nMACs) # anything seen on this port in dot1d table?
:} {
:} $ifTable{$ifIndex}{dot1d}{$MAC} = { # record for each MAC seen on port: latest time returned last so eventual record will be most recent
:} mtime => $MAC_mtime,
:} nMACs => $nMACs,
:} } ;
:} $username and $ifTable{$ifIndex}{dot1d}{$MAC}{users}{$username} = $user_mtime ; # get a record for each username seen, with latest time seen
:} $username and $ifTable{$ifIndex}{dot1d}{$MAC}{last_user} = $username ; # get a record for each username seen, with latest time seen
:} }
:} }
None of this code is changing $ifIndex, $nMACs, $Name, $Speed or $MAC,
so, I'm not surprised you only save one $MAC.
If you manage to save more $MACs in some variant, you are hiding essential
code.
YOU CANNOT BE HELPED IF YOU DON'T SHOW THE PROBLEM.
Abigail
------------------------------
Date: Wed, 17 Jan 2001 16:03:07 -0000
From: "Garry Heaton" <garry@heaton6.freeserve.co.uk>
Subject: (Beginner) ?<! question
Message-Id: <944fll$fjs$1@newsg1.svr.pol.co.uk>
I'm reading Larry Wall's "Programming Perl" (3rd ed.) and on p.204 there's
an example of the Negative Lookbehind pattern:
s/(?<!c)ei/ie/g
This is intended to match the spelling rule "I before E, except after C" ,
but wouldn't this be simpler:
s/cei/cie/g
??
Garry Heaton
------------------------------
Date: Wed, 17 Jan 2001 00:21:28 -0800
From: Ned Konz <ned@camano.net>
Subject: ANNOUNCE: Archive-Zip version 0.11 on CPAN
Message-Id: <t6basbn6033gd0@corp.supernews.com>
The 0.11 version of Archive::Zip is available at CPAN in
http://www.cpan.org/authors/id/N/NE/NEDKONZ/Archive-Zip-0.11.tar.gz
or
http://www.cpan.org/authors/id/N/NE/NEDKONZ/Archive-Zip-0.11.zip
though you should use your local mirror instead of www.cpan.org.
It is also available from my Perl homepage at http://bike-nomad.com/perl/
Note that you need a recent (>1.06) version of Compress::Zlib
to make this work.
DESCRIPTION
The Archive::Zip module allows a Perl program to create,
manipulate, read, and write Zip archive files.
Zip archives can be created, or you can read from existing
zip files. Once created, they can be written to files,
streams, or strings.
Members can be added, removed, extracted, replaced, rear
ranged, and enumerated. They can also be renamed or have
their dates, comments, or other attributes queried or mod
ified. Their data can be compressed or uncompressed as
needed. Members can be created from members in existing
Zip files, or from existing directories, files, or
strings.
This module uses the Compress::Zlib library to read and
write the compressed streams inside the files.
CHANGES SINCE LAST VERSION
0.11 Tue Jan 9 11:40:10 PST 2001
- Added examples/ziprecent.pl (by Rudi Farkas)
- Fixed up documentation in Archive::Zip::Tree
- Added to documentation in Archive::Zip::Tree
- Fixed bugs in Archive::Zip::Tree that kept predicates from working
- Detected file not existing errors in addFile
------------------------------
Date: 17 Jan 2001 09:44:52 -0500
From: stanb@panix.com (Stan Brown)
Subject: Another stupid regex question
Message-Id: <944b54$9ne$1@panix6.panix.com>
Sorry to bugh people with this again, we visited this a few days ago, and I
thought I had it fixed, but todat it failed to work corectly again :-(
I am using the following regex for Parse::Lex
'[a-z\-A-Z_0-9:\+<> .\#\/%\\(\)]{1,32} '
And it's failing to fire for:
column FULLTEXT, data ->504TEA:SGT051E.190/71# LETD POSITION FEEDBACK MISMATCH ALM HIDEV 01-17-01 09:33:44:7 11.22% ( 10.55) MISMATCH ALM <-
The 2 previous tokens are firing. They are
column COMPOUND, data ->504TEA:<-
column BLOCK, data ->SGT051E.<-
Any sugestiosn as to what I am doing wrong?
If necessary, I can post the whole lexer.
------------------------------
Date: Wed, 17 Jan 2001 07:29:04 -0700
From: "bowman" <bowman@montana.com>
Subject: Re: converting Internet Explorer 'favorites' to Netscape bookmark file
Message-Id: <h%h96.3599$d25.24048@newsfeed.slurp.net>
rob <nospam@ireland.com> wrote in message
news:3A6590D4.74363A72@ireland.com...
> Hi
> I'm trying to import the favourites I've created in IE to Netscape. IE
> uses a .url file for the actual link, so in my favourites, I can click
> "MSN" which uses information from the file below.
Unless you are doing this as an exercise, look at 'Import and Export' under
the 'File' menu on IE.
------------------------------
Date: Wed, 17 Jan 2001 14:02:54 GMT
From: rog <rfoskett@my-deja.com>
Subject: File::Find wont traverse CDROM !?
Message-Id: <9448ma$rk0$1@nnrp1.deja.com>
Hello,
I have a pfs mounted cdrom (HPUX) which I am trying to recurse using
File::Find - though am having problems getting it to traverse further
than the current directory. This works fine however (as expected) when
the start point is on a normal disk.
Does anyone have any ideas on this??
many thanks
roger
(code snippet below)
-----------------------------------------------
#!/usr/bin/perl -w
use strict;
use File::Find;
use File::Copy;
use Cwd;
my $startdir = "/SD_CDROM/DOC/";
my $instdir = "/opt/www/htdocs/docs/ora817/";
my %types;
my $test = 1;
my $process = sub {
my $path = $File::Find::name;
my ($relpath) = ($path =~ /^$startdir(.*)$/);
my ($suffix) = ($path =~ /[.]([^.\/]+)$/);
my ($from,$to) = ($startdir.$relpath,$instdir.$relpath);
$suffix ||= "";
if (-d $from) {
if ($test) {
print "TEST> mkdir $to\n" if !-d $to;
} else {
mkdir ($to,0755) if !-d $to;
}
} elsif ($suffix =~ /(htm|html|gif|jpg|jpg)/) {
$types{$suffix} = exists $types{$suffix}
? $types{$suffix} + 1 : 1;
if ($test) {
print "TEST> copy $from $to\n";
} else {
my $status = copy ($from,$to);
printf ("%s %s\n",$relpath,($status?"OK":"FAILED: $!"));
}
}
};
find ({ wanted=>$process, follow => 0 }, $startdir);
print "\nType summary:\n";
foreach (sort keys %types) {
printf (" %6s = %s\n",$_,$types{$_});
}
-----------------------------------------------
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 17 Jan 2001 07:52:36 -0700
From: Tad Pepperling <tad@cyberconceptscorp.com>
Subject: Re: Fork lots of children
Message-Id: <3A65B1B4.4DAEF3B1@cyberconceptscorp.com>
Chris,
I am working on a project that we need to spawn multiple processes and for the
life of me I can not get it to work.
I would love to invest more time in learning it but the 72 hours that I have
in it so far tells me that I need to do something different.
What the script does is use LWP to run queries on search engines and return
the results. Whe we run a querie on 10 engines it takes between 30 seconds and
120 seconds. We are hoping that forking the process so that each search engine
get quired at the same time instead of sequentially would cut down the time.
Below is the code we are using..
Can you help us?
Tad Pepperling
sub search {
#usage: @results = &search($url,$phrase);
# this will return an array with three strings per element seperated by
# pipes "|" $search|$engine_name|$rank use split to retreive these.
#
# foreach (@results){
# ($search,$engine_name,$rank) = split (/\|/,$_);
# print "$search,$engine_name,$rank\n";
# }
#
# $| = 1; These are required to work properly
# use LWP::Simple;
# This file is a text file listing the search engines (10) each
ion its own line.
my $datapath =
"/usr/local/etc/httpd/htdocs/ready/cgi-bin/analyzer/position.txt";
my ($c_url,$prase,$name,$url,$search,$split,@mark,@results,$found);
($c_url,$phrase) = @_;
open(FILE,"$datapath")|| die "Can not open $datapath $!"; # opens the
search engine list
@lines = <FILE>;
close(FILE);
$phrase =~ tr/ /+/;
$c_url =~ tr/+/ /;
$c_url =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$c_url = quotemeta($c_url);
$num_lines = @lines;
$num_lines--;
my $pid = $$;
for ($i = 0; $i <= $num_lines; $i++) {
chomp($lines[$i]);
($name,$url,$search,$split,@mark) =
split(/\|/,$lines[$i]);
for ($j = 0; $j <= 1; $j++) {
$pos = "";
if (substr($mark[$j],-1,4) eq "\$") {
chop($mark[$j]); $pos = "l"; }
if (substr($mark[$j],-1,1) eq "\$") {
chop($mark[$j]); $pos = "f"; }
$mark[$j] = quotemeta($mark[$j]);
if ($pos eq "l") { $mark[$j] = "$mark[$j]" .
"\$"; }
if ($pos eq "f") { $mark[$j] = "^" .
"$mark[$j]"; }
}
@searches = split(/\^/,$search);
my $senum = @searches;
$searches[0] =~ s/\[search for this\]/$phrase/ig;
$rank = 0; $found = 0;
foreach $search (@searches) {
$search =~ s/\[search for
this\]/$phrase/ig;
##### need to fork this to speed things up
$page = get($search); ## LWP call to search the engines
#### Stop fork here
@searchlines =
split(/$split/, $page);
foreach $line(@searchlines)
{
if ($line =~
/$mark[0]/ && $line =~ /$mark[1]/ && $found == 0) {
$rank++;
if
($line =~ /$c_url/) { $found = -1; }
}
}
if ($found) { last }
}
$results[$i] = "$searches[0]|$name|$rank-$$";
}
return @results;
}
1;
Chris Stith wrote:
> Collin Starkweather <collin.starkweather@collinstarkweather.com> wrote:
> > Bill Buchan wrote:
> >>
> >> I'd like to run a number of processes at the same time (unix).
>
> fork() should work, unless you need threading support instead.
>
> >> I've been using fork but I seem to have to create a child process, then
> >> spawn a child from the child, and a child from this child etc. until I
> >> have a whole heirarchy of children. This works but the code is a real
> >> mess.
>
> So your code must look something like this:
>
> my $pid = fork();
> $pid = fork();
> $pid = fork();
>
> The secret to doing most anything a number of times in a sequential
> programming language ( including forking processes so you don't
> have to do everything in sequence after all ) is to use a loop. A
> fairly simple example of how to handle multiple children is below.
> This is slightly different from what's in _Perl_Cookbook_, and I
> don't claim that mine's better. It is cheaper than buying a book
> for one example, though. I'd still recommend the Ram, as it is a
> good source of other examples as well.
>
> My apologies for keeping the copyright notice and the license
> in the example when posting to the group. It might be tacky,
> but, "once released, a copyrighted work must always bear the
> notice" and yadda yadda yadda... This is a section of a much
> larger program, slightly mutated to be a simple example.
>
> ###-------------------------------------------------------------
> #!/usr/bin/perl -w
> # Quints
> # example of multiple children from one parent by Chris Stith
> # Copyright 2000, 2001 Christopher E. Stith
>
> # You may use this source code in another program or base another
> # program entirely on this source code, alter this source code
> # as you see fit, and you may copyright the program which makes
> # use of or is derived from this code. The original author maintains
> # copyright on this source code as it is. Any copyright notice for
> # a program making use of this source code, or derived from it,
> # should note that portions are copyrighted by Christopher E. Stith
> # and that these sections are used with permission.
>
> # NOTE: many of the `sections' described in the comments could
> # be turned into a single subroutine call inside the control
>
> # use strict is always a good idea.
> # It is usually a very good idea.
> use strict;
>
> # This section sets up the children.
> my $children_to_spawn = 5; # number of children we want to spawn
> my $num_children = 0; # number we have now
> my $im_the_parent = 1; # is this process the parent?
> my @kid_pid = (); # array of child PIDs
> for(my $i = 0; $i < $children_to_spawn; $i++ ) {
> if( my $p = fork() ) {
> # Only the parent does this.
> push( @kid_pid, $p ); # add to the array of child PIDs
> $num_children = $i + 1; # The loop starts at 0, so add 1 here
> # (or, we could have started the loop
> # at 1, used <= instead of <, not
> # added anything here, and been more
> # efficient but slightly less clear.
> } else {
> # Only the child does this.
> $im_the_parent = 0; # We only want the original process
> # to perform any actions meant for
> # the parent.
> last; # We want out of the loop so we don't also spawn
> # children within the loop.
> }
> }
>
> # This section is for any initialization or preprocessing
> # peculiar to the parent or its children. Also, if the
> # parent shouldn't do any real processing and should
> # just wait for the children, you can put your main processing
> # section within the child section (the else clause) of this
> # if.
> if( $im_the_parent ) {
> # Only the parent does this, because we cleared
> # $im_the_parent in the child section of the loop.
> my $kids = join( ', ', @kid_pid );
> print "I'm the parent. My pid is $$, and I have spawned $kids.\n";
> } else {
> # Only the children do this.
> print "I'm a child. My pid is $$.\n"
> }
>
> # You can do main processing here to make sure the parent and
> # all children do the same thing.
> #
> # Everything does this because there's no check on which process
> # is running.
> # It's probably not a good idea to put an infinite loop or
> # something similar in this section, since that would tie the
> # parent up as well as the children. I always prefer to have my
> # parent shortly available to wait on the children. If you really
> # want to make the main part of the children into an infinite loop
> # or use deep recursion, it might be best to make this section
> # test for which process is running just like the above and below
> # sections.
> #
> # If there's nothing we want the parent AND its children to do,
> # we can leave this section empty.
> print "$$ says: We can all do the same thing now.\n\n";
>
> # Cleanup section!
> # This is a good place to wait for your children. I wouldn't
> # do much else inside the while() loop in this section,
> # because wait is, by nature, asynchronous (we don't want to
> # use waitpid() with &WNOHANG here, because we're in a loop
> # and we want to be nice to the system). Code that the
> # parent should run might go in the if() block here but
> # outside the while() loop. If you want to be sure the
> # parent has no children left before it does its final
> # cleanup, put such code after the while() loop.
> if( $im_the_parent ) {
> # Only the parent does this, because we cleared
> # $im_the_parent in the child section of the loop.
> while( $num_children ) {
> my $dead_child = wait;
> print "I just reaped $dead_child.\n";
> $num_children--;
> }
>
> # parent cleanup section!
> # This is where the parent can do anything we want it
> # to do after the children are all dead.
> print "$$: Alas, I've no children left!\n";
> } else {
> # child cleanup section!
> # This is where the child can perform any last actions
> # that the parent need not do as well.
> print "$$: My service to my parent is done.\n";
> }
> exit(0);
> ###----------------------------------------------------------
>
> >> All I want is one parent and multiple children all at the same level in
> >> the process heirarchy. Is this possible? Or is there a better way to
> >> go about it - ie. other than fork? Or does somebody have a tidier bit
> >> of code to do this!?
>
> I haven't seen the OP's code, so I can't be sure that mine is much
> tidier. Mine is tested, though, and it does what the OP asks.
>
> IIRC, my code above is commented more thoroughly than the example
> in the Ram. It'd probably be best to get the Ram ( _Perl_Cookbook_ ),
> and compare and contrast two different sources of code which both
> deal with the same issue. I've never been asked to write a book
> on Perl, so I wouldn't be offended to hear "The Ram does it better"
> or similar comments from the OP or anyone else.
>
> >> Many thanks for any information
>
> I hope this helps. Of course, you'd never write multiple forks
> into a production program just to print out a couple dozen strings.
> ;)
>
> > You'll find what you need in the Perl Cookbook.
>
> Indeed. I hate telling someone to buy a book for one example. The
> Ram is handy, though, so I wouldn't tell someone not to buy it.
>
> Chris
>
> --
> Christopher E. Stith
>
> "Get real! This is a discussion group, not a helpdesk. You post
> something, we discuss its implications. If the discussion happens to
> answer a question you've asked, that's incidental." -- nobull in clp.misc
------------------------------
Date: Wed, 17 Jan 2001 14:54:32 GMT
From: RUATurtle <jack.haberle@bigfoot.com>
Subject: Forwarding NT Event Log to Syslog
Message-Id: <944bn5$u7b$1@nnrp1.deja.com>
Hi,
I'm looking for a way to forward NT Eventlogs to a syslog on a Linux
box. I've found some shareware (Adiscon EventReporter; $29/license) but
no luck thus far finding something completely free.
Any hints that anyone might offer will be appreciated.
TIA,
-J
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 17 Jan 2001 15:41:45 +0000
From: tim fulcher <fulchetr@drink.bt.co.uk>
Subject: help on a (maybe trivial?) upgrade from 5.005 -> 5.6 query
Message-Id: <3A65BD39.BB00A353@drink.bt.co.uk>
Hi,
Yeah I just installed 5.6.0 from CPAN which seemed to go smoothly
enough. However I've tried a couple of my old scripts and they fail to
find the relevant modules. The ones in question reside in
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris
sun4-solaris was the archname for 5.00503 but when I installed 5.6 I
perhaps naively selected a threading option (not ithreads), but this
means the archname is sun4-solaris-thread. Does that have a bearing on
this ?
I notice my new @INC contains
(@INC contains: /usr/local/lib/perl5/5.6.0/sun4-solaris-thread
/usr/local/lib/perl5/5.6.0
/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris-thread
/usr/local/lib/perl5/site_perl/5.6.0
/usr/local/lib/perl5/site_perl/5.005 /usr/local/lib/perl5/site_perl .)
Have I got to go fetch the modules afresh for 5.6 or is there some point
here I'm missing ?
cheers
Tim
------------------------------
Date: Wed, 17 Jan 2001 10:08:11 -0500
From: "Dennis Fortin" <dfortin@eftia.com>
Subject: HELP!! : Bi-Directional TCP Perl Sockets
Message-Id: <Szi96.121008$Z2.1448565@nnrp1.uunet.ca>
Good Day,
I have a question involving bi-directional communication using TCP sockets
in Perl. Just for some background, I'm using the IO::Socket interface.
Anyways, I'm trying to write a server that can take in a request from a
client over a single socket connection, process this request, then send back
a response over the same connection. Sounds simple enough.
This is what I've managed to accomplish so far. I've set up a TCP connection
between the client and server on a specific port. My client sends a
text-based request string down the socket, and my server receives it. But,
as soon as my client tries to read the response from the server on the same
socket connection, both programs hang. It's not until I kill my client that
the server actually goes through processing the request, and sending a
response (although, at this point, there is no point because there is no
more client).
Here's a quick and basic example of what I'm talking about :
=========================================
# --- Client ---
# Set up TCP socket and connect with server.
$socket = new IO::Socket::INET(...);
print $socket $requestString;
while($response = <$socket>) {
print $response;
}
=========================================
# --- Server ---
# Create TCP socket and listen to it.
$socket = new IO::Socket::INET(...);
while( $new_sock = $socket->accept()) {
die "Unable to fork : $!\n" unless defined($childpid = fork());
if($childpid != 0) {
# Parent here.
next;
}
else { # Child here
while($line = <$new_sock>) {
$request .= $line;
}
# Process request here, and create $response....
print $new_sock $response;
$new_sock->close();
exit(0);
}
}
=========================================
For some reason, as soon as I try to read/write to a socket I've just
written/read from, the programs hang. I've even tried other methods, such as
IO::Select handles to make sure that socket is ready for I/O. I've also used
$socket-send() and $socket-recv() with protocols on how much information is
being sent down the socket. I even tried sysread() and syswrite(). Nothing
seems to work. I have come to the conclusion that either Perl sockets are
really not bi-directional, or that God hates me and this is my punishment.
;)
In any case, I'm looking for some insite to my problem. Maybe there's
something that I missed, or am not looking at. Any help will be greatly
appreciated. BTW, I need the fork() action to be in the server side. I've
seen examples that have the fork in the client, which wasn't much help to
me.
Thanks,
D Fortin
------------------------------
Date: Wed, 17 Jan 2001 16:06:43 +0100
From: Craig Manley <noemail@nospam.org>
Subject: How do you detect modem rings in Perl (if possible)?
Message-Id: <3A65B503.8E405795@nospam.org>
Hi all,
I need to write a simple program that must monitor a modem for incoming
calls and execute another program when the modem rings - that's all. I
have no modem so I'ld like to ask first if and how this can be done
before I buy and install one.
The target platform may be Linux or Windows.
My guess is:
Open the modem device for reading just as if it is a file.
Read lines from the device and whenever the text "RING" is received an
external program is executed.
Code:
open(MDM,'<ttyS0'); # or for Windows: open(MDM,'<COM1');
while (<MDM>) {
chomp($_);
if ($_ eq 'RING') {
system('anotherprog');
}
}
-Craig Manley.
------------------------------
Date: Wed, 17 Jan 2001 16:33:03 +0100
From: Martin Jost <Martin.Jost@icn.siemens.de>
Subject: How to turn 'die' in 'warn' on the fly
Message-Id: <3A65BB2F.E7D9F06A@icn.siemens.de>
Hello,
I think I read some time ago about a trick to turn all 'dies' in
'warns' on the fly.
So that during one run of the perl-hack, all dies become a warn,
without changing the source.
Now I would have a good use of that trick, but unluckily, I can't find
this info again
(I looked at the FAQs, used 'glimpse' on my perl-tree, used DejaNews -
I came up with some very interesting things, but not what I looked
for...)
Can somebody please point me in the right direction ?!
TIA
Martin
------------------------------
Date: Wed, 17 Jan 2001 15:55:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to turn 'die' in 'warn' on the fly
Message-Id: <i1gb6tshagtu446v7bj59erihbf28h1avr@4ax.com>
Martin Jost wrote:
>I think I read some time ago about a trick to turn all 'dies' in
>'warns' on the fly.
>So that during one run of the perl-hack, all dies become a warn,
>without changing the source.
>
>Now I would have a good use of that trick, but unluckily, I can't find
>this info again
Maybe you mean
$SIG{__DIE__} = sub { warn shift };
but careful. If people put a "die" somewhere, they usually don't
reconsider the possibility that the program would continue regardless.
I'd rather do the reverse, warn in non-critical places, and temporarily
make warn die.
$SIG{__WARN__} = sub { die shift };
(untested code snippet
)
--
Bart.
------------------------------
Date: Wed, 17 Jan 2001 15:54:57 GMT
From: Brian <brosson@my-deja.com>
Subject: Re: Newbie question: hash tables and dbm files; what am I doing wrong?
Message-Id: <944f8c$1di$1@nnrp1.deja.com>
Gee, thanks for the tip...try to keep up with us here. If you don't
have anything more constructive to add to the thread than the "read the
documentation" reply then don't waste our time.
In article <942erp$dpm$1@nnrp1.deja.com>,
gnari@my-deja.com wrote:
> In article <941ksn$kps$1@nnrp1.deja.com>,
> Brian <brosson@my-deja.com> wrote:
> > I've had the same experience, it's frustrating. I finally read that
> > you can't save hashes of hashes in a dbm file. It was very
difficult
> > to locate any reference material that addresses this.
> >
>
> really? this is too much!
>
> perldoc -q DBM
>
> if you dont know how to use perldoc, try
> perldoc perldoc
> and then why not
> perldoc perl
>
> if perldoc is not installed on your system, do not despair. try
> man perlfaq
> and search for DBM
>
> if man pages are too much, then look in this newsgroup for the regular
> FAQ postings. any one of them contains links to online docs
>
> a quick search on deja.com for 'FAQ DBM' actually locates this very
FAQ
> and an excellent reply by Garry Williams to a similar posting less
than
> 3 weeks ago
>
> if you need printed documentation, may I recommend the Perl Cookbook
> published by O'Reilly. The index has in the Database Access section:
> 14.8: Storing Complex Data in a DBM File
>
> gnari
>
> Sent via Deja.com
> http://www.deja.com/
>
--
Brian R.
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Wed, 17 Jan 2001 07:26:30 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl and AOL. How is this possible?
Message-Id: <slrn96b3rl.2s0.tadmc@tadmc26.august.net>
Dave <david.obrien@ssmb.com.au> wrote:
[ you should provide attributions when you quote someone ]
>>> Are you always so rude?
>>
>>Abigail is very curt with her answers. But if you look at what she
>>says, she's usually addressing the core of the problem. Abigail is kind
>>of like Unix manpages. Nearly worthless at first glance, but solid gold
>>after you have attained a certain level of knowledge.
>Abigail reminds me of Godzilla (where is she anyway?).
You have not attained a certain level of knowledge yet since
you cannot discern the gold there. Keep learning.
Abigail's answers are correct, the troll's are nearly always wrong.
Abigail messes with people who ask off-topic questions or questions
easily answered by searching the standard docs. (posts that are
forbidden by netiquette in the first place)
The troll messes with people (nearly always a "newbie") asking
legitimate Perl questions in the Perl newsgroup. (posts that are
the reason for the newsgroup's very existence).
They are at *opposite* ends of the spectrum.
>Completely off
>putting to genuine posters, because they don't frame the problem exactly
^^^^^^^
>the way they want it.
I think you have assumed the wrong reason.
I think it was because the OP asked a non-Perl question in
a Perl newsgroup. Even so, Abigail pointed out a good place
to get the answer:
Abigail> should you be asking in a browser group?
>Your problem is a browser problem,
So you agree with Abigail then!
>but since you are using perl, I think
>you are within your rights to post here,
Thank you for identifying yourself as a non-believer in standard
netiquette, I have made use of that information.
>though you might get a nicer
>response from comp.infosystems.www.authoring.cgi
Dave reminds me of Abigail, pointing people who have wandered into
the wrong place to where the right place is.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Jan 2001 15:46:31 GMT
From: contact@stevencoutts.org.uk
Subject: Quick Problem
Message-Id: <944eok$uh$1@nnrp1.deja.com>
OK I need to make a quick change to a script. What I have is a form
processing script that emails the contents of a form. I want to edit
this script so that if for example the name filled in on the form was
equal to 'letmein' then it would re-direct to another page.
Can anyone give me an example of how I would structure the if
statements etc with some example code? Perl is not my strong point!!
Cheers
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 17 Jan 2001 11:04:58 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Random Numbers with a Twist
Message-Id: <m3wvbuw4et.fsf@mumonkan.sunstarsys.com>
"John Boy Walton" <johngros.NOSPAM@bigpond.net.au> writes:
> "Joe Schaefer" <joe+usenet@sunstarsys.com> wrote in message
> news:m366jfxfye.fsf@mumonkan.sunstarsys.com...
> > Indeed, and it would essentially reproduce the correct solution
> > that Craig submitted a while ago. For reasons that are unclear
> > to me, the topic of this thread has now become the domain of
> > applicability of his code, since noone has offered any alternative.
> > Bizarre.
> >
> > If ifs and buts were candy and nuts, we'd all have a merry Christmas.
> Sorry Joe I read the first four posts in this thread and thought it
> was too esoteric to help. So I submitted my post then read the rest and
> yes Craigs solution is much better than mine. I have to try and adapt my
> minesweeper to use his hash idea. I don't have the problem of no bombs
> being adjacent to others so it would speed up my code and avoid the
> problem Abigail and Garry pointed out.
It's not an esoteric problem- it's a quite simple one that can become
esoteric if you stray too far from the original conditions. Everyone
here seems to agree on the "right" technique for arbitrarily choosing
unique points from a set. (I'm pretty sure that's the one you're using
in your minesweeper code.)
The question is whether the same technique extends to this problem, and
the answer depends on whether or not the geometry inherent in the
problem is somehow relevant. In a case like this one (packing boxes within
a bigger box) it's not relevant until you've covered at least 10%
of the total area (one box for each 3x3 grid).
Does that mean you can't use Craig's solution once your requirements
exceeded 10% of the total area? Of course not- but you should include
some error handling code to deal with the unlikely event of randomly
choosing an optimal configuration.
Should you use it for cases exceeding 50% - obviously not. But that
would amount to a 10-fold increase in the number of boxes from OP's
original question.
Of course, you could just test his code out yourself, since he made
it very easy to play with.
HTH
--
Joe Schaefer
------------------------------
Date: Wed, 17 Jan 2001 07:58:30 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Random text script, got one?:-)
Message-Id: <slrn96b5nm.2s0.tadmc@tadmc26.august.net>
Stefan Serena <sserena@freesurf.ch> wrote:
>
>It's always a good idea to go to www.cgi-resources.com
It's *never* a good idea to go to www.cgi-resources.com.
Many many of the programs there have bugs and security holes.
The code by the maintainer of that site (written when he was a
teenager and seldom/never updated) is pretty famous as an example
of Really Bad Code that people who don't know any better use
without knowing what they are exposing themselves to.
Be careful out there.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 17 Jan 2001 16:03:03 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Random text script, got one?:-)
Message-Id: <1cgb6t8esshekdtdg2db8sh7vjg3k1rlcm@4ax.com>
johnstarr2001@my-deja.com wrote:
>Hi I looking for a random text script if someone has already have made.
Perhaps you're interested in this entry from the FAQ.
How do I select a random line from a file?
Here's an algorithm from the Camel Book:
srand;
rand($.) < 1 && ($line = $_) while <>;
This has a significant advantage in space over reading the whole
file in. A simple proof by induction is available upon request
if you doubt its correctness.
If you want to select one of a group of lines, just put a delimiter
string of your choice between the lines. Set $/ to that, with a leading
and trailing newline. Or, with $/ set to "", this will use an empty line
as delimiter. chomp() will then remove this delimiter from the string.
--
Bart.
------------------------------
Date: Wed, 17 Jan 2001 15:41:00 GMT
From: dtbaker_dejanews@my-deja.com
Subject: Re: techniques for finding slow code?
Message-Id: <944eea$hv$1@nnrp1.deja.com>
In article <slrn969e10.14i.tadmc@tadmc26.august.net>,
tadmc@augustmail.com wrote:
> dtbaker_dejanews@my-deja.com <dtbaker_dejanews@my-deja.com> wrote:
> >I'd like to hear if ya'll have some favorite techniques for zeroing
in
> >on slow code.
>
> You mean beyond the ones offered in the answer to your Frequently
> Asked Question? No.
>
-----------------
yes, beyond the use of benchmark as described in FAQ3...
The script is large enough where it is a little difficult to pull apart
and feed parameters to put into a benchmark loop. There are enough
iterative sections where I'd have to isolate each section manually
anyway... Especially hard since it is fired up as a cgi, and it would
take a while to set up the parameters to feed it "offline". What I am
hoping for is a way to profile it in-situ while running "real" data.
Some kind of stack trace or profiler as is available in some other
languages that I may not have heard about or used with perl yet. Perhaps
some runtime flag that would write a timestamp trace file or whatever.
I dont usually use the debugger, usually do just fine with print
statements, but in this case I am hoping for some ideas to help shorten
the process.
D
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 79
*************************************