[12557] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6157 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 28 14:07:14 1999

Date: Mon, 28 Jun 99 11:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 28 Jun 1999     Volume: 8 Number: 6157

Today's topics:
    Re: 2 simple (not to me tho) questions (I R A Aggie)
        cgi-lib.pl <shannon@compar.com>
    Re: cgi-lib.pl (J Alex)
    Re: CGI.pm, hashes, passing by reference and two differ dzuy@my-deja.com
    Re: Comparing two associative arrays (Andrew Allen)
    Re: Comparing two associative arrays (John Cochran)
        Connectivity to Oracle databae. ("Saurabh, Sangeet (C) (STP)")
    Re: Connectivity to Oracle databae. (John D Groenveld)
    Re: FAQ 2.12: Perl in Magazines (Rich Morin)
    Re: FAQ 3.23: How can I compile Perl into Java? <cassell@mail.cor.epa.gov>
    Re: FAQ 3.23: How can I compile Perl into Java? (Randal L. Schwartz)
    Re: How to start a thread in Perl <cassell@mail.cor.epa.gov>
    Re: Linux better than perl? <upsetter@ziplink.net>
    Re: Linux better than perl? <gt7202e@prism.gatech.edu>
        Looking For A Perl Programmer scott_mark@my-deja.com
        Multiple Mail Messages from Perl <druttle@gb.pepperl-fuchs.com>
    Re: Newbie question (Perl within a C program) <swiftkid@bigfoot.com>
        Outputting Search results in parts (like yahoo) <shaddy@shaddy.com>
        perl mongers in Columbus, OH (J Alex)
        Perl redirection script question <alexaugot@future-wave.com>
        please help! regular expression! hamed53@my-deja.com
    Re: random numbers ? <swiftkid@bigfoot.com>
    Re: random numbers ? (Marcel Grunauer)
    Re: random numbers ? (Randal L. Schwartz)
        Skipping lines from my text file j_a_p@my-deja.com
    Re: Skipping lines from my text file (Randal L. Schwartz)
        Somebody Help Me! (Jonathan Chum)
    Re: Unlink == delete files? Why (on earth) is it called (I R A Aggie)
    Re: Verifying an existing file with a PERL web script <cassell@mail.cor.epa.gov>
    Re: Viral matters [completely off-topic] <kullstam@ne.mediaone.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 28 Jun 1999 17:35:42 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: 2 simple (not to me tho) questions
Message-Id: <slrn7nfcnr.4cj.fl_aggie@thepentagon.com>

On Mon, 28 Jun 1999 15:36:16 GMT, greyed@my-deja.com <greyed@my-deja.com>, in
<7l84pf$jtf$1@nnrp1.deja.com> wrote:

+ In article <376faf51@cs.colorado.edu>, tchrist@mox.perl.com (Tom
+ Christiansen) wrote:

+ >     $var = [ qw/grok this/ ];
+ >     fn( $var );
+ >     fn("$var");

+     I don't see print in there.

Literalist, eh?

+ >     @var = qw/grok this/;
+ >     fn( @var );
+ >     fn("@var");
+ 
+     Still no print.

Ok, compare and constrast:

@var=qw/I see this as a sentance. Perl sees this as a list./;
print 'A:',@var,"\n\n";
print "B: @var\n";

Results:

A:Iseethisasasentance.Perlseesthisasalist.

B: I see this as a sentance. Perl sees this as a list.

Are they different? is there *really* more than one way to skin this
particular cat?

James - nay, you get *different* results


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

Date: Mon, 28 Jun 1999 17:03:04 GMT
From: Shannon Dorey <shannon@compar.com>
Subject: cgi-lib.pl
Message-Id: <3777AAED.D25AB9F0@compar.com>

Has anyone used this library before. I downloaded it from perl.com but I
can't seem to get it to work. I assume you just put the program in the
same directory as your interperter but I'm not sure if you have to do
something to the code. Thanks.

--
Sincerely,

Shannon Dorey
Computer Partners <http://www.compar.com/>
Permanent, Personal, Private Email <http://www.EmailONE.nu>
Software Super Store <http://www.softwareshop.nu>




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

Date: Mon, 28 Jun 1999 17:28:40 GMT
From: jalex@pobox.com (J Alex)
Subject: Re: cgi-lib.pl
Message-Id: <377caff6.12731007@nntp.service.ohio-state.edu>

