[7713] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1339 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 18 17:17:25 1997

Date: Tue, 18 Nov 97 14:00:26 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 18 Nov 1997     Volume: 8 Number: 1339

Today's topics:
     Re: adding to the end of each element in an array (Charles DeRykus)
     Re: An elegant solution wanted for removing .. in path <cboget@apdi.net>
     Re: An elegant solution wanted for removing .. in path (Tad McClellan)
     Atomic operations (was Re: exclusive file rights) <camerond@mail.uca.edu>
     AutoLoader and sub AUTOLOAD (Tom Harrington)
     Re: Better Way in Perl (brian d foy)
     Re: Chomp vs Chop <markm@nortel.ca>
     Re: Chomp vs Chop (Bart Lateur)
     Re: control characters (brian d foy)
     Re: Debugging CGI programs <stevenjm@olywa.net>
     Extracting key-value pairs from HTML FORM text <chris@ixlabs.com>
     Re: HELP - Perl CGI script stops working after SQL quer (Jared Evans)
     how to invoke sendmail for mailing list? (Kevin Kelleher)
     max size of cookie? (kim slack)
     Re: max size of cookie? (brian d foy)
     Re: modules, ignoring Tom Phoenix <rra@stanford.edu>
     MSQL's message: Can't connect to local MSQL server at / clarkp@atlanta.com
     Re: Multihomedness and Socket::inet_aton() <jay@rgrs.com>
     Multiple item pricing <alertall@epix.net>
     Q: How many elements in a %HASH ? <hollosi@sbcm.com>
     Re: Q: How many elements in a %HASH ? (Matthew Cravit)
     Re: Q: How many elements in a %HASH ? (Jim Allenspach)
     Re: Q: How many elements in a %HASH ? (Jim Allenspach)
     Re: Q: How many elements in a %HASH ? (Mike Stok)
     Re: Why no case statement in Perl? (John Moreno)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 18 Nov 1997 20:31:49 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: adding to the end of each element in an array
Message-Id: <EJuzp1.F1r@bcstec.ca.boeing.com>

In article <3471ec64.39161497@news.ais.net>, Steve <syarbrou@ais.net> wrote:
 > I have searched far and wide and can not find the answer to this.
 > 
 > I know chomp can take a character or group of characters off each
 > element in an array.  Is there something that can do the opposite?  In
 > otherwords if I have an array, and want to add \n to the end of each
 > element, is there a single command like chomp to do this?  I know a
 > simple foreach would do it, but what's the point.  This is
 > perl(shorter the better).
 > 


Here're some ways:


@new_array = map { "$_\n" } @array;  # create new unchomped array 
@array = map { "$_\n" } @array;      # unchomp same array 

or, maybe:

foreach (@array) { push @new_array, "$_\n" }    # new 
foreach (@array) { $_ .= "\n" }                 # same 


HTH,
--
Charles DeRykus


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

Date: Tue, 18 Nov 1997 15:18:37 -0500
From: "Sorrow" <cboget@apdi.net>
Subject: Re: An elegant solution wanted for removing .. in path
Message-Id: <64stb3$7i2$1@news2.cais.com>

> s#/+#/#g; $_ = "/$_/";       #"sentinels"
> 1 while s#/[^/]+/\.\./#/#;
> chop($_ = substr($_,1));     #or something like that


