[13767] in Perl-Users-Digest
Perl-Users Digest, Issue: 1178 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 27 21:37:17 1999
Date: Wed, 27 Oct 1999 18:37:08 -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: <941074627-v9-i1178@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 27 Oct 1999 Volume: 9 Number: 1178
Today's topics:
Fetching array from dbm palan_mud@my-deja.com
File download script <carl.johansson@mbox201.swipnet.se>
Re: File download script <rootbeer@redcat.com>
Re: file manipulation II (Randal L. Schwartz)
Re: file manipulation II <lr@hpl.hp.com>
Re: file manipulation II <lr@hpl.hp.com>
Re: file manipulation II (Brett W. McCoy)
Re: file manipulation II makau@multimania.com
Re: file manipulation II makau@multimania.com
Re: file manipulation II (Michael Budash)
Re: file manipulation II (Ken Hirsch)
Re: file upload problem <ehpoole@ingress.com>
FindBin except for Modules??? <nospam@work.com>
Re: FindBin except for Modules??? <tlewis@gte.com.no.spam.please>
Re: FindBin except for Modules??? <tlewis@gte.com.no.spam.please>
Re: FindBin except for Modules??? <jeffp@crusoe.net>
Re: FindBin except for Modules??? <jeffp@crusoe.net>
Re: finding date and time <gellyfish@gellyfish.com>
Re: finding date and time <shmooth@yahoo.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 25 Oct 1999 19:42:23 GMT
From: palan_mud@my-deja.com
Subject: Fetching array from dbm
Message-Id: <7v2bqu$k30$1@nnrp1.deja.com>
Hi,
I came across something perplexing and hoping you can help me out. I
store an array into a dbm file but I am having difficulty fetching it
out.
The essential code of storing the dbm.
dbmopen(%check_entry, $file, 0666);
open (LIST, "${FromDir}/$FileName") or die "Can't open
${FromDir}/$FileName: !!\n";
while ($EmailAddress = <LIST>) {
chop ($EmailAddress);
@input = ($EmailAddress, $TestName, $letter_no, $date_created);
#printf "input = $input[0] & $input[1] & $input[2] &
$input[3]\n";
next unless (@input ne "");
#Check for entry in hash indicating a message already went to
#the address.
next unless ($check_entry{@input} eq "");
#Message is sent to individual list
Sendmail ($FileLocation, $EmailAddress);
#Store the array in the dbm
#how to fetch it back?
$check_entry{@input} = @input;
}
close LIST;
To fetch it back, dbmopen(%check_entry,
"/home/httpd/html/intra/kocams/bin/mailing.log", 066\
6);
open (LIST, "${FromDir}/$FileName") or die "Can't open
${FromDir}/$FileNam\
e: !!\n";
while ($EmailAddress = <LIST>) {
chop ($EmailAddress);
@input = ($EmailAddress, $TestName, $letter_no, $date_created);
#printf "input = $input[0] & $input[1] & $input[2] &
$input[3]\n";
next unless (@input ne "");
#Check for entry in hash indicating a message already went to
#the address.
next unless ($check_entry{@input} eq "");
#Message is sent to individual list
$FileLocation =
"/home/kocams/kocams/${TestName}/${letter_no}.txt";
Sendmail ($FileLocation, $EmailAddress);
$check_entry{@input} = @input;
}
close LIST;
To retrieve the array, I tried something like this:
while ((@value) = each %check_entry) {
for ($i = 0; $i < 2; $i+=1)
{
printf "([$i]): $value[$i] ::\t";
}
print "\n";
}
dbmclose %check_entry;
Unfortunately, it returned back to me "4" which is probably the size of
the array. What am I doing wrong? Any suggestion please.
/dave
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 25 Oct 1999 21:42:01 +0200
From: Carl Johansson <carl.johansson@mbox201.swipnet.se>
Subject: File download script
Message-Id: <3814B289.39B0CEAC@mbox201.swipnet.se>
How do I do if I want a user to download a file without see the URL to
the file,
just the URL to the CGI script?
Like http://www.freedrive.com has!
------------------------------
Date: Mon, 25 Oct 1999 14:27:10 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: File download script
Message-Id: <Pine.GSO.4.10.9910251426150.29843-100000@user2.teleport.com>
On Mon, 25 Oct 1999, Carl Johansson wrote:
> How do I do if I want a user to download a file without see the URL to
> the file, just the URL to the CGI script?
>
> Like http://www.freedrive.com has!
If you want to do what that site does, follow the same protocol that that
site does. Of course, you can do that with or without perl. Perhaps you
should search for the docs, FAQs, or newsgroups about the protocol you
wish to use. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 25 Oct 1999 09:55:45 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: file manipulation II
Message-Id: <m1r9ij2xda.fsf@halfdome.holdit.com>
>>>>> "makau" == makau <makau@multimania.com> writes:
makau> open(RTFM,"+>lazydude.txt") or die "wtf???:$!\n";
makau> and it would work (hopefully).
"hopefully" should always be a warning word. As in "I haven't tried
this, but I guess..." :).
makau> "+>" is to open a file for both reading and writting
No, in this case, it's to clobber the existing data, but then
yes be able to both read and write through the same filehandle.
You want:
"+<lazydude.txt"
instead.
print "Just another Perl hacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Mon, 25 Oct 1999 10:25:14 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: file manipulation II
Message-Id: <MPG.127e3259f0f92cd098a11e@nntp.hpl.hp.com>
In article <7v1te0$8qo$1@nnrp1.deja.com> on Mon, 25 Oct 1999 15:36:32
GMT, makau@multimania.com <makau@multimania.com> says...
>
> > #!/usr/bin/perl
> > open(pray,">dead.txt")||die"Shit:$!\n";
>
> It is :
>
> open(RTFM,"+>lazydude.txt") or die "wtf???:$!\n";
> while (<RTFM>){
> /adm/ and print RTFM "no more\n";
> }
>
> and it would work (hopefully).
>
> "+>" is to open a file for both reading and writting
After truncating the file to zero length when it is opened!
Surely you mean '+<'.
But also, the proper answer is in perlfaq5, as others have noted.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 25 Oct 1999 10:27:04 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: file manipulation II
Message-Id: <MPG.127e32c81f5d169998a11f@nntp.hpl.hp.com>
In article <7v1tc4$8q4$1@nnrp1.deja.com> on Mon, 25 Oct 1999 15:35:33
GMT, makau@multimania.com <makau@multimania.com> says...
>
> > #!/usr/bin/perl
> > open(pray,">dead.txt")||die"Shit:$!\n";
>
> It is :
>
> open(RTFM,">lazydude.txt") or die "wtf???:$!\n";
> while (<RTFM>){
> /adm/ and print RTFM "no more\n";
> }
>
> and it would work (hopefully).
Reading from a file opened for writing isn't likely to do anything
useful, is it?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 25 Oct 1999 13:53:29 GMT
From: bmccoy@foiservices.com (Brett W. McCoy)
Subject: Re: file manipulation II
Message-Id: <slrn818ofn.u3d.bmccoy@moebius.foiservices.com>
Also Sprach brunonuts@my-deja.com <brunonuts@my-deja.com>:
>i am trying to write a script to search and overwrite
>paterns in a file, but for some reason, it is erasing the whole file
>here is the thing:
No -w on your shebang line... no 'use strict'... they'll tell you more
about why you're program isn't working than we can...
>#!/usr/bin/perl
>open(pray,">dead.txt")||die"Shit:$!\n";
^^^^^^^^^^
This is going to overwrite your file every time you run the program. You
want to use >> to open and append. By convention, file handles are all
caps, also.
>while ($line=<pray>){
> if($line=~/adm/){
> print pray"no more\n";
> }
>}
This isn't going to *replace* data in your file, just write over what you
already had. Even with the append operator, it still isn't going to work.
You'll need to get everything into memory (like in a hash), and then write
everything back out when you want to 'save' your file.
--
Brett W. McCoy bmccoy@foiservices.com
Computer Operations Manager (Alpha Geek) http://www.foiservices.com
FOI Services, Inc./DIOGENES 301-975-0110
---------------------------------------------------------------------------
------------------------------
Date: Mon, 25 Oct 1999 15:36:32 GMT
From: makau@multimania.com
Subject: Re: file manipulation II
Message-Id: <7v1te0$8qo$1@nnrp1.deja.com>
> #!/usr/bin/perl
> open(pray,">dead.txt")||die"Shit:$!\n";
It is :
open(RTFM,"+>lazydude.txt") or die "wtf???:$!\n";
while (<RTFM>){
/adm/ and print RTFM "no more\n";
}
and it would work (hopefully).
"+>" is to open a file for both reading and writting
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 25 Oct 1999 15:35:33 GMT
From: makau@multimania.com
Subject: Re: file manipulation II
Message-Id: <7v1tc4$8q4$1@nnrp1.deja.com>
> #!/usr/bin/perl
> open(pray,">dead.txt")||die"Shit:$!\n";
It is :
open(RTFM,">lazydude.txt") or die "wtf???:$!\n";
while (<RTFM>){
/adm/ and print RTFM "no more\n";
}
and it would work (hopefully).
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Mon, 25 Oct 1999 01:13:50 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: file manipulation II
Message-Id: <mbudash-2510990113500001@adsl-216-103-91-123.dsl.snfc21.pacbell.net>
In article <7v0vln$j9n$1@nnrp1.deja.com>, brunonuts@my-deja.com wrote:
>hi, whats up my dear perl freaks?
>i am trying to write a script to search and overwrite
>paterns in a file, but for some reason, it is erasing the whole file
>here is the thing:
>
>#!/usr/bin/perl
>open(pray,">dead.txt")||die"Shit:$!\n";
^
^ you just killed your file!
also, it's accepted practice to use upper case names for filehandles...
>while ($line=<pray>){
> if($line=~/adm/){
> print pray"no more\n";
> }
>}
>
anyway, see perlfaq5's "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?"
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Mon, 25 Oct 1999 04:15:42 -0400
From: kenhirsch@myself.com (Ken Hirsch)
Subject: Re: file manipulation II
Message-Id: <MPG.127ddbbb635497ee989683@news.compaq.net>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <7v0vln$j9n$1@nnrp1.deja.com>, brunonuts@my-deja.com says...
> hi, whats up my dear perl freaks?
> i am trying to write a script to search and overwrite
> paterns in a file, but for some reason, it is erasing the whole file
> here is the thing:
>
> #!/usr/bin/perl
> open(pray,">dead.txt")||die"Shit:$!\n";
You just erased the file with this open. See the documentation for
perl's -i option
perldoc perlrun
------------------------------
Date: Tue, 26 Oct 1999 02:31:54 -0400
From: "Ethan H. Poole" <ehpoole@ingress.com>
Subject: Re: file upload problem
Message-Id: <38154ADA.8B09B0F4@ingress.com>
jsahoo@my-deja.com wrote:
>
> I have written a perl script for upload any type of file. The problem is
> that it is able to upload all the files , but when it is downloaded and
> seen thru respective viewer, the text files shows ok but the binary
> files gives garbage(in case of image) or an error showing that the
> format is not correct.
>
> What could be the problem??
Research binmode() ... on the input and output.
--
Ethan H. Poole **** BUSINESS ****
ehpoole@ingress.com ==Interact2Day, Inc.==
(personal) http://www.interact2day.com/
------------------------------
Date: Wed, 27 Oct 1999 14:53:40 -0400
From: Tim Lewis <nospam@work.com>
Subject: FindBin except for Modules???
Message-Id: <38174A34.71E96771@work.com>
Is there a module like FindBin that returns the path and
filename for a Perl module or library. In other words, is
there something that will do something like:
BEGIN {
require File::Basename;
$ModuleDir = File::Basename::dirname(__FILE__);
.
.
.
}
(i.e. return the module path, real module path, module file name,
and real module file name at compile time). I would find something
like this very useful, but I can seem to find a module that will do
the trick. I have made my own module that does this, and it's not as easy
to do as one would think for the general case. This is why I am thinking that
there must be a simpler way or that someone already did it. Am I missing
something here? Is there actually a module or some such to do what I want?
If there isn't (doubtful), I will see about donating my module to CPAN.
Tim Lewis
------------------------------
Date: Wed, 27 Oct 1999 17:15:58 -0400
From: Tim Lewis <tlewis@gte.com.no.spam.please>
To: japhy@pobox.com
Subject: Re: FindBin except for Modules???
Message-Id: <38176B8E.D5D3DE71@gte.com.no.spam.please>
Jeff Pinyan wrote:
>
> > %INC has the values of each file that was loaded by a do or require.
> > If you use it for a module loaded with use, you get an uninitialized value.
>
> No, actually, the code I pasted had a slight error.
Yeah, I figured that out after posting. :-)
I was just about to post a message about that. I couldn't get it to
work with 'require Module;' either, and that kind of tipped me off as to
what was going on. Page 138 of the camel isn't too explicit about that
particular case.
Still, I'm not sure that it helps my situation any. It's pretty much the same as
with '__FILE__'. In other words, I'd still have to munge the name to get the directory.
But, thanks for providing me with another way to do it. I am most appreciative.
> Shame on me.
Me too.
Tim Lewis
------------------------------
Date: Wed, 27 Oct 1999 16:12:16 -0400
From: Tim Lewis <tlewis@gte.com.no.spam.please>
To: japhy@pobox.com
Subject: Re: FindBin except for Modules???
Message-Id: <38175CA0.2BC93D8A@gte.com.no.spam.please>
Jeff Pinyan wrote:
>
> If you want the path to a module, try this:
>
> BEGIN {
> use Module;
> $path = $INC{Module};
> }
Thank you for your answer.
However, %INC doesn't actually work like this.
%INC has the values of each file that was loaded by a do or require.
If you use it for a module loaded with use, you get an uninitialized value.
I don't know if this has changed in the 5.6 release.
Tim Lewis
------------------------------
Date: Wed, 27 Oct 1999 16:39:48 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: FindBin except for Modules???
Message-Id: <Pine.GSO.4.10.9910271637540.2694-100000@crusoe.crusoe.net>
[posted & mailed]
> > BEGIN {
> > use Module;
> > $path = $INC{Module};
> > }
>
> Thank you for your answer.
>
> %INC has the values of each file that was loaded by a do or require.
> If you use it for a module loaded with use, you get an uninitialized value.
No, actually, the code I pasted had a slight error.
jeffp@friday [4:37pm] ~ #163> perl -MCGI -le 'print $INC{"CGI.pm"}'
/usr/local/lib/perl5/5.00502/CGI.pm
The code should have been:
BEGIN {
use Module::Name::Here;
$path = $INC{"Module/Name/Here.pm"};
}
Shame on me.
--
MIDN 4/C PINYAN, USNR, NROTCURPI
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
------------------------------
Date: Wed, 27 Oct 1999 15:44:45 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: FindBin except for Modules???
Message-Id: <Pine.GSO.4.10.9910271544170.2694-100000@crusoe.crusoe.net>
If you want the path to a module, try this:
BEGIN {
use Module;
$path = $INC{Module};
}
--
MIDN 4/C PINYAN, USNR, NROTCURPI
jeff pinyan japhy@pobox.com
perl stuff japhy+perl@pobox.com
CPAN ID: PINYAN http://www.perl.com/CPAN/authors/id/P/PI/PINYAN/
------------------------------
Date: 26 Oct 1999 20:05:36 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: finding date and time
Message-Id: <7v51ig$io3$1@gellyfish.btinternet.com>
On Mon, 25 Oct 1999 19:38:54 GMT Shmooth wrote:
> ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
> print "sec is $sec...<br>\n";
> print "min is $min...<br>\n";
> print "hour is $hour...<br>\n";
> print "mday is $mday...<br>\n";
> print "mon is $mon...<br>\n";
> print "year is $year...<br>\n";
> print "wday is $wday...<br>\n";
> print "yday is $yday...<br>\n";
> print "isdst is $isdst...<br>\n";
>
> You'll notice that some of the places are 0-indexed...
>
One might also notice something else about one of the values in just
over two months - this of course of discussed in the localtime() entry
in the perlfunc manpage.
And BTW so is the *optional* parameter.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: Mon, 25 Oct 1999 19:38:54 GMT
From: Shmooth <shmooth@yahoo.com>
Subject: Re: finding date and time
Message-Id: <3814B0B2.31A8A50F@yahoo.com>
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
print "sec is $sec...<br>\n";
print "min is $min...<br>\n";
print "hour is $hour...<br>\n";
print "mday is $mday...<br>\n";
print "mon is $mon...<br>\n";
print "year is $year...<br>\n";
print "wday is $wday...<br>\n";
print "yday is $yday...<br>\n";
print "isdst is $isdst...<br>\n";
You'll notice that some of the places are 0-indexed...
Aaron Walker wrote:
> Hello,
>
> I would think that this question would be a FAQ, but I did not come
> across it in the comp.lang.perl.misc FAQ. I am trying to find the date
> and time. I read somewhere to use the localtime() function. I found
> out that this is not formatted for about, since it is just a series of
> numbers. How would I format the output of localtime()? Is there a
> better way to discover the data and time?
>
> Thanks,
> Aaron
>
> --
> Aaron Walker
> amwalker@gate.net
> http://iconmedia.com/aaron/
------------------------------
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 1178
**************************************