Use CGI.pm by Lincoln Stein.  The online documentation at
http://stein.cshl.org/~lstein/ is very well written.  Lincoln is one
of the better perl/CGI authors also - buy his book(s).

To install CGI.pm (and I hope you are using unix, otherwise you would
use 'ppm' in windows) use the CPAN module in unix.  You can use it by
typing 'perl -MCPAN -e shell' and then you will see a prompt.  Youcan
get help by typing ? or 'help' at this prompt.  'install CGI' may
work...who knows.  I usually query it and then instlal whatever it's
listed as.
--Jason


On Mon, 28 Jun 1999 17:03:04 GMT, Shannon Dorey <shannon@compar.com>
wrote:

>Has anyone used this library before. I downloaded it from perl.com but I
>can't seem to get it to work. I assume you just put the program in the
>same directory as your interperter but I'm not sure if you have to do
>something to the code. Thanks.



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

Date: Mon, 28 Jun 1999 15:51:08 GMT
From: dzuy@my-deja.com
Subject: Re: CGI.pm, hashes, passing by reference and two different results?
Message-Id: <7l85l7$ka7$1@nnrp1.deja.com>

In article <37777D66.D651AB06@tivoli.com>,
  John Warner <john.warner@tivoli.com> wrote:
> Ah ha!  I knew I must be missing something obvious.  Now for the $64
dollar
> question:  how do I fix it?  I've tried every way, except  the correct
way,
> I can think of to reference @row.
>
> John

	John,

	I ran your script on my apache server (run as a CGI) and it
	works fine.  The output appears like what you described as you
	ran it by the command line.

	Like I said, I think you should examine the way you CGI.pm is
	loaded or pre-loaded (as in mod_perl?) which can affect the name
	space of your script variables.

	Dzuy

>
> Ronald J Kimball wrote:
>
> > John Warner <john.warner@tivoli.com> wrote:
> >
> > > If I change the line
> > >             table({-border=>"none"},TR(td([@row]))),
> > > to
> > >             table({-border=>"none"},TR(td([\@row]))),
> > >
> > > Both the browser and command line return:
> > > <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
> > > <HTML><HEAD><TITLE>Untitled Document</TITLE>
> > > </HEAD><BODY><TABLE
> > >
BORDER="none"><TR><TD>ARRAY(0x10c57b8)</TD></TR></TABLE></BODY></HTML>
> > >
> > > Does anyone have an idea what is happening here?
> >
> > [\@row] is a reference to a reference to an array, but td() expects
a
> > reference to an array.  Thus, it stringifies the inner reference,
and
> > returns '<TD>ARRAY(0x10c57b8)</TD>'.
> >
> > --
> >  _ / '  _      /       - aka -
> > ( /)//)//)(//)/(   Ronald J Kimball      rjk@linguist.dartmouth.edu
> >     /
http://www.tiac.net/users/chipmunk/
> >         "It's funny 'cause it's true ... and vice versa."
>
> --
> John Warner                     Tivoli Systems Inc.
> Sales Support Engineer          9442 Capital Of Texas Hwy North
> Sales Infrastructure Group      Austin, TX 78759
> john_warner@tivoli.com
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 28 Jun 1999 16:07:20 GMT
From: ada@fc.hp.com (Andrew Allen)
Subject: Re: Comparing two associative arrays
Message-Id: <7l86jo$pk0$1@fcnews.fc.hp.com>

Andrew Allen (ada@fc.hp.com) wrote:
:   "@{[%hash1]}" eq "@{[%hash2]}"

: almost works (but can you explain why?).