Please forgive me for asking (I'm a newbie),
but what does the above do?  I do not understand.

Thanx for your help.

Chris



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

Date: Tue, 18 Nov 1997 15:34:32 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: An elegant solution wanted for removing .. in path
Message-Id: <8l1t46.qd3.ln@localhost>

Sorrow (cboget@apdi.net) wrote:
: > s#/+#/#g; $_ = "/$_/";       #"sentinels"
: > 1 while s#/[^/]+/\.\./#/#;
: > chop($_ = substr($_,1));     #or something like that


: Please forgive me for asking (I'm a newbie),
: but what does the above do?  I do not understand.


1 while s#/       # match a slash
          [^/]+   # match as many non-slash chars as possible
          /       # match a slash
          \.\.    # match two dots (need to escape them to get literal dots)
          /       # match a slash
         #/#x;    # replace all of that with a slash (x lets me put these
                  #                                   comments here)


: Thanx for your help.

You're welcome.


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Tue, 18 Nov 1997 13:54:23 -0600
From: Cameron Dorey <camerond@mail.uca.edu>
Subject: Atomic operations (was Re: exclusive file rights)
Message-Id: <3471F26F.3FA2E435@mail.uca.edu>

James Richardson wrote:
> 
> [snip]
> The test for the file, and the subsequent creation of the file
> is not an
> atomic action. This is undergrad 1st year stuff...
[detailed 1st yr undergrad stuff snipped]

James, thank you (and Jeremy, thank you for your email explaining atomic
processes), now, how would I know what processes on a Win95 machine are
atomic, i.e., where would I look, not so much gimmee the answer (but if
you want to tell me, who am I to argue)?

Cameron Dorey
camerond@mail.uca.edu


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

Date: 18 Nov 1997 20:56:12 GMT
From: tph@longhorn.uucp (Tom Harrington)
Subject: AutoLoader and sub AUTOLOAD
Message-Id: <64svdc$b5e4@eccws1.dearborn.ford.com>

I have a module that I'd like to split up so that I could use AutoLoader.
This module contains a sub AUTOLOAD.  If I split it up with AutoSplit,
I get messages like the following when I attempt to use the module:

Undefined subroutine &SynperlCore::AUTOLOAD called at SynperlCore.pm line 41.

If I remove sub AUTOLOAD from the module, however, it works fine.
Except that non-defined subroutines don't get auto-loaded any more,
of course.  So I'm reasonably sure that I have the module set up
properly for AutoLoader, with the exception of the AUTOLOAD sub.

The Camel book says "...if you have your own AUTOLOAD and are using
the AutoLoader too, you probably know what you're doing."  If only
that were true!  Can I combine these?

--
Tom Harrington --------- tph@rmii.com -------- http://rainbow.rmii.com/~tph
  Why would anyone buy a book with "...for Dummies" in the title?  Isn't
                 that a rather severe form of self-insult?
Cookie's Revenge: ftp://ftp.rmi.net/pub2/tph/cookie/cookies-revenge.sit.hqx


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

Date: Tue, 18 Nov 1997 14:21:56 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Better Way in Perl
Message-Id: <comdog-ya02408000R1811971421560001@news.panix.com>

In article <34712D8F.7E7@coos.dartmouth.edu>, rjk@coos.dartmouth.edu wrote:

>brian d foy wrote:
>> 
>> In article <34639803.A2960A9F@ei.kodak.com>, Walker Curtis <curtis@ei.kodak.com> wrote:


>> >perl -e 'for(<*>){`mv $_ $\``if/\.cin$/}'
>> 
>> >Does someone know of a short way, white space counts.

>> % a
>> 
>> if you can use sed or perl, i can write a program called "a" to do it.
>> one letter from the command line. :)
>
>Next time read the *whole* message:

i did.  perhaps you just missed the point of my response.  think on it
a bit in the context of some of the other responses and perhaps you'll
understand it.  

>> There are also no aliases, custom programs, etc... being used.
>
>And you thought you were so clever!

well, the original poster chuckled (he understood the point that you
missed).

you're going to have to get up a lot earlier if you want to post a good
flame.

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 18 Nov 1997 15:38:56 -0500
From: Mark Mielke <markm@nortel.ca>
Subject: Re: Chomp vs Chop
Message-Id: <lq1k9e6544f.fsf@bmers2e5.nortel.ca>

Matt Pezzuto <mpezzuto@link.com> writes:
> "When using Chop, it is almost always used to remove an eol character. 
> The typical reason would be to remove eol's from the following sample 
> of data:
> 
> @dirlist=`ls -1`;
> foreach (@dirlist)
> {
>   chop;
> }

uhh why not:  chomp(@dirlist=`ls`);
but i'd use DirHandle or something anywayz...

> ls -1 forces the ls output into a single column of data (which is the
> default for outputting data to non-STDIO outputs).  Perl also breaks the
> list into different array entries on the eol.  So, if there isn't an
> eol, then we can't have an array.  If no array, ls is really broken 
> (but this is a simplistic example).  So, since we know an eol must be
> the delimiter between entries, why can't I just non-discriminantly chop
> off the last character?"

I guess the answer is that you can to whatever you want :-)
You can ALSO choose to use `ls` and spawn a second shell instead of doing
it quite efficiently write their in your perl script. And you could also:

   open(F, "abc.txt");

