[12112] in Perl-Users-Digest
Perl-Users Digest, Issue: 5712 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 18 11:07:19 1999
Date: Tue, 18 May 99 08:00:22 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 18 May 1999 Volume: 8 Number: 5712
Today's topics:
Re: ==> Returnig Filehandles from Subroutines <== <swarren@www.wwwdotorg.org>
Re: A Perl Script (Larry Rosler)
Re: A Perl Script <emschwar@rmi.net>
Accents Sensitivity amenrique@my-dejanews.com
backspace in file output question papakee@aol.com
can someone help me with locking??? <mlynch@bfsec.bt.co.uk>
Re: changing drive letters on NT? <swarren@www.wwwdotorg.org>
Re: Error message when reading a file <dgris@moiraine.dimensional.com>
Re: Extracting form fields <swarren@www.wwwdotorg.org>
Re: FAQ 4.15: How do I find yesterday's date? <dgris@moiraine.dimensional.com>
Re: File with TABS (Tad McClellan)
Re: File with TABS (Larry Rosler)
Re: get date <rwmip@glink.net.hk>
How to create modules? <ldkronos@umd.umich.edu>
Re: inserting a byte into a file (Larry Rosler)
Re: inserting a byte into a file <dgris@moiraine.dimensional.com>
Object Oriented Perl - good reference? <"%GIVEN NAME%.o'regan"@port.ac.uk>
object oriented perl-good reference? <"%GIVEN NAME%.o'regan"@port.ac.uk>
Re: OOP and Perl-a good book? <jll@skynet.be>
Re: OOP and Perl-a good book? (Bart Lateur)
Re: Perl "constructors" <jdporter@min.net>
Re: Perl "constructors" <jdporter@min.net>
Re: Perl "constructors" zenin@bawdycaste.org
Problem to upload image file <ex5316@netvigator.com>
Re: Removing Data from the File <swarren@www.wwwdotorg.org>
Re: Sorting problem (Randal L. Schwartz)
Re: Sorting problem <gellyfish@gellyfish.com>
Telnet Prompt <pdncoop@americasm01.nt.com>
Re: Weird socket behaviour <gellyfish@gellyfish.com>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 18 May 1999 10:48:10 -0400
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: ==> Returnig Filehandles from Subroutines <==
Message-Id: <7hrum8$1ot$1@owl.slip.net>
Andreas Fischer <Andreas.Fischer@germany.Sun.COM> wrote in message
news:37412E1A.98220FE0@germany.Sun.COM...
> Hello,
> does anybody know a solution for the following problem?
>
> MakeSomthing(*F);
>
> sub MakeSomething
> {
> local(*G)=@_;
> .....
> .....
> return(*G);
> }
>
> I want return the filehandle to main on that point where "MakeSomething"
> stops.
In this case, why bother? main already has the file-handle since it passed
it into the function! Simply having a function read from the filehandle
won't stop the filehandle referring to the file correctly. What you're
actually doing is making the (local to MakeSomething value of) global symbol
G refer to exactly the same thing as global F - you're affecting the exact
same file-handle.
Assuming you're on Perl5, your sub could also look like:
sub MakeSomething
{
my $fh = shift ;
# or: my ( $fh ) = @_ ;
}
Then, $fh would be a reference to a file-handle and so you could do:
print $fh "hello\n" ;
which would get rid of the local.
--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com http://www.techhouse.com/
mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
MIME, S/MIME and HTML mail are acceptable
------------------------------
Date: Tue, 18 May 1999 07:10:44 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: A Perl Script
Message-Id: <MPG.11ab14ad7d19a567989a92@nntp.hpl.hp.com>
In article <7hrm3u$e3n$1@fleetstreet.Austria.EU.net> on Tue, 18 May 1999
14:23:26 +0200, Thomas Klinger <t.klinger@mobilkom.at> says...
...
> >print "Your IP Address is $ENV{REMOTE_ADDR}.\n";
> $ENV{4REMOTE_ADDR4} is needed here.
Those ticks don't look like ASCII single-quotes. And even if they were,
they're *not* needed here.
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 18 May 1999 08:18:21 -0600
From: Eric The Read <emschwar@rmi.net>
Subject: Re: A Perl Script
Message-Id: <xkfzp32ihqq.fsf@valdemar.col.hp.com>
"Thomas Klinger" <t.klinger@mobilkom.at> writes:
> somebody else whose name he snipped wrote:
> >print "Your IP Address is $ENV{REMOTE_ADDR}.\n";
> $ENV{=B4REMOTE_ADDR=B4} is needed here.
Assuming that =B4 is a ' or " (please use ASCII for ASCII characters), then=
=
it's not necessary, unless the hash key has spaces or non-word characters
in it.
$ENV{REMOTE_ADDR} is fine
$ENF{'REMOTE ADDR'} requires quotes.
-=3DEric
------------------------------
Date: Tue, 18 May 1999 13:02:55 GMT
From: amenrique@my-dejanews.com
Subject: Accents Sensitivity
Message-Id: <7hrodu$6jb$1@nnrp1.deja.com>
I have developed a search engine in Spanish. It works fine. The problem
is that users are trying to find words without writing the accents used
in spanish, i.e. they search for Maria with no results, as the right
spelling is Marma (with an accent on the i)
Is there an easy way the make the search "not sensitive" to the
accents, so a search for Maria would return all findings with Marma?
Sorry if the answer is obvious, but I have tried to find a solution at
the Perl Man and the FAQs on www.perl.com without success.
Antonio
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Tue, 18 May 1999 12:48:45 GMT
From: papakee@aol.com
Subject: backspace in file output question
Message-Id: <7hrnjd$64h$1@nnrp1.deja.com>
I wrote my first perl program which simply
takes input from STDIN and printf's it to
an output file. If I have to backspace to
correct a typo, the offending characters and the
backspace appears in the output file also.
This is on a DOS/Win version of perl. Anyone
know how to process the backspace before it
appears in the file?
Thanks in advance: Tim
papakee@aol.com
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Tue, 18 May 1999 15:37:18 +0100
From: "Martin Lynch" <mlynch@bfsec.bt.co.uk>
Subject: can someone help me with locking???
Message-Id: <7hru04$bvg$1@pheidippides.axion.bt.co.uk>
Hi
Fairly new to this perl game and my question is this
Ive got a web based form where a user can enter details. These details that
are submitted are then added to a web page. This is working fine
What i want to ensure is that if two people are submitting simultaneously, i
dont loose one set of data. So i need to employ some sort of locking to
avoid this happening.....
Thing is i dont know where or how to do this........
hope someone can help... heres my current code
#!/usr/bin/perl
require("cgi-lib.pl");
print "Content-type: text/html";
print "\n";
# Get data from HTML page #
#########################
&ReadParse;
print &PrintHeader;
print "<HTML>\n<HEAD><TITLE>RFC Tool</TITLE>\n";
print "</HEAD>\n";
print '<BODY BGCOLOR=YELLOW"
TEXT="black"
LINK="blue"
VLINK="blue"
ALINK="blue">'."\n";
# Set the path of the data file
$path="/pathname/test.htm";
# Ensure that the TITLE isn't blank.
$title = $in{'title'};
if ($title eq '')
{
$title = '-';
}
#Ensure that the DETAILS field isnt blank
$details = $in{'$details'};
if ($details eq '')
{
$details = '-';
}
# Write the data out to the file.
open(INDEX,">>".$path);
print INDEX
"<P>
<HR WIDTH=\"100%\">
<LI>
<B><FONT FACE=\"Arial\"><FONT SIZE=+0>".$title."</FONT></FONT></B></LI>"
."<BR><FONT FACE=\"Arial\"><FONT
SIZE=+0><PRE>".$in{details}."</PRE></FONT></FONT>";
close (INDEX);
# This prints a message to the screen to tell the user of success
print '<center><br><br><H3>Details added sucessfully.</H3><BR><br>
------------------------------
Date: Tue, 18 May 1999 10:50:22 -0400
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: changing drive letters on NT?
Message-Id: <7hruqc$1ph$1@owl.slip.net>
James T Uren <jturen@earthlink.net> wrote in message
news:37413949.20E1@earthlink.net...
> Hi,
> I am learning Perl on a PC.
> I am able to perform "net view", "net use * \\host\share"
> and etc. But I am curious why I can't select other drive
> letters. I've tried many combinations of
> system 'g:';
> system 'chdir /d g:\\';
system() simply starts a sub-process to execute the command you gave. This
sub-process cannot affect the parent process's current working directory.
You need to:
perldoc -f chdir
--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com http://www.techhouse.com/
mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
MIME, S/MIME and HTML mail are acceptable
------------------------------
Date: 18 May 1999 07:32:10 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Error message when reading a file
Message-Id: <m3k8u6jyg5.fsf@moiraine.dimensional.com>
Dick Latshaw <latsharj@my-dejanews.com> writes:
> Correct! Readdir gives you a directory listing, including . , .., and
> any subdirectories. Next take a look at: for my $filename (<*>) {
The standar perl idiom for scanning directories is-
for ( grep { !/^\.\.?$/ } readdir (DIR)) {
do_stuff($_);
}
This is a big win as it doesn't involve invoking a potentially
buggy csh.
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Tue, 18 May 1999 10:41:54 -0400
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: Extracting form fields
Message-Id: <7hruaf$1n9$1@owl.slip.net>
<jenmei@my-dejanews.com> wrote in message
news:7hr82b$see$1@nnrp1.deja.com...
> Is there an easy way to extract form fields using Perl?
You might try the CGI module:
use CGI ;
> I'm just
> looking for a quick way to automate logging into a Web page (all HTML,
> no password dialogs) and submitting a few forms. I was hoping someone
> may have written something that would make this easier.
It sounds like you're trying to use HTML forms for security. Re-inventing
the wheel may not be the most secure thing in the world...
Perhaps you should go to the comp.infosystems.www.authoring.cgi newsgroup
and read their FAQ - some of the answers you want are probably there, since
this newsgroup doesn't really have anything to do with CGI specifically
(although you could use Perl to write your CGI scripts)
--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com http://www.techhouse.com/
mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
MIME, S/MIME and HTML mail are acceptable
------------------------------
Date: 18 May 1999 07:39:23 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: FAQ 4.15: How do I find yesterday's date?
Message-Id: <m3emkejy44.fsf@moiraine.dimensional.com>
"Jim The Perl Guy" <news@thebeaches.to> writes:
> No matter what day of the week, month, year, decade or century, there are
> only 86,400 seconds unless it's a daylight savings switch. In that case,
> you'll have to write a rather large sub to recognize those dates. Doable but
> it only makes a difference twice a year. Is it that much of a difference?
Not handling time changes means that you are producing buggy code
that only works some of the time. Doing so when you know better
is The Wrong Thing, it isn't fair to the person who maintains your
code, your employer, or your users.
Fortunately, you don't have to write a large sub to handle
this--Russ Allbery already did that.
http://moiraine.dimensional.com/~dgris/cgi-bin/pfr?func=yesterday&type=exact
dgris
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Tue, 18 May 1999 03:52:38 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: File with TABS
Message-Id: <686rh7.f49.ln@magna.metronet.com>
John Wilkinson (john.wilkinson@soton.sc.philips.com) wrote:
: Now I have a little problem I cannot solve on my own, I need help.
But you *can* solve it on your own (well, really with the help
of the doc files already on your hard disk).
: I need to be able to read in the file and strip off the TABS before I
: add the extension. I have tried using chomp, to no avail.
: Any ideas please.
Perl FAQ, part 4:
"How do I strip blank space from the beginning/end of a string?"
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 18 May 1999 07:22:11 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: File with TABS
Message-Id: <MPG.11ab176c692cfe29989a93@nntp.hpl.hp.com>
In article <7hrkld$1cb$1@news.auaracom.net> on Tue, 18 May 1999 07:58:15
-0400, Jim The Perl Guy <news@thebeaches.to> says...
> Use a REgExp:
>
> $filename = "/bin/foo.tl";
> $filename =~ s/\t+//g;
$filename =~ tr/\t//d; # This is much faster, if it matters.
> or if that doesn't work correctly for you, then:
> $filename =~ s/\W//g;
print $filename; # Prints 'binfootl'.
More likely you meant \s instead of \W. The tr///d approach also
handles a set of characters, but you have to name each of them
explicitly:
$filename =~ tr/ \t\n\r\f\b//d;
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 18 May 1999 21:26:36 +0800
From: Raymond Ip <rwmip@glink.net.hk>
Subject: Re: get date
Message-Id: <37416A8C.1588820@glink.net.hk>
Thanks for your information.
I try to use the follow command, why the $mon has one month difference,
today's month is May, but return is April.
Best Regards
Raymond Ip
Me <g9D!G
> Raymond Ip wrote:
> >
> > How do I get the current date and use it as a filename ??
> >
> > eg 990517.log
> >
> > Thanks and Best Regards
> >
> > Raymond Ip
>
> you can use localtime() eg.
>
> ($sec,$min,$hr,$mday,$mon,$yr,$wday,$yday,$isdat)=localtime(time);
> ....
> --
>
> ---------------------------------------------------------------------
> Protect privacy, boycott Intel PIII: http://www.bigbrotherinside.org
> ---------------------------------------------------------------------
------------------------------
Date: Tue, 18 May 1999 11:00:01 -0400
From: "Ron Frazier" <ldkronos@umd.umich.edu>
Subject: How to create modules?
Message-Id: <kff03.224$Em.4068@news.itd.umich.edu>
How do I create and use modules? Say I have a function called Test() that I
want to put in another file (we'll call it subs.pm). Then I want to use the
Test() function is testing.pl. How do I define everything (in both the
subs.pm and the testing.pl files).
Thanks to anyone who can help. If you dont mind, please email me your
response.
--
Ron Frazier
ldkronos@umd.umich.edu
http://www-personal.umd.umich.edu
------------------------------
Date: Tue, 18 May 1999 07:45:39 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: inserting a byte into a file
Message-Id: <MPG.11ab1ce61770db35989a94@nntp.hpl.hp.com>
In article <7hrkhp$1c2$1@news.auaracom.net> on Tue, 18 May 1999 07:56:25
-0400, Jim The Perl Guy <news@thebeaches.to> says...
> This isn't easy but it's a workaround:
Wrong -- it is a nonwork-around. And you didn't test the code at all
before posting it. This is BAD!
> open(TEMP1, "<$file") || die "Can't open $file: $!\n";
> open(TEMP2, "<New_$file") || die "Can't open $file: $!\n";
Wrong -- opens nonexistent file for input.
> while(<>) {
> if($_ =~ /your_pattern_match/) {
> print TEMP2 "$new_input\n";
> } else {
> print TEMP2 "$_\n";
Wrong -- unless you want two lines for every line in the input file.
> }
> }
> close(TEMP1);
> close(TEMP2);
> rename("New_$file", "$file");
The quotes around $file are superfluous (a string is a string). Where
is the test for failure of this system call?
You are trying to answer a FAQ, which is not necessarily a good idea.
perlfaq5: "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?"
--
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 18 May 1999 08:58:14 -0600
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: inserting a byte into a file
Message-Id: <m3aev2jwb1.fsf@moiraine.dimensional.com>
"Jim The Perl Guy" <news@thebeaches.to> writes:
> This isn't easy but it's a workaround:
Not only is it not easy, it is also not correct, not an example
of good style, and not helpful to the original questioner.
> open(TEMP1, "<$file") || die "Can't open $file: $!\n";
This looks fine, and you even remembered to check the
status of the system call.
> open(TEMP2, "<New_$file") || die "Can't open $file: $!\n";
This isn't so good, I'm thinking. You've just opened that
filehandle for reading, but you want to write to it later.
> while(<>) {
Now you loop on either-
1. The contents of each file named in @ARGV
2. The data passed in via STDIN
Either way you aren't reading the data that you think
you're reading.
> if($_ =~ /your_pattern_match/) {
> print TEMP2 "$new_input\n";
> } else {
> print TEMP2 "$_\n";
> }
> }
This section would work if $_ was set to anything (which it
probably isn't) and if TEMP2 had been opened for writing.
> close(TEMP1);
> close(TEMP2);
You need to check the status of these to make sure that
you didn't run out of disk.
Try this (not portable to POB systems)-
#!/home/dgris/bin/perl
use strict;
my $file = shift || die "Specify a file on the command line, please\n";
open (F, $file ) || die "Couldn't open $file: $!";
unlink ( $file ) || die "Couldn't unlink $file: $!";
open (O, ">$file") || die "Couldn't open $file for writing: $!";
while (my $line = <F>) {
if ($line =~ /^\s*#.*$/) {
$line = ''; # clobber comments
}
print O $line;
}
close (F) || die "Close failed for readonly file $file: $!";
close (O) || die "Close failed for writable file $file: $!";
__END__
In the future, please do not post untested code.
--
Daniel Grisinger dgris@moiraine.dimensional.com
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'
------------------------------
Date: Tue, 18 May 1999 14:53:47 +0100
From: "%GIVEN NAME% o'regan" <"%GIVEN NAME%.o'regan"@port.ac.uk>
Subject: Object Oriented Perl - good reference?
Message-Id: <374170EB.458AE6B0@port.ac.uk>
I am learning PERL and have a project coming up to design web forms for
on-line
submission of information. I was thinking I could use Object-Oriented
principles to design
the basic form class and grow from there. (I have done some very basic
OOAD and some
very basic JAVA so I already have a good understanding of the basics of
OO) I have tried
creating objects in PERL, but still struggling with the 500 error.
Would any be able recommend a good book that addresses OO in Perl
comprehensively?
Has anyone ever approached this type of project in this way?
any help appreciated.
David O'Regan
------------------------------
Date: Tue, 18 May 1999 14:55:10 +0100
From: "%GIVEN NAME% o'regan" <"%GIVEN NAME%.o'regan"@port.ac.uk>
Subject: object oriented perl-good reference?
Message-Id: <3741713E.21068BD4@port.ac.uk>
I am learning PERL and have a project coming up to design web forms for
on-line
submission of information. I was thinking I could use Object-Oriented
principles to design
the basic form class and grow from there. (I have done some very basic
OOAD and some
very basic JAVA so I already have a good understanding of the basics of
OO) I have tried
creating objects in PERL, but still struggling with the 500 error.
Would any be able recommend a good book that addresses OO in Perl
comprehensively?
Has anyone ever approached this type of project in this way?
any help appreciated.
David O'Regan
------------------------------
Date: Tue, 18 May 1999 15:38:57 +0100
From: Jean-Louis Leroy <jll@skynet.be>
Subject: Re: OOP and Perl-a good book?
Message-Id: <VA.0000023d.2000d449@godot>
In article <37415EBF.4FBE040E@utk.edu>, Jay Flaherty wrote:
> "Advanced Perl Prograqmming" by S. Srinivasan (ISBN 1-56592-220-4)
Yes it's an excellent book but watch out: ObjectTemplate doesn't work,
as this example demonstrates:
package Person;
use ObjectTemplate;
@ISA = qw(ObjectTemplate);
attributes qw(address);
package NaturalPerson;
use ObjectTemplate;
@ISA = qw(Person);
attributes qw(x);
package LegalPerson;
use ObjectTemplate;
@ISA = qw(Person);
attributes qw(y);
package main;
$n = NaturalPerson->new();
$n->address('Springfield');
print $n->address(), "\n"; # Springfield
$l = LegalPerson->new();
$l->address('One Microsoft Way');
print $n->address(), "\n"; # One Microsoft Way!
Jean-Louis Leroy
http://ourworld.compuserve.com/homepages/jl_leroy
------------------------------
Date: Tue, 18 May 1999 13:44:10 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: OOP and Perl-a good book?
Message-Id: <37416cdc.23749570@news.skynet.be>
Phil Voris wrote:
>I've been vainly attempting to learn the practical usage of OO. Being
>as I'm most familiar with Perl, I began a project using OO Perl and Perl
>Tk. I rapidly realized that understanding OO syntax was not sufficient:
>I still had problems implimenting the GUI as a separate class from the
>heart of the application. I apparently didn't 'get it.'
There's a whole chapter (no, 3; plus an appendix with an overview)
devoted to Perl/tk in the Advanced Perl Programming book. It looks not
too daunting. And I remeber having seen a WHOLE BOOK about Perl/Tk in a
shop!
http://www.oreilly.com/catalog/lperltk/
Bart.
------------------------------
Date: Tue, 18 May 1999 12:48:12 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7hrnic$5ta$1@nnrp1.deja.com>
In article <7hrbsk$ur3$1@nnrp1.deja.com>,
armchair@my-dejanews.com wrote:
> Returning an integer gives you a perfect way to show different types
of
> failure, and is why I prefer it. Since you (and others here) only
return
> undef or a success/result , how are you differentiating between
> failures?
Um, what about proceeding as normal on success (no return code to
test), and throwing an exception on error?
--
John Porter
Put it on a plate, son. You'll enjoy it more.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: Tue, 18 May 1999 13:10:50 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Perl "constructors"
Message-Id: <7hrosq$6vj$1@nnrp1.deja.com>
In article <7hqo34$hlt$1@nnrp1.deja.com>,
armchair@my-dejanews.com wrote:
> I said "new", but I think the same name as the Module/Class would
> actually be better. But since Perl does not have what C++ calls
> "function overloads" where the same name can be used for different
> functions, who each differ by input parameter types - having only one
> allowable name for a constructor would preclude having multiple
> constructors of an object. I can see where that would be undesirable.
So
> I wouldn't propose any restriction on the constructor name unless Perl
> added support for two or more methods having the same name.
Groovy. Although, even if Perl did add support for overloading, the
restriction on naming you propose would still be bogus.
> > But this is a bogus restriction that makes life worse for Perl
> > programmers while adding nothing of any benefit to anyone else.
>
> I think there is some benefit to be looking at code and instantly see
> that a method is a constructor, or not.
You suppose that you do. But have you ever worked with a system
that did not have this "benefit"? I can imagine that if suddenly
C++ let you name your constructors anything and everything, you'd
be pulling your hair out, because of the memory management issues.
"Who allocated this? Where? Who owns it? Where's it gonna get
deleted"? But these issues are absent in Perl.
> > "Right" is only meaningful in context. When you're programming
> > in Perl, the Perl way *is* the right way. At least, "more right"
than
> > the way of some alien language.
>
> I would agree that "right" is a matter of opinion in many things,
> including this.
Sure; but that's not what I said. When you're programming in Perl,
the Perl way is the right way. That's context.
> I am using size of the project to try and amplify a value or benefit.
> If I recommended you use a squeegee to clean your windshielf, you
would
> laugh and say "I've been using a paper towel just fine for years and
> so have all my friends and we have the cleanest windhields in town".
And
> that's true, with one windshield cleaning
> a month, the benefit of a squeegee is negligible. But when you are
> assigned the task of cleaning every windshield in the mall parking,
the
> benefit of a squeegee starts to become significant. Size matters.
Here's your analogy corrected: Perl is a squeegee and spray bottle
used by the mall lot crew. C++ is the high-pressure hose at the
truck depot.
> > > I have not run into any brick wall,
> >
> > Then your argument is merely academic.
> > Perl doesn't respect academic arguments.
> > Perl gets real work done in the real world.
> > That its design philosophy! Perl is Practical.
>
> You write "Perl doesn't respect academic arguments".
> Can you please define Perl as used in your statement.
By convention, "Perl" refers to the language, and "perl" refers
to any given executable program which interprets that language.
So I'm saying: the language, by its design, does not attempt to
satisfy ivory-tower notions of what a programming language ought
to be. At every decision point, the path was chosen which optimizes
the practicality of the language.
> As a Perl advocate, I would refrain from using the phrase "kludgy
> half-baked OOPL wannabe".
Hey, I like C++ too. I have used it for years. But anyone who
supposes that C++ is a full-blown OO language really doesn't know
from OO. C++'s OO is kludgy, becuase of the way it was grafted
onto C. (Same sitch with Perl, of course, but I don't think anyone
is making any claims for Perl's supremacy as an OO language.)
> ...a chorus of - "you don't
need
> objects, objects don't buy you anything, you can get there from here
> without objects, don't put your box on Perl,
> think the Perl way, you're not smart enough for Perl, go use a
language
> other than Perl."
For some strange reason I see your proposed naming restrictions on
constructors as being more of the "boxing in" type than the
liberating type. Whereas adding objects -- which no one is required
to use -- is hardly boxing in.
> And yet.... now Perl has objects. The point being,
> Perl is a dynamic language, like most languages seeing continued
usage.
> Things have been added to Perl over the years, and I am sure they will
> continue to be added, in the same way C++ has added strings, and via
the
> STL, dynamic arrays and maps. So I can only hope that you won't try
and
> put Perl in a box regarding things like records. I don't think Perl
> would like that.
Oh, records. As I said elsewhere -- You have the source code.
--
John Porter
Put it on a plate, son. You'll enjoy it more.
--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---
------------------------------
Date: 18 May 1999 14:36:45 GMT
From: zenin@bawdycaste.org
Subject: Re: Perl "constructors"
Message-Id: <927038345.900648@localhost>
armchair@my-dejanews.com wrote:
: In article <7hp5o4$dko$1@nnrp1.deja.com>,
: John Porter <jdporter@my-dejanews.com> wrote:
:> In article <7hlu8v$bl9$1@nnrp1.deja.com>,
:> armchair@my-dejanews.com wrote:
:> > Maybe agreement isn't the right word, but I certainly have gotten lots
:> > of positive feedback.
:>
:> Really? The most positive thing I could say about your unwarranted
:> complaints about Perl is: you do well to think critically about the
:> design of the language, but eventually you'll see why the decisions
:> were made the way they were.
:
: Thanks, on balance I think we are definitely dealing with a positive
: number.
*the mind boggles*
:> > That is one reference per object. $self. I am aware that you can
: have
:> > that reference point to a data structure, which in turn can hold
:> > references to other data structures.
Your browser still can't linewrap correctly.
:> And how is this different from C++ exactly?
:> (Answer: It's not.
:>
:> p = new SomeStruct;
:> p->ptr1 = new Foo( 10, 20 );
:> p->ptr2 = new That( 10, 20 );
:
: The difference is that p is a pointer to a struct, and Perl has no structs
: (records).
No, it has hashes, which have the same effect for nearly all
practical uses.
: And yet is has something that is only a special symbol away from being one
: as I illustrated elsewhere:
:
: my #time_record
: ( $sec,
: $min,
: $hour,
: $mday,
: $mon,
: $year,
: $wday,
: $yday,
: $isdst
: ) = localtime(time);
my %time_record;
@time_record{qw(
sec
min
hour
mday
mon
year
wday
yday
isdst
)} = localtime;
What's your point?
: And just what is the big horrid taboo about records? What is so
: outrageous about the concept?
There is none. Quite the opposite actually, as perl has built in
support for hashs (records).
: What would happen to Perl programmers if you had my record ( $name,
: ^$address, $city, $state, $zip, $ref_other ); in the
: language?
What would it gain over a hash? Hint: nothing.
:> Maybe you don't relish the idea of all your numbers being stored
:> as strings, and getting converted -- a costly operation -- to an
:> integer or float each time you use it. That's why Perl caches the
:> result of the conversion. And this cached conversion works both
:> ways:
:>
:> $n = $x + 5; # a number
:> print $n; # convert to string
:> $s = "$n zots"; # use the cached string value again
:
: If I followed your description, it seems the comments would be
: $n = $x + 5; # convert string to number add 5, convert number to string
: # assign to other string
Wrong. If $x already has a valid number component it is used,
otherwise it is converted. The result stored in $n is a number.
All other slots of $n are flagged invalid.
: print $n; # print string
Wrong. Convert number to string and store in $n's string slot.
Print the string. The number slot of $n remains and is still
flagged valid (because it is).
: $s = "$n zots"; # combine string var with string literal,
: # assign result to string
Correct, for once.
: I am not looking for a separate type for short, int, double, just one
: that holds numeric values.
my $n;
If you want to be anal and blow chunks if anyone ever tries to put
anything "non-numeric" into $n, make yourself a pretty little tied
scalar class.
: What technique do you use to validate that the $var you as being passed
: is actually a numeric value?
It depends; Define numeric. Decimal, float? Also note that in perl
"123 foo bar dog" == 123. Of course under -w you'll get a warning
if you do that, however if $n = '0 but true' you won't. It will all
"work" however.
If you want to be anal, use a regexp to check it.
There is a method to this madness however, that you don't have the
experience to understand as yet.
:> It's all in how you understand the work "LOOK". You can't do this and
:> expect sensible results:
:>
:> $n = 5; # a number
:> $n->(); # deref as a function reference?
:
: # deref method of an object?
No. See above about not expecting sensible results. $n->() is a
cleaner shorthand for &{$n}(), but with $n not being a code ref that
won't work.
: I am not sure how showing me code that illustrates how dollar sign does
: not differentiate the type of the variable, helps your case.
We're still waiting for you to make a valid case at all, what's
the difference?
:> You can't even do this:
:> $r = [ 5, 9 ]; # an array ref
:> $r->{'foo'}; # deref as a hash reference?
:> perl (the interpreter) is far more concerned with the types of the
:> *values* than the types of any things which hold values.
:
: It's concerned enough to require you to explicitly specify the "type" as
: a prefix to every variable both at declaration and at every usage. And
: of course I am not complaining about that explicit differentiation, and
: will even praise it. But, the $ type symbol is obviously ambiguous -
: string? number? reference to another variable?
It's a single value, which is why we call it a "scalar" value. It's
not ambiguous at all.
--
-Zenin (zenin@archive.rhps.org) Caffeine...for the mind.
Pizza......for the body.
Sushi......for the soul.
-- User Friendly
------------------------------
Date: Tue, 18 May 1999 21:58:40 +0800
From: Alex <ex5316@netvigator.com>
Subject: Problem to upload image file
Message-Id: <37417210.EF4B1A07@netvigator.com>
Hi all,
Please tell me why I cannot use the following to upload an image file to
the file $uploadimg.
open(TMP, ">$uploadimg");
binmode(TMP);
print TMP $CGI{'UploadedFile'}->{'Contents'};
close(TMP);
There is no problem to upload the text file with the above script.
Thank you
alex
------------------------------
Date: Tue, 18 May 1999 10:37:49 -0400
From: "Stephen Warren" <swarren@www.wwwdotorg.org>
Subject: Re: Removing Data from the File
Message-Id: <7hru2r$1lp$1@owl.slip.net>
Wassim Metallaoui <wassimk@iname.com> wrote in message
news:3740e732.0@wznews.webzone.net...
> Can someone please explain some of this too me.. . I am trying to remove
the
Re-indented for clarity. Comments moved to avoid wrapping...
> sub unsubscribe {
>
> # routine that makes sure its an okay e-mail address to use.
> # if its not okay then it will exit and tell me
> &checkaddress;
>
> # opens the database file, each line is an e-mail address
> open (DAT,"$listdir/emails.txt");
Add: || die "Can't open '$listdir/emails.txt' for reading: $!" ;
> # just locks the file
> if ($LOCK_EX){ flock(DAT, $LOCK_EX); }
> # puts everything into an array
> @database_array = <DAT>;
> close(DAT); #closes the file
>
> #standard html header
> print "Content-type: text/html\n\n";
>
> #opens the file again
> open (DAT,"<$listdir/emails.txt");
> # locks it
> if ($LOCK_EX){ flock(DAT, $LOCK_EX); }
One wonders why - you don't read from it again.
If you do keep this, you should add the '|| die' part here too.
> #defines the lines from the database array
> foreach $lines(@database_array) {
> # chops off the end character on the lines
> chomp($lines);
End of line characters!
> # e-mail inputted from the web
> $email = $INPUT{'email'};
Why not do this outside the loop?
> # changes all of the lines contents from
> $lines =~ tr/A-Z/a-z/;
> uppercase to lowercase
One might consider storing the email addresses in the file in lower case so
that this wasn't required each time.
> # changes all of the e-mails contents from uppercase to lowercase
> $email =~ tr/A-Z/a-z/;
Again, this should be done outside the loop.
> # if the database has the e-mail in it then tell me so and move on
> if ($lines eq $email)
> # tell me whats going on
> print "removed successfully";
> # close the data file
> close (DAT);
Never used it!
> # opens file with write permissions
> open (DAT,">$listdir/emails.txt");
More like opens file for writing *if* you have write permissions.
Again, you need to add '|| die' part here. (Or some error checking)
> # locks it
> if ($LOCK_EX){ flock(DAT, $LOCK_EX); }
> # defines the lines in the array
> foreach $lines(@database_array) {
*Reads* not defines the lines. You're using the same variable name as your
outer loop which probably isn't a good idea.
One might also name your variable as a non-plural name - $lines actual
contains one line, not multiple lines.
> # chops of the ends of the lines
> chomp($lines);
>
> # the e-mail from the we
> $email = $INPUT{'email'};
You already have this.
> # converts uppercase to lower
> $lines =~ tr/A-Z/a-z/;
> # converts uppercase to lower
> $email =~ tr/A-Z/a-z/;
You already did this.
> # if the email is not in the database then there is nothing to
remove
> if ($lines ne $email) {
> print DAT "$lines\n"; #so put everything back in
The bit you're looking for is here. A line gets written back to the file if
it isn't (case-insensitive)-equal to the email from the form.
> }
> }
> # close the file
> close (DAT);
>
> # exit the script
> exit;
> }
> }
> # tell me I am not in it...
> print "Your not in the database";
You're
> # close something again..
> close (DAT);
> # exit the script
> exit;
>
> } #closes the sub
I don't think the braces match unless I mis-interpreted your code...
This seems an extremely convoluted way of doing things. A better way would
be something more like:
Open original for reading/writing
Open temp file for writing
foreach line in the file
{
if the line doesn't match the email
write to output file
}
close writing file
seek back to beginning of reading file
open temp file for reading
foreach line of temp file
write to original file
close temp file
close original file
With the appropriate locking. This way you're guaranteed a backup copy in
the event of a crash. It also separates out the algorithm from nested loops.
--
Stephen Warren, Snr Systems Engineer, Technology House, San Francisco
mailto:swarren@techhouse.com http://www.techhouse.com/
mailto:swarren@wwwdotorg.org http://www.wwwdotorg.org/
MIME, S/MIME and HTML mail are acceptable
------------------------------
Date: 18 May 1999 07:22:01 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Sorting problem
Message-Id: <m1wvy6lapi.fsf@halfdome.holdit.com>
>>>>> "Arjun" == Arjun Ray <aray@nmds.com> writes:
Arjun> | Naaah... I'd go with more of:
Arjun> |
Arjun> | print
Arjun> | map "<tr>$_</tr>",
Arjun> | map { join "", map { "<td>".(/^$/ ? "-" : $_)."</td>" } @$_ }
Arjun> | sort { $b->[2] <=> $a->[2] }
Arjun> | grep { $_->[1] =~ m/$FORM{'TNSET'}/i }
Arjun> | map { chomp; [ split /;/ ] }
Arjun> | @techlines;
Arjun> Hey, pretty cool. (Reminds me of APL!)
Arjun> I suppose the only thing that might be dodgy is the 'join ""' part.
Arjun> Wouldn't a strategic 'print @array' take care of this automatically?
I had considered making an arrayref instead of a single string, and
then realized I'd be building a data structure with no purpose, since
the next stage just wraps the whole thing anyway. I mean, to get a
little weirder, I could have done this:
print
map { local $" = ""; "<tr>@$_</tr>" }
map { [map "<td>$_</td>", map { /^$/ ? "-" : $_ } @$_] }
sort { $b->[2] <=> $a->[2] }
grep { $_->[1] =~ m/$FORM{'TNSET'}/i }
map { chomp; [ split /;/, $_, 9 ] }
@techlines;
That'd be much more APL-like. :)
print "Just another APL, er, Perl hacker,"
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 18 May 1999 15:38:07 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Sorting problem
Message-Id: <37417b4f@newsread3.dircon.co.uk>
Thomas Klinger <t.klinger@mobilkom.at> wrote:
> Arjun Ray schrieb in Nachricht <37d5f89d.2693474261@news1.newscene.com>...
>>In <m1vhdrm4jj.fsf@halfdome.holdit.com>,
>>merlyn@stonehenge.com (Randal L. Schwartz) wrote:
>>
>>| Naaah... I'd go with more of:
>>|
>>| print
>>| map "<tr>$_</tr>",
>>| map { join "", map { "<td>".(/^$/ ? "-" : $_)."</td>" } @$_ }
>>| sort { $b->[2] <=> $a->[2] }
>>| grep { $_->[1] =~ m/$FORM{'TNSET'}/i }
>>| map { chomp; [ split /;/ ] }
>>| @techlines;
>>
>>Hey, pretty cool. (Reminds me of APL!)
>>
>>I suppose the only thing that might be dodgy is the 'join ""' part.
>>Wouldn't a strategic 'print @array' take care of this automatically?
>>(Also, looking back at Thomas' problem, there's also the cases from
>>split dropping trailing delimiters, whereas the sorry state of current
>>browsers generally behooves us to get the number of <td>s right.) So,
>>how about this
>>
>> print
>> map { ('<tr>', @$_, '</tr>', "\n") }
>> map { [ map { '<td>'.(/^$/ ? "-" : $_).'</td>' } @$_ ] }
>> sort { $b->[2] <=> $a->[2] }
>> grep { $_->[1] =~ m/$FORM{'TNSET'}/i }
>> map { chomp; [ split /;/, $_, 8 ] }
>> @techlines;
>>
>>| But no, that's not the canonical Schwartzian Transform either, not
>>| as coined by Mr. Christiansen.
>>
>>Well, it starts with a map, has a sort somewhere, and ends with a map.
>>Good enough for me...
>>
>>
>>:ar
>
>
> Well, I don't want to disturb a deeply philosophical discussion on sorting
> :) but the last 3 posting were completly too high to me (as I am new at PERL
> and no perlhacker (learning nealry 1 year but can't guess what I'm doing
> [:)])).
> Anyway, the article from tbsmith@deltacom.net answered my question in a way
> I can reproduce and sounds easy to me.
>
I think you'll find that if you have more than a few items to sort you will
rue that decision - the thing behind these STs and variants is to reduce
the work that is done in the comparison function, moving that work to the
outside of the sort where it is only done once for each item rather the
many times that the comparison function is used.
The:
# sort{ (split /;/, $a)[2] cmp (split /;/, $b)[2]} @techlines
Will need to do two splits for every comparison.
map { join ';' @{$_} }
sort { $a->[2] cmp $b->[2] }
map {[split /;/ ] } @techlines;
Is the equivalent STish thing - now performing only one split (and one join
admittedly :) per input item
You ought to check out:
<http://language.perl.com/CPAN/doc/FMTEYEWTK/sort.html>
For a discussion of this subject.
> Now, how should I work to get the orderdescending (700, 699, 698, ....)
> instead of 698, 699, 700?
>
Er, swap over the $a and $b ...
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: Tue, 18 May 1999 09:26:55 -0400
From: "Puddister, Shannon" <pdncoop@americasm01.nt.com>
Subject: Telnet Prompt
Message-Id: <37416A9F.8E29CF58@americasm01.nt.com>
I'm writing a program to connect to a remote server by way of Telnet,
and having a little diffculty understanding the Prompt construct of the
Telnet module. Does this prompt refer to the expected prompt of my
computer, or that of the host? I'm using :
$t = net Net::Telnet(Timeout=>5,Prompt=>'/[\$]/');
Does the Prompt, as above wait for the '$' on my computer? How exactly
does this syntax work?
Thanks all around,
Shannon
------------------------------
Date: 18 May 1999 14:14:14 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Weird socket behaviour
Message-Id: <374167a6@newsread3.dircon.co.uk>
James Smith <engjs@cc.newcastle.edu.au> wrote:
> I have written a perl program to open an internet socket and download
> a webpage, the sort of thing Netscape does. It works fine in some cases
> and not in others. The problem appears to be with the site I am
> downloading from (which is one of a number of such sites).
>
> If I connect to the site using netscape, it connects to the right
> page. If I connect using my program, it returns a totally different
> page. If I connect to the site using Netscape, using numbers rather
> than a name, then Netscape returns the wrong page.
>
> The problem appears to be that the site has a number of different
> names that translate to the same set of numbers. I have been unable
> to figure out how Netscape works out that this is happening and
> deals with it.
>
It is an example of a name based virtual host - the browser is expected
to send a header to the server which indicates which name it is requesting
and the server behaves appropriately.
> Does anyone know what's going on? Can anyone quote some perl code to
> get around the problem?
>
At a guess :
print "Host: www.whatever.com\n"
Actually thats not a guess but there you go.
If you want to read more about this subject you might want to look at
RFC2068.
An alternative your current approach might be to use the LWP::UserAgent
module that allows you to specify arbitrary headers in your request.
/J\
--
Jonathan Stowe <jns@gellyfish.com>
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 5712
**************************************