Wow, 13 responses for 30 characters of code. I think I've come
up with a solution that removes the "almost" (assuming a strange-
enough $"):

  keys %hash1==keys %hash2 && "@{[values %hash1]}" eq "@{[@hash2{keys %hash1}]}"

of course, you're probably just better off (in the perl golf sense) with:

  keys %hash1==keys %hash2 && !grep($hash1{$_} ne $hash2{$_},keys %hash1)

Andrew


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

Date: Mon, 28 Jun 1999 12:41:57 -0400
From: jdc@johnc.connectionsusa.com (John Cochran)
Subject: Re: Comparing two associative arrays
Message-Id: <mk88l7.ttq.ln@johnc.connectionsusa.com>

In article <7l6ud5$o7d$1@monet.op.net>, Mark-Jason Dominus <mjd@op.net> wrote:
>I forgot to mention: Thanks to John Cochran, because without his post
>on this matter I probably wouldn't have thought about it.

You're welcome,

John



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

Date: Mon, 28 Jun 1999 11:41:54 -0500
From: sangeet.saurabh@guidant.com ("Saurabh, Sangeet (C) (STP)")
Subject: Connectivity to Oracle databae.
Message-Id: <258B1B3C175ED211BEA90008C75601A571451E@stpmsx11.stp.guidant.com>

Hi,
    I am new to Perl, I need some help on how to connect to Oracle database
from Perl script. I know that there are some Perl modules available which I
could use to connect to Oracle database and run my SQL queries. Can somebody
please let me know  where I could get help on this.    

BTW I need to write Perl scripts which would contain Insert/Update/Inquiry
SQLs for Oracle database. 

thanks,
Sangeet Saurabh



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

Date: 28 Jun 1999 13:23:46 -0400
From: groenvel@cse.psu.edu (John D Groenveld)
Subject: Re: Connectivity to Oracle databae.
Message-Id: <7l8b32$hpj$1@grolsch.cse.psu.edu>

http://www.cpan.org/modules/00modlist.long.html
John
groenveld@acm.org


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

Date: 28 Jun 1999 09:21:28 PDT
From: rdm@cfcl.com (Rich Morin)
Subject: Re: FAQ 2.12: Perl in Magazines
Message-Id: <rdm-2806990921230001@205.158.144.205>

In article <377345d0@cs.colorado.edu>, perlfaq-suggestions@perl.com (Tom
and Gnat) wrote:

>     The first and only periodical devoted to All Things Perl, *The Perl
>     Journal* contains tutorials, demonstrations, case studies, ...

I am also a big fan of TPJ, but I think you should also mention PerlMonth
(http://www.perlmonth.com).  They have published two issues so far and seem
to be doing a decent job.  Here are some article titles from Issues 1 & 2:

  An application with perl/Tk: tkgnuplot
  Creating Dynamic Pages With Embperl
  From Perl4 to Perl5
  Finding your files with File::Find
  Getting Started with Perl/Tk
  Interactive Perl Debugging under mod_perl
  Learning From Docs
  MacPerl Oddities: if ($^O eq 'MacOS')
  MacPerl: There's More than One Way to Do it
  Modules, References, Data Structures and Objects
  Parsing Command Line Options with GetOpt::
  Server Setup
  Some Practical Uses of eval
  Uses of Autoload
  What is mod_perl?

FWIW, the authors are a mixture of noted authorities and "new blood":

  Stas Beckman, Vicki Brown, Dave Cross, Mark-Jason Dominus,
  Stephen O. Lidie, Doug MacEachern, Steven McDougall, Slaven Rezic,
  Kurt Starsinic, Paul Vining

-r

P.S.  I may be biased by the fact that my spouse, Vicki Brown, has a
      column ("Script Different") in the new publication.

-- 
Canta Forda Computer Laboratory       | Prime Time Freeware - quality 
UNIX consulting, training, & writing  | freeware at affordable prices
+1 650-873-7841                       | +1 408-433-9662   -0727 (Fax)
Rich Morin, rdm@cfcl.com              | www.ptf.com, info@ptf.com


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

Date: Mon, 28 Jun 1999 09:31:33 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: FAQ 3.23: How can I compile Perl into Java?
Message-Id: <3777A365.31C340A9@mail.cor.epa.gov>

Tom Christiansen wrote:
> [snip of header]
>   How can I compile Perl into Java?
> 
>     You can't. Not yet, anyway. You can integrate Java and Perl with
>     the Perl Resource Kit from O'Reilly and Associates. See
> [snip of rest]

Has anyone come up with a reason *why* you would want to compile
a Perl program into Java?  Not an excuse, but a real reason that
actually makes sense?

Just wondering, because I haven't found one yet.  I seldom have
a need for a slower, less portable, less maintainable, less
functional solution.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 28 Jun 1999 10:20:26 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: FAQ 3.23: How can I compile Perl into Java?
Message-Id: <m13dzc8co5.fsf@halfdome.holdit.com>

>>>>> "David" == David Cassell <cassell@mail.cor.epa.gov> writes:

David> Has anyone come up with a reason *why* you would want to compile
David> a Perl program into Java?  Not an excuse, but a real reason that
David> actually makes sense?

To make toys that work client-side in a web situation.  For those that
want to put a lot more sizzle than steak into a marketing
situation. :)

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Mon, 28 Jun 1999 09:45:22 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How to start a thread in Perl
Message-Id: <3777A6A2.6156180D@mail.cor.epa.gov>

osman durrani wrote:
> 
> Hi people,
>  could anyone tell me how to do start a function in a thread in perl ?.I
> have perl on NT and cant do a fork.

Depending on what you want, you could try Win32::Process::Create,
which comes with ActiveState Perl.  If that doesn't meet your needs 
and you can't wait a few months for ActiveState to patch fork() into
their Perl, you can:
[A] go with cygwin32 and install your own Perl;
[B] go with linux    and install your own Perl;
[C] become close friends with Bill Gates and get him to direct
his minions to fix this for you personally.

Answer [C] would have additional benefits, if you can swing it.  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 28 Jun 1999 16:02:05 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: Linux better than perl?
Message-Id: <10Nd3.118$6M6.40032@news.shore.net>

Nedret <nedred@my-deja.com> wrote:
: In article <7l6lmt$vio$10@newsfeed.smartt.com>,
:   joey@hecnyyvr.com (J.Y.) wrote:
:> Linux better than perl?
:> -JY
:>
:>

: - What is the difference between the crocodile?
: - The crocodile is longer than green.

I thought it was "One leg is both the same."

--Art
-- 
--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: Mon, 28 Jun 1999 13:46:56 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: Linux better than perl?
Message-Id: <3777B510.BD6E0D9B@prism.gatech.edu>

Henry Vermeulen wrote:
> 
> Nedret wrote:
> 
> > In article <7l6lmt$vio$10@newsfeed.smartt.com>,
> >   joey@hecnyyvr.com (J.Y.) wrote:
> > > Linux better than perl?
> >
> > - What is the difference between the crocodile?
> > - The crocodile is longer than green.
> >
> > :-)
> >
> > --
> > Nedret
> 
> What's the difference between a dead bird?
> 
> The one leg has the same lenght!
> 
> Henry


