[17657] in Perl-Users-Digest
Perl-Users Digest, Issue: 5077 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 10 18:10:31 2000
Date: Sun, 10 Dec 2000 15:10:14 -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: <976489814-v9-i5077@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 10 Dec 2000 Volume: 9 Number: 5077
Today's topics:
Please help with a simple problem <edd@texscene.com>
Re: Please help with a simple problem <jeff@vpservices.com>
Re: Please help with a simple problem <edd@texscene.com>
Re: problem with script <mbudash@sonic.net>
Qmail Attachments (O R)
Re: Reading first 5 lines data (Richard Zilavec)
Re: substitution regexp <onthebog@hotmail.com>
SUPER::DESTROY??? <bcaligari@my-deja.com>
Re: Tie hash of hash using MLDBM (Chris Fedde)
Re: Tie hash of hash using MLDBM <bwalton@rochester.rr.com>
Using OLE to make InternetExplorer print john@fake.uk
Re: Why isn't Perl highly orthogonal? <johnroth@ameritech.net>
Re: Why isn't Perl highly orthogonal? <bart.lateur@skynet.be>
Re: Why isn't Perl highly orthogonal? (Logan Shaw)
Re: Why isn't Perl highly orthogonal? <iltzu@sci.invalid>
Re: Why isn't Perl highly orthogonal? <nospam@david-steuber.com>
Re: Willing to review a 90 line Perl program? <abe@ztreet.demon.nl>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 10 Dec 2000 20:35:46 -0000
From: "Edd" <edd@texscene.com>
Subject: Please help with a simple problem
Message-Id: <3a33e727@news-uk.onetel.net.uk>
I am trying to write to a file 'web1.html' from a web page. I use the
code below which just doesn't work. I am new at perl programming, and I am
at a loss about what I am doing wrong. I have changed the permissions of
the file I am writing to, both by telneting to the Unix server and in this
program. In fact I check the file attributes at the bottom of the page and
they verify.
If somebody helps I'll be grateful immensely!
Edd
-------------------THE PERL CODE --------------------
#!/usr/bin/perl
print "Content-type: text/html\n\n";
# Below I set the permissions
if (-e "web1.html") {
chmod(0766, "web1.html");
print "<P>the permissions changed";
} else {
print "<P>the permissions.....,";
}
# Below I write to web1.html
open(LOG, ">web1.html") || print "could not open web1.html $!";
print LOG "<HTML><HEAD><TITLE>Hello Visitor</HEAD></TITLE><BODY>";
print LOG "</BODY></HTML>";
close(LOG);
# Below I check to see if the atributes of web1.html is OK
if (-e "web1.html") {
print "<p>web1.html exists";
} else {
print "<p>it doesn't exist";
}
if (-r "web1.html") {
print "<p>it can be read\n";
} else {
print "<p>it can't be read";
}
if (-x "web1.html") {
print "<p>it can be executed\n";
} else {
print "<p>it can't be executed";
}
if (-w "web1.html") {
print "<p>it can be written to\n";
} else {
print "<p>it can't be written to";
}
if (-d "web1.html") {
print "<p>it is a dir\n";
} else {
print "<p>it is not a dir";
}
#Below I write to the Browser to create a link to the page 'web1.html'
print "<HTML><BODY>";
print "<p>to see web page click on the link below";
print "<p><a href=\"/web1.html\">LINK TO WEB1</a></p>";
print "</BODY></HTML>";
------------------------------
Date: Sun, 10 Dec 2000 12:54:13 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Please help with a simple problem
Message-Id: <3A33ED75.FEE9D3E9@vpservices.com>
Edd wrote:
>
> I use the code below which just doesn't work.
What in the world does that mean "doesn't work"? Does your computer
start to smoke? Is a file created but the wrong one? Are there error
messages? If there aren't error messages, why not? Telling us simply
"it doesn't work" is as useful as telling your doctor "it hurts" without
telling him/her what "it" is.
> #!/usr/bin/perl
You should use -w for warnings and -T for taint checking.
You should use "use strict" for more warnings.
> print "Content-type: text/html\n\n";
Since you are testing this code in a browser, you need to be able to
send error messages to the browser. put "use CGI::CARP
qw(fatalsToBrowser);" near the top of your script. You should also
check the script from the command line first anyway because some
warnings and errors will only show up on the command line.
> open(LOG, ">web1.html") || print "could not open web1.html $!";
Good, you checked for an error and printed out the error message.
[snip of remainder of script which looks ok on first glance]
> print "<p><a href=\"/web1.html\">LINK TO WEB1</a></p>";
It gets confusing to backwhack quotes, a here-doc or the q() or qq()
operators are easier to read:
print q( <p><a href="/web1.html">LINK TO WEB1</a></p> );
And, BTW, that looks for a file called "web1.html" in the root directory
("/"), is that where you created the file and changed the file's
permissions? There's nothing in the code above that indicates that the
directory where you are creating and writing the file is the root
directory so that is probably your major mistake.
--
Jeff
------------------------------
Date: Sun, 10 Dec 2000 22:31:12 -0000
From: "Edd" <edd@texscene.com>
Subject: Re: Please help with a simple problem
Message-Id: <3a340234@news-uk.onetel.net.uk>
First of all thank you for various tips which I will use in the future. You
are right, I wasn't specific about the "problem". The problem is that
nothing is written to the "web1.html" file. I mnually created this file
beforehand with a simple line of; <HTML>new web</HTML>. After I run the
perl code in question, this file remains exactly the same. It doesn't get
amended.
Regarding the question of the correct path, I think I use the right path
because when the perl code finishes running, You can access the file
"web1.html" with the hyperlink created by the code. If the path was wrong,
the hyperlink wouldn't work either. Am I right?
Edd.
"Jeff Zucker" <jeff@vpservices.com> wrote in message
news:3A33ED75.FEE9D3E9@vpservices.com...
> Edd wrote:
> >
> > I use the code below which just doesn't work.
>
> What in the world does that mean "doesn't work"? Does your computer
> start to smoke? Is a file created but the wrong one? Are there error
> messages? If there aren't error messages, why not? Telling us simply
> "it doesn't work" is as useful as telling your doctor "it hurts" without
> telling him/her what "it" is.
>
> > #!/usr/bin/perl
>
> You should use -w for warnings and -T for taint checking.
> You should use "use strict" for more warnings.
>
> > print "Content-type: text/html\n\n";
>
> Since you are testing this code in a browser, you need to be able to
> send error messages to the browser. put "use CGI::CARP
> qw(fatalsToBrowser);" near the top of your script. You should also
> check the script from the command line first anyway because some
> warnings and errors will only show up on the command line.
>
> > open(LOG, ">web1.html") || print "could not open web1.html $!";
>
> Good, you checked for an error and printed out the error message.
>
> [snip of remainder of script which looks ok on first glance]
>
> > print "<p><a href=\"/web1.html\">LINK TO WEB1</a></p>";
>
> It gets confusing to backwhack quotes, a here-doc or the q() or qq()
> operators are easier to read:
>
> print q( <p><a href="/web1.html">LINK TO WEB1</a></p> );
>
> And, BTW, that looks for a file called "web1.html" in the root directory
> ("/"), is that where you created the file and changed the file's
> permissions? There's nothing in the code above that indicates that the
> directory where you are creating and writing the file is the root
> directory so that is probably your major mistake.
>
> --
> Jeff
------------------------------
Date: Sun, 10 Dec 2000 13:56:32 -0800
From: Michael Budash <mbudash@sonic.net>
Subject: Re: problem with script
Message-Id: <mbudash-478ED1.13563210122000@news.pacbell.net>
In article <20001209174215.02444.00003022@ng-fb1.aol.com>,
fryar386@aol.com (Fryar386) wrote:
> E-mail: $input{e-mail}
should be:
E-mail: $input{'e-mail'}
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Sun, 10 Dec 2000 14:27:57 -0500 (EST)
From: OrlandoReeves@webtv.net (O R)
Subject: Qmail Attachments
Message-Id: <955-3A33D93D-87@storefull-116.iap.bryant.webtv.net>
I wrote a simple perl script to send Qmail from my account at Hypermart.
The "meat" of the script is this:
$mail_prog = '/var/qmail/bin/qmail-inject';
open(MAIL, "|$mail_prog");
print MAIL "TO: $FORM{'to'}\n";
print MAIL "FROM: $FORM{'from'}\n";
print MAIL "SENDER: $FORM{'sender'}\n";
print MAIL "BCC: $FORM{'bcc'}\n";
print MAIL "SUBJECT: $FORM{'subject'}\n\n";
print MAIL "$FORM{'message'}";
close(MAIL);
It works fine, but how do I go about including an image attachment?
------------------------------
Date: Sun, 10 Dec 2000 16:41:59 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: Reading first 5 lines data
Message-Id: <3a33aef6.218460940@news.tcn.net>
On Sun, 10 Dec 2000 09:19:01 -0500, "K6" <blnukem@hotmail.com> wrote:
>next five after that with a link on the bottom. If you have an example of
>this type of function please post.
It would be nice to see what you have done, have you considered posted
some of the code?
--
Richard Zilavec
rzilavec@tcn.net
------------------------------
Date: Sun, 10 Dec 2000 18:00:25 -0000
From: "Al Bennett" <onthebog@hotmail.com>
Subject: Re: substitution regexp
Message-Id: <910gck$jhg$1@news8.svr.pol.co.uk>
hello
thanks for taking the time everyone, this looks like it'll solve my problem!
i wasn't aware of the /e modifier, i'll have a look into all the modifiers,
i'm sure there's alot i don't know about here
also, point taken about .* i noticed it could be dangerous, i'll sort
that out too
thanks again
al
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Quantum Mechanics: The dreams stuff is made of.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Uri Guttman <uri@sysarch.com> wrote in message
news:x7aea5l0d8.fsf@home.sysarch.com...
> >>>>> "AB" == Al Bennett <onthebog@hotmail.com> writes:
>
> AB> $output =~ s/%%pagejump .*%%/replacement/g;
>
> AB> that matches the number
>
> AB> $output =~ s/%%pagejump .*%%/&subroutine($&)/g;
>
>
> use the /e modifier.
>
> also don't use .* casually like that. it probably works as you don't
> cross newlines and . won't match a newline by default. if you ever added
> the /s modifier, it could blow up on you by matching too much. use the ?
> (non_greedy) modifier to limit the match.
>
> read perlre for more on /e and ?
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ----------
http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX
Consulting
> The Perl Books Page -----------
http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net ----------
http://www.northernlight.com
------------------------------
Date: Sun, 10 Dec 2000 21:16:30 GMT
From: Brendon Caligari <bcaligari@my-deja.com>
Subject: SUPER::DESTROY???
Message-Id: <910rrb$tkf$1@nnrp1.deja.com>
Suppose I have a 'Cat' inherited from 'Pest' where both 'Cat'
and 'Pest' should have a DESTROY function.
Is it sensible to manually call Pest's DESTROY from within Cat's? Am I
missing anything?
eg
package Cat;
use strict;
use Pest;
.
.
.
sub DESROY {
my $refPest = shift;
.
.
$refPest->SUPER::DESTROY;
}
cheers
Brendon
++++
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Sun, 10 Dec 2000 20:43:11 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Tie hash of hash using MLDBM
Message-Id: <zVRY5.114$B9.170590208@news.frii.net>
In article <910173$aa5$1@nnrp1.deja.com>, <debjit@my-deja.com> wrote:
>I'm facing problem in tie a has of hash to disk file.
>snip
>use MLDBM qw(DB_File Storable);
>tie %HoH, 'MLDBM', 'mldbm_file', O_CREAT|O_RDWR, 0640;
>....
>Read from text file: $name $value1 $value2
>
>$HoH{name}{value1} = value2;
Did you really mean to use bare words there?
I suppose that you really meant:
$HoH{$name}{$value1} = $value2;
>If I read the 'mldbm_file' only keys come not values,
>
>BUT if I assign like
>%HoH = (
> name1 => { val1 => val2, val3 => val4, },
> name2L => { val1 => val2, val3 => val4, }
>
> );
>I get the value hashes as well.
>
I'd recommend coding up the smallest reasonable demo that illustrates
the problem. As you are writing it you may find the problem your
self. If you dont you'll have a nice small piece of code that you
can post that will make it clearer to us what is going on.
chris
--
This space intentionally left blank
------------------------------
Date: Sun, 10 Dec 2000 21:08:27 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Tie hash of hash using MLDBM
Message-Id: <3A33F16A.BC9FE848@rochester.rr.com>
debjit@my-deja.com wrote:
>
> I'm facing problem in tie a has of hash to disk file.
> snip
> use MLDBM qw(DB_File Storable);
> tie %HoH, 'MLDBM', 'mldbm_file', O_CREAT|O_RDWR, 0640;
> ....
> Read from text file: $name $value1 $value2
>
> $HoH{name}{value1} = value2;
>
> ___
> If I read the 'mldbm_file' only keys come not values,
>
> BUT if I assign like
> %HoH = (
> name1 => { val1 => val2, val3 => val4, },
> name2L => { val1 => val2, val3 => val4, }
>
> );
> I get the value hashes as well.
...
> Debjit
...
That's right. Read the docs:
perldoc MLDBM
looking in particular at the "BUGS" section (even though it isn't really
a bug). Basically, due to the nature of how MLDBM works, it is
necessary to retrieve and store only complete structures under a given
top-level key. For example, to change $HoH{name}{value1}, do
[untested]:
my $tempref=$HoH{name};
$tempref->{value1}={value2};
$HoH{name}=$tempref;
What MLDBM is really doing is simply passing whatever it gets or
retrieves to/from keys through Data::Dumper (or Storable or FreezeThaw)
for serialization. That only works when getting or retrieving keys --
tie doesn't see attempts to access substructures of the hash, and hence
they don't get processed and retrieved from/written to the file. HTH.
--
Bob Walton
------------------------------
Date: Sun, 10 Dec 2000 17:52:53 GMT
From: john@fake.uk
Subject: Using OLE to make InternetExplorer print
Message-Id: <3a33c1bd.5026541@news.hw.ac.uk>
I seem to have walked into a minefield in wanting to use OLE to print
from InternetExplorer. I have found a number of articles that describe
some of the problems and suggest some devious programming.
As I have a "simple" problem I would be grateful for any pointers that
would get me up and running quickly and I promise to read all the docs
and figure it out at my leisure.
I want to use OLE from a Perl Win32 programme to fire up
InternetExplorer (that's OK), load a page from a URL (that's OK),
change to a named printer (how?), print the page (how?), change back
to the original printer (how?) and quit InternetExplorer (that's OK).
Thanks for any help on the "printing" part.
John
------------------------------
Date: Sun, 10 Dec 2000 11:40:05 -0600
From: "John Roth" <johnroth@ameritech.net>
Subject: Re: Why isn't Perl highly orthogonal?
Message-Id: <t37fp0f48i1pfc@news.supernews.com>
Terrence Brannon <brannon@lnc.usc.edu> wrote in message
news:lby9xqj7pp.fsf@lnc.usc.edu...
>
> One day my boss asked me: "how do you get the length of an array in
> Perl?" So I told him:
>
> scalar @array;
>
> But of course what irked me is how unintuitive and irregular Perl is
> and how this forced my boss to ask me something like that.
>
> LENGTH $string => length $string
> LENGTH @array => scalar @array
>
> PORTION $string => substring $string, $offset, $length
> PORTION @array => @array[$offset..$offset+$length]
>
> In other words, conceptually similar operations do not map to the same
> name in Perl. Why does this make Perl a better and not worse language,
> than the intended replacement to Perl, Ruby, which is in fact highly
> regular in all places where Perl isn't, with the above being just a
> few examples?
>
> --
> Terrence Brannon
>
The trouble with this is trying to figure out why on earth an
array should be conceptually similar to a string. There is a major
ambiguity here in that you either can regard a string as a single
entity, i.e. $String in Perl syntax, or as an array of characters,
i.e. @String. C choses the later mapping, and thus loses the
ability to manipulate strings as first class entities. Perl lost the
ability to resolve the ambiguity when Larry decided to make
$X and @X different variables. In the case of strings, they
clearly should be the same variable, with $X treating the
string as an entity, and @X treating it as an array of characters.
That would get rid of some of the string processing functions.
But that's not the way Perl grew.
Or would you rather have the ability to refer to characters
in a string as if they were mapped into a hash? "1st" -> 1,
"2nd" -> 2, etc. That would be really othogonal.
John Roth
>
------------------------------
Date: Sun, 10 Dec 2000 18:04:28 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why isn't Perl highly orthogonal?
Message-Id: <q8h73t0mujv47cjdelpvo789asfve7cjb4@4ax.com>
Terrence Brannon wrote:
>One day my boss asked me: "how do you get the length of an array in
>Perl?"
>But of course what irked me is how unintuitive and irregular Perl is
Didn't you even wonder why your boss insists on calling this "length"? I
call it "number of elements", or "count".
A string has a length. A string is not an array.
--
Bart.
------------------------------
Date: 10 Dec 2000 12:36:50 -0600
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Why isn't Perl highly orthogonal?
Message-Id: <910ig2$qqs$1@boomer.cs.utexas.edu>
In article <q8h73t0mujv47cjdelpvo789asfve7cjb4@4ax.com>,
Bart Lateur <bart.lateur@skynet.be> wrote:
>Didn't you even wonder why your boss insists on calling this "length"? I
>call it "number of elements", or "count".
>
>A string has a length. A string is not an array.
No, but an array is a string. A Perl array may not be the same thing
as a Perl scalar, but that doesn't matter. (Especially since a Perl
scalar isn't really a scalar in the first place. But then again, an
integer in most languages is a bit vector, so they aren't scalars
either...)
- Logan
------------------------------
Date: 10 Dec 2000 20:54:06 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Why isn't Perl highly orthogonal?
Message-Id: <976481346.18717@itz.pp.sci.fi>
In article <t37fp0f48i1pfc@news.supernews.com>, John Roth wrote:
>i.e. @String. C choses the later mapping, and thus loses the
>ability to manipulate strings as first class entities. Perl lost the
>ability to resolve the ambiguity when Larry decided to make
>$X and @X different variables. In the case of strings, they
>clearly should be the same variable, with $X treating the
>string as an entity, and @X treating it as an array of characters.
>That would get rid of some of the string processing functions.
Well, you _can_ have it that way, if you want.
http://www.sci.fi/~iltzu/temp/CharArray.pm
Any comments? Should I try submitting it to the CPAN?
[Note followups.]
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Sun, 10 Dec 2000 21:41:25 GMT
From: David Steuber <nospam@david-steuber.com>
Subject: Re: Why isn't Perl highly orthogonal?
Message-Id: <m3vgsslzta.fsf@solo.david-steuber.com>
Bart Lateur <bart.lateur@skynet.be> writes:
' Didn't you even wonder why your boss insists on calling this "length"? I
' call it "number of elements", or "count".
'
' A string has a length. A string is not an array.
How long is a piece of string?
For some reason, it has never bothered me that to get the length of
$string you use a function called length (not unlike the C library
function strlen() and to get the number of elements in an array or
hash you evaluate it in a scaler context or use the scaler function.
The current piece of string that is giving me fits is the one that is
tied. Specifically, the entire tie business that is discussed in the
Camel book after discussing how objects are implimented. I get bless,
sort of. But how is tie different? It looks like two different ways
to do the same or similar thing.
I've also never understood the concept of orthogonality in a
programming language. C++ claims to be full of it. How this relates
to geometry is a complete mystery to me.
No, I am not drunk. I just received a severe blow to the head.
--
David Steuber | Perl apprentice. The axe did not stop the
NRA Member | mops and buckets from flooding my home.
ICQ# 91465842
*** http://www.david-steuber.com/ ***
------------------------------
Date: Sun, 10 Dec 2000 17:44:29 +0100
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Willing to review a 90 line Perl program?
Message-Id: <3ec73tgrqek3vlt14tda433ovi43vg3hn5@4ax.com>
On Wed, 6 Dec 2000 07:35:17 -0500, tadmc@metronet.com (Tad McClellan)
wrote:
> Philip Garrett <philipg@atl.mediaone.net> wrote:
>
> >You may want
> >something more like this:
> >
> >while( defined($line = <IN>) ) {
>
>
> That doesn't really change anything. perl automatically applies
> the defined() test for the original code. If you leave it out,
> perl will put it in.
>
> I looked around for quite a while trying to find this in the
> standard docs (not counting perldelta*). I could not locate it...
It's in perlop.pod, section "I/O Operators":
while (my $line = <STDIN>) { print $line }
In these loop constructs, the assigned value (whether assignment is
automatic or explicit) is then tested to see whether it is defined.
The defined test avoids problems where line has a string value that
would be treated as false by Perl, for example a "" or a "0" with no
trailing newline. If you really mean for such values to terminate the
loop, they should be tested for explicitly:
...
--
Good luck,
Abe
perl -wle '$_=q@Just\@another\@Perl\@hacker@;print qq@\@{[split/\@/]}@'
------------------------------
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 5077
**************************************