And not check return codes... and use global symbols for filehandles...
and you could never my() your variables... you could never use object
oriented programming for anything... you could leave out parens where
it might have been clearer to save bytes in your file... heck you could
leave out comments even! :-) I mean like... YOU know what your talking
about right? so why comment it? :-)

mark

--                                                  _________________________
 .  .  _  ._  . .   .__    .  . ._. .__ .   . . .__  | Northern Telecom Ltd. |
|\/| |_| |_| |/    |_     |\/|  |  |_  |   |/  |_   | Box 3511, Station 'C' |
|  | | | | \ | \   |__ .  |  | .|. |__ |__ | \ |__  | Ottawa, ON    K1Y 4H7 |
  markm@nortel.ca  /  al278@freenet.carleton.ca     |_______________________|


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

Date: Tue, 18 Nov 1997 22:03:14 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Chomp vs Chop
Message-Id: <3472103c.38865204@news.tornado.be>

Matt Pezzuto <mpezzuto@link.com> wrote:

>So, since we know an eol must be
>the delimiter between entries, why can't I just non-discriminantly chop
>off the last character?"

You're right, for every but the very last line. This line needn't end on
a EOL, so, on this line only, you could chop off too much.

	Bart.


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

Date: Tue, 18 Nov 1997 14:25:24 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: control characters
Message-Id: <comdog-ya02408000R1811971425240001@news.panix.com>

In article <slrn6735st.a6d.gabor@vinyl.quickweb.com>, gabor@vinyl.quickweb.com (Gabor) wrote:

>In article <comdog-ya02408000R1711972342550001@news.panix.com>, brian
>d foy wrote:

>>In article <Pine.OSF.3.95q.971117214552.25328A-100000@osf1.gmu.edu>,
>>smantri@gmu.edu wrote:

>>>Can anyone tell me how to remove any control character??????????

>>how about just using their octal values?
>>   tr/\000-\037//;

>tr/\000-\037//d;
>              ^ need the 'd' to actually delete the found chars
>of course this will also remove newlines and tabs. 

ah yes.  thank you for the proofreading :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 18 Nov 1997 12:46:06 -0800
From: Steven May <stevenjm@olywa.net>
Subject: Re: Debugging CGI programs
Message-Id: <3471FE8E.8A282428@olywa.net>

Bart Lateur wrote:

> "Joseph N. Hall" <joseph@5sigma.com> wrote:
>
> >Get the CGI module (that's what it's called, and it's part of
> >the 5.004 distribution) and learn to run your program from the
> command
> >line.  Also you might want to check out Lincoln's book.
>
> "Lincoln's book"? I haven't heard of this one before. What's the
> title,
> what's it about, and... how good is it?
>

Possibly 'How to Set Up and Maintain a Web Site', by Lincoln D. Stein.
The title is self-explanatory, yes?

I have the second edition, printed December 1996, published by
Addison-Wesley.

And yes, it is an excellent book.  It was not in stock, but Barnes and
Noble ordered it for me about 4 months ago.

Highly recommended, as is a visit to Lincoln's site at

 http://www-genome.wi.mit.edu/~lstein/

Enjoy!

Steve





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

Date: Tue, 18 Nov 1997 13:46:46 -0800
From: Chris Schoenfeld <chris@ixlabs.com>
Subject: Extracting key-value pairs from HTML FORM text
Message-Id: <34720CC6.6BFA@ixlabs.com>

I retreive an HTML document containing a FORM using LWP.

Now I want to access the key-value pairs of the FORM elements without
doing the regexp's myself, out of both laziness and a desire that the
parser be very robust and heavily tested (quotes/noquotes, names w/o
values, multi-line tags, etc.etc.).

I have looked over the LWP/HTML module docs, but I can't seem to find
this ability - does it exist?

Thanks
Chris


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

Date: 18 Nov 1997 19:03:21 GMT
From: jared@node6.cwnet.frontiernet.net (Jared Evans)
Subject: Re: HELP - Perl CGI script stops working after SQL query
Message-Id: <64sopp$22f4$1@node6.cwnet.frontiernet.net>


