[10287] in Perl-Users-Digest
Perl-Users Digest, Issue: 3880 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 3 03:07:16 1998
Date: Sat, 3 Oct 98 00:00:37 -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 Sat, 3 Oct 1998 Volume: 8 Number: 3880
Today's topics:
build database connection in CGI... (GEMINI)
Re: build database connection in CGI... <zenin@bawdycaste.org>
Re: DEL in PERL <zenin@bawdycaste.org>
Re: DEL in PERL (Ronald J Kimball)
Re: Function calls <zenin@bawdycaste.org>
Re: Getopt::Std (Ronald J Kimball)
Re: Inconsistency in -w for substr outside of string (Ronald J Kimball)
Large random strings (MAX)
mailing from within PERL (Peter Bismuti)
memory leak when deleting multidimension hash cjiang@my-dejanews.com
Need help from Perl guru (Peter Bismuti)
Re: Need help from Perl guru (Ronald J Kimball)
One week from today, encrypted (Peter J. Kernan)
Re: Perl as solution? (Ilya Zakharevich)
Re: Perl as solution? <dgris@perrin.dimensional.com>
Perl formating (majeed)
Re: POLL: Perl features springing into your face <bholzman@goose.prod.itd.earthlink.net>
Re: POLL: Perl features springing into your face (Ronald J Kimball)
Re: Puzzling \( @blah ) behaviour (Ronald J Kimball)
Re: Puzzling \( @blah ) behaviour <zenin@bawdycaste.org>
Re: Script does not write to file (Ronald J Kimball)
Re: Script does not write to file <ismkoehlerism@nmism-us.campus.mci.net>
Re: Script does not write to file (Peter J. Kernan)
Re: uppercase to lowercase (Craig Berry)
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 3 Oct 1998 02:39:01 GMT
From: dennis@info4.csie.nctu.edu.tw (GEMINI)
Subject: build database connection in CGI...
Message-Id: <6v42o5$p54$2@netnews.csie.NCTU.edu.tw>
hi all,
I have a CGI written in Perl that
will query some data from database for
every request from web page. However,
I have to open the database connection,
then query data, and close the connection
for each request. The performance is not good
because it takes long time to load DBI and DBD
module, and build connection to database.
So is there any way to build the database
connection 'per session' rather than 'per request'?
That is, the connection is build once for the first page,
and query data directly for the web pages that belong to
the same user request session.
Besides, is there any way to speed up the load of
dynamic loaded modules, say DBI?
Thanks.
------------------------------
Date: 3 Oct 1998 03:52:23 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: build database connection in CGI...
Message-Id: <907386645.890907@thrush.omix.com>
[posted & mailed]
GEMINI <dennis@info4.csie.nctu.edu.tw> wrote:
: So is there any way to build the database
: connection 'per session' rather than 'per request'?
: That is, the connection is build once for the first page,
: and query data directly for the web pages that belong to
: the same user request session.
: Besides, is there any way to speed up the load of
: dynamic loaded modules, say DBI?
http://www.apache.org/perl/
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: 3 Oct 1998 03:56:20 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: DEL in PERL
Message-Id: <907386883.314069@thrush.omix.com>
[posted & mailed]
Computer Guru <computerguru@mailexcite.com> wrote:
: find2perl? I have to look into that...I'm assuming it's a third party app?
It comes with the stock Perl distribution.
>snip<
: begin 666 Computer Guru Consulting.vcf
>snip<
What the hell is this shit? 4 line sig only. No V-Cards, no lame
attachments, no uuencoded garbage. Simple text only, thanks.
Computer Guru my ass... :-/
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Sat, 3 Oct 1998 00:32:15 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: DEL in PERL
Message-Id: <1dgarwu.16fbl3q5m81uhN@bay1-183.quincy.ziplink.net>
Computer Guru <computerguru@mailexcite.com> wrote:
> find2perl? I have to look into that...I'm assuming it's a third party app?
Look into the bin directory. find2perl is included in the Perl
distribution.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 3 Oct 1998 03:59:08 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Function calls
Message-Id: <907387050.579683@thrush.omix.com>
[posted & mailed]
Atul Ankola <ankola@purdue.edu> wrote:
: I was wondering how to call another function from antoher file. For
: example: I am in FILE1 and I want to call a function that is in FILE2.
: Is there a way to do that?
file2.pl:
sub foo {
...do foo stuff...
}
file1:
require "file2.pl";
foo();
Or better yet, run:
$ h2xs -AX -n Foo
...stuff prints out...
$ cd Foo
$ vi Foo.pm
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Fri, 2 Oct 1998 23:47:04 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Getopt::Std
Message-Id: <1dgao6g.1diypiw4wdla8N@bay1-183.quincy.ziplink.net>
Corey <corey@virtual-impact.com> wrote:
> I've found myself at somewhat of a loss in implementing a
> nice way of issuing a usage function under the circumstance
> in which a correct option is specified ( as declared via
> a 'getopts' statement ), but is lacking an argument.
use Getopt::Long;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 2 Oct 1998 23:47:02 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Inconsistency in -w for substr outside of string
Message-Id: <1dganh6.y5ds3c1v0tivoN@bay1-183.quincy.ziplink.net>
Larry Rosler <lr@hpl.hp.com> wrote:
> perl -we '$x = "x"; print substr $x, 2'
>
> produces two warnings:
>
> substr outside of string at -e line 1.
> Use of uninitialized value at -e line 1.
>
> But the following produces no warnings:
>
> perl -we '$x = "x"; print substr $x, 1'
>
> Is this a bug? Perl -v: 5.005_02
> and all the previous versions I have checked.
I don't think that's a bug.
substr($x, 1) is the zero-length string at position 1 in the string 'x'.
substr($x, 2), on the other hand, is past the end of the string, and
thus undefined.
Consider substr() as an lvalue:
substr($x, 2) = 'foo';
substr($x, 1) = 'foo';
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 3 Oct 1998 01:42:17 GMT
From: max@panix.com (MAX)
Subject: Large random strings
Message-Id: <6v3vdp$1oe@news1.panix.com>
What's the best way to generate long random bitstrings.
Best means efficient without loss of randomness.
Is it crazy to do something like:
use integer; $x = rand(2**$n - 1);
--
max@panix.com
"What are the preditors of humans?"
------------------------------
Date: 3 Oct 1998 05:40:52 GMT
From: bismuti@cs.fsu.edu (Peter Bismuti)
Subject: mailing from within PERL
Message-Id: <6v4dd4$n2n$1@news.fsu.edu>
Hi again,
I'm trying to write a script that will automatically send e-mail,
I've found partial examples in books, but not that are complete.
One way is to dump the contents of the message to a temporary file,
then use the system command:
system ("mail address < tmp.mail");
or something like this. Is there any way of doing this without
writing the contents to a temporary file?
Thanks again!
_______________________________________________________________________
| Pete Bismuti |
| Department of Computer Science |
| Florida State University |
| bismuti@cs.fsu.edu (850) 644-1685 |
|_____________________________________________________________________|
------------------------------
Date: Sat, 03 Oct 1998 02:58:41 GMT
From: cjiang@my-dejanews.com
Subject: memory leak when deleting multidimension hash
Message-Id: <6v43t0$fl3$1@nnrp1.dejanews.com>
Perl Guru,
I did:
while (1) {
$a{"apple"}{"dog"} = 10;
$a{"apple"}{"cat"} = 20;
$a{"orange"}{"dog"} = 30;
%a = ();
}
Would this cause memory leak problem? In general, how do you guru
free up memory which was used in multidimension hash
Thanks a lot.
-Clement
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 3 Oct 1998 03:41:00 GMT
From: bismuti@cs.fsu.edu (Peter Bismuti)
Subject: Need help from Perl guru
Message-Id: <6v46cc$ddm$1@news.fsu.edu>
I have a bug in my code and I think that it is actually a bug
in PERL itself (famous last words, I know). What is happening
is that when I access a particular hash array twice in a row,
(there is an array of hash arrays)
the second time PERL doesn't see all of the elements in the
array. The PERL debugger shows that the array is fully intact,
but the command 'each':
while ( ($key2,$value2) = each(%{$rh_class->{rh_student}[$studid]}) )
does not see all of the elements. But again, this only happens if
you try to access an array twice in a row.
If you are up to a challenge and you think you can figure out what is
happening, I would appreciate it if I could send you my code and
instructions on finding the bug. It is a relatively small code.
Thanks from a PERL novice.
Da Zdrastbuytye PERL!
_______________________________________________________________________
| Pete Bismuti |
| Department of Computer Science |
| Florida State University |
| bismuti@cs.fsu.edu (850) 644-1685 |
|_____________________________________________________________________|
------------------------------
Date: Sat, 3 Oct 1998 00:32:17 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Need help from Perl guru
Message-Id: <1dgas0p.118p52b1ealyieN@bay1-183.quincy.ziplink.net>
Peter Bismuti <bismuti@cs.fsu.edu> wrote:
> The PERL debugger shows that the array is fully intact,
> but the command 'each':
>
> while ( ($key2,$value2) = each(%{$rh_class->{rh_student}[$studid]}) )
>
> does not see all of the elements. But again, this only happens if
> you try to access an array twice in a row.
Do you modify the hash while looping over each? Do you break out of the
loop before reaching the end of the hash?
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 3 Oct 1998 04:10:53 GMT
From: pete@localhost.localdomain (Peter J. Kernan)
Subject: One week from today, encrypted
Message-Id: <6v484d$3et$1@pale-rider.INS.CWRU.Edu>
There seems to be a few recurring threads recently in this
newsgroup involving calculating future dates and encryption.
We have noticed that there has been frequently posted a rather
brilliant solution to the former problem, i.e.
sleep 86400; scalar localtime;
As rather new readers of this group we do not know whom deserves
credit for this observation but have been inspired by the clarity
of the solution. However we feel that it does not address the
issue of fully utilizing system resources regarding the solution
of such an important problem (as evidenced by the frequency for
which a solution to this type of problem is requested despite the
abundance of directly relevant material in the FAQs and other
worthy publications). To properly address the importance of these
issues we undertook an extensive research program (approximately
a full half hour) to come up with yet more solutions. You would
be well advised to know that the solution of problems of such
tantamount importance requires significant system resources.
For this reason we have endeavored for both simplicity and
elegance in the algorithms at the expense of a forgivable
indulgence on the demanded resources.
Note that object oriented methodologies were applied where required,
regular expressions essential to the task were verified in
the Owl and as always the Camel guided us through the desert,
though the Llama we have only seen, we have felt the force of the Ram.
Also is seems that there has been recent attention (again we
do not know how primordial this trend is) on the laudable goal
of protecting one's perl intellectual investment through
encryption. We have thus also decided to encrypt our intellectual
obscurity to the degree that it warrants with a penetrable
encryption scheme.
The code:
#!/usr/local/bin/perl -w
use Reverse;
;"n\syad 0$ :egasu" eid ro tfihs = syad$
;"n\deriuqer syad fo rebmun regetni" eid ro /$)+d\(^/ ~= syad$
...hhhuuuud 06 * 06 * 42# ;00468 >= SCES tnatsnoc esu
;"n\...won morf syad syad$ emit gnitaluclac" tnirp
.slangis niatrec no yllufecarg eunitnoC #
= }'TRBA'{GIS$ =}'PUH'{GIS$ = }'MRET'{GIS$ = }'TIUQ'{GIS$ = }'TNI'{GIS$
;};"n\...tneitap eb esaelp ,gnikrow llits :$$" tnirp{ bus
;)syad$(syad
;"n\})emitlacol ralacs(\{$" tnirp
89/2/01 3 notsob 4 snaidni# { worromot bus
;SCES : tfihs ? _@ = t$ ym
{ )krof = dip$ ym( fi
;0 ,dip$ diptiaw
)lenrek xif esle( ereh ko elbat ssecorp emussa# { esle }
;)t$( fi )1-t$( worromot peels
;t$ tixe
}
;"n\...t$ nwwwwaaay" tnirp
;1
}
{ syad bus
evoba ees # ;SCES = yad$ ym
;tfihs = syad$ ym
;";" . syad$ x ")yad$ dna " . "1" . syad$ x "( worromot" = _$
;lave
}
Authors And Copyright; peter j kernan and Craig J Copi, caveat emptor.
Technical notes;
1) you benefit from CPAN/modules/by-module/Filter
2) neat article about above by Paul Marquess in TPJ 11
3) Reverse.pm => roll your own, see 2)
--
Pete Kernan CWRU Physics and Statistics Depts
http://theory2.phys.cwru.edu/~pete
Craig J Copi CWRU Physics Dept
http://erebus.phys.cwru.edu/~copi
------------------------------
Date: 3 Oct 1998 06:02:02 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl as solution?
Message-Id: <6v4ekq$eck$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Daniel Grisinger
<dgris@perrin.dimensional.com>],
who wrote in article <m3vhm2ur7t.fsf@perrin.dimensional.com>:
> my $neighbor = 'fred';
> my $is_annoying = 1;
>
> while (1) {
> if ($sentry -> is_disturbed) {
> if ($neighbor = is_annoying()) {
^^^
|
I wonder what missile guidance AI could detect an error like this one?
Ilya
------------------------------
Date: Sat, 03 Oct 1998 06:11:52 GMT
From: Daniel Grisinger <dgris@perrin.dimensional.com>
Subject: Re: Perl as solution?
Message-Id: <m3pvcauqm1.fsf@perrin.dimensional.com>
Elaine -HappyFunBall- Ashton <eashton@bbnplanet.com> writes:
> My neighbor has one of those darned car alarms that goes off every
> morning at 3am with that 'dive dive dive' sound.
>
> For hours.
>
> I would like to solve this annoying problem. Could perl help me develop
> a guidance system for the missile I would like to launch at it?
RTFM.
$ perldoc -q 'car alarm'
=head1 Found in perlfaq1764.pod
=head2 How do I deal with annoying car alarms using perl?
This is a tough one, as it requires the acquisition of a
complete rocket delivery system. Fortunately, that is
well beyond the scope of this FAQ and will not be addressed
here. Besides, if you don't know how to acquire a complete
missile delivery system then you just aren't ready to handle
this task anyway.
Still with me? Good. Assuming you have acquired your
delivery system, this should handle the rest for you.
[Note: Some may consider this program buggy. They
haven't had my neighbors.]
#!/usr/bin/perl -w
use strict;
use Noise::Detector;
use Missile;
my $sentry = new Noise::Detector;
my $missile = new Missile;
my $neighbor = 'fred';
my $is_annoying = 1;
while (1) {
if ($sentry -> is_disturbed) {
if ($neighbor = $is_annoying) {
$missile -> blow_up_neighbor_and_car;
}
else {
$missile -> blow_up_car;
}
}
}
$
Hope this helps :-).
dgris
--
Daniel Grisinger dgris@perrin.dimensional.com
`By about halfway through I was beginning to guess the
ending, but it still kind of surprised me.'
David Hatunen, talking about the movie Titanic
------------------------------
Date: Sat, 03 Oct 1998 01:16:38 GMT
From: majeed@dircon.co.uk (majeed)
Subject: Perl formating
Message-Id: <361579cc.218058421@news.dircon.co.uk>
Hi
I am running the following script. I pump the out put of find command
which searching for abc.log.
#!/usr/local/bin/perl
$test = `find /export/home/majeed/test -name abc.log `;
@var = split ('/',$test);
print "$test\n";
$filename = pop(@var);
$junk = pop(@var);
push(@var, 'logs');
$pathnew = join ('/',@var);
print "$pathnew \n";
The output i get is as follows
/export/home/majeed/test/test1/access/abc.log
/export/home/majeed/test/test2/access/abc.log
/export/home/majeed/test/test3/access/abc.log
When i do the pop push and join it only works on the last line as
shown below
/export/home/majeed/test/test1/access/abc.log
/export/home/majeed/test/test2/access/abc.log
/export/home/majeed/test/test3/logs
How do i get ouput which appends test1 and test2 to the same as test3
Your help is much appreciated
------------------------------
Date: Sun, 27 Sep 1998 11:31:48 -0400
From: Benjamin Holzman <bholzman@goose.prod.itd.earthlink.net>
Subject: Re: POLL: Perl features springing into your face
Message-Id: <360E5A64.E80C78D4@mail.earthlink.net>
> While we're talking about pet peeves, I'd also add:
>
> barewords - if you want a quoted string, for gosh sakes put $#@!
> quotes around it!
Ugh. This whole idea looks like it could quickly degenerate into
use style 'Ilya';
Different people are bound to have different ideas here; I wonder what
kind of consensus you'll really be able to achieve.
Pessimistically,
Ben Holzman
------------------------------
Date: Fri, 2 Oct 1998 23:47:20 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: POLL: Perl features springing into your face
Message-Id: <1dgapxq.1k7x8g2egvnndN@bay1-183.quincy.ziplink.net>
Larry Wall <larry@kiev.wall.org> wrote:
> >Definitely I like barewords where they are unambiguous: in ->{foo},
> >foo => and `use foo'. A list of places where they should be allowed
> >should be created.
>
> According to the official definition of "bareword", none of these examples
> are. Real barewords are already outlawed by 'use strict'.
This means, ironically, that there are no barewords in this statement:
no clothes;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Fri, 2 Oct 1998 23:47:14 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Puzzling \( @blah ) behaviour
Message-Id: <1dgap81.1fc5oddyzs4m8N@bay1-183.quincy.ziplink.net>
Paul Makepeace <Paul.Makepeace@POBox.com> wrote:
> This is probably an easy one but I've been verbose.
>
> Abstract: why does $a = \( @blah ) not always return scalar(@blah)?
>
> perlref says:
>
> Note that taking a reference to an enumerated list is
> not the same as using square brackets--instead it's
> the same as creating a list of references!
>
> @list = (\$a, \@b, \%c);
>
> Surely, since \( ) is list of references of its
> elements as per docs, when evaluated in a scalar context it would return the
> number of elements? So why isn't my %data full of ones (i.e. length of list
> in (), not the number 1 I have there) ?
Nope. In a scalar context, a comma-separated 'list' evaluates all the
expressions and returns the value of the last expression. \( ) is a
comma-separated 'list' of references.
Only actual arrays return the number of elements when evaluated in a
scalar context.
> paul:~$ perl -e '$b=1;$c=3; $a = \($b, $c); print $$a'
> 3
>
> It's clearly (er, to me) not behaving like a normal list operator but
> applying the scalar context to the thing _inside_ the \( ) which is
> evaluating as a comma-operator rather than list separator. Why would it do
> that? Where would I R about this in the FM?
This behavior is exactly according to the documentation.
$a = \($b, $c);
is equivalent to
$a = (\$b, \$c);
And, in a scalar context (provided here by the scalar lvalue on the lhs
of the assignment), the comma operator evaluates both operands and
returns the value of the *right-hand* operand.
Thus,
$a = \($b, $c);
has the same effect as:
$a = \$c;
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 3 Oct 1998 04:30:56 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Puzzling \( @blah ) behaviour
Message-Id: <907388959.219557@thrush.omix.com>
[posted & mailed]
Paul Makepeace <Paul.Makepeace@POBox.com> wrote:
: Abstract: why does $a = \( @blah ) not always return scalar(@blah)?
Not always? It never should. You're assigning a list value (a
list of scalar refs actually) to a scaler. $a will get a reference
to the last value of @blah, if there are any values.
: perlref says:
: $data{$level}{$element} = \($time_cache{$product->IntervalList} = 1);
:
: Now, why does this work? Surely, since \( ) is list of references of its
: elements as per docs, when evaluated in a scalar context it would return the
: number of elements?
No, arrays do that, lists don't. Lists are not arrays.
: paul:~$ perl -e '$b=1;$c=3; $a = \($b, $c); print $$a'
: 3
: It's clearly (er, to me) not behaving like a normal list operator
Sure it is:
$ perl -e '$b=1;$c=3; $a = ($b, $c); print $a'
3
You're thinking of an array evaluated in scalar context:
$ perl -e '@b=(1, 3); $a = (@b); print $a'
2
Just watch the braces, they can bite you:
$ perl -e '@b=(1, 3); ($a) = (@b); print $a'
1
Of course, if you must have a list evaluated as an array, you can
work around it like this:
$ perl -e '$b=1;$c=3; $a = @{[\($b, $c)]}; print $a'
2
But that's very ugly, and I've never seen any reason to do it in
real code, but ya never know.
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Fri, 2 Oct 1998 23:47:18 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Script does not write to file
Message-Id: <1dgapmg.69lu6f1c5i6z5N@bay1-183.quincy.ziplink.net>
Roberto Cerini <rob@ccsn.com> wrote:
> My script has the following lines in it:
>
> open(testfile,"/home/user/public_html");
> print testfile "This is a test\r\n";
> close testfile
>
> When I run the script, nothing happens to the testfile (which I have already
> created).
>
> Any suggestions?
1. Read the documentation.
2. Check the return value of open.
3. Open the file for *writing*. Duh!
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Sat, 3 Oct 1998 00:04:29 -0600
From: "Rick K" <ismkoehlerism@nmism-us.campus.mci.net>
Subject: Re: Script does not write to file
Message-Id: <6v4epq$s6i$1@news.campus.mci.net>
Ronald J Kimball wrote in message
<1dgapmg.69lu6f1c5i6z5N@bay1-183.quincy.ziplink.net>...
>Roberto Cerini <rob@ccsn.com> wrote:
>
>> My script has the following lines in it:
>>
>> open(testfile,"/home/user/public_html");
>> print testfile "This is a test\r\n";
>> close testfile
>>
>> When I run the script, nothing happens to the testfile (which I have
already
>> created).
>>
>> Any suggestions?
>
>1. Read the documentation.
>
>2. Check the return value of open.
>
>3. Open the file for *writing*. Duh!
I guess it might matter if he wants to open a file for writing, or
append stuff to the pre-existing file. I agree whole-heartedly
that folks need to read the docs ... and this is basic stuff here.
But, if he opens the file for writing ...
open(FILEHANDLE, ">somefile");
print FILEHANDLE "Put this in my file.\n";
close(FILEHANDLE);
his pre-existing file is over-written, and now only consists of the
output of the print statement. Since he refers to the file saying
"... which I already have created", I doubt he wants that to happen.
Roberto, if you're still tuned in to c.l.p.m., try:
open(FILEHANDLE, ">>yourfile"); #opens file for appending data
print FILEHANDLE "I want to add this line to my file.\n";
close(FILEHANDLE);
The double right-facing angle brackets (>>) prefixed to the
filename are the key item here. HTH.
And do read all the wonderful docs that Perl folks have
worked so hard create. (and maybe, buy the Camel or Llama
or Gecko, as appropriate).
------------------------------
Date: 3 Oct 1998 05:57:07 GMT
From: pete@localhost.localdomain (Peter J. Kernan)
To: "Roberto Cerini" <rob@ccsn.com>
Subject: Re: Script does not write to file
Message-Id: <6v4ebj$ob5$1@pale-rider.INS.CWRU.Edu>
[Posted and mailed]
In article <6v3qoh$em8@nnrp1.farm.idt.net>,
"Roberto Cerini" <rob@ccsn.com> writes:
> My script has the following lines in it:
>
> open(testfile,"/home/user/public_html");
> print testfile "This is a test\r\n";
> close testfile
>
> When I run the script, nothing happens to the testfile
>(which I have already created).
>
> Any suggestions?
looks like you probably tried to open a directory (public_html).
1) habitually use -w switch
2) understand difference between filehandle and file
#!/usr/bin/perl -w
open TESTFILE, ">/home/user/public_html/testfile" or die $!;
print TESTFILE "This is a test\r\n"; #why \r ? bizarre OS?
close TESTFILE;
--
Pete Kernan CWRU Physics and Statistics Depts
http://theory2.phys.cwru.edu/~pete
------------------------------
Date: 3 Oct 1998 05:16:48 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: uppercase to lowercase
Message-Id: <6v4c00$s6o$2@marina.cinenet.net>
etrim@my-dejanews.com wrote:
: I have a very simple question. I want to check if the user correctly entered
: address of the image (gif or jpg) Using $image =~ /.gif/ i can find out if
: $image contains .gif in it.
No you can't:
print ("xgif" =~ /.gif/) ? "does" : "doesn't";
prints "does". And even if you fix this rather trivial bug, what about
long filenames containing internal periods -- "my.gift.to.you.bmp" would
register as a '.gif' match. Think carefully about what the pattern you
want to match *really* is.
: But what if the users wrote .Gif, or .JPg and so
: on....i don't want to check for earch one. Is there a quicker way of doing
: this? I thought of converting $image to lowercase and then check for .gif or
: .jpg but i don't even know the command to do that.
Then read the docs. I'm sorry, but there's no easier way. There are at
least two good ways to approach this, with infinite subdivisions (m//i and
lc: m//), but you really won't be doing yourself a favor getting this
specific solution handed to you without understanding the big picture.
Get thee to a Llama!
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| "Ripple in still water, when there is no pebble tossed,
nor wind to blow..."
------------------------------
Date: 12 Jul 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 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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 3880
**************************************