[19858] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2053 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 2 06:05:27 2001

Date: Fri, 2 Nov 2001 03:05:07 -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: <1004699106-v10-i2053@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 2 Nov 2001     Volume: 10 Number: 2053

Today's topics:
        AI Neural Network - predicting CPU load example (Stephen Spence)
        apostrophe character in text boxes and mysql <hugo@fractalgraphics.com.au>
    Re: apostrophe character in text boxes and mysql <nospam_ojngo@home.com>
    Re: apostrophe character in text boxes and mysql <thepoet@nexgo.de>
    Re: apostrophe character in text boxes and mysql <jeff@vpservices.com>
        Can't call method "add_handler" error. (Scott)
        Email errors <milan@balkanmedia.com>
    Re: Failed scripts leave Perl behind <BROWNHIK@Syntegra.Bt.Co.Uk>
        HELP: how to turn off echo when connect to server(use P (wade)
        hi  <hugo@fractalgraphics.com.au>
        how to debug perl cgi at homepage <tkcheung@vtc.edu.hk>
    Re: Leftmost SHORTEST (Logan Shaw)
        Need help creating a small flatfile DB program <rvalcourt@telus.net>
    Re: Newbie Hash Slice Question <aeropaul@sbcglobal.net>
    Re: Newbie Hash Slice Question <aeropaul@sbcglobal.net>
        Newbie WebMail Question (v)
        perl bots from Net::IRC  <moorepete@telocity.com>
    Re: reading flat-file db and replacing a word <uri@stemsystems.com>
        Sorry, POE::Wheel::ReadWrite (wade)
    Re: Taint problem with BEGIN block (BUCK NAKED1)
    Re: Unsigned 8 bit math (addition and subtraction) (Villy Kruse)
    Re: variable number of socket descriptors nobull@mail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 1 Nov 2001 21:56:29 -0800
From: stephen.spence@workcoverqld.com.au (Stephen Spence)
Subject: AI Neural Network - predicting CPU load example
Message-Id: <b86da09d.0111012156.38f91061@posting.google.com>

Hi,

Email prefered

A little while ago I saw a posting of an example program
that looked at CPU usage using AI neural Network.

Could somebody point me to where I can find it OR
just email it to me - as I recall, it was not very big.

Cheers,
Stephen Spence
stephen.spence@workcoverqld.com.au


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

Date: Fri, 02 Nov 2001 15:25:52 +0800
From: hugo <hugo@fractalgraphics.com.au>
Subject: apostrophe character in text boxes and mysql
Message-Id: <3BE24A80.E52D869D@fractalgraphics.com.au>

Hi

(Apologies - I am reposting this as I didn't have a proper subject line
in the 
message I sent previously.) 

I have a perl file with text boxes that users can fill in. The contents
of the text boxes is stored in a mysql database. This all works fine,
except when someone puts a apostrophe ' character in a text box e.g.,
something like: 

Company's web site. 

When you have something with a ', all entries from all text boxes on the
perl page are emptied out of mysql, presumably because the ' character
messes with the INSERT statement and terminates it early. Note that the
contents of the text boxes are retrieved with perl's param function
using CGI.pm and stored in variables. Subsequently, these variables are
used  in the mysql INSERT statement when a call is made to the mysql
database. 

How can I have people include the ' character without it causing
problems for mysql? 

Any help will be greatly appreciated.      

Thanks

Hugo 





-- 
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics 
57 Havelock Street, West Perth 6005
Western Australia 6009
Tel: +618 9211 6000 Fax: +618 9226 1299
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au


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

Date: Fri, 02 Nov 2001 07:36:47 GMT
From: "oj" <nospam_ojngo@home.com>
Subject: Re: apostrophe character in text boxes and mysql
Message-Id: <j2sE7.6694$Tb.3671918@news1.sttln1.wa.home.com>

hugo,

you need to parse this at the client (perl) before passing into sql.  you
just need to double up the apos...

insert into sql values('This apple''s good.')

-oj


"hugo" <hugo@fractalgraphics.com.au> wrote in message
news:3BE24A80.E52D869D@fractalgraphics.com.au...
> Hi
>
> (Apologies - I am reposting this as I didn't have a proper subject line
> in the
> message I sent previously.)
>
> I have a perl file with text boxes that users can fill in. The contents
> of the text boxes is stored in a mysql database. This all works fine,
> except when someone puts a apostrophe ' character in a text box e.g.,
> something like:
>
> Company's web site.
>
> When you have something with a ', all entries from all text boxes on the
> perl page are emptied out of mysql, presumably because the ' character
> messes with the INSERT statement and terminates it early. Note that the
> contents of the text boxes are retrieved with perl's param function
> using CGI.pm and stored in variables. Subsequently, these variables are
> used  in the mysql INSERT statement when a call is made to the mysql
> database.
>
> How can I have people include the ' character without it causing
> problems for mysql?
>
> Any help will be greatly appreciated.
>
> Thanks
>
> Hugo
>
>
>
>
>
> --
> Dr Hugo Bouckaert
> R&D Support Engineer, Fractal Graphics
> 57 Havelock Street, West Perth 6005
> Western Australia 6009
> Tel: +618 9211 6000 Fax: +618 9226 1299
> Email:hugo@fractalgraphics.com.au
> Web: http://www.fractalgraphics.com.au




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

Date: Fri, 2 Nov 2001 10:42:29 +0100
From: "Christian Winter" <thepoet@nexgo.de>
Subject: Re: apostrophe character in text boxes and mysql
Message-Id: <9rtpld$1nc$1@newsread2.nexgo.de>

"oj" <nospam_ojngo@home.com> wrote:
> hugo,
>
> you need to parse this at the client (perl) before passing into sql.  you
> just need to double up the apos...
>
> insert into sql values('This apple''s good.')

hi,

or from perl he could use the DBI function quote()
(perldoc DBI).

Greetings
Christian




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

Date: Fri, 02 Nov 2001 01:38:54 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: apostrophe character in text boxes and mysql
Message-Id: <3BE269AE.CEC9D9A3@vpservices.com>

[upside-down posting rearranged]

oj wrote:
> 
> "hugo" <hugo@fractalgraphics.com.au> wrote in message
> news:3BE24A80.E52D869D@fractalgraphics.com.au...
> >
> > I have a perl file with text boxes that users can fill in. The contents
> > of the text boxes is stored in a mysql database. This all works fine,
> > except when someone puts a apostrophe ' character in a text box e.g.,
> > something like:
>
> you need to parse this at the client (perl) before passing into sql.  you
> just need to double up the apos...

Since you mention perl, I presume you are using DBI.  If so, ignore the
advice above.  Use DBI's built in quote() method, or even better, use
DBI placeholders.  Expecially since you are getting your data from a CGI
script, you should be using placeholders for both quote handling and
security.  See the DBI docs.  Here's an example with an embedded
apostrophe:

  my $sth = $dbh->prepare("INSERT INTO foo VALUES( ?, ? )");
  $sth->prepare( "Conan", "O'Brien" );

-- 
Jeff



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

Date: 1 Nov 2001 21:53:54 -0800
From: pkbapt2@go.com (Scott)
Subject: Can't call method "add_handler" error.
Message-Id: <27181847.0111012153.79d0efa1@posting.google.com>

Hello all.  I am fairly inexperienced with Perl, done some minor Web
projects and whatnot with it, but never tried anything too advanced. 
Lately, I've been exploring the AIM libraries in Net::AIM after
stumbling across this article:

A P2P AIM Robot in Perl
http://www.webreference.com/perl/tutorial/13/

which discusses the Net::AIM library and how to build a simple AIM
bot.  In any case, I downloaded the module and installed it
successfully, and can logon with the test program and send/receive
messages.

 Anywho, the article has a test script that contains the following
code snippet:


my $aim = new Net::AIM;

$aim->debug(1);
my $conn = $aim->newconn(Screenname   => 'aimhandle',   
                         Password     => 'password')
    or die "Can't connect to AIM server.\n";

$conn->add_handler('config',    \&on_config);
$conn->add_handler('im_in',    \&on_im);   
$conn->add_handler('error',    \&on_error);

# later on...
sub on_config {
    my ($self, $event) = @_; 
    my ($str) = $event->args;
    $self->set_config($str);
    $self->send_im($nick, 'testing...');
}


However, when I try to run it, I get the following error message:
Can't call method "add_handler" without a package or object reference
at ./aim_message.pl line 13

I've searched on the Web and on newsgroups for this error and got very
few results, none of which seemed like applicable answers to my
problems.  I also searched the Web for code for other AIM bots, but
had no luck there.  (If you know of any sites that have such code, I'd
be greatful if you could pass on the link...)

In any case, any hints on what this error message means or how to fix
it?  TIA!

  Scott Mitchell
  mitchell AT 4GuysFromRolla DOT com


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

Date: Fri, 2 Nov 2001 10:46:10 +0100
From: "Milan Jaksic" <milan@balkanmedia.com>
Subject: Email errors
Message-Id: <9rtpvg$cnl$1@news.eunet.yu>

Hi

I am trying to write script that could handle mail errors, and this is the
part of script that i thought it would work:
$Mail_send="/usr/lib/sendmail -t";
open (MAIL,"|$Mail_send");
    print MAIL "Content-type: text/html\n";
    print MAIL "From: $defaultmail\n";
    print MAIL "To: $in{mail}\n";
    print MAIL "Subject: $subjectext\n\n";
    print MAIL "$outmail";
    write MAIL;
close MAIL;

when I tried to see what hapens when i try to send mail to unknown user the
following hapens:
I get a message in browser that it could not send mail since the user is
unknown on domain, and it
writes mail to file dead letterl.

So my question is how to capture error while sending mail in my own file;

Thanks,

Milan




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

Date: Fri, 2 Nov 2001 09:56:53 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: Failed scripts leave Perl behind
Message-Id: <9rtqs1$i9r$1@pheidippides.axion.bt.co.uk>

I think it's Windows. I had a similar problem when writing CGI programs on
IIS, using visual C++ on NT4. If the program failed, the process was left
open, leaving lots of processes which could only be killed from task
manager.

Hope this helps (though I didn't find a solution).

Kevin Brownhill

"Ken" <perl@omnibus-systems.net> wrote in message
news:4d84ut4q79otmhtg2lmm1v8p34p93soek9@4ax.com...
> When my students write perl scripts and the script fails for whatever
> reason, the Perl interpretor is not shut down. The server is Windows
> 2000 with ActiveState Perl. It doesn't matter is we use .pl or .plx
> extensions (.pl use Perl and .plx goes thru dllhost). The only mention
> of this issue I found was in an apache news thread where the
> participants said only that it was necessary to reboot the server. I
> have found pskill from sysinternals able to stop Perl so I don't have
> to reboot.
>
> But I dont want to continuely monitor the server for orphan/zombie
> Perl processes (they hog resources and brings the server to a crawl).
> Any suggestions?
>
> TIA




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

Date: 2 Nov 2001 00:55:25 -0800
From: jjchen@alumni.ice.ntnu.edu.tw (wade)
Subject: HELP: how to turn off echo when connect to server(use POE)?
Message-Id: <4259465b.0111020055.21bb5874@posting.google.com>

Hello everyone, help me!
  I wrote a server use POE.
  I tried to "telnet" to my server, how to turn off "ECHO" when get PASSWORD!


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

Date: Fri, 02 Nov 2001 15:00:55 +0800
From: hugo <hugo@fractalgraphics.com.au>
Subject: hi 
Message-Id: <3BE244A7.1CB8DA4C@fractalgraphics.com.au>

Hi

I have a perl file with text boxes that users can fill in. The contents
of the text boxes is stored in a mysql database. This all works fine,
except when someone puts a apostrophe ' character in a text box e.g.,
something like: 

Company's web site. 

When you have something with a ', all entries from all text boxes on the
perl page are emptied out of mysql, presumably because the ' character
messes with the INSERT statement and terminates it early. Note that the
contents of the text boxes are retrieved with perl's param function
using CGI.pm and stored in variables. Subsequently, these variables are
used  in the mysql INSERT statement when a call is made to the mysql
database. 

How can I have people include the ' character without it causing
problems for mysql? 

Any help will be greatly appreciated.      

Thanks

Hugo 

-- 
Dr Hugo Bouckaert
R&D Support Engineer, Fractal Graphics 
57 Havelock Street, West Perth 6005
Western Australia 6009
Tel: +618 9211 6000 Fax: +618 9226 1299
Email:hugo@fractalgraphics.com.au
Web: http://www.fractalgraphics.com.au


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

Date: Fri, 2 Nov 2001 16:28:25 +0800
From: "Alex CTK" <tkcheung@vtc.edu.hk>
Subject: how to debug perl cgi at homepage
Message-Id: <9rtlke$rs0$1@dragon.vtc.edu.hk>

I am running a perl script at apache web server. I would like to know how to
make it run the debug for perl.

Thanks




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

Date: 2 Nov 2001 01:01:43 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Leftmost SHORTEST
Message-Id: <9rtgcn$f41$1@charity.cs.utexas.edu>

In article <7e13fafe.0111010918.620731f3@posting.google.com>,
Zilt <zilt@iname.com> wrote:
>but how do you work around SEQUENCES? E.g. C-stlye comments: /* */ or
>BEGIN .. END blocks in Pascal (assuming multi-line records)? As far as
>I know, there's no way to NOT match an expression in gawk, e.g.
>/BEGIN(^END)*END/ would not work.

That's because regular expressions aren't powerful enough to properly
match strings in those languages.  Any language that can contain
arbitrarily deep levels of matching items is too complicated to be a
member of the set of languages that regular expressions can match.

What you need if you want to match BEGIN / END pairs is a grammar for
your language, and a parser to use that grammar.  There is a recursive
descent parser module on CPAN; you might look at it if you really need
to do that.

  - Logan
-- 
"In order to be prepared to hope in what does not deceive,
 we must first lose hope in everything that deceives."

                                          Georges Bernanos


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

Date: Fri, 02 Nov 2001 10:39:45 GMT
From: "Robert Valcourt" <rvalcourt@telus.net>
Subject: Need help creating a small flatfile DB program
Message-Id: <RJuE7.11572$i4.1113559@news0.telusplanet.net>

Hey everyone,

I am very new to Perl. My boss has given me the task of creating a small
"time tracking" program using perl on the web out of a CGI-BIN. What I need
it a perl created page that has two text fields, a start and stop button, a
description field, and a submit button. Here is what it would do.

When I am given a job, this program would be used to track my labour hours.
I would go to this page and hit start. When my job is finished I would press
stop. The start and stop time would be shown in the two text fields. EG :

In the first text field : 08:00
In the second text field : 08:30 ( times just used as an example )

This of course would mean I hit the start button at 8AM and hit the stop
button at 8:30AM. The page would also have a "work description" textarea box
where I could describe the job performed. Once this info has been filled
out, I would hit submit and the data would be sent to a flatfile text based
database. I would like the flatfile database to hold multiple jobs. A
theoretical "week old" database would look like this:

08:00 - 08:30 - November 1 - Fixed broken link
09:22 - 09:58 - November 2 - Fixed broken link
08:05 - 10:47 - November 3 - Fixed broken link
04:00 - 05:33 - November 4 - Fixed broken link

This of course means that each time I use the time tracker, and submit the
info, the info is compiled in the database instead of overwriting old data.
Now I am familiar enough with Perl to be able to open and save data to
files. I am not, however, able to compile data without overwriting the old
data. I am also not able to create the timer code.

Can someone(s) please help me with this? some code examples or direction
would be most appreciated! And I would return the favour anytime!

TIA to all!

Rob




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

Date: Fri, 02 Nov 2001 06:06:48 GMT
From: Paul Johnson <aeropaul@sbcglobal.net>
Subject: Re: Newbie Hash Slice Question
Message-Id: <uud4utg8sd9odfrvsrt6r8lf88kggi4hnl@4ax.com>

On Fri, 02 Nov 2001 04:02:04 GMT, Uri Guttman <uri@stemsystems.com>
wrote:

>>>>>> "UG" == Uri Guttman <uri@stemsystems.com> writes:
>
>  UG> this might be a known typo. go to oreilly.com and look for that
>  UG> book. they have errata pages.
>
>	http://www.oreilly.com/catalog/lperlwin/errata/lperlwin.498
>
>that errata page covers this typo.
>
>it doesn't show a mixed { and ) so that must be your mistyping.

Actually, they didn't catch that until the NEXT edition. (c;

Paul

>
>uri



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

Date: Fri, 02 Nov 2001 06:08:49 GMT
From: Paul Johnson <aeropaul@sbcglobal.net>
Subject: Re: Newbie Hash Slice Question
Message-Id: <o0e4utk73t7lc1c6milgkst08s9gseof9t@4ax.com>

Thanks for all the responses.  It is nice to get such complete answers
to my questions.  Some time after I posted this question, it occured
to me that there might be an errata on the internet (as several people
suggested), and, indeed, there it was.

Thanks again!

Paul <-- now up to page 98  (c;


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

Date: Fri, 02 Nov 2001 07:39:42 GMT
From: vig@pop.jaring.my (v)
Subject: Newbie WebMail Question
Message-Id: <3be24daf.10321438@news.jaring.my>

Hi,
I'm thinking of offering a hotmail type service on my site. How do I
go about setting up such a service? Is there reliable scripts for such
a service?

I have scoured the web.. most of the available programs are
essentially email clients (I like to offer their own email address at
my domain eg username@mydomain.com ).

I feel I'm missing a big part of the puzzle here. Is there anywhere I
can learn more about this?


Thanx,
v


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

Date: Fri, 2 Nov 2001 01:26:36 -0600
From: "Peter Moore" <moorepete@telocity.com>
Subject: perl bots from Net::IRC 
Message-Id: <5WrE7.907$e6.599403@newsrump.sjc.telocity.net>

Ive been playing with the Net::IRC perll module which im making a bot from.
One of the things ive not been able to work out is how to get
$conn->who("#channel")  to work on it. My problem is that i need to respond
to the person with a "I dont understand" message if he is not on the
#channel. So  I need to fetch the names from the channel for this but im not
having any luck.

Anyone know what im talking about and know how to do it ?
thanks in advance

sinple to IRC connect,

use Net::IRC;
$irc = new Net::IRC;
$conn = $irc->newconn(Nick => "somenick", Server  => 'irc.server.com', Port
=>  6667 );

$conn->add_handler('msg', \&on_msg);
$conn->join("#test");
$irc->start;

sub on_msg {
    my ($self, $event) = @_;
    my ($nick) = $event->nick;

    print "*$nick*  ", ($event->args), "\n";
    $self->privmsg($nick, "hello $nick");
    print $self->who("#test");  # <<<<<<<<<<<<< doesn't work although it
prints a number
}






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

Date: Fri, 02 Nov 2001 05:11:13 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: reading flat-file db and replacing a word
Message-Id: <x7ady5wycd.fsf@home.sysarch.com>

>>>>> "s" == sameer  <s@yenga.com> writes:

  s> This should work:
  s> open(FILE1, "filename1");

you don't check the return of open.

  s> $file1 = <FILE1>;

and what about the rest of the lines in the file?

  s> $file1 =~ s/$word1/$word2/gi;

  s> open(FILE2, ">filename2");

again no check on open.

  s> print FILE2 $file1;
  s> close(FILE2);

  s> You can mess around with the search and replace to make it do exactly
  s> what you want and it might help to use arrays and a foreach loop
  s> depending on what kind of search and replace you're doing.

there is no such operator as search and replace in perl. it is
substitute. it does not do a search, but a regular expression match.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs  --------------------------  http://jobs.perl.org


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

Date: 2 Nov 2001 01:22:06 -0800
From: jjchen@alumni.ice.ntnu.edu.tw (wade)
Subject: Sorry, POE::Wheel::ReadWrite
Message-Id: <4259465b.0111020122.185774c6@posting.google.com>

sorry, how to turn off PROMPT when using
POE::Wheel::ReadWrite?
I want to turn off echo when getting password


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

Date: Fri, 2 Nov 2001 00:46:47 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: Taint problem with BEGIN block
Message-Id: <13336-3BE24157-184@storefull-247.iap.bryant.webtv.net>

Wyzell wrote:
> $f is sourced from outside your program
> so is potentially tainted. 
> Pass $f through a regex before you
> use it and ensure that you capture
> only what you would expect to be 
> valid. That is how to 'untaint' the data. 
> $cleanf = $1 if $f =~ m/(a valid pattern here)/; 
> # where 'a valid pattern here' is replaced
> by what are allowable characters 
> rmdir $cleanf; 
> Wyzelli

Thanks a bunch! I thought that might be the problem, but I had tried a
regex for $f, and it didn't work. It looks like you have to change $f to
a new scalar name. If so, that's what I missed. 

I'm still not sure if I got the regex's to untaint my variables correct
or not. The way I understand it, is that a variable isn't really
untainted unless the regex pattern is done correctly to make it secure. 

Furthermore, since I just want directories that consist of 4 digit names
under "wkdir", I used /(\d{4})/ for my $cleanf regex. I also had to use
the unix "rm -r" to remove directories that were not empty.  

Here's my corrected version below that works. My apologies for the bad
word wrap.


BEGIN {
  $ENV{PATH} = "/usr/bin:/bin:/usr/local/bin";

  $dir = "wkdir";
  $dir =~ /^([-\@\w]+)$/; 
  $dir = $1;

  opendir(DIR, $dir) || die "can't opendir $dir: $!";
  my @files = grep { /(\d{4})/ && -d "$dir/$_" } readdir(DIR);
  closedir DIR;

  my $age = time() - 1*3600;  
  foreach my $f (@files) { 

  if ( -d $f ) {
  my $stats = stat($f);  
  if ($stats->mtime < $age) { 
     } 
  } 

$cleanf = $1 if $f =~ m/(\d{4})$/;  
system("rm", "-r", "wkdir/$cleanf")
     } 
  1;
}


Regards,
--Dennis



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

Date: 02 Nov 2001 08:36:16 GMT
From: vek@pharmnl.ohout.pharmapartners.nl (Villy Kruse)
Subject: Re: Unsigned 8 bit math (addition and subtraction)
Message-Id: <slrn9u4mnv.rh1.vek@pharmnl.ohout.pharmapartners.nl>

On 1 Nov 2001 22:41:31 GMT,
    Ilmari Karonen <iltzu@sci.invalid> wrote:


>
>Actually, what perl does is rely on the integer modulus operator of the
>C compiler it was built with.  This means that, in current versions of
>perl, modulus is only consistently defined across different platforms
>for small non-negative integers (where "small" means "less than 2**31").
>
>



Depending on if you "use integer": (that is what my "perlop" says also)


perl -Minteger -e ' print -20 % 7, "\n";'
-6
perl -e ' print -20 % 7, "\n";'
1


Your C library on your system might do the % operation the same way
as perl does when working on floating point numbers, so in that case
you won't see any difference.
  Also, the % operation in C is often computing the reminder rather than
the modulus, and the value of the reminder depends on how you choose to
truncate the result after a division.  If you truncate towards zero as
in -2.857 => -2 then the reminder becomes negative as it must satisfy


q = a / b
r = a % b

q * b + r == a


Villy


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

Date: 02 Nov 2001 10:16:30 +0000
From: nobull@mail.com
Subject: Re: variable number of socket descriptors
Message-Id: <u9wv197a0x.fsf@wcl-l.bham.ac.uk>

"Swanthog" <lhswartw@ichips.intel.com> writes:

> I need to be able to use a variable number of socket descriptors in a module
> I wrote that creates a socket connection. For example(doesn't work):
> %socks;
> $sock_n = 0;
> ...
> socket( $socks{ $sock_n}->{ sock}, AF_INET, SOCK_STREAM, $proto) or die;

Should work fine in 5.6.x so long as $socks{$sock_n}{sock} is not
already defined.  BTW why is %socks a hash not an array?

> Know a way to do this?

The neat looking (but somewhat slower) solution is the IO::Socket
module.

If you want to avoid the IO:: module interface and also do not want to
upgrade to 5.6.x then prefix the socket() call with:

use Symbol;
$socks{$sock_n}{sock} = gensym;

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


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 2053
***************************************


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