[13752] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1162 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Oct 24 01:05:36 1999

Date: Sat, 23 Oct 1999 22:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <940741508-v9-i1162@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 23 Oct 1999     Volume: 9 Number: 1162

Today's topics:
    Re: CPAN modules in RPM format. (Martien Verbruggen)
    Re: eval using the wrong namespace? (Eric Kuritzky)
    Re: file accessing problem <rc3csb@usa.net>
    Re: file upload <ab@cd.com>
    Re: hashes of hashes to/from DBM files... <bwalton@rochester.rr.com>
    Re: How can print a HTML file? <slanning@bu.edu>
    Re: How can print a HTML file? <slanning@bu.edu>
        How to approach this Array problem? dabbu_2000@my-deja.com
    Re: Is it the list or the re? (Andy Smith)
    Re: Is it the list or the re? (Andy Smith)
    Re: Long menus -- any solutions? <lusol@Pandora.CC.Lehigh.EDU>
    Re: not Perl, but please read! (Martien Verbruggen)
    Re: not Perl, but please read! <dan@tuatha.sidhe.org>
        numbers only, no text (Joe Zelwietro)
    Re: numbers only, no text <schapel@cs.uiowa.edu>
    Re: passing an array as a hash value? <bwalton@rochester.rr.com>
    Re: Perl vs. REBOL <bz9t@yahoo.com>
    Re: Picking 5 items from a random list <lr@hpl.hp.com>
    Re: Picking 5 items from a random list <skilchen@swissonline.ch>
    Re: Picking 5 items from a random list (AcCeSsDeNiEd)
    Re: Picking 5 items from a random list (Craig Berry)
    Re: Reference challenge <dan@tuatha.sidhe.org>
    Re: Reference challenge (Sean McAfee)
    Re: Retrieving directory contents (newbie) (Tad McClellan)
        Security on the web with Perl (Jim)
    Re: Security on the web with Perl (Craig Berry)
    Re: uninitialized value on ftp subroutine <schapel@cs.uiowa.edu>
    Re: What is THE book for PERL? <glenlee@holiness.dhis.org>
        Why doesn't this work? <khalilm@home.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 24 Oct 1999 03:13:58 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: CPAN modules in RPM format.
Message-Id: <slrn814uc9.e0v.mgjv@wobbie.heliotrope.home>

On Sat, 23 Oct 1999 13:51:08 -0400,
	Elaine -HFB- Ashton <elaine@chaos.wustl.edu> wrote:
> Jonathan Stowe wrote: 
> > I would not recommend using RPM  to install Perl modules as it cannot take
> > into account local differences in configuration and must by definition
> 
> Oh, I don't know, there aren't many modules where actual site name and
> such are important as long as the platform and OS are the same. 
> 
> > perl -MCPAN -e'install "Some::Module"'
> 
> I love the CPAN shell too, but try it on 500+ machines for a
> distribution...sometimes it is very convenient to have a package that
> will dist and install overnight. :)

If you have to maintain 500+ installations of perl, and you haven't
written your tools for that yet, you should really start at it :).

RPM or Sun's pkg* stuff of course is platform dependent. If any of the
500+ machines is a different OS, you suddenly have two distribution
scripts.

For 500+ machines that all need perl, it may actually be a good plan to
put up some NFS servers for that. Trims down the number of machines to
update.

If you want something simple

perl -MCPAN -e 'install some-module'

on each machine will work fine. 

If you mainly have one platform, or maybe two, run the above on those,
and then use rsync or rdist to update the others.

I can come up with many, many other ways of easily automating the
process of module installation in perl, and using any packaging scheme
that the various OS distributors have come up with only gets in my way.

I try to not use RPMs for anything that is not a very low level OS or
development thing. They make upgrading a pain, and if you want some high
level thing to be an RPM, then all the underlying dependencies have to
be RPMs as well, unless you simply keep forcing installation.

Sun's pkgadd stuff is also bad, but it's harder to avoid, since I can't
just get the sources for the stuff they package anyway :)

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia                  | 


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

Date: 24 Oct 1999 01:12:18 GMT
From: kuritzky@pub-708c-22.math.berkeley.edu (Eric Kuritzky)
Subject: Re: eval using the wrong namespace?
Message-Id: <7utmdi$ssk$1@agate-ether.berkeley.edu>

Let's see:

~> perl
my $content;
{
        $_ = '$content = "yadda yadda";';
        my $content;
        eval;
        print "inner=$content\n";
}
print "outer=$content\n"

 ...I then hit control-D...

inner=yadda yadda
outer=

It looks like it's modifying the right one.

--Eric



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

Date: Sun, 24 Oct 1999 13:01:41 +0800
From: "csb" <rc3csb@usa.net>
Subject: Re: file accessing problem
Message-Id: <381292b7.0@news.highway1.com.au>

oh., ookie, thx