What is the difference between one sparrow?

That it has two legs equally long, especially the left one.



andy!


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

Date: Mon, 28 Jun 1999 17:40:50 GMT
From: scott_mark@my-deja.com
Subject: Looking For A Perl Programmer
Message-Id: <7l8c30$n9r$1@nnrp1.deja.com>

Hello

I'm looking for a Perl programer that offers resonible rates for a
project or a 50/50 split on the money made from this project.

Here is what we need. A program that can grab information from
different databases and put into a page span ( Like you would see from
a search engine). we need to link this to a affiliate program that will
track the searches done on the databases that we can pay by search.

If you are intrested please send email: computel @ yahoo.com
Note: remove spaces in email address to reply


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Mon, 28 Jun 1999 17:30:02 +0100
From: "Dann-o" <druttle@gb.pepperl-fuchs.com>
Subject: Multiple Mail Messages from Perl
Message-Id: <3777b177.0@news2>

I'm using perl to read data from a text file on a Linux server.
The @Litrequests is an array that holds 7 seprate literature requests
(collected via a web form and then dumped to the server).

The code below works, but I receive 6 mail messages all with the same
content, but messages 3 to 6 contain an extra byte of information!!

Does anyone know why?

open (MAIL, "|/usr/sbin/sendmail -t");

print MAIL "To: someone\@someserver.co.uk\n";
print MAIL "From: log_system\@sourceserver.com\n";
print MAIL "Subject: Literature Requests\n\n";

print MAIL "@Litrequests";

close (MAIL);

thanks
Danny





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

Date: Mon, 28 Jun 1999 21:01:18 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: Newbie question (Perl within a C program)
Message-Id: <7l99gh$4323@news.cyber.net.pk>

Pierre-Michel Ansel <pierre-michel.ansel@steria.fr> wrote in message
news:377794EC.7A98E9B5@steria.fr...
> Hello,
>
> I would like to execute a Perl script from within an executable
> (C language).
> - First question : is it possible? do I need special packages or
>     libraries?

chmod script to 755, and execute a system() call from C program.

To embed a perl program into C see perlembed man page.

perl.h (comes with perl)

> - Second question : what kind of data structures can be exchanged
>     between the Perl script and the executable?. Are there
>     limitations (type of return value ...).

You can get the output of perl into your C program, but I don't know
how (i am not very good at C)