Make sure you have permissions set correctly and you are printing out
Content-type: html/text\n\n   before you are printing out any HTML code to
STDOUT.

---------

In article <3471B2EF.F4409A76@shurflo.com>,
Thomas Beardshear  <u2537@shurflo.com> wrote:
>I'm trying to write a few simple programs to access data through our
>intranet. The script works fine from the bash shell but does not print
>anything after the query statement when run on a browser. Anyone have
>any ideas?
>
>Here is the code:
>===================================
>#!/usr/bin/perl
># Perl Script
># 11/18/97
># tjb
>
>require "cgi-lib.pl";
>use Mysql;
>
>&PrintHeader;
>
>$dbh = Mysql->connect("bunny","mysql");
>print "\n\nTHIS PRINTS OK\n\n";
>$sth = $dbh->query("select user from user;");
>
>print "THIS DOES NOT PRINT\n";
>
>@list = $dbh->listtables;
>
>print "\n";
>print $list[1],"\n";
>print $list[2],"\n";
>print $list[3],"\n";
>print "\n";
>===================================
>The last 6 lines do not print when the script is run by the browser.
>i.e. The last 6 perl print statements' output is NOT sent to the
>browser.


-- 
open(G,"|gzip -dc");$_=<<EOF;s/[0-9a-f]+/print G pack("H*",$&)/eg
1f8b080853ed5434000b7465737400e3e5f24a2c4a4d51702d4bcc2bd655e0e55250f02a2d2e0133141412f3f24b32528ba03c058580d4a21c384741212331393bb5488f978b970b000e2b3b4448000000
EOF


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

Date: Tue, 18 Nov 1997 14:53:08 GMT
From: kevink@NOSPAM-mit.edu (Kevin Kelleher)
Subject: how to invoke sendmail for mailing list?
Message-Id: <3471aa3e.93088312@news.mit.edu>


Premise: I can't create mail aliases on my ISP, yet I want to
run a group of email discussion lists.

So, I wrote a small knockoff of majordomo that works pretty
well, but it takes a long time (minutes) to send all the
mail.

At first I was looping on the list of subscribers and
doing this:

  system ("/usr/lib/sendmail $subscriber < $letter");

but when I saw how slow it was I moved the loop into
a shell script:

  #/bin/sh
  letter=$1
  for i in `grep command that gets subscribers`
  do
    /usr/lib/sendmail $i < $letter
  done

which I invoke from the perl script, but it doesn't
look any faster.  The reason I did this was because
I figured the slowness was due to system's having to
fork a process each time and wait for it to die,
but now I think it's just that sendmail is so slow.

Can anyone suggest a quicker/better way?

Kevin Kelleher
kevink@mit . edu  (address altered to avoid spam)



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

Date: 18 Nov 97 14:34:33 GMT
From: kas5670@vaxb.isc.rit.edu (kim slack)
Subject: max size of cookie?
Message-Id: <3471a779.0@isc-newsserver.isc.rit.edu>

How much data can you fit in a cookie?  Geoff


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

Date: Tue, 18 Nov 1997 16:33:35 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: max size of cookie?
Message-Id: <comdog-ya02408000R1811971633350001@news.panix.com>

In article <3471a779.0@isc-newsserver.isc.rit.edu>, kas5670@vaxb.isc.rit.edu wrote:

>How much data can you fit in a cookie?  Geoff

perhaps you might like to read the cookie references in the CGI Meta
FAQ. :)

not really a perl question... followups set

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 18 Nov 1997 10:42:29 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: modules, ignoring Tom Phoenix
Message-Id: <m3n2j2gi22.fsf@windlord.Stanford.EDU>

Darwin O V Alonso <dalonso@u.washington.edu> writes:

> I haven't tried out the marriage of C and perl yet, however I see
> infinite possibilities and feel that my life is irrevocably changed.

*grin*  This is not an uncommon reaction to XS.

> But, speaking of unholy alliances, will XS to allow perl to access a
> fortran function?