Brett W. McCoy ¼¶¼g©ó¤å³¹ ...
>Also Sprach csb <rc3csb@usa.net>:
>
>>    I have a file stores users information and that file might access by
>>different users at the same time..so when both users trying to open that
>>file at the same time.... error occur on either side. Is there any method
in
>>perl that can block another user to access the file while some1 using it?
>
>Yes, the flock function can help you here.  See perldoc -f flock AND the
>manpage for the C function flock also.
>
>--
>Brett W. McCoy                             bmccoy@foiservices.com
>Computer Operations Manager (Alpha Geek)   http://www.foiservices.com
>FOI Services, Inc./DIOGENES                301-975-0110
>---------------------------------------------------------------------------




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

Date: Sat, 23 Oct 1999 20:28:53 -0500
From: "Blair Heuer" <ab@cd.com>
Subject: Re: file upload
Message-Id: <7utnej$li2$1@fir.prod.itd.earthlink.net>

Ok, now i am not exactly sure what to do, so I will fully explain my
situation, and then you might be able to suggest the best way to go about
things.

The script I am working on is a homepage community script and users need to
be able to upload all types of files, text and binary. The server runs on
Windows. I need to find the best, and most reliable way for the script to
discern between binary and text, so either type is not corrupted by setting
it to the other type.

Should I just go ahead an binmode all files? Will that keep all web
documents safe from corruption?

I can't feasible make a list of extensions that are binmoded and those which
are not, that would be an insanely big list. Or maybe would it be wise to
always binmode except when the extension is a certain type, protecting the
most common text files from any problems? Or is that not worth it?

Any suggestions are welcome. Thanks in advance, again.
-Blair Heuer


Larry Rosler <lr@hpl.hp.com> wrote in message
news:MPG.127a3384c3646afd98a0f8@nntp.hpl.hp.com...
> In article <7uo8k4$euc$1@fir.prod.itd.earthlink.net> on Thu, 21 Oct 1999
> 18:44:26 -0500, Blair Heuer <ab@cd.com> says...
> > > You have to use binmode before you do any reading or writing to your
> > files.
> > >
> > > open INFILE, "<$myfile";
> > >
> > > binmode(INFILE);
> >
> > Now do I only use this if it is a binary file then? Sounds dumb even as
I
> > ask it, but i must know. This script is not only used for pictures... it
is
> > used for all files, I had just noticed how it messed up the pictures.
> >
> > Should i do a statement like:
> >
> > if (-B $myfile) { binmode(INFILE); }
>
> That is a weak heuristic, even weaker for text files that may contain
> Latin-1 characters from the upper half of the code table.
>
> There are other clues -- MIME types and filename suffixes.
>
> > or will it work for both text and binary?
>
> A Unix text file transfered as binary to Windows/DOS will work fine with
> many text editors (not including Notepad) and with Perl.
>
> A Windows/DOS text file transfered as binary to Unix will have trailing
> CRs before the LFs.  It will look odd with many text editors, and the #!
> line may be misinterpreted by Perl.
>
> I don't have a reliable answer to your question -- ya' pays yer money
> and ya' takes yer cherce (my Brooklyn upbringing coming throush :-).
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com





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

Date: Sat, 23 Oct 1999 21:01:17 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: hashes of hashes to/from DBM files...
Message-Id: <38125A5D.7B4BCE3D@rochester.rr.com>

seether wrote:
> 
> Help. I'm having a problem either a. writing a hash table of hashes to
> a dbm or b. reading ... or of course both.
> 
> here is my write code:
> 
> dbmopen  ( %OUTFILE, $FILENAME, 0666  ) || die "\nCannot open file
> $!\n";
> 
>         foreach $PageKey ( keys %hash_table ){
> 
>                 $OUTFILE{$PageKey} = $hash_table{$PageKey};
> 
>                 foreach $NameKey ( keys %{ $hash_table{$PageKey} } ){
> 
>                         $OUTFILE{$PageKey}{$NameKey} = $hash_table{$PageKey}{$NameKey};}}
> 
> dbmclose ( %OUTFILE );
 ...
You have a fundamental problem here.  I assume from 
your code that $hash_table{$PageKey} is a reference to a
hash.  If so, the statement

         $OUTFILE{$PageKey} = $hash_table{$PageKey};

will store the reference on disk (since %OUTFILE is tied to a DBM-type
file).  Note carefully that the hash itself is not stored, but only
a reference to the hash is stored.  Later attempts in another program 
to retrieve the hash reference will find only a reference to an 
entity which has never existed in the second program.

One solution to this problem is to use the Data::Dumper module
to make a scalar out of the hash reference, which scalar can
later be eval'ed to retrieve the original hash.  If you wish,
you could use the MLDMB module to automate the use Data::Dumper
in this fashion.  Bear in mind that typical DBM-style implementations
have length limitations on the keys and values.  You might consider
tie'ing to DB_File or GDBM for a better implementation.

See recipies 14.8 and 14.9 in "Perl Cookbook" for additional info.
-- 
Bob Walton


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

Date: 23 Oct 1999 22:35:59 -0400
From: Scott Lanning <slanning@bu.edu>
Subject: Re: How can print a HTML file?
Message-Id: <kusg0z1wkmo.fsf@bottom.bu.edu>

