[20016] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2211 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 26 18:06:06 2001

Date: Mon, 26 Nov 2001 15:05:10 -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: <1006815910-v10-i2211@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 26 Nov 2001     Volume: 10 Number: 2211

Today's topics:
    Re: "can't coerce array into hash" problem.... <joe+usenet@sunstarsys.com>
        2D Array from Text File <paul_wasilkoff@ucg.org>
    Re: 2D Array from Text File <rsherman@ce.gatech.edu.SPAMBLOCK>
    Re: 2D Array from Text File <Laocoon@eudoramail.com>
        [resource] perl script <oddjob10@lycos.com>
    Re: A Perl Bug? <jake@chaogic.com>
    Re: A Perl Bug? <bart.lateur@pandora.be>
    Re: call-by-reference, no newbie question (Malcolm Dew-Jones)
    Re: Can I avoid 2 passes? (Daniel Berger)
    Re: documentation for functions in c <mgjv@tradingpost.com.au>
    Re: documentation for functions in c (Malcolm Dew-Jones)
    Re: ISO Country Code Lookup (Mike Norton)
    Re: ISO Country Code Lookup <tintin@snowy.calculus>
        OT:Need new ISP <rickryan@datrixnet.com>
    Re: OT:Need new ISP <zak@mighty.co.za>
    Re: Perl and Windows 2000 Service. <bubba_1947@lycos.com>
        Perl CGI scripts with read access contain passwords to  (Owain McGuire)
    Re: Perl CGI scripts with read access contain passwords <spam@thecouch.homeip.net>
        random pages... (galaxy motion)
    Re: random pages... <jurgenex@hotmail.com>
    Re: random pages... <paul_wasilkoff@ucg.org>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 26 Nov 2001 16:51:14 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: "can't coerce array into hash" problem....
Message-Id: <m3itbx5hgt.fsf@mumonkan.sunstarsys.com>

"Martin" <no.th@ank.you> writes:

> %t=undef;
  ^^^^^^^^

"Odd number of elements in hash assignment ..."
That's not likely to be the cause of your problem, though.

> 
> $one[$i] = ...."code to populate @one";
> $two[$i]= ...."code to populate @two";
> 
> while..... { blah
>     $t{$one[$i]}{$two[$i]}++;
> }

It might help if you actually investigated all those blahs and
dots; that's likely to be where the error is.  See if you can produce 
a small code segment that exhibits the problem you describe.

> foreach my $key1 (sort keys %t) {
> 
>     foreach my $key2 (sort keys %{$t{$key1}}) {
>         print FILE "$key1,$key2,$t{$key1}{$key2}\n";
>     }
> }

What you've written here seems just fine; assuming $t{$key1} is 
really a hashref in your initialization step:

  % perl -wle '$t{$_}{$_}++ for 1..3; foreach $k1 (sort keys %t){ 
    foreach $k2 (sort keys %{$t{$k1}}) { print "$k1,$k2,$t{$k1}{$k2}" }}'
  1,1,1
  2,2,1
  3,3,1

-- 
Joe Schaefer     "Always forgive your enemies; nothing annoys them so much."
                                               -- Oscar Wilde



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

Date: Mon, 26 Nov 2001 15:07:31 -0500
From: "Paul Wasilkoff" <paul_wasilkoff@ucg.org>
Subject: 2D Array from Text File
Message-Id: <u05888rkn3k86f@corp.supernews.com>

I would like to generate a 2D array from a text file containing 2 lines -
one line containing a 2 digit source code, and the other with corresponding
descriptions for the codes.  This way I can easily access the list of source
codes and their descriptions at will.

What is the best way of doing this?

eg: file as follows:

AA,BB,CC,DD
Alpa Pub,Number Two,Tertiary Print,Forth Chapter

How then would you display a list of source codes (AA,BB,CC,DD) and
descriptions?

PAW




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

Date: Mon, 26 Nov 2001 21:34:26 +0000 (UTC)
From: Robert Sherman <rsherman@ce.gatech.edu.SPAMBLOCK>
Subject: Re: 2D Array from Text File
Message-Id: <9tuch2$mjv$1@news-int.gatech.edu>

In article <u05888rkn3k86f@corp.supernews.com>, Paul Wasilkoff wrote:
> I would like to generate a 2D array from a text file containing 2 lines -
> one line containing a 2 digit source code, and the other with corresponding
> descriptions for the codes.  This way I can easily access the list of source
> codes and their descriptions at will.
> 
> What is the best way of doing this?
> 
> eg: file as follows:
> 
> AA,BB,CC,DD
> Alpa Pub,Number Two,Tertiary Print,Forth Chapter
> 
> How then would you display a list of source codes (AA,BB,CC,DD) and
> descriptions?
> 