>
> Best regards.
>
>
> Pierre-Michel Ansel




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

Date: Mon, 28 Jun 1999 16:05:19 GMT
From: "Shaddy International Ltd." <shaddy@shaddy.com>
Subject: Outputting Search results in parts (like yahoo)
Message-Id: <37779CFC.E85D5C95@shaddy.com>

This is a multi-part message in MIME format.
--------------C706238E1B53206BDCCCD5EC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hey people
I'm looking for a way to display the results of a search in a web
browser like yahoo and other search pages do e.g matchs 1-20 then matchs
21-40.
Currently I have the records in my data file that match the search
beening put into a text delimited file. Then a display the lines outta
that file with a while loop.
Thi cause wayyyy too much data to be downloads to the browser at once.
I'm looking for a way I can display the first 20 lines of the file and
then when the user wants to by clicking a hypertext link they can get
the next 20 matchs.

Is this possible in perl
Please is you have some info it would be great.


Jason
sova0001@algonquinc.on.ca

--------------C706238E1B53206BDCCCD5EC
Content-Type: text/x-vcard; charset=us-ascii;
 name="shaddy.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for Shaddy International Ltd.
Content-Disposition: attachment;
 filename="shaddy.vcf"

begin:vcard 
n:;Shaddy Int'l Marketing LTD.
x-mozilla-html:FALSE
version:2.1
email;internet:shaddy@shaddy.com
x-mozilla-cpt:;0
fn:Shaddy Int'l Marketing LTD.
end:vcard

--------------C706238E1B53206BDCCCD5EC--



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

Date: Mon, 28 Jun 1999 17:12:32 GMT
From: jalex@pobox.com (J Alex)
Subject: perl mongers in Columbus, OH
Message-Id: <377babc6.11658622@nntp.service.ohio-state.edu>

I was at YAPC in Pitt this past week and noticed that I couldn't find
anyone from COlumbus OH there.  COME ON!!  Columbus is a huge
technical place.  You can't have THAT many people who program and work
on software projects and not have a few perl geeks.

If any of you know any perl mongers in Columbus OH, email me or
something.  I can start the section if it's not here, but 4 people are
registered on www.pm.org from Columbus.  (counting me)  If I don't
hear from anyone in a week or so, I am going to act like there is no
perl monger group yet started here, and start it myself.


--Jason Alexander
jalex@pobox.com



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

Date: 28 Jun 1999 10:49:51 PDT
From: "Alex Augot" <alexaugot@future-wave.com>
Subject: Perl redirection script question
Message-Id: <7l8cjv$mb2@journal.concentric.net>

Hi.
I'm currently trying to solve a problem that I have with a few clients and
their domain names.  I have an account on a server, with a nice 700 meg
limit, but my provider won't let me divide up accounts so they can be used
with domain names.  They only let me "park" domain names, which means every
domain name I park redirects back to my main page. (ie. Everyone who types
in www.parrealtygroup.com will get my main page at www.future-wave.com )
What I am wondering, is if there are any scripts out there that can tell
what name request is being made, and then redirect to a sub dir.  I know you
can emulate 3rd lv domains somewhat simply, so is this realistic?

If there are no scripts out there like that, how would I go about writing
one.  I'm pretty much a beginner at perl, but I think I could get it to work
if I tried.

-Alex Augot





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

Date: Mon, 28 Jun 1999 15:58:45 GMT
From: hamed53@my-deja.com
Subject: please help! regular expression!
Message-Id: <7l863d$kgh$1@nnrp1.deja.com>

hi
can you help me on this please, i am not very good at regular
expressions :)
i have this string:
$mytext  = "-f-hamed-f- -e-hello-e- -f-omid-f- -e-bye-e-";
as you can see the texts are placed beetween 2 characters: (-e-,-f-)
like this:
-f-hamed-f- or -e-hello-e-
i want to change every character in the format -f- to their replace
characters: for example
change the h to 1
i know i can do this by :
$mytext  =~ s/h/1/g; or $mytext  =~ s/h/2g;
they characters inside each -f-(.*)-f is variable, so i dont know what
it is, it can be -f-good-f-
after i changed all the character inside each -f-(.*)-f- i would remove
the -f- and just write the characters which i have replaces (although
the new word)
but also i want to remove all the -e- and just leave the text in
between them!
so at the end i would have something like this:
my replacement chars:
$mytext =~ s/h/q/g;
$mytext =~ s/a/w/g;
$mytext =~ s/m/t/g;
$mytext =~ s/e/y/g;
$mytext =~ s/d/k/g;
$mytext =~ s/i/u/g;
$mytext =~ s/o/l/g;
my string at the end would be:
$mytext  = "qwtyk hello ltuk bye";
i might have N number of -e- and/or -f-
by the way e represents english, f represents farsi, so that all the
words insite the -f- is farsi and all the words inside the -e- is
english language
thats y i want to translate all the letters inside the -f- :)
thanks
hamed


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Mon, 28 Jun 1999 20:58:24 +0500
From: "Faisal Nasim" <swiftkid@bigfoot.com>
Subject: Re: random numbers ?
Message-Id: <7l99b2$4322@news.cyber.net.pk>