Jing Shi <Jing.Shi@usa.alcatel.com> writes:
> Will that print out the file with all the HTML tags?
> Yes, I can use HTML::Parse to get rid of those tags. But I mean
> how  I can get the print out just like I print it from Netscape?

#!/usr/local/bin/perl -w
#gets a raw HTML document
#usage: gethtml [filename] [servername]
#######################################
use Socket;
use strict;

my $port   = 80;
my $doc    = $ARGV[0] ? $ARGV[0] : "/~slanning/index.html";
my $server = $ARGV[1] ? $ARGV[1] : "physics.bu.edu";

socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp'))
    or die "socket: $!";
connect(SOCK, sockaddr_in($port, inet_aton($server)))
    or die "connect: $!";
select(SOCK); $| = 1;
select(STDOUT); $| = 1;

print SOCK "GET $doc\r\n";
print while(<SOCK>);

-- 
"If there were gods, how could I bear to be no god?
Consequently there are no gods." --Nietzsche


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

Date: 23 Oct 1999 22:47:55 -0400
From: Scott Lanning <slanning@bu.edu>
Subject: Re: How can print a HTML file?
Message-Id: <kusbt9pwk2s.fsf@bottom.bu.edu>

Scott Lanning <slanning@bu.edu> writes:
> #!/usr/local/bin/perl -w
> #gets a raw HTML document
> #usage: gethtml [filename] [servername]
> #######################################
> use Socket;
> use strict;
> 
> my $port   = 80;
> my $doc    = $ARGV[0] ? $ARGV[0] : "/~slanning/index.html";
> my $server = $ARGV[1] ? $ARGV[1] : "physics.bu.edu";
> 
> socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname('tcp'))
>     or die "socket: $!";
> connect(SOCK, sockaddr_in($port, inet_aton($server)))
>     or die "connect: $!";
> select(SOCK); $| = 1;
> select(STDOUT); $| = 1;
> 
> print SOCK "GET $doc\r\n";
> print while(<SOCK>);

Sorry, I misunderstood the question. You want the HTML rendered.
For that I'd use 'lynx -dump'; e.g., replace

    print while(<SOCK>);

with

    open(LYNX, "| lynx -dump");
    print LYNX while(<SOCK>);
    close(LYNX);

and then

    $ gethtml /foo.html foo.bar.com | lpr -Pprintername

-- 
"One should not confuse this craving for change and novelty with the
indifference of play which is in its greatest levity at the same time
the most sublime and indeed the only true seriousness." --Georg Hegel


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

Date: Sun, 24 Oct 1999 04:40:49 GMT
From: dabbu_2000@my-deja.com
Subject: How to approach this Array problem?
Message-Id: <7uu2kh$nm7$1@nnrp1.deja.com>

Problem:

time1 key1 start
time2 key1 blah
time3 key1 blah...
time4 key1 stop

This is the pattern of the file I want to parse. I am trying to store
the time1 and time4 associated with "start" and "stop". Once successful,
I will be doing a calc (time4-time1).