use a hash

use split to generate a list of keys from the first line, then use split 
again to generate a list of values from the second line...plug them into the
hash with for loops.




-- 
robert sherman
css3, school of civil and environmental engineering
georgia institute of technology
atlanta, ga, usa


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

Date: Mon, 26 Nov 2001 23:07:03 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: 2D Array from Text File
Message-Id: <Xns9165EB2E54EDLaocooneudoramailcom@62.153.159.134>

As it was already said , use a hash.
Here's a bit of sample code :

 ...
my (%hash,$i);
my @codes = <INPUT> =~ /\d+/g;
my @desc  = <INPUT> =~ /[^,]+/g;    	
for (@codes) {
    	$hash{$_} = $desc[$i++]
}	
 ...

Now you can access all the descriptions as values of the hash.


Lao 


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

Date: Mon, 26 Nov 2001 22:45:31 GMT
From: logikal nonsense <oddjob10@lycos.com>
Subject: [resource] perl script
Message-Id: <MPG.166c659b7a610b89897be@207.217.77.25>

                  Maybe you guys can help me out with the problem
                  since I haven't had time to work on it. Here is a
                  message I posted to a msg board asking about the
                  problem:

                  I was wondering if any of you guys could help me
                  with a
                  resource issue here.

                  I'm using a perl script (in my web mixmaster
                  interface cgi script) to
                  open mixmaster (2.9beta23) using:

                  open(MIX, "|$mix -p -l
                  \"$remailer1\",\"$remailer2\"");


                  and then i'm putting in the input:

                  ..
                  print MIX "Subject: $subject\n";
                  ..and whatever else

                  and then I'm closing MIX (which adds the msg to the
                  mixmaster msg pool):

                  close(MIX);

                  This will add the message to the pool.

                  However, on the close(MIX); statement, the mix
                  process is still open
                  in the system and it can sometimes take one or two
                  minutes for it to
                  finally "close" and add the message to the pool. It
                  only takes a
                  second to send when I type the command in
                  manually at the console. 
                  By MIX not closing right away, it's causing a system
                  resource problem
                  since mix processes are still waiting to be executed
                  and more are
                  coming in (from the web). I do notice that user
                  "apache" is running
                  the mixmaster executable, but I made sure the
                  executable and pool
                  directory were writable so "apache" has no problems
                  running it.

                  If anyone knows what could be causing the long
                  delays in closing MIX
                  to add the message to the pool, I sure would
                  appreciate it.

                  Thanks
                  xenophon 
                  
                  If possible,please also email me at                                     
                  xenophon at techmonkeys dot net





      
                                   
                   





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

Date: Mon, 26 Nov 2001 14:18:34 -0600
From: "Jake Fan" <jake@chaogic.com>
Subject: Re: A Perl Bug?
Message-Id: <9tu83g$cjo$1@Masala.CC.UH.EDU>

Randal L. Schwartz wrote:

> No, it's possible that a very large software vendor in Redmond Washington
> placed the default cursor in the wrong location, and the masses were
> too lazy to move the cursor to the right place.

Good point.  There were a few minor issues I wanted to point out but figured
we probably don't need an MS good vs. MS evil war in the middle of the
posting style war.

> Top posting ultimately breaks down when replies are intermingled with
> the things on which they are commmenting.  Can you at least agree to
> that?  If so, the anti-top-posting crowd is not doing it just based on
> tradition.  It's based on *what works* in the long run.

I don't think it's a clear-cut situation of "this work, that doesn't".  It
largely depends on the circumstances and the author.  Personally I found
that posting style makes little difference for a well written post.  On the
other hand, a sloppy post can be a nightmare for readers, whether it's
interleaved or top-posted.  Ever came across an interleaved post with three
or more levels of quoting, and with words at the end of the lines wrapped
around due to line length restriction by the server and/or client, and with
most of the actual comments less than a line long?  Talk about horror
stories.  One of my own loose guidelines is, use as few levels of quoting as
possible, preferably only one level.

If you followed the development of this thread or read the webpage I put up
in some earlier posts, you'll probably see that I am not a pro-top,
anti-bottom advocate or vice versa.  As a matter of fact I use different
styles depending on different situations.  I only found that some people's
knee jerk reaction of "top post bad" a little imposing.






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