Use srand; in your program.

Optimized version:

# begin

srand;
$range = 47;

for ( 1 .. 6 )
{
  my $num = int rand $range;
  redo if exists $tmp { $num };
  $tmp { $num } = 1;
  push @num , $num;
}

print join ',' , sort { $b <=> $a } @num; #descending sort

__END__

--
Faisal Nasim (the Whiz Kid)
Web: http://wss.hypermart.net/
AOL: Whiz Swift  ICQ: 4265451
FAX: (815) 846-2877

charlie <greatest@pacific.net.hk> wrote in message
news:37778F93.A940EE85@pacific.net.hk...
>
>   Hello all, i am new to perl and have a lot don't understand.
>   i try to generate six numbers out of 1 to 47 randomly by
>   the code below, but it generate the same six numbers every time.
>   THANK YOU !
>
>  #!/usr/local/bin/perl -w
> $drawn = 0;
> $range = 47;
> DRAWN:while ($drawn < 6){
> $num[$drawn] = int(rand $range) + 1;
> $check = scalar(@num);
> if ($check > 1){
>    for ($compare=0; $compare < ($check - 1); $compare++ ){
>         if ($num[$drawn] == $num[$compare] ){
>         print "having same number twice.\n";
>         redo DRAWN;                         }
>                                                          }
>                 }
>                         }  continue {
>                            $drawn++;}
> @num = sort {$b <=> $a} @num;
> print "@num\n";
>
>




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

Date: Mon, 28 Jun 1999 16:15:02 GMT
From: marcel.grunauer@lovely.net (Marcel Grunauer)
Subject: Re: random numbers ?
Message-Id: <377a9ed6.25604367@enews.newsguy.com>

On Mon, 28 Jun 1999 23:06:59 +0800, charlie <greatest@pacific.net.hk>
wrote:

>
>  Hello all, i am new to perl and have a lot don't understand.
>  i try to generate six numbers out of 1 to 47 randomly by
>  the code below, but it generate the same six numbers every time.
>  THANK YOU !
>
> #!/usr/local/bin/perl -w
>$drawn = 0;
>$range = 47;
>DRAWN:while ($drawn < 6){
>$num[$drawn] = int(rand $range) + 1;
>$check = scalar(@num);
>if ($check > 1){
>   for ($compare=0; $compare < ($check - 1); $compare++ ){
>        if ($num[$drawn] == $num[$compare] ){
>        print "having same number twice.\n";
>        redo DRAWN;                         }
>                                                         }
>                }
>                        }  continue {
>                           $drawn++;}
>@num = sort {$b <=> $a} @num;
>print @num\n;
>

Here's a more idiomatic version of the lottery script:

#!/usr/bin/perl -w

use strict;

my $range = 47;
my @numbers = (1..$range);
my @num;

foreach (0..5) {
	$num[$_] = splice(@numbers, int rand($range-$_),1);
}
@num = sort { $a <=> $b } @num;

print join(',',@num);



Good luck!

Marcel



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

Date: 28 Jun 1999 10:25:16 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: random numbers ?
Message-Id: <m1yah46xvn.fsf@halfdome.holdit.com>

>>>>> "Faisal" == Faisal Nasim <swiftkid@bigfoot.com> writes:

Faisal> Use srand; in your program.
Faisal> Optimized version:

well, first off, srand's not necessary in 5.004 and above.

Second, there's an even faster way to do what you want.

Faisal> # begin

Faisal> srand;
Faisal> $range = 47;

Faisal> for ( 1 .. 6 )
Faisal> {
Faisal>   my $num = int rand $range;
Faisal>   redo if exists $tmp { $num };

This is scary.

Faisal>   $tmp { $num } = 1;
Faisal>   push @num , $num;
Faisal> }