My solution (of course, doesn't work):

#!/usr/bin/perl

eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_0-9]+=)(.*)/ && shift;
$[ = 1;				# changing the index origination at 1
foreach $file (@ARGV) {

	open(FILE,$file) || warn "Can't open $file $!\n";


	while (<FILE>) {
	chop;
	@Fld = split(' ', $_);

	if (($Fld[3] =~ /start\b/) || ($Fld[3] =~ /stop\b/))
	{


	if($Fld[3] =~ /start\b/) {   #time slected
	$c_start{$Fld[1]}++;
	$c_key{$Fld[2]}++;
$c_START{$Fld[1],$Fld[2]}={$Fld[2]}; #storing both the time and key
	}

	if($Fld[9] =~ /stop\b/) {   #time and the corresponding key
	$c_stop{$Fld[1]}++;
	$c_key{$Fld[2]}++;
	$c_STOP{$Fld[1],$Fld[2]} = {$Fld[2]};
	}
       }

      }
}		# end of the looking and parsing

## have to use the stored values (variable used are initialized to 0)

	foreach $co (keys %c_START) {

	foreach $ct (keys %c_STOP) {



	### if the key is the same
	if ($ct == $co)
	{
	#printf ("\n\n%s\t",$ct);
	$c_count++;
### ?????????????????? how to retrieve the time1 and time4 values??
###                    Is this the right way? Did I store them at all?

	}

	}
}
printf "Total: %s", $c_count;




Thanks for Any input


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 24 Oct 1999 02:31:12 GMT
From: asmith@hsonline.net (Andy Smith)
Subject: Re: Is it the list or the re?
Message-Id: <38126e97$0$70838@news.hsonline.net>

On Sat, 23 Oct 1999 14:23:45 -0400, tadmc@metronet.com (Tad McClellan)
wrote:

>Andy Smith (asmith@hsonline.net) wrote:
>: All I really want to do is pull some info from syslog. 
>: I'm sure there are scripts out there to do this, but 
>: I need the practice (badly as you can see). MYFILE is the
>: sytem log, and NEWFILE a log that the info will go into.
>: I am pretty sure the re is what is screwy. Perl -w tells me
>: there is an error near "\s+\d+)\s+(".
>
>
>:  while(my $linage = <MYFILE>)
>:     {
>:  
>: if (s/^\w+\s+\d+\S+\s+?/);
>      ^^                 ^
>      ^^                 ^
>
>   besides that, you are missing the BLOCK part of the if() construct.
>
>
>: list($date, $time, $service) = ($linage =~
>  ^^^^
>  ^^^^
>
>   What is that?
>
>
>: s/^(S+\s+\d+)\s+(\d{2}:\d{2}:\d{2})\s+(S+:).*?/);
>  ^^                                            ^
>  ^^                                            ^
>
>
>   s/PATTERN/REPLACEMENT/ ( s/// ) is  2-part thingie.
>   ^^       ^           ^
>   ^^       ^           ^
>
>
>   you have a couple of 1-part thingies there...
>
>
>--
>    Tad McClellan                          SGML Consulting
>    tadmc@metronet.com                     Perl programming
>    Fort Worth, Texas
Ouch...I should pay more attention to my typing! I didn't even notice
the s/ until after I posted. That took care of one error.

Andy


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

Date: Sun, 24 Oct 1999 02:45:15 GMT
From: asmith@hsonline.net (Andy Smith)
Subject: Re: Is it the list or the re?
Message-Id: <381271de$0$444@news.hsonline.net>

On Sat, 23 Oct 1999 16:43:15 -0700, Larry Rosler <lr@hpl.hp.com>
wrote:

>In article <3811f89f$0$70842@news.hsonline.net> on 23 Oct 1999 18:04:15 
>GMT, Andy Smith <asmith@hsonline.net> says...
>> All I really want to do is pull some info from syslog. 
>> I'm sure there are scripts out there to do this, but 
>> I need the practice (badly as you can see). MYFILE is the
>> sytem log, and NEWFILE a log that the info will go into.
>> I am pretty sure the re is what is screwy. Perl -w tells me
>> there is an error near "\s+\d+)\s+(".
>> 
>> 
>>  while(my $linage = <MYFILE>)
>>     {
>
>It is common and humane to indent code within a block like this.
>
>> if (s/^\w+\s+\d+\S+\s+?/);
>
>Is this line above supposed to mean something?  You have posted code 
>that cannot compile.  This is poor policy, because who wants to go 
>further?
>
K...well...this part was taken from a chunk of another script. I have
no clue who wrote it, but I just started with the language myself. The
s/ was my fault. I suppose I should have used $_ with the re, or one
of those built in variables. It was supposed to act on the input file
at any rate. Oops!! I do apreciate the assistance though. I finally
borrowed a book and have a much better understanding of re syntax than
I did this morning. Amazing what a little reading will do.
>> list($date, $time, $service) = ($linage =~
>
>The above invokes a function list() as an lvalue?  Unusual, I'd say.

Fixed that too. Should have been simply ($date, $time, $service). Is
this correct to match the parens in the re? Seems to work at any rate.
>
>> s/^(S+\s+\d+)\s+(\d{2}:\d{2}:\d{2})\s+(S+:).*?/);
>      ^
>      Missing a backslash here, or do you really want to match a leading 
>string of S's?
>
Still having trouble with the re, even with the backslash. I'll keep
hacking (and choking). Thanks for the help. 
>> print(NEWFILE "$date $time $service\n");
>>     };
>
>Please copy and paste well-formatted code that actually compiles and 
>runs.  Then maybe the responses will be useful to you.
>
>-- 
>(Just Another Larry) Rosler
>Hewlett-Packard Laboratories
>http://www.hpl.hp.com/personal/Larry_Rosler/
>lr@hpl.hp.com



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

Date: 23 Oct 1999 23:44:50 GMT
From: "Stephen O. Lidie" <lusol@Pandora.CC.Lehigh.EDU>
Subject: Re: Long menus -- any solutions?
Message-Id: <7uth9i$1t6a@fidoii.cc.Lehigh.EDU>

In comp.lang.perl.tk Makarand Kulkarni <makkulka@cisco.com> wrote:
> Stacy Doss wrote:

>> Is there any way to have a menu widget display in multiple columns?

> assuming that you are talking about menu widgets in the inside
> HTML forms 

In a Tk group?

Anyway, use a menu item's -columnbreak option ...


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

Date: 24 Oct 1999 03:22:58 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: not Perl, but please read!
Message-Id: <slrn814ut8.e0v.mgjv@wobbie.heliotrope.home>

On Sat, 23 Oct 1999 10:18:28 GMT,
	Michel Dalle <michel.dalle@usa.net> wrote:
> In article <7urgip$3n1$1@nnrp1.deja.com>, yoga9900@my-deja.com wrote:
> >This is a breaking story: http://www.msnbc.com/news/323734.asp?cp1=1
> <snip>
> 
> Have you tried the Meditation::Yoga module from CPAN ?
> That might help you reach the right frame of mind.

Only when used together with Chant::Ommmmmmmmmmmm.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I took an IQ test and the results
Commercial Dynamics Pty. Ltd.   | were negative.
NSW, Australia                  | 


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

Date: Sun, 24 Oct 1999 03:49:15 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: not Perl, but please read!
Message-Id: <%kvQ3.564$cP2.3165@news.rdc1.ct.home.com>

Craig Berry <cberry@cinenet.net> wrote:
> Michel Dalle (michel.dalle@usa.net) wrote:
> : In article <7urgip$3n1$1@nnrp1.deja.com>, yoga9900@my-deja.com wrote:
> : >This is a breaking story: http://www.msnbc.com/news/323734.asp?cp1=1
> : <snip>
> : 
> : Have you tried the Meditation::Yoga module from CPAN ?
> : That might help you reach the right frame of mind.

> I tried it.  I felt just the same, but my server seemed much calmer.

Ah, wrong module. To make the user calmer you need to use Coy instead.

					Dan


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

Date: Sun, 24 Oct 99 04:11:44 GMT
From: deplib@citytel.net (Joe Zelwietro)
Subject: numbers only, no text
Message-Id: <381287fa@rsl2.rslnet.net>

Hello All:

I know this is basic but I'll ask.  I have a script that searches a file and 
dumps the pertinent lines into a variable (sometimes an array, sometimes an 
scalar, depending on how many times the pattern searched for occurs)

Anyway, my script finds the appropriate line (eg. below)

 ...
This line contains the number 1234
 ...

My first attempt to deal with this was to use the substr function.  That 
is, have the script place the final 4 bytes of the line into the variable.  
Such as:
push (@allNunbers, substr($_-4)."\n";

But as you probably guessed this only works for numbers of 4 digit width AND 
only those numbers at the end of the line and thus it isn't a suitable method. 
 I want a function (or a pattern substitution which strips the variable of all 
NON-numeric elements.  

Any advice as to a good way to do this?

Thanks in Advance,
Joe 



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

Date: Sat, 23 Oct 1999 23:57:39 -0500
From: Steve Chapel <schapel@cs.uiowa.edu>
Subject: Re: numbers only, no text
Message-Id: <381291C3.D841368C@cs.uiowa.edu>

Joe Zelwietro wrote:
> 
> Hello All:
> 
> I know this is basic but I'll ask.  I have a script that searches a file and
> dumps the pertinent lines into a variable (sometimes an array, sometimes an
> scalar, depending on how many times the pattern searched for occurs)
> 
> Anyway, my script finds the appropriate line (eg. below)
> 
> ...
> This line contains the number 1234
> ...
> 
> My first attempt to deal with this was to use the substr function.  That
> is, have the script place the final 4 bytes of the line into the variable.
> Such as:
> push (@allNunbers, substr($_-4)."\n";
> 
> But as you probably guessed this only works for numbers of 4 digit width AND
> only those numbers at the end of the line and thus it isn't a suitable method.
>  I want a function (or a pattern substitution which strips the variable of all
> NON-numeric elements.

How about a regular expression:

while (<STDIN>) {
    if (/(\d+)$/) {
        print "$1\n"; # $1 is now the last whole number on the line
    }
}


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

Date: Sat, 23 Oct 1999 20:21:01 -0400
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: passing an array as a hash value?
Message-Id: <381250ED.AA721512@rochester.rr.com>

TK Soh wrote:
> 
> Bob Walton wrote:
> <snip>
> >      $hash{$word}=\@array;
> <snip>
> > and how to get the entire array out:
> >
> >      $arrayout=@{$hash{$word}};
>        ^
>        Oops! got the number of elements instead.

Yes, sorry about the typo.  I had it right in my test
program, too!

BTW, it turns out the original poster was using a *SDBM-tied*
hash, and his difficulties were caused by the reference
to his anonymous array disappearing from memory when the
hash element is written to disk via garbage-collection.
Then subsequent attempts at retrieval fail because the
array is no longer there.

> 
> -TK


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

Date: Sat, 23 Oct 1999 23:49:27 -0400
From: "Billy Zhao" <bz9t@yahoo.com>
Subject: Re: Perl vs. REBOL
Message-Id: <7utvkt$8ta$1@murdoch.acc.Virginia.EDU>

Martien,

"Keep in mind that it is intended to help inform newcomers."  That's in the
email from Nathan Torkington.  I count myself as a newcomer.  If you feel
like patronizing me, email the reponse to me, there's no need to post
sarcastic comments to the group.  If you don't feel like helping, don't.
But please keep your mean spirited arrogance to yourself.

Thanks.

Billy Zhao

Martien Verbruggen <mgjv@wobbie.heliotrope.home> wrote in message
news:slrn813cue.dii.mgjv@wobbie.heliotrope.home...
> On Fri, 22 Oct 1999 23:05:48 -0400, Billy Zhao <bz9t@yahoo.com> wrote:
> > Hi,
> >
> > I'm working on a project for my programming languages class.  Given as
> > how REBOL is still relatively new and there're not too many
> > testimonials out there, I was just wondering if someone who has used
> > REBOL and/or Perl can run down a list of specs I have and tell me
> > which language has the advantage over the other?
>
> Why do you want us to do that? Let me quote again what you said:
>
> > I'm working on a project for my programming languages class.
>   ^^^
>
> That is first person singular, right? So why do you ask us?
>
> > The project is to evaluate the suitability of Perl and REBOL for use
> > in "constructin an infrastructure for sharing information among a set
> > of company databases."   This infrastructure should communicate with
> > the databases though their APIs.  Although, I imagine that the fact
> > that it is to be used in a database is pretty much irrevelant, we're
> > just trying to contrast the two languages.
>
> And now it's 'we'. But that's still not clpm. Why do you want us to do
> that project for you?
>
> Besides all that... We do not generally like to discuss 'differences'
> between languages, especially not when phrased like 'which one is
> better?', not even when followed by the qualifier 'for such and such a
> task'. It leads to chaos, flames, harsh words, crying, long time
> clpm-ers leaving, and many psychiatric sessions as well as a need for a
> long and slow recovery process after the thread is over. If you want to
> discuss that sort of thing, go to one of the advocacy groups or one of
> the general programming groups for the subject you're interested in. We
> talk about Perl here. Perl programmers don't need to flex their muscles
> at other languages.
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | You can't have everything, where
> Commercial Dynamics Pty. Ltd.   | would you put it?
> NSW, Australia                  |




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

Date: Sat, 23 Oct 1999 17:08:27 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Picking 5 items from a random list
Message-Id: <MPG.127bedced31a447598a10d@nntp.hpl.hp.com>

In article <38123b44.2152336@news.magix.com.sg> on Sat, 23 Oct 1999 
22:48:50 GMT, AcCeSsDeNiEd <dillon_rm@magix.com.sg> says...
 ...
> I have a list of 10 items. I know how to pick one item at random. It
> goes like this: 
> 
> @items =
> ("Item1","Item2","Item3","Item4","Item5","Item6","Item7","Item8","Item9","Item10");

 ...

> My question is, how do I pick 5 items at one time randomly from the
> list?

Populate a hash with five random integers as keys, then use the keys as 
an array slice.

#!perl -w
use strict;

my @items = ("Item1","Item2","Item3","Item4","Item5",
    "Item6","Item7","Item8","Item9","Item10");

my %hash;
$hash{int rand @items}++ until keys %hash == 5;

my @out = @items[keys %hash];

print "@out\n";
__END__


There is another, shorter approach using splice, but it destroys the 
input and is quadratic in behavior.  The approach above is far superior.

my @out = map splice(@items, rand @items, 1) => 1 .. 5;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sun, 24 Oct 1999 00:17:28 GMT
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: Picking 5 items from a random list
Message-Id: <sesQ3.26222$m4.95049346@news.magma.ca>

AcCeSsDeNiEd <dillon_rm@magix.com.sg> wrote in message
news:38123b44.2152336@news.magix.com.sg...
>
> I have a list of 10 items.
>
> My question is, how do I pick 5 items at one time randomly from the
> list?
> I could do a while loop, but then the 5 times picked will surely have
> duplicates.

You need to do some bookkeeping about the indices already used. The
simplest way is to make a parallel list where you mark the used indices.
- Try a random position
- Check in the parallel list if that position was already used
  - If yes: retry with another random position
  - If no: mark the current position as used
Repeat until you have the requested number of selected items.

This process can be somewhat optimized to prevent the use of an
additional list where used items are marked. Such an optimization leads
to something similar to the fisher_yates_shuffle from perlfaq4:

#!wherever/perl -w
use strict;

sub rand_k_perm {
  # get a random permutation of k numbers in the range 0 .. n
  my ($n, $k) = @_;

  my @range   = 0..$n;
  my @result  = ();

  for (my $i = 0; $i < $k; $i++) {
    my $r = int(rand($n - $i)) + $i;
    @range[$i, $r] = @range[$r, $i];
    push(@result, $range[$i]);
  }
  return sort {$a <=> $b} @result;
}

my @items = ("Item1","Item2","Item3","Item4","Item5",
             "Item6","Item7","Item8","Item9","Item10");

my @random5 = @items[rand_k_perm($#items + 1, 5)];

{
  local $" = "\n";
  print "@random5", "\n";
}




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

Date: Sun, 24 Oct 1999 02:41:29 GMT
From: dillon_rm@magix.com.sg (AcCeSsDeNiEd)
Subject: Re: Picking 5 items from a random list
Message-Id: <381271d1.179810@news.magix.com.sg>

Thanks for all the help guys!

To e-mail me, remove "_rm"


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

Date: Sun, 24 Oct 1999 04:27:28 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Picking 5 items from a random list
Message-Id: <s152lgeb85980@corp.supernews.com>

AcCeSsDeNiEd (dillon_rm@magix.com.sg) wrote:
: I have a list of 10 items. I know how to pick one item at random. It
: goes like this: 
: 
: @items =
: ("Item1","Item2","Item3","Item4","Item5","Item6","Item7","Item8","Item9","Item10");
: 
: srand(time ^ $$);

That's generally a bad idea.  Modern perls don't really need srand (it's
done for you, and better than that).

: $num = rand(@items); # Pick a Random Number
: 
: # Print Out Random Item
: print "Random Item picked is: $items[$num]\n";
: 
: My question is, how do I pick 5 items at one time randomly from the
: list?
: I could do a while loop, but then the 5 times picked will surely have
: duplicates.
: Any hints? 

My suggestion:  Copy off the list if you need to preserve it, then
'shuffle' it into a random order (see the FAQ), and grab the first five
items via pop() or list slice as convenient.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "They do not preach that their God will rouse them
      a little before the nuts work loose." - Kipling


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

Date: Sun, 24 Oct 1999 00:26:03 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Reference challenge
Message-Id: <vmsQ3.547$cP2.2744@news.rdc1.ct.home.com>

Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:

> perlfunc guarantees only that ref() returns FALSE if its argument is not a
> reference.  Sure, ref() returns "" *now* if passed a non-reference, but
> suppose a future version of Perl returned 0 instead?  Your code would
> break.

Yeah, but perl's false is always the empty string. If perl started
returning something else for false after all this time, I think you'd
find all sorts of things breaking in odd and subtle ways.

					Dan


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

Date: Sun, 24 Oct 1999 03:35:51 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Reference challenge
Message-Id: <r8vQ3.551$4G.105670@news.itd.umich.edu>

In article <vmsQ3.547$cP2.2744@news.rdc1.ct.home.com>,
Dan Sugalski  <dan@tuatha.sidhe.org> wrote:
>Sean McAfee <mcafee@waits.facilities.med.umich.edu> wrote:
>> perlfunc guarantees only that ref() returns FALSE if its argument is not a
>> reference.  Sure, ref() returns "" *now* if passed a non-reference, but
>> suppose a future version of Perl returned 0 instead?  Your code would
>> break.

>Yeah, but perl's false is always the empty string. If perl started
>returning something else for false after all this time, I think you'd
>find all sorts of things breaking in odd and subtle ways.

Well, exec() is documented to return false if the command to be executed
does not exist, and the following prints "0" on my system:

perl -le 'print exec "non-existent-command";

That's just the first counterexample I found; I imagine there are others.

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


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

Date: Sat, 23 Oct 1999 19:53:43 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Retrieving directory contents (newbie)
Message-Id: <7qhtu7.ub4.ln@magna.metronet.com>

Morris (acacia@online.no) wrote:
: I'm wondering if anyone here knows how to make a script that retrieves all
: the filenames (just the names + extension)
: in a given directory...


# UNTESTED
opendir DIR '.' or die "could not open current directory  $!";
my @files = grep -f, readdir DIR;
closedir DIR;


   
--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 23 Oct 1999 23:59:26 -0500
From: jkrogerDONCHA_SPAM_ME@earthlink.net (Jim)
Subject: Security on the web with Perl
Message-Id: <jkrogerDONCHA_SPAM_ME-2310992359260001@ip216.princeton.nj.pub-ip.psi.net>




Hi, I have a question about Perl security on the web.

I want to do a web site that takes info from a form, feeds it to a
program, takes the output from the program, and puts it back on the
website for the reader to see.

The program will be a compiled C program, but as far as I know the way you
feed info between the web page and the program is using CGIs, which are
Perl. If I'm not mistaken those have to be text files which the Perl
interpreter reads. So what is to stop somebody from stealing my program,
and my Perl scripts? The program alone would not help them, because
without the scripts it wouldn't make sense, but with the scripts they
could basically steal the
entire engine driving my site (let's say it's a horiscope program). Also,
the Perl scripts are useful themselves, and they can just read them. 

How do I protect my stuff? Should I try to use all C instead of Perl? They
can still steal it though.

Thanks in advance for any help,

Jim



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

Date: Sun, 24 Oct 1999 04:36:28 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Security on the web with Perl
Message-Id: <s1536ck985913@corp.supernews.com>

Jim (jkrogerDONCHA_SPAM_ME@earthlink.net) wrote:
: Hi, I have a question about Perl security on the web.
: 
: I want to do a web site that takes info from a form, feeds it to a
: program, takes the output from the program, and puts it back on the
: website for the reader to see.

That, in a nutshell and to a first approximation, is what CGI is all
about.

: The program will be a compiled C program, but as far as I know the way you
: feed info between the web page and the program is using CGIs, which are
: Perl.

CGI ("Common Gateway Interface") is an interface spec, not a program or
language.  A "CGI app" (one which a web server can "talk to" via the CGI
interface) can be written in virtually any language, including C, C++,
Java, Perl, Python, REXX, or assembly.

: If I'm not mistaken those have to be text files which the Perl
: interpreter reads.

Yes, in general, if we now understand 'those' to be 'Perl scripts, which
might happen to be CGI apps' rather than 'CGI apps in general, which must
be Perl scripts.

: So what is to stop somebody from stealing my program,
: and my Perl scripts? The program alone would not help them, because
: without the scripts it wouldn't make sense, but with the scripts they
: could basically steal the
: entire engine driving my site (let's say it's a horiscope program). Also,
: the Perl scripts are useful themselves, and they can just read them. 

If your web server is configured properly, the scripts themselves will be
inaccessible to outsiders.  Only the results of running such scripts will
be visible to the outside world.

: How do I protect my stuff? Should I try to use all C instead of Perl? They
: can still steal it though.

Hope this makes more sense, now.

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "They do not preach that their God will rouse them
      a little before the nuts work loose." - Kipling


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

Date: Sat, 23 Oct 1999 23:41:27 -0500
From: Steve Chapel <schapel@cs.uiowa.edu>
Subject: Re: uninitialized value on ftp subroutine
Message-Id: <38128DF7.B7BD44B2@cs.uiowa.edu>

Dutch McElvy wrote:
> 
> I am using the following script to upload all files in a certain directory
> and place them on the remote machine under a new name and a new directory
> created from a portion of the file name. This could probably be done more
> cleanly but it seems to work ok only I get an error when I use -w of
> "uninitialized value" at the lines containing $newname and $newdir. What
> could I do to elimante this warning?
> 
>  (@filenames, $newname, $newdir) =  readdir(DIR);

The array variable @filenames is "greedy" and eats up the whole array.
As a result, $newname and $newdir get set to undef. The solution:
remove the useless $newname and $newdir from this line and initialize
them on some other line.


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

Date: Sat, 23 Oct 1999 23:13:15 -0500
From: Glen Lee Edwards <glenlee@holiness.dhis.org>
Subject: Re: What is THE book for PERL?
Message-Id: <Pine.LNX.4.10.9910232305260.17823-100000@holiness.dhis.org>

Scott,

To learn perl you might try:

"PERL 5 Interactive Course" by Jon Orwant.  It's certified by Marquette
University.

You might also try "The PERL 5 Programmer's Reference" by R. Allen Wyke
and Luke Duncan, publisher Ventana Communications Group.

Glen
Glen Lee Edwards
glenlee@holiness.dhis.org

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: "perl-programmers@egroups.com" for general perl questions
::  perl-programmers-subscribe@egroups.com
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::




On Thu, 14 Oct 1999, Scott McMahan wrote:

>Johnny 'Loopy' Ooi (jjyooi@dcs.qmw.ac.uk) wrote:
>> Can anyone in the know tell me the _best_ book to read/buy for research
>> and reference into PERL?
>
>It used to be Programming Perl, but Perl is so BIG now that you can't
>do it in one book anymore. It just depends on where you are and what
>you're doing.
>
>I have some recommendations of what I use myself at the URL below.
>If you're going to buy one anyway, do it through my web site :) (I get
>lots of clicks, but no one buys anything. :))
>
>Scott
>
>http://autoperl.skwc.com Automating Windows With Perl
>
>



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

Date: Sun, 24 Oct 1999 01:25:11 GMT
From: "Khalil Mohammed" <khalilm@home.com>
Subject: Why doesn't this work?
Message-Id: <XdtQ3.4779$MX.334524@news1.rdc2.on.home.com>

I have an HTML form on my UNSECURE server that posts to myprogram.cgi in my
cgi-bin directory.

I take this information and dependent upon the data, manipulate it. I then
repost this information to a SECURE server (using HTTPS) located in another
domain.

(For clarity: The user enters his name, address, country etc. Dependent upon
the country, I add the appropriate shipping cost in my product string. Then
I post this data to my credit card processors' website hoping to keep this
transparent to the user).

Here is the code I came up with so far:

#!/usr/local/bin/perl

use CGI;
use CGI::Carp qw(fatalsToBrowser);
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);

$query = new CGI;

foreach $key ($query->param)
{ 
    $value = $query->param($key); 

    if ($key eq "xxx") 
    { 
        $mn = $value; 
    }     
    elsif ($key eq "yyy") 
    { 
        $ru = $value; 
    } 
    elsif ($key eq "zzz") 
    { 
        $prod = $value; 
                #manuipulate value here 
    }
} 

$ua = new LWP::UserAgent; 
my $req = POST 'https://secure.server.com/theirprocess.cgi', [ value1 => $mn, value2 => $ru, value3 => $prod]; 
my $res = $ua->request($req); 
print $res->as_string; 
exit; 


However when I do this I get a: 

501 (not implemented) Protocol scheme https is not supported 

rather than the secure servers web page. 
However when I look at the documentation for LWP it says it does implement the HTTPS protocol. 

I've have noticed some other posts that suggest the use of Net::SSLeay. However my provider only has OpenSSL installed. No Net::SSL or IO::Socket::SSL. I might be able to convince them to install this but I am not sure. But why would I be able to directly post this information to the secure server if I bypass my script. Confusion rains....

Anyway, if someone could help me with this code or suggest another solution (along with exact code please) I would be very grateful. 
  










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

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 V9 Issue 1162
**************************************


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