Date: Mon, 26 Nov 2001 20:57:04 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: A Perl Bug?
Message-Id: <82b50u8ds5aj7u6ejoqep3tv6mq45f21mh@4ax.com>

[about top posting]

Randal L. Schwartz wrote:

>No, it's possible that a very large software vendor in Redmond Washington
>placed the default cursor in the wrong location, and the masses were
>too lazy to move the cursor to the right place.

The proper default would have been to select everything quoted. If this
person is too lazy to put his cursor where it should have been, he
shouldn't be quoting.

Maybe.

-- 
	Bart.


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

Date: 26 Nov 2001 14:40:20 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: call-by-reference, no newbie question
Message-Id: <3c02c4d4@news.victoria.tc.ca>

Rafael Garcia-Suarez (rgarciasuarez@free.fr) wrote:
(snip)
: Aliasing :

:     sub alter (\$) {
: 	no strict "vars";	# strictures won't allow this !
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
sure it does, 

	use strict;
	use vars qw($t) ;


: 	my $r = shift;		# reference on $s
: 	*t = $r;		# alias $t to $s

In addition, you may wish to localize "t" 

 	local *t = $r;		# alias $t to $s

and then any previous use of $t will be restored when you leave this
routine.  The only issue is that if $t is used a a global variables in
your program then you have just (temporarily) given it a new value. 
However, if you are using your own package for $t then presumably you know
what symbols you are using and can easily select names that can't conflict
with your own code.  ("local" is still useful as then you can use the same
standard variable names in all your subs for this kind of task).

	use var qw( $alias $temp %hash ) ; # useful placeholder names

	sub one { local *alias =something; two(); "$alias still ok"   }
	sub two { local *alias =otherthing;       "$alias for two ok" }



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

Date: 26 Nov 2001 11:23:36 -0800
From: djberg96@hotmail.com (Daniel Berger)
Subject: Re: Can I avoid 2 passes?
Message-Id: <6e613a32.0111261123.605bb65f@posting.google.com>

bh_ent@hotmail.com (Drew Myers) wrote in message news:<d1b6a249.0111200654.40aceba@posting.google.com>...
> I'm writing a small perl program to parse the contents of a Unix
> /etc/passwd file into a hash.
<snip>

Drew,

In addition to the multiple posts already provided, consider the
Unix::PasswdFile module.  Available on CPAN.

Regards,

Mr. Sunblade.


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

Date: Mon, 26 Nov 2001 21:46:38 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: documentation for functions in c
Message-Id: <slrna05e28.enm.mgjv@verbruggen.comdyn.com.au>

On Mon, 26 Nov 2001 19:53:24 +0100,
	Roger Faust <roger_faust@bluewin.ch> wrote:
> hi
> 
> I'm searching some docs for writing functions for perl in C. i've alredy 
> found perlapi, perlguts, perlxs and perlxstut. is there more around?

There are some others that you may want to read after you've finished
with those:

perlintern, perlclib, perlapio and maybe perlcall. 

If you're just trying to provide a Perl interface to a C library, the
documents you already mentioned are probably enough (also read the
documentation on h2xs). In that case, however, you might want to also
look at SWIG, which someone else has already mentioned.

Martien
-- 
                                | 
Martien Verbruggen              | This matter is best disposed of from
Trading Post Australia Pty Ltd  | a great height, over water.
                                | 


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

Date: 26 Nov 2001 14:10:13 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: documentation for functions in c
Message-Id: <3c02bdc5@news.victoria.tc.ca>

Roger Faust (roger_faust@bluewin.ch) wrote:
: hi

: I'm searching some docs for writing functions for perl in C. i've alredy 
: found perlapi, perlguts, perlxs and perlxstut. is there more around?

Not documentation, and I've never used it, but the Inline module(s) might
be of interest to you.




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

Date: 26 Nov 2001 14:53:06 -0800
From: mnorton2000@hotmail.com (Mike Norton)
Subject: Re: ISO Country Code Lookup
Message-Id: <93b16924.0111261453.16d6c5a3@posting.google.com>

This is only based on the TLD it does not return the country on the
record and also I need to lookup all URL's to start with any other
suggestions ?

Thanks

Mike

Tony Curtis <tony_curtis32@yahoo.com> wrote in message news:<877ksdzedq.fsf@limey.hpcc.uh.edu>...
> >> On 26 Nov 2001 08:22:23 -0800,
> >> mnorton2000@hotmail.com (Mike Norton) said:
>  
> > I am trying to write a script in Perl Which allows me to
> > enter an IP address and it will lookup which country
> > that IP address is located within, however I do not want
> > to use the tld which is e.g .com (us commercial) as this
> > is very innacurate. To find a more accurate way I want
> > to use the ISO country codes. When you go to the ripe
> > whois database and type in the ip you get the following
> > information :-
> 
> Net::ParseWhois is probably what you want:
> 
>  http://search.cpan.org/doc/ABEROHAM/Net-ParseWhois-0.62/lib/Net/ParseWhois.pm
> 
> or maybe just Net::Whois
> 
>  http://search.cpan.org/doc/DHUDES/Net-Whois-1.9/Whois.pm
> 
> hth
> t


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

Date: Tue, 27 Nov 2001 09:56:20 +1100
From: "Tintin" <tintin@snowy.calculus>
Subject: Re: ISO Country Code Lookup
Message-Id: <3c02c832_1@news.iprimus.com.au>


"Mike Norton" <mnorton2000@hotmail.com> wrote in message
news:93b16924.0111260822.136577a6@posting.google.com...
> I am trying to write a script in Perl Which allows me to enter an IP
> address and it will lookup which country that IP address is located
> within, however I do not want to use the tld which is e.g .com (us
> commercial) as this is very innacurate. To find a more accurate way I
> want to use the ISO country codes. When you go to the ripe whois
> database and type in the ip you get the following information :-

Keep in mind that doing lookups on netblocks is *slightly* more accurate
than using the TLD, but not by much.




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

Date: Mon, 26 Nov 2001 21:17:07 GMT
From: "Rick Ryan" <rickryan@datrixnet.com>
Subject: OT:Need new ISP
Message-Id: <njyM7.21732$py4.13357056@news2.nash1.tn.home.com>

I have an old system that uses perl scripts to fire off a system command
which drives the system. My old ISP, All Information Systems, was sold off
to Interliant and now has been sold to Interland. End result is the new
servers won't allow a system command to be run from perl scripts. Can
anybody recommend a good ISP that's NT-based and allows system commands to
run a .exe file on the server?

Thanks.

a copy to my email rickryan@datrixnet.com is greatly appreciated also.

--
Rick Ryan - Computer Consultant
http://www.datrixnet.com
Need E-Commerce? http://www.datrixnet.com/ecommerce.htm






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

Date: Tue, 27 Nov 2001 00:02:55 +0200
From: "Zak McGregor" <zak@mighty.co.za>
Subject: Re: OT:Need new ISP
Message-Id: <20011127.000255.722308542.3969@mighty.co.za>

In article <njyM7.21732$py4.13357056@news2.nash1.tn.home.com>, "Rick Ryan"
<rickryan@datrixnet.com> wrote:

So just prefixing a post with "OT" is enopugh to then go ahead and post
whatever you like to whichever newsgroup is closest? I don't think so.

> I have an old system that uses perl scripts to fire off a system command
> which drives the system. My old ISP, All Information Systems, was sold
> off to Interliant and now has been sold to Interland. End result is the
> new servers won't allow a system command to be run from perl scripts.
> Can anybody recommend a good ISP that's NT-based and allows system
> commands to run a .exe file on the server?

I would say that "good" and NT-based are almost certainly
mutually-exclusive terms. But, the short answer is "no".

> a copy to my email rickryan@datrixnet.com is greatly appreciated also.

And highly unlikely.

Zak.


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

Date: Mon, 26 Nov 2001 19:30:11 +0000 (UTC)
From: "Bubba Frank" <bubba_1947@lycos.com>
Subject: Re: Perl and Windows 2000 Service.
Message-Id: <aae204bf7677363141ddf0b23d7e7ac6.42091@mygate.mailgate.org>

Mark,

"Mark" <admin@asarian-host.net> wrote in message
> You should see NAME_OF_SERVICE in your task manager, which could be the name
> of your script
I named it MyDBWatch(descriptive name) and ran the svrany. MyDBWatch did 
come up in the Services list.

Next,regeditted new MyDBWatch string keys:
Application - D:\Perl\bin\perl.exe & 
AppParameters: D:\WatchDB\Watch.pl

Back to Administrator->Services->MyDBWatch. Checked all the declarations.
Set service to automatic. Started the service. Rebooted the server.

My real dilemma is, is my service running at all? When I run the Watch.pl from
C.Prompt, i have messages like 'Watching Oracle Table XYZ'... Now, since the
service is running silently(dont know) and i have no C.Prompt open, I am not 
sure it is running. And I cannot really test it as I am working on a Production
Database. So I have to make sure this is Production ready before moving to the
real server...

=Frank


-- 
Posted from  [65.115.221.98] 
via Mailgate.ORG Server - http://www.Mailgate.ORG


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

Date: Mon, 26 Nov 2001 19:46:20 GMT
From: owain@nospam.demon.co.uk (Owain McGuire)
Subject: Perl CGI scripts with read access contain passwords to database
Message-Id: <3c029aa1.35973356@news.demon.co.uk>

I am using an ISP that runs Apache under the user nobody.  In order
for Apache to be able to read and execute my Perl CGI scripts it needs
global read and exec access (only global read for the modules I
think).  The problem is that one of my modules contains the userid and
password to my Mysql database and hence anyone who has access to the
ISP's  filesystem can mess my database up.

How do I prevent this?

O.
------------------
Owain McGuire owain@nospam.ofrm.demon.co.uk (Minus the nospam.)


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

Date: Mon, 26 Nov 2001 16:59:36 -0500
From: "Mina Naguib" <spam@thecouch.homeip.net>
Subject: Re: Perl CGI scripts with read access contain passwords to database
Message-Id: <bXyM7.11101$Mm.1141510@wagner.videotron.net>


"Owain McGuire" <owain@nospam.demon.co.uk> wrote in message
news:3c029aa1.35973356@news.demon.co.uk...
> I am using an ISP that runs Apache under the user nobody.  In order
> for Apache to be able to read and execute my Perl CGI scripts it needs
> global read and exec access (only global read for the modules I
> think).  The problem is that one of my modules contains the userid and
> password to my Mysql database and hence anyone who has access to the
> ISP's  filesystem can mess my database up.

#1 Make sure you pick a trustworthy web hosting provider
#2 Make sure that if someone steals the username/pass for the database and
log on, it will allow them to do minimal to zero changes (maybe permissions
to only do SELECT queries). This is a restriction that's implemented on the
database side
#3 Not really a great idea, but use security through obscurity. Try to
obfiscuate your password to an extent that a casual sysadmin will not be
able to figure it out. Think of a neat way to do 2-way enc/dec/ryption and
store the password in the encrypted form, to be encrypted dynamically at
runtime.
#4 See if you can compile the script or delegate the password setting to a
compiled piece. Note that statically declared strings in source code are
often seen as plaintext inside a compiled binary executable, so you might
want to use this option in conjunction with option #3

That's all I can think of. Hopefully someone will provide better ideas.

>
> How do I prevent this?
>
> O.
> ------------------
> Owain McGuire owain@nospam.ofrm.demon.co.uk (Minus the nospam.)




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

Date: 26 Nov 2001 13:20:18 -0800
From: djones@flintschools.org (galaxy motion)
Subject: random pages...
Message-Id: <fe63d339.0111261320.4432a08c@posting.google.com>

Hello...

I'm working on a site and I have 50 pages but I want them to pop up
randomly and I  also want a set of 6 different pages every 100 times
someone clicks a link on the site.  Can someone help me with this? 
All help is greatly appreciated.


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

Date: Mon, 26 Nov 2001 13:39:17 -0800
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: random pages...
Message-Id: <3c02b685$1@news.microsoft.com>

"galaxy motion" <djones@flintschools.org> wrote in message
news:fe63d339.0111261320.4432a08c@posting.google.com...
> I'm working on a site and I have 50 pages

Perl doesn't have a concept of pages

> but I want them to pop up
> randomly

perldoc -f rand
You may want to multiply the result with 50 to get the full range of your 50
pages.

> and I  also want a set of 6 different pages every 100 times
> someone clicks a link on the site.  Can someone help me with this?

Perl doesn't have a concept of clicks and sites

> All help is greatly appreciated.

You may be better off asking this type of question in a newsgroup, that
actually cares about web authoring.

jue




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

Date: Mon, 26 Nov 2001 17:08:29 -0500
From: "Paul Wasilkoff" <paul_wasilkoff@ucg.org>
Subject: Re: random pages...
Message-Id: <u05fb3788vg659@corp.supernews.com>

Like Jue suggested, research a bit into rand....

But to answer your Perl question.....
Given a list of file names in an array, for instance, you can choose a file
at random.  Then print the contents of that file through $_.

What do you mean by "6 different pages every 100 times"?

PAW

> Hello...
>
> I'm working on a site and I have 50 pages but I want them to pop up
> randomly and I  also want a set of 6 different pages every 100 times
> someone clicks a link on the site.  Can someone help me with this?
> All help is greatly appreciated.




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

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


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