Faisal> print join ',' , sort { $b <=> $a } @num; #descending sort


Let's do this:

    ## chose 6 draws of 47, non-replacing:
    @deck = (1..47);
    @draws = ();
    for (1..6) {
      push @draws, splice @deck, rand @deck, 1;
    }

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Mon, 28 Jun 1999 15:49:00 GMT
From: j_a_p@my-deja.com
Subject: Skipping lines from my text file
Message-Id: <7l85h7$k7h$1@nnrp1.deja.com>

I have written a simple search engine that basically compares two
elements and prints out the line if the element matches.  I am
comparring a user input from the web and a element in my textfile.

if ($input_data[0] eq $str2)  #this works
{
    foreach $line (@output_data)
    {
        @field_data = split(/::/, $line);
        if($input_data[1] =~ /$field_data[4]/i)
        {

           if($field_data[1] eq ""){next;} #so I don't print empty lines
        print "<tr><td>$field_data[0]</td><td>$field_data[1]</td><td>
$field_data[2]</td><td>$field_data[3]</td><td>$field_data[4]</td><td>
$field_data[5]</td><td>$field_data[6]</td><td>$field_data[7]</td></tr>
\n"; #prints out row in table form
        }
       else{next;}
    }
}
Input_data and str3 are two strings that get compared and if they match
then the next input data is compared. This is the part that is giving
me trouble.  $field_data[4] is an address that is compared with
input_data[1].  This works on some of the address but not all of them.
I don't really see a patern as to the ones that match or don't match.
My text file looks like this


text::text::text text::text text::text::text::text

There are about 1500 lines that follow this format some are larger that
others.  Does anyone know why this some address wouldn't be
matched.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 28 Jun 1999 10:28:31 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Skipping lines from my text file
Message-Id: <m1u2rs6xq8.fsf@halfdome.holdit.com>

>>>>> "j" == j a p <j_a_p@my-deja.com> writes:

I didn't read the rest of your post, but this line looks the scariest:

j>         print "<tr><td>$field_data[0]</td><td>$field_data[1]</td><td>
j> $field_data[2]</td><td>$field_data[3]</td><td>$field_data[4]</td><td>
j> $field_data[5]</td><td>$field_data[6]</td><td>$field_data[7]</td></tr>
j> \n"; #prints out row in table form

This would be much simpler as:

	print
		"<tr>",
		map("<td>$_</td>", @field_data),
		"</tr>";

Or, if you're using CGI.pm (which you probably should be):

	print Tr(td(\@field_data));

print "Just another Perl hacker,"

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Mon, 28 Jun 1999 17:49:09 GMT
From: jchum@jps.net (Jonathan Chum)
Subject: Somebody Help Me!
Message-Id: <3777b55c.3112036@news.jps.net>

Okay, here's what I got so far. I am a newbie to Perl programming.
I use the LWP module to get a url content. Now I need to parse
the HTML to whatever I want. The problem is that, it doesn't seem
to parse at all.

Here's a code snippet:

# Loop through the results pulling out each link.	
	if ($total) {	
		while ($results =~ m#<a
href="([^"]+)">([^<]+)</a>#sog) {
			($url, $title) = ($1, $2);
			$output .= qq~<p><a href="$url">$title</a>~;
		}
	}
}

The results of the get url is in the variable $results and hopefully
it should extract each link out and put it into the variable $output.
What am I doing wrong?  I am trying to get a modification for Links
2.0 (Gossamer-threads.com) as soon as possible. . .



Techdevelopers
http://www.techdevelopers.com
CGI, ASP, DHTML, FLASH, and more


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

Date: 28 Jun 1999 17:45:15 GMT
From: fl_aggie@thepentagon.com (I R A Aggie)
Subject: Re: Unlink == delete files? Why (on earth) is it called unlink?
Message-Id: <slrn7nfd9o.4cj.fl_aggie@thepentagon.com>

On Mon, 28 Jun 1999 15:52:39 GMT, Scratchie <upsetter@ziplink.net>, in
<bTMd3.115$6M6.40032@news.shore.net> wrote:

+ The reasons have to do (I believe) with the file system used by Unix and
+ its variants (which some on this ng apparently believe is so obvious and
+ self-evident that it doesn't need to be described).

Of course, since the underlying library is already documented elsewhere.
One may obtain an encyclopedia, but the encyclopedia does not contain the
sum of human knowledge, does it? Nor does perl provide you with deep
background reading of the underlying unix base.

Any way, a quick trip to any unixen provides us with this:

% man 2 unlink

UNLINK(2)           Linux Programmer's Manual           UNLINK(2)

NAME
       unlink - delete a name and possibly the file it refers to
                ^^^^^^^^^^^^^     !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

James


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

Date: Mon, 28 Jun 1999 09:54:55 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Verifying an existing file with a PERL web script
Message-Id: <3777A8DF.DB32EF6@mail.cor.epa.gov>

frm_79@my-deja.com wrote:
> 
> Hello,
> 
> I have a script that needs to verify that a file exists in either Excel
> format (.xls) or Word format (.doc) inside a directory, and give a link
> to it.  What I have it do is open the file with the 'open
> (filehandle,filename)' command inside an if loop as follows  (I'm

You're not being lazy enough.  Look up the -X operators in the
perlop pages, and check out in particular -e .

> assuming that open returns TRUE if it opens the file and FALSE if it
> doesn't):

You're *assuming* this?  Isn't that kind of risky?  Why don't
you just read the perlfunc pages and make sure?
 
>      $filename = "file";
>      if (open(FILE1,"../$filename.xls"))
>          { print "this file exists in .xls format";}
>          elsif (open(FILE1,"../$filename.xls"))
>              { print "this file exists in .doc format";}
>                  else { print "this file does not exist in either .xls
> or .doc format";}
> 
> This works fine if I run it in manually, but it doesn't if I run it
> from the web.  It goes to ELSE and tells me the file doesn't exist even
> [snip]

Okay, the real problem here is not Perl-related.  It is your
web server.  You're using a relative apth to your file.  But
IIS (and plenty of other web servers) change the environment
of the CGI process.  It runs your script as a different user
[probably user nobody] from a different directory.  So you'll
have to: 
[1] specify the 'absolute' path instead; and
[2] make sure that the permissions on your files are suitable
for whatever you want to do next.

If you need to open() those files for reading or writing,
you'll want to check that you open() succeeded, and if not,
you'll want to look at the special variable $! to see why not.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 28 Jun 1999 12:47:20 -0400
From: Johan Kullstam <kullstam@ne.mediaone.net>
Subject: Re: Viral matters [completely off-topic]
Message-Id: <uvhc8z2zr.fsf@res.raytheon.com>

Dan Carson <dbc@tc.fluke.com> writes:

> On 24 Jun 1999, Dale Henderson wrote:
> 
> >      I am very aware of why there are few to no virus written for Unix
> >      systems. It is because it would be impractical. As I've said
> >      before, the only way to do any real damage on a Unix box is with
> >      root access. And the practicality of hacking root in a virus is
> >      nil. 
> 
> Unfortunately, "hacking root" is getting more practical all the time.  For
> some reason, some people want Linux to "compete" with Microsoft.  So in the
> interest of making Linux "easy to use", the Standard Operating Procedure
> is becoming:
> 
> 1.  Download anything you see on the net with a '.rpm' extension.
> 
> 2.  su root.
> 
> 3.  Type rpm -whatever.
> 
> 4.  Voila!  Something happened!  I have no idea what, but whatever it was,
>     it ran as root!

true enough.  however there's a good number of people doing

1) download anything you see on the net with a .tar.gz extension.
2) tar xvzf whatever
3) cd whatever
4) make
5) su root.
6) make install

you can have the build create whatever binaries you like.  i do not
sift through all the source of everything i compile.  i do not expect
most people do either.

if you simply assume that people are using i386 linux, it'd be a snap
to include a trojan horse binary (statically linked for maximum
portability) to be installed at the make install step.  scripting
languages like perl are reasonably portable and could wreak havok as
well.  this could trap a number of unsuspecting people.

granted, these types of shennanigan would be caught fairly early by
someone scrutinizing the sources and an alert would go out.  however,
just because you do not use rpm doesn't make you safe.

remedies such as downloading from trusted ftp sites and using pgp
signatures apply to any format including both .tar.gz and .rpm.

> Now maybe /bin/ls is suid root and does something in addition to the
> standard functionality.
> 
> Am I just being paranoid?

just because you're paranoid doesn't mean they really aren't out to
get you. ;-)

-- 
johan kullstam


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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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