Yup.  (Although I haven't done it myself and you may potentially have to
go through C linkage; I'm not sure.  But in general, XS will let you talk
to anything that C can talk to provided that you can make it into a
dynamically loadable library.)

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Tue, 18 Nov 1997 14:01:38 -0600
From: clarkp@atlanta.com
Subject: MSQL's message: Can't connect to local MSQL server at /usr/lib/perl5/site_perl/Msql.pm line 75.
Message-Id: <879882705.15820@dejanews.com>

Hi

I am getting an error while running a perl program that is trying to
connect to the msql server.  I am running this program from the command
line. I get this error whether I run this program as root or as another
user.
*************************************************************************
*** ** ERROR FROM PROGRAM:

MSQL's message: Can't connect to local MSQL server at
/usr/lib/perl5/site_perl/Msql.pm line 75.
--
--
LINE IN Msql.pm

return &$meth(@_);   LINE 75

PROGRAM:
#!/usr/bin/perl -w

print "Content-type:  text/html \n\n";

use Msql;
$buffer=9999;
print "\$buffer is $buffer\n";
#read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$buffer);
foreach $pair (@pairs)
{
  ($name, $value) = split(/=/,$pair);
  $value =~ tr/+/ /;
  $value =~ s/%([a-fA-F0-9] [a=fA-F0-9])/pack("C",hex($1))/eg;
  $form{$name} = $value;
}

$dbh = Msql->connect;

print <<"HTML"; <HTML> <HEAD><TITLE>Cust num</TITLE></HEAD> <P> The
customer nnum is <B>$form{'cust_num'}</B><BR> </BODY> </HTML> HTML exit;
*************************************************************************
*** ** NOTES:	  -msql2d is running as a background process(as root)	 
 and when starting up msql2d there are no error messages	-I do not
have a problem connecting to the msql sever when using	       lite and
its functions.. msqlConnect()

	-I also do not have a problem doing the below at the command line:
		#msql cesdb
		#mSQL> issue DML\g

	-Both Perl and Msql were downloaded from RedHat

	-@INC shows /usr/lib/perl5/site_perl.. where Msql.pm is

	-/usr/local/Hughes is where msql and the like is installed
msql.conf:

[general]

Inst_Dir = /usr/local/Hughes
mSQL_User = root
Admin_User = root
Pid_File = %I/msql2d.pid
TCP_Port = 1114
UNIX_Port = %I/msql2.sock

[system]

msync_timer = 30
-----
-----
msql.acl:

database=test
read=bambi,-root
write=root
host=*
access=local,remote
option=rfc931

database=minerva
read=*
write=minerva
access=local

database=cesdb read=* write=* access=local
*************************************************************************
*** ** SOFTWARE VERSIONS:	    perl    ->5.004		   
apache	->1.1.1 		linux	->4.0, kernal 2.0.18 on i486 --
--		msql  ->SEE BELOW: Version Details :-

	msqladmin version 	2.0 Beta 7
	mSQL server version 	2.0 Beta 7
	mSQL protocol version 	22
	mSQL connection 	Localhost via UNIX socket
	Target platform 	Linux-2.0.27-i686
Configuration Details :-

	Default config file	/usr/local/Hughes/msql.conf	TCP
socket	    1114    UNIX socket     /usr/local/Hughes/msql2.sock    mSQL
user	   root    Admin user	   root    Install directory	  
/usr/local/Hughes	PID file location      
/usr/local/Hughes/msql2d.pid -- --		msql.pm  ->$VERSION =
$VERSION = "1.17";		  hostname  -> localhost	 
database name  -> cesdb(It has been created)
*************************************************************************
*** **** QUESTIONS:	  (1) What is wrong with: $dbh = Msql->connect;  
		-I took it right from the Msql.pm module	       
(2) Do I have the correct version of Msql.pm to work		  with
the version of msql?			 -I can connect to the server and
then the cesdb				from the command line OR from a
lite program..				I used the www_setup that came
with the msql code			 and it connects creates a
bookmarks db and uses			      the msqlconnect() function

		(2) What UNIX socket should I be using?
			-msql2.sock is created and permissions are rwx for
		         owner(root), group, and other BUT the file is empty

		(3) Do I need to create the /dev/msql socket?  OR will the
		    above in #2 suffice?

		(4) Are Msql.pm and the other modules that came with it in
