[13950] in Perl-Users-Digest
Perl-Users Digest, Issue: 1360 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 12 12:05:38 1999
Date: Fri, 12 Nov 1999 09:05:16 -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: <942426315-v9-i1360@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 12 Nov 1999 Volume: 9 Number: 1360
Today's topics:
Re: Aack Auto-Responder... <lee@insync.net>
Re: Can Perl Modules help me? (Kragen Sitaker)
Can't locate object method <einarth@srstudios.is>
CHMOD for Net::FTP. Help, cool hackers ! <mwiz@mail.ru>
Re: CHMOD for Net::FTP. Help, cool hackers ! (Anno Siegel)
Re: CHMOD for Net::FTP. Help, cool hackers ! <dan@tuatha.sidhe.org>
Re: CHMOD for Net::FTP. Help, cool hackers ! <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Re: Click the banner, get the click counted, and go to (www.www2.internetpros.com)
Re: Debugging CGI under NT... <murat.uenalan@sietec.de>
Re: freeing memory timfi@my-deja.com
Re: freeing memory (Anno Siegel)
Function to calculate a 30-day expiration date rancorr@hotmail.com
Re: Function to calculate a 30-day expiration date (Michael Budash)
Re: Function to calculate a 30-day expiration date <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Re: Function to calculate a 30-day expiration date <sariq@texas.net>
Re: funny behaviour of Perl <lr@hpl.hp.com>
Re: GURU HELP NEEDED FOR NEWBIE <sariq@texas.net>
Re: Help needed fast please <chris@chrismail.connectfree.co.uk>
Help with collecting -w information! <khowe@performance-net.com>
Re: Help with collecting -w information! <jeffp@crusoe.net>
Re: Help with collecting -w information! (Tad McClellan)
Re: Help woth perl <chris@chrismail.connectfree.co.uk>
Re: how to create a random id? (Kragen Sitaker)
Re: how to create a random id? <sariq@texas.net>
Re: HOW TO CUT FILE???? (Kragen Sitaker)
Re: mySql, DBI, and pop-up menus <latsharj@my-deja.com>
Re: Need help with arrays. <seshadri@ptc.com>
Re: Need help with editing a word in a flat text file.. (Kragen Sitaker)
Re: Perl parseing (Tad McClellan)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 12 Nov 1999 09:30:18 -0600
From: "Lee Sharp" <lee@insync.net>
Subject: Re: Aack Auto-Responder...
Message-Id: <coWW3.15396$Ph7.111503@insync>
Kragen Sitaker wrote in message
<2TMW3.461$YI2.26152@typ11.nn.bcandid.com>...
|In article <3tMW3.303$ZU3.19733@wagner.videotron.net>,
|Joe Dalton <genpenn@hotmail.com> wrote:
|>i'm looking for a perl script called Aack Auto-Responder... can anyone
|>help??
|No. Please don't post here unless you have a question (or an answer)
|about programming in Perl.
Of all the groups I read, only the Perl folks will spend so much energy
being completely unhelpful. Assuming you have tried cpan, try
http://www.technotrade.com/cgi/ http://www.cgi-resources.com/
http://cgi.resourceindex.com/Programs_and_Scripts/Perl/
http://www.perlarchive.com/index.shtml Good luck.
Lee
--
SCSI is *NOT* magic. There are *fundamental technical reasons* why it is
necessary to sacrifice a young goat to your SCSI chain now and then. * Black
holes are where God divided by zero. - I am speaking as an individual, not
as a representative of any company, organization or other entity. I am
solely responsible for my words.
------------------------------
Date: Fri, 12 Nov 1999 14:29:06 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Can Perl Modules help me?
Message-Id: <SuVW3.884$YI2.75674@typ11.nn.bcandid.com>
In article <HTCW3.257$zG1.12024@news1.mts.net>,
Peter <peterclones@yahoo.com> wrote:
>I've made a web chatroom using Perl cgi and it works fine, but it gets
>sluggish as more people enter the room of course. The script I have writes
>messages to a common text file, then is read by all the users every few
>seconds. I don't know anything about modules, so I'm wondering if there's
>someway modules could speed up this process? If so, which ones should I be
>looking at and how can I get help implementing them. Just need to be
>pointed in the right direction.
You will probably want to build a chat server, which forwards input
messages on any of its connections to all of its connection (or a
subset thereof). This will scale the same as your current solution
(work to be done will be proportional to the number of messages input
plus the number of messages output), but the constant factors will be
much smaller. As a special bonus, people will get messages
immediately.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Fri, 12 Nov 1999 13:50:03 +0000
From: Einar =?iso-8859-1?Q?=DE=F3r?= Einarsson <einarth@srstudios.is>
Subject: Can't locate object method
Message-Id: <382C1B0B.F67DA455@srstudios.is>
OK, I'm relatively new to perl, but I have searched the web, searched
through the faq etc, etc, etc.
I've been hacking my way through a perl script to access pop mail and
display a message as a web page.
Now, most of the time I get an error msg "Can't locate object method
"new" via package "MIME::Parser" when entering the MIME parsing
routines.
Now, this is:
a) utterly wrong because
i) it's inherited from ParserBase and
ii) Because I've also tried to implement it explicitly in
MIME/Parser.pm
and
b) (more important) not consistant. When I click the link to display
the message I sometimes get the message displayed as intented and
sometimes not. Current solution is to repeatedly click link, click back,
click link, etc. etc. until it displays itself, usually after ca. 3-6
attempts.
All required modules are installed as per documentation.
the @INC is correct.
perl -w & use diagnostics don't generate anything even remotly relevant.
Can anyone give me a hint as what could be causing this? or a theory?
Could it have something to do with a file locking mechanism in the
kernel or the web server? I'm out of ideas, and don't know how to debug
this since I can't get to that portion of the code in offline mode (then
it fails to locate object method "new" via package Net::POP3 (sigh))
Any hints, tips, whatever would be most welcome.....
P.S. If this is indeed a stupid question, who's answer should be dead
obvious to anyone with half a brain (or a compatible device), feel free
to flame me, and I shall go and stand in the corner with a shameful
expression my entire lunch break...
--
Cheers
Einar Th.
------------------------------
Date: Fri, 12 Nov 1999 14:05:56 GMT
From: MetaWizard <mwiz@mail.ru>
Subject: CHMOD for Net::FTP. Help, cool hackers !
Message-Id: <80h6s2$n56$1@nnrp1.deja.com>
I need realization of CHMOD method for Net::FTP.
Please, help me!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 12 Nov 1999 15:32:37 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: CHMOD for Net::FTP. Help, cool hackers !
Message-Id: <80hbul$qq1$1@lublin.zrz.tu-berlin.de>
MetaWizard <mwiz@mail.ru> wrote in comp.lang.perl.misc:
>I need realization of CHMOD method for Net::FTP.
>Please, help me!
There is no CHMOD. If you want chmod, you'll find a description
via perldoc -f chmod.
Anno
------------------------------
Date: Fri, 12 Nov 1999 15:41:41 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: CHMOD for Net::FTP. Help, cool hackers !
Message-Id: <VyWW3.3141$c06.28283@news.rdc1.ct.home.com>
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> MetaWizard <mwiz@mail.ru> wrote in comp.lang.perl.misc:
>>I need realization of CHMOD method for Net::FTP.
>>Please, help me!
> There is no CHMOD. If you want chmod, you'll find a description
> via perldoc -f chmod.
And there's no chmod at all under FTP. You have to do a quot() or site()
depending on the FTP server and hope for the best.
Dan
------------------------------
Date: Fri, 12 Nov 1999 07:50:01 -0800
From: Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Subject: Re: CHMOD for Net::FTP. Help, cool hackers !
Message-Id: <000b8d9b.df2e5124@usw-ex0101-006.remarq.com>
In article <80h6s2$n56$1@nnrp1.deja.com>, MetaWizard <mwiz@mail.ru>
wrote:
> I need realization of CHMOD method for Net::FTP.
As the underlying ftp protocol has no chmod command (as far as I can
discover), I don't see what you're asking for. Could you outline what
you envisage such a CHMOD method doing?
In other words, tell us what you want to do rather than how you _think_
it could be done by adding a feature to a module.
Regards
--
Mark B
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Fri, 12 Nov 1999 15:17:03 GMT
From: mpm@unix2.megsinet.net (www.www2.internetpros.com)
Subject: Re: Click the banner, get the click counted, and go to destination (CGI)?
Message-Id: <slrn82oc4a.30.mpm@unix2.megsinet.net>
In article <3827be19.216385406@news.supernews.com>, Kendar wrote:
>I need to be able to do the following:
>
>When the user clicks into a banner, he/she activates a perl/cgi
>program which registers the click for that banner and sends the
>user to the supposed destination. Does anyone know of such a cgi
>program?
>
>Thanks!
>
>medusa@beaute.org
In the HTML:
<A HREF="/path/to/cgi-bin/clickthrough.cgi?loc=www.sitename.com"><IMG
SRC="/path/to/images/picture.gif"></A>
The CGI script:
#!perl -w
use strict; use CGI; # CGI is your friend!
# Give the server something back first
print "Location: http://",param('loc'),"\n\n";
my $basedir = '/absolute/path/to/banner/data/files';
my $count; # used to record total clicks for this banner
my $loc = param('loc');
if (-e "$basedir/$loc") { # IF the data file exists for this banner:
open DATA, "$basedir/$loc"; # open the file,
$count = <DATA>; # read the numeric data, and
close DATA; # close the file.
} else { # OTHERWISE:
$count = 0; # there's no data yet, so start counting at 0
}
$count++; # increment the number of clithroughs by 1,
open NEW, ">$basedir/$loc"; # open the new data file,
print NEW $count; close NEW; # put the new data into it, and
exit; # we're done.
-----8<-----CUT HERE-----8<-----CUT HERE-----8<-----
That should give you a good start.
--Mike
------------------------------
Date: Fri, 12 Nov 1999 16:36:08 +0100
From: Murat Uenalan <murat.uenalan@sietec.de>
Subject: Re: Debugging CGI under NT...
Message-Id: <382C33E8.A4732BE@sietec.de>
There is another workarround: Simply pass your name=value pairs as simple
arguments like this:
perl cgiscript.pl todo=list name=nobody
This is more comfortable since your have a faster workflow.
Have fun,
M. Uenalan
Matthew Miller wrote:
> Hello,
>
> Me and a friend were debugging a CGI script under NT 4 and noticed some odd
> behavior. The first thing is that while debugging the script we entered the
> the name=value pairs for the CGI we couldn't get the script to continue. On
> my linux box typing cntl-d ends the input of the name-value pairs and the
> debugging session continues. We were using Activesite build 519. We couldn't
> find any way to continue execution. We found no clues under perldoc CGI.
> What is done at this point?
>
> The second problem is it seems that under NT perl doesn't support command
> line arguments. Regardless of the number of command line arguments #$ARGV
> always equals -1! I wrote a test script and seen it for my self, I wouldn't
> have thought it otherwise.
>
> So whats going on? Other than doing this on NT? btw we got the debugging
> done by telneting to my machine and doing the work
>
> Thanks, Matthew
>
> reply here, to email edit my address.
>
> --
> A prohibitionist is the sort of man one wouldn't care to drink with --
> even if he drank. -- H.L. Mencken
------------------------------
Date: Fri, 12 Nov 1999 15:25:00 GMT
From: timfi@my-deja.com
Subject: Re: freeing memory
Message-Id: <80hbg7$qlm$1@nnrp1.deja.com>
In article <80gnsa$qqj$1@pegasus.csx.cam.ac.uk>,
mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:
> Tad McClellan <tadmc@metronet.com> wrote:
> >On Thu, 11 Nov 1999 19:10:24 GMT, timfi@my-deja.com <timfi@my-
deja.com> wrote:
> >
> >>What is the best way to free memory for a complex data structure,
i.e.
> >>hash of hashes of hashes?
> >
> > %hash = (); # and let garbage collection do its job
>
> With one small qualification: Garbage collection won't retrieve
> looped data structures, such as
>
> $hash{key} = \%hash;
>
> But you're probably not doing that.
>
> Mike Guy
>
Actually, that is what I am doing. That is what I meant by "hash of
hashes of hashes". A complex data structure of nested hashes.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 12 Nov 1999 15:42:34 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: freeing memory
Message-Id: <80hcha$qsv$1@lublin.zrz.tu-berlin.de>
<timfi@my-deja.com> wrote in comp.lang.perl.misc:
>In article <80gnsa$qqj$1@pegasus.csx.cam.ac.uk>,
> mjtg@cus.cam.ac.uk (M.J.T. Guy) wrote:
>> Tad McClellan <tadmc@metronet.com> wrote:
>> >On Thu, 11 Nov 1999 19:10:24 GMT, timfi@my-deja.com <timfi@my-
>deja.com> wrote:
>> >
>> >>What is the best way to free memory for a complex data structure,
>i.e.
>> >>hash of hashes of hashes?
>> >
>> > %hash = (); # and let garbage collection do its job
>>
>> With one small qualification: Garbage collection won't retrieve
>> looped data structures, such as
>>
>> $hash{key} = \%hash;
>>
>> But you're probably not doing that.
>>
>> Mike Guy
>>
>Actually, that is what I am doing. That is what I meant by "hash of
>hashes of hashes". A complex data structure of nested hashes.
No, that's not the problem. Note that the example $hash{key} = \%hash;
puts a reference to %hash into the very same %hash. That creates
problems for the garbage collector; arbitrary complex structures
without self-reference don't.
Anno
------------------------------
Date: Fri, 12 Nov 1999 15:49:37 GMT
From: rancorr@hotmail.com
Subject: Function to calculate a 30-day expiration date
Message-Id: <80hcuf$rul$1@nnrp1.deja.com>
I want to create a subroutine in Perl to calculate a 30-day expiration
date when given a starting date for this 30-day interval.
however, due to the fact that certain months have 30 days, others have
31 days -- and february has 28 days, sometimes 29 (due to leap year),
what would be the easiest way of coding this subroutine?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 12 Nov 1999 08:14:31 -0800
From: mbudash@wcws.com (Michael Budash)
Subject: Re: Function to calculate a 30-day expiration date
Message-Id: <mbudash-1211990814310001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article <80hcuf$rul$1@nnrp1.deja.com>, rancorr@hotmail.com wrote:
> I want to create a subroutine in Perl to calculate a 30-day expiration
> date when given a starting date for this 30-day interval.
>
> however, due to the fact that certain months have 30 days, others have
> 31 days -- and february has 28 days, sometimes 29 (due to leap year),
> what would be the easiest way of coding this subroutine?
easiest? use Date::Manip
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@wcws.com
------------------------------
Date: Fri, 12 Nov 1999 08:15:04 -0800
From: Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Subject: Re: Function to calculate a 30-day expiration date
Message-Id: <000b8d9b.e5b79037@usw-ex0101-006.remarq.com>
In article <80hcuf$rul$1@nnrp1.deja.com>, rancorr@hotmail.com wrote:
> I want to create a subroutine in Perl to calculate a 30-day
> expiration
> date when given a starting date for this 30-day interval.
> however, due to the fact that certain months have 30 days, others
> have
> 31 days -- and february has 28 days, sometimes 29 (due to leap
> year),
> what would be the easiest way of coding this subroutine?
Turn the start date into an internal date, add 30 days worth of
seconds, turn the result back into a normal date.
Module like Time::Local, Date::* and possibly POSIX could help - see
the docs for these.
--
Mark Bluemel
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Fri, 12 Nov 1999 10:10:58 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: Function to calculate a 30-day expiration date
Message-Id: <382C3C12.9C9217D4@texas.net>
rancorr@hotmail.com wrote:
>
> I want to create a subroutine in Perl to calculate a 30-day expiration
> date when given a starting date for this 30-day interval.
>
> what would be the easiest way of coding this subroutine?
use Date::Calc;
It's available at CPAN, as is Date::Manip, a larger alternative.
- Tom
------------------------------
Date: Fri, 12 Nov 1999 07:12:56 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: funny behaviour of Perl
Message-Id: <MPG.1295ce5448c35f2a98a1e9@nntp.hpl.hp.com>
In article <80gop3$2no$1@justus.ecc.lu> on 12 Nov 1999 10:05:23 GMT,
Stefaan A Eeckels <Stefaan.Eeckels@ecc.lu> says...
> In article <80gn54$l6q$1@gellyfish.btinternet.com>,
> Jonathan Stowe <gellyfish@gellyfish.com> writes:
> >
> > I was looking at some stuff on a machine at work and the files were all
> > rwx--x--x and they *did* work which came as somewhat of a suprise - I cant
> > remember what version of Unix it was though ... Pick one of SCO OpenServer
> > or Solaris.
>
> Typically, shell scripts (and Perl programs) need to be
> readable, compiled programs only need to be executable.
Perl programs invoked as:
perl foobar
need to be readable.
Perl programs invoked as:
foobar
need to be readable and executable.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 12 Nov 1999 08:58:32 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: GURU HELP NEEDED FOR NEWBIE
Message-Id: <382C2B18.5A1AF4FD@texas.net>
Kragen Sitaker wrote:
>
> My PERL script doesn't work. What's wrong?
>
Heh.
Was that the PERL script that said the 'Internet stock bubble' would
burst on 1999-11-08? ;)
Gotta admit, though, I thought you were prescient when the Microsoft
ruling came down...
- Tom
------------------------------
Date: Fri, 12 Nov 1999 16:28:22 -0000
From: "Chris" <chris@chrismail.connectfree.co.uk>
Subject: Re: Help needed fast please
Message-Id: <382c4e38.0@news2.cluster1.telinco.net>
I keep getting told Bad header=: http://blsoftpart.hypermart.net/sign_up.pl
all the time even with corrections shown
------------------------------
Date: Fri, 12 Nov 1999 10:25:43 -0400
From: "Kevin Howe" <khowe@performance-net.com>
Subject: Help with collecting -w information!
Message-Id: <psVW3.189677$5r2.430456@tor-nn1.netcom.ca>
I'm trying to make a simple web-based Perl Syntax Checker for our customers.
They type in the name of their script (ex: /path/to/script.pl) and my script
tests that script with the the -w tag, and prints the results to the screen.
The backtick operator works when there is no error, but when a syntax error
occurs the error/warning information gets stored somewhere else, not
returned, so I can't put it into a variable and print it.
How do I collect this information?
THE SCRIPT
--------------------------
use CGI ':standard';
$file = param('file');
$cmd = `perl -w $file`;
print "Content-type: text/html\n\n";
print $cmd;
Much appreciated,
KH
------------------------------
Date: Fri, 12 Nov 1999 10:21:15 -0500
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Help with collecting -w information!
Message-Id: <Pine.GSO.4.10.9911121017170.24181-100000@crusoe.crusoe.net>
[posted & mailed]
> I'm trying to make a simple web-based Perl Syntax Checker for our customers.
> They type in the name of their script (ex: /path/to/script.pl) and my script
> tests that script with the the -w tag, and prints the results to the screen.
Wow, someone asked almost this exact same question last month.
> The backtick operator works when there is no error, but when a syntax error
> occurs the error/warning information gets stored somewhere else, not
> returned, so I can't put it into a variable and print it.
"Somewhere else" is STDERR. You only get the STDOUT captured when you use
backticks. A solution is to use IPC::Open3, which you should already
have.
use IPC::Open3;
open3(\*WRITE, \*READ, \*ERRORS, "/usr/bin/perl", $filename) or
die "can't run /usr/bin/perl $filename: $!";
print "On STDOUT\n", map "\t$_\n", <READ>;
print "\nOn STDERR\n", map "\t$_\n", <ERRORS>;
close WRITE;
close READ;
close ERRORS;
perldoc IPC::Open3
--
MIDN 4/C PINYAN, USNR, NROTCURPI http://www.pobox.com/~japhy/
jeff pinyan: japhy@pobox.com perl stuff: japhy+perl@pobox.com
"The Art of Perl" http://www.pobox.com/~japhy/book/
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
PerlMonth - An Online Perl Magazine http://www.perlmonth.com/
------------------------------
Date: Fri, 12 Nov 1999 06:15:31 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Help with collecting -w information!
Message-Id: <slrn82ntmj.iv.tadmc@magna.metronet.com>
On Fri, 12 Nov 1999 10:25:43 -0400, Kevin Howe
<khowe@performance-net.com> wrote:
>I'm trying to make a simple web-based Perl Syntax Checker for our customers.
^^^^^^^^^^^^^^
But what you have below is a Perl Script Executer...
>They type in the name of their script (ex: /path/to/script.pl) and my script
>tests that script with the the -w tag, and prints the results to the screen.
^^^
It is not a tag.
It is a switch.
>The backtick operator works when there is no error,
The backtick operator also works when there is an error.
It is _your program_ that does not work when there is an error :-)
> but when a syntax error
>occurs the error/warning information gets stored somewhere else, not
>returned, so I can't put it into a variable and print it.
>How do I collect this information?
Perl FAQ, part 8:
"How can I capture STDERR from an external command?"
>THE SCRIPT
>--------------------------
>use CGI ':standard';
>$file = param('file');
>
>$cmd = `perl -w $file`;
Whoa nelly!
The crackers are gonna *love* you...
I would suggest `perl -cw $file` rather than running just
any old program, it might do Something Bad...
The command line _switches_ for perl are documented in the
'perlrun.pod' man page.
>print "Content-type: text/html\n\n";
^^^^
Backticks do not return HTML. You shouldn't lie to the browser
like that...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 12 Nov 1999 16:28:42 -0000
From: "Chris" <chris@chrismail.connectfree.co.uk>
Subject: Re: Help woth perl
Message-Id: <382c4e4b.0@news2.cluster1.telinco.net>
I keep getting told Bad header=: http://blsoftpart.hypermart.net/sign_up.pl
all the time even with corrections shown
------------------------------
Date: Fri, 12 Nov 1999 14:11:52 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: how to create a random id?
Message-Id: <IeVW3.867$YI2.73083@typ11.nn.bcandid.com>
In article <382BFE80.D8B0348B@linda.ch>, Fabian Rahm <fabian@linda.ch> wrote:
>Hi everybody
>
>I want to generate in perl a random id like e3479b76955is5349
>
>How can I make it?
Figure out what chars you want to include, figure out where you're
getting your randomness from (the TrulyRandom module? MD5 of stuff in
/proc?), generate a stream of random numbers, index into the list of
chars with each number in the stream, and finally join together the
results.
Something like
my @chars = ('a'..'z', 0..9); #UNTESTED
join '', map { $chars[randgenerator @chars] } 1..20; #UNTESTED
Note rand() won't give you enough randomness to make your example
random id very random.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Fri, 12 Nov 1999 09:11:24 -0600
From: Tom Briles <sariq@texas.net>
Subject: Re: how to create a random id?
Message-Id: <382C2E1C.B84EDEA7@texas.net>
Abigail wrote:
>
> $id = '=' x 17;
If there's one thing I've learned in the time I've been reading
Abigail's posts, it's that she's obsessed with the number 17.
Fess up, Abigail! What's the significance? IQ / 10? The age at which
you first (fill in the blank)ed?
Enquiring minds want to know!
- Tom
------------------------------
Date: Fri, 12 Nov 1999 14:16:54 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: HOW TO CUT FILE????
Message-Id: <qjVW3.873$YI2.73770@typ11.nn.bcandid.com>
In article <382BF4CC.CAEC3350@uninet.net.id>,
Danang Suharno <cinoban@uninet.net.id> wrote:
>How to cut file length in perl?
>
>In MSDOS I just write to a file with bytes writtten is ZERO!
Use the function TRUNCATE!
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Fri, 12 Nov 1999 14:01:39 GMT
From: Dick Latshaw <latsharj@my-deja.com>
Subject: Re: mySql, DBI, and pop-up menus
Message-Id: <80h6k0$n0t$1@nnrp1.deja.com>
In article <80fcva$kje$1@msunews.cl.msu.edu>,
"Davis Ford" <forddavi@pilot.msu.edu> wrote:
> Hello, I want to create a pop-up menu (drop-down list) html form
> object where the options for the list will come from a DBI query.
>
> $stm = $dbh->prepare("SELECT projName FROM project") or die "Unable to
> prepare sql: $dbh->errstr\n";
>
> then later...
>
> while (my $ref = $stm->fetchrow_arrayref)
> {
> @project = (\"%s\", $$ref[0];
> }
Inside the loop try:
push @project, $ref->[0];
assuming you want the first field in the row.
> print $q->popup_menu( -name=>'Projects', -values=>\@project,
-default=>'
> ' );
--
Regards,
Dick
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 12 Nov 1999 10:10:28 -0500
From: Seshadri <seshadri@ptc.com>
Subject: Re: Need help with arrays.
Message-Id: <382C2DE4.A81BFCCE@ptc.com>
John Iyezack wrote:
> I have this array filled with numbers. I need to be able to go through
> the array an take out all of the duplicate entrys and place them into
> another array. Seems strange and simple, but, I can't figure it out!
>
> Example:
>
> array 1:
> 1
> 1
> 2
> 2
> 3
> 1
> 2
> 2
> 1
> 2
> 5
> 3
> 4
> 2
> 1
> 3
> 9
> 8
>
> Array 2 would only have all the number listed once.
> 1
> 2
> 3
> 5
> 9
> 8
>
> I tired using a loop to test each the new array against the contents of
> the old one. But, it is just not working properly.
>
> Can anyone show me an easy way to do this, without me having the hudge
> cluster of a 1000 ifs and loops ?
> Thanks
>
> * Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
> The fastest and easiest way to search and participate in Usenet - Free!
Say @array1 is your array1. @array2 is your final array.
foreach (@array1) {
$seen{$_} = 1 if (! exists $seen{$_});
}
@array2 = keys %seen;
HTH
- Sesh
------------------------------
Date: Fri, 12 Nov 1999 14:13:24 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Need help with editing a word in a flat text file...
Message-Id: <8gVW3.868$YI2.73467@typ11.nn.bcandid.com>
In article <382c000b.97636024@news.inet4u.com>, Slim <group or email> wrote:
>and update and write back to the file
>
>[USER=editedName]
>Password=editedPass
>
>over top of the same place...
>
>I can't figure out how to replace a word in a file and save it without
>loosing the other infomation
>
>please help if you can... thanks"
perldoc -q insert says:
=head1 Found in /usr/local/lib/perl5/5.00503/pod/perlfaq5.pod
=head2 How do I change one line in a file/delete a line in a file/insert a line in the middle of a file/append to the beginning of a file?
Those are operations of a text editor. Perl is not a text editor.
Perl is a programming language. You have to decompose the problem into
low-level calls to read, write, open, close, and seek.
Although humans have an easy time thinking of a text file as being a
sequence of lines that operates much like a stack of playing cards -- or
punch cards -- computers usually see the text file as a sequence of bytes.
In general, there's no direct way for Perl to seek to a particular line
of a file, insert text into a file, or remove text from a file.
(There are exceptions in special circumstances. You can add or remove at
the very end of the file. Another is replacing a sequence of bytes with
another sequence of the same length. Another is using the C<$DB_RECNO>
array bindings as documented in L<DB_File>. Yet another is manipulating
files with all lines the same length.)
The general solution is to create a temporary copy of the text file with
the changes you want, then copy that over the original. This assumes
no locking.
$old = $file;
$new = "$file.tmp.$$";
$bak = "$file.orig";
open(OLD, "< $old") or die "can't open $old: $!";
open(NEW, "> $new") or die "can't open $new: $!";
# Correct typos, preserving case
while (<OLD>) {
s/\b(p)earl\b/${1}erl/i;
(print NEW $_) or die "can't write to $new: $!";
}
close(OLD) or die "can't close $old: $!";
close(NEW) or die "can't close $new: $!";
rename($old, $bak) or die "can't rename $old to $bak: $!";
rename($new, $old) or die "can't rename $new to $old: $!";
Perl can do this sort of thing for you automatically with the C<-i>
command-line switch or the closely-related C<$^I> variable (see
L<perlrun> for more details). Note that
C<-i> may require a suffix on some non-Unix systems; see the
platform-specific documentation that came with your port.
# Renumber a series of tests from the command line
perl -pi -e 's/(^\s+test\s+)\d+/ $1 . ++$count /e' t/op/taint.t
# form a script
local($^I, @ARGV) = ('.orig', glob("*.c"));
while (<>) {
if ($. == 1) {
print "This line should appear at the top of each file\n";
}
s/\b(p)earl\b/${1}erl/i; # Correct typos, preserving case
print;
close ARGV if eof; # Reset $.
}
If you need to seek to an arbitrary line of a file that changes
infrequently, you could build up an index of byte positions of where
the line ends are in the file. If the file is large, an index of
every tenth or hundredth line end would allow you to seek and read
fairly efficiently. If the file is sorted, try the look.pl library
(part of the standard perl distribution).
In the unique case of deleting lines at the end of a file, you
can use tell() and truncate(). The following code snippet deletes
the last line of a file without making a copy or reading the
whole file into memory:
open (FH, "+< $file");
while ( <FH> ) { $addr = tell(FH) unless eof(FH) }
truncate(FH, $addr);
Error checking is left as an exercise for the reader.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
The Internet stock bubble didn't burst on 1999-11-08. Hurrah!
<URL:http://www.pobox.com/~kragen/bubble.html>
------------------------------
Date: Fri, 12 Nov 1999 04:58:04 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Perl parseing
Message-Id: <slrn82np5c.33.tadmc@magna.metronet.com>
On Fri, 12 Nov 1999 01:31:53 GMT, teknik2000@my-deja.com
<teknik2000@my-deja.com> wrote:
>I am trying to split up the following string -
>
>&time=1999.11.03.13.03.12&X_PREF=_tst1&CT_AMID=34&
>DB_DATA=Alphabet|3_5
>
>I information I require is between the "=" and
>the follwing "&".
I hope that you are not doing URL decoding yourself (unless you
happen to be doing it correctly, which is rare :-)
> For example in the above I am
>after 4 components:
>1999.11.03.13.03.12
>_tst1
>34
>Alphabet|3_5
Uhh, that last one is NOT qq/between the "=" and the follwing "&"/
as there is no follwing "&" ...
>Does any have any ideas?
my @parts = /=([^&]*)(?:&|$)/g;
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
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 1360
**************************************