the
		    correct directory?
			/usr/lib/perl5/pod/site_perl
		(5) Do I have the correct version of Msql.pm?
		(6) Do I need to create the test and minerva databases?
			-I downloaded perl AND msql.pm AND msql 2.0 BETA 7
			 from redhat softare and it comes in a rpm package
			 so maybe I need a different setup
		(7) What is this msql.t file?
			-In doing a find / -name msql.t -print.. shows
			 I do not have this file



Any help would be very much appreciated.  I hope I have included as much
information as possible.  Thank you and have a good day.

Pam Polk.. in Atlanta GA USA

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 18 Nov 1997 15:41:04 -0500
From: Jay Rogers <jay@rgrs.com>
To: "Philip A. Prindeville" <philipp@enteka.com>
Subject: Re: Multihomedness and Socket::inet_aton()
Message-Id: <82wwi6vstb.fsf@shell2.shore.net>

"Philip A. Prindeville" <philipp@delete-this.enteka.com> writes:

> I was just wondering why the inet_aton() call doesn't return an
> array of 4 byte packed strings instead of a single value, when a
> host is multihomed.

That's kind of a neat idea, but I'm afraid the cat is already out of
the bag in terms of the interface - so as to speak :-)

> We are using perl scripts to monitor some
> routers here, and when we can't connect to one address we would
> like to be able to connect to others... (since the interface
> corresponding to the first address we try might be down).
> 
> Since a typical usage is:
> 
>         $x = inet_ntoa(...)
> 
> returning an array should not break things, as the first element in
> the list will go into $x, as before.

So in a scalar context inet_aton() would return only one value and in
an array context it could potentially return multiple values if
multihomed?

The problem is that there's bound to be existing code where
inet_aton() is used in a list context.  That code would probably
break. 

> I'm using Net::Telnet 3.00 and I would be willing to make the
> necessary mods to support multihomedness.

Here's one way to do it:

    use Socket qw(inet_ntoa);
    use Net::Telnet ();
    $telnet = new Net::Telnet;
    
    ## Get IP addrs in "d.d.d.d" string notation.
    ($name, $aliases, $type, $len, @addrs) = gethostbyname $hostname
        or die $!;
    @addrs = map { inet_ntoa($_) } @addrs;
    
    ## Try to connect to one of the IP addrs.
    $telnet->errmode("return");
    for $addr (@addrs) {
        last if $telnet->open(Host => $addr,
                              Timeout => 5);
    }
    
    die "problem connecting to $hostname"
        if $telnet->eof;

--
Jay Rogers
jay@rgrs.com


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

Date: Tue, 18 Nov 1997 13:22:55 -0600
From: Curt Berstler <alertall@epix.net>
Subject: Multiple item pricing
Message-Id: <879869332.32417@dejanews.com>

I am trying to implement multiple price breaks per item in PerlShop.  I
was able to change my page to reflect a price table and allow customers
to manually enter the unit price based on the qty break.  When the
customer adds the item to the shopping cart, an error message is
displayed.

Can anyone give me help on the possible causes and solutions to this
problem.

Thanks

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Tue, 18 Nov 1997 19:11:54 GMT
From: Jozsef Hollosi <hollosi@sbcm.com>
Subject: Q: How many elements in a %HASH ?
Message-Id: <EJuvzw.69u@nonexistent.com>

Hi,

is there a simple way to tell how many elements a hash holds?
I know I can do

@TEST = %TEST; $n = ($#TEST+1)/2;

but that generates a whole new @TEST array, which takes too much
time and memory for large hashes.

I can also cycle through the hash using the "each" iterator, but
that is even slower (although doesn't waste memory).

Any better tricks?

Thanks,
Jozsef
hollosi@sbcm.com


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

Date: 18 Nov 1997 11:45:02 -0800
From: mcravit@best.com (Matthew Cravit)
Subject: Re: Q: How many elements in a %HASH ?
Message-Id: <64sr7u$r2g$1@shell3.ba.best.com>

In article <EJuvzw.69u@nonexistent.com>,
Jozsef Hollosi  <hollosi@sbcm.com> wrote:
>Hi,
>
>is there a simple way to tell how many elements a hash holds?

I don't know if this is any better than any of the other solutions you've
suggested, but it does work:

    %foo = ( a => 1, b => 1, c => 1 );
    
    print "Number of keys in hash is: ", do { map {$i++} (keys %foo); $i; };
    print "\n";

As an aside, does anyone know if there are memory or performance issues
associated with the use of "do" in a context like this? Is this a bad idea
for any other reason I haven't thought of?

/MC

-- 
Matthew Cravit, N9VWG               | Experience is what allows you to
E-mail: mcravit@best.com (home)     | recognize a mistake the second
        mcravit@taos.com (work)     | time you make it.


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

Date: 18 Nov 1997 14:51:46 -0600
From: jima@REMOVE.ME.mcs.com (Jim Allenspach)
Subject: Re: Q: How many elements in a %HASH ?
Message-Id: <64sv52$e8e$1@Mercury.mcs.net>

Jozsef Hollosi <hollosi@sbcm.com> writes:

>Hi,

>is there a simple way to tell how many elements a hash holds?
>I know I can do

>@TEST = %TEST; $n = ($#TEST+1)/2;

>but that generates a whole new @TEST array, which takes too much
>time and memory for large hashes.

>I can also cycle through the hash using the "each" iterator, but
>that is even slower (although doesn't waste memory).

>Any better tricks?

>Thanks,
>Jozsef
>hollosi@sbcm.com

--
#!/usr/bin/perl -- jim allenspach (jima at mcs dot com)
print join(' ',map{$_ if!s/(.+)-(.*)ay(.*)/$2$1$3/||s/^([a-z])([A-Z])
/\u$1\l$2/x||1}split(/ /,"Ust-jay another-ay Erl-pay acker-hay,\n"));


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

Date: 18 Nov 1997 14:58:46 -0600
From: jima@mcs.com (Jim Allenspach)
Subject: Re: Q: How many elements in a %HASH ?
Message-Id: <64svi6$eke$1@Mercury.mcs.net>

[ Argh. Sorry for the previous post. Technology screws me again! ]


>is there a simple way to tell how many elements a hash holds?

	This and many other questions are answered in the Perl FAQ (a nice
place to visit):

	http://language.perl.com/CPAN/doc/FAQs/FAQ/PerlFAQ.html

Have a look under the section labelled "Data: Hashes (Associative Arrays)".
HTH...

jma

--
#!/usr/bin/perl -- jim allenspach (jima at mcs dot com)
print join(' ',map{$_ if!s/(.+)-(.*)ay(.*)/$2$1$3/||s/^([a-z])([A-Z])
/\u$1\l$2/x||1}split(/ /,"Ust-jay another-ay Erl-pay acker-hay,\n"));


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

Date: 18 Nov 1997 21:05:56 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Q: How many elements in a %HASH ?
Message-Id: <64svvk$lge@news-central.tiac.net>

In article <EJuvzw.69u@nonexistent.com>,
Jozsef Hollosi  <hollosi@sbcm.com> wrote:

>is there a simple way to tell how many elements a hash holds?

If you're using a modern perl then

  $numberOfKeys = keys %hash;

should do the trick.   According to the perlfunc documentation:


       keys HASH
               Returns a normal array consisting of all the keys
               of the named hash.  (In a scalar context, returns
               the number of keys.)  The keys are returned in an
               apparently random order, but it is the same order
               as either the values() or each() function produces
               (given that the hash has not been modified).  As a
               side effect, it resets HASH's iterator.


Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Tue, 18 Nov 1997 14:19:49 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: Why no case statement in Perl?
Message-Id: <1czwug5.18nx4zvfwsktiN@roxboro-176.interpath.net>

Jaime Metcher <metcher@no.junk.mail> wrote:

] Phil R Lawrence wrote:
] > 
] > > I often use the case statement in other languages.  Anyone know
] > > the reason there is none in Perl?  It seems odd to be limited to
] > > If-elsif-else statements.

The reason why is covered in the manual - look in perl syntax.

One way of doing case statements is by using associative arrays and
eval, like so:

%case=(1,
'print "Case ";
print "$_\\n";',
2,
'print "Case ";
print "2\\n";'
);


for (1..2) {
eval $case{$_};
}

which is equivalent to this pascal case:

for i:=1 to 2 do
1: begin 
    write "Case ";
    write "i";
   end;
2: begin
    write "Case ";
    write "2";
   end;
end;

-- 
John Moreno


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1339
**************************************

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