[16500] in Perl-Users-Digest
Perl-Users Digest, Issue: 3912 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 4 09:05:29 2000
Date: Fri, 4 Aug 2000 06:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965394313-v9-i3912@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 4 Aug 2000 Volume: 9 Number: 3912
Today's topics:
cgi file upload <starktdh@gmx.de>
Comparing strings in an array <dtd2@ukc.ac.uk>
Re: Comparing strings in an array nobull@mail.com
Re: cookie..mmm <daniel@blackomega.com>
Re: Directory mover <newt@veko.ne.mediaone.net>
Re: FormMail.pl problems <flavell@mail.cern.ch>
Re: Gee, thanks for all the help :-( <newt@veko.ne.mediaone.net>
Re: get files from other servers aqutiv@my-deja.com
How do I convert a decimal number to a binary string?? <olofsson@stam.com>
Re: How do I convert a decimal number to a binary strin <brendon@shipreg.com>
Re: How to explain this expression? nobull@mail.com
Re: How to open and append to a file <c-stone@att.net>
How to Send Data to another PC ??? Help Please !!! hugo.b@derivs.com
my what? <kellym36@drink.bt.co.uk>
Re: my what? <gregory_griffiths@cargill.com>
Re: my what? <tom.kralidis@ccrs.nrcanDOTgc.ca>
Re: need help running .pl files with Apache <daniel@blackomega.com>
New Perl upload sample code 2 <abel@inlander.es>
New Perl upload sample code <abel@inlander.es>
Re: Novice Question: Outputting an existing file <neil@thump.org>
Re: Novice Question: Outputting an existing file aqutiv@my-deja.com
Re: Perl and mSQL Database <daniel@blackomega.com>
Problems creating a file <abel@inlander.es>
Re: Problems creating a file (Rafael Garcia-Suarez)
Re: Problems creating a file (Jens)
Re: Q: split on fixed length string <rich_guy@hotmail.com>
Re: remove entry from file --anyone!! (Anno Siegel)
Re: semijoin() - a better way? (Anno Siegel)
Re: SOLVED: Configure Win32::ODBC Connection to a SQL S <cbegemann@orga.com>
Re: split strings by number (Anno Siegel)
Re: stripping - ? html tags <kellym36@drink.bt.co.uk>
Re: Subclassing an opaque class (Anno Siegel)
SV: Loop for selecting text? <Aage.Vaksdal@rasmus.uib.no>
Re: Tk module for Windows NT <carvdawg@patriot.net>
Re: uuuuuuuAaron Kulkis is a Communist Buttfucker <kellym36@drink.bt.co.uk>
Re: very cool routine (Tim Hammerquist)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 4 Aug 2000 14:18:01 +0200
From: "Johannes Stark" <starktdh@gmx.de>
Subject: cgi file upload
Message-Id: <8meccr$rd3$1@merlin.rembrandtstr.bocholt.de>
I'm using neither cgi.pm nor cgi-lib. My script should read posted files
coming via multipart-fomdata. The 25kB test file has been received in every
trial. But - randomly - only the first 1000 up to 14000 Byte.
Has anyone an idea?
Thanks
------------------------------
Date: Fri, 04 Aug 2000 12:01:51 +0100
From: dtd2 <dtd2@ukc.ac.uk>
Subject: Comparing strings in an array
Message-Id: <398AA29F.6C4@ukc.ac.uk>
Hi all.
I've just started learning Perl, so I'm still groping in the dark.
Does anyone know if there is a way to check through an array of unknown
size, check if any of the srings appear more than once, and then print
out those strings which are duplicated?
Thanks in advance.
David.
------------------------------
Date: 04 Aug 2000 12:35:16 +0100
From: nobull@mail.com
Subject: Re: Comparing strings in an array
Message-Id: <u9k8dx2r9n.fsf@wcl-l.bham.ac.uk>
dtd2 <dtd2@ukc.ac.uk> writes:
> I've just started learning Perl, so I'm still groping in the dark.
You need to find the FAQ that was installed alongside your copy of
Perl. You will then be groping in the light.
Type:
perldoc perlfaq
> Does anyone know if there is a way to check through an array of unknown
> size, check if any of the srings appear more than once, and then print
> out those strings which are duplicated?
Having typed "perldoc perlfaq" look at the list of questions for one
similar to the one you asked:
How can I extract just the unique elements of an array?
OK so it's actually the exact opposite but that's probably close
enough.
Pick a word or two from that question e.g. "unique" and do:
perldoc -q unique
You'll find amongst other stuff:
undef %saw;
@out = grep(!$saw{$_}++, @in);
You, of course need to alter the condition so that rather than
filtering @in down to elements that have not been seen before it
filters the list down to elements that have been seen exactly once
before.
undef %saw;
@out = grep(1 == $saw{$_}++, @in);
Actually its better to limit the scope of %saw and (IMHO) to write the
grep more reably with a BLOCK argument.
{
my %saw;
@out = grep { 1 == $saw{$_}++ } @in;
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 4 Aug 2000 11:25:20 +0100
From: "Daniel Foster" <daniel@blackomega.com>
Subject: Re: cookie..mmm
Message-Id: <8me5ot$63v$3@news7.svr.pol.co.uk>
> I've been wondering if this is a problem with Internet
Explorer or
> me..but I'm using the following code to set a cookie that expires
within 1
> second. It works fine with Netscape but IE doesn't seem to respond
to it.
> For example...say i set the cookie for 10 mins at the start of the
> program..they hit on a logout button..and it sets the expire time to
1s.
> Anyone have any suggestions or comments......
>
> my $cookie_expire='+1s' ;
> $cookie = $query->cookie(-name=>'HOTTOP',
> -value=>$session{_session_id},
> -expires=>$cookie_expire,
> -path=>'/',
> -domain=>$cookie_domain);
>
> print $query->header(-cookie=>$cookie);
> print $query->start_html('Admin Logout');
Thanks for asking your question twice, very good. Take a look at the
thread 'CGI.pm cookie failure' from a day or two ago. Same problem.
Basically IE doesn't want anything to do with cookies that have an
expiration of anything shorter than '+2h'.
---
Through the darkness, the future past, the magician longs to see,
One chants out, between two worlds, fire, walk with me.
- Twin Peaks
Daniel Foster - daniel@blackomega.com
------------------------------
Date: Fri, 04 Aug 2000 10:32:34 GMT
From: <newt@veko.ne.mediaone.net>
Subject: Re: Directory mover
Message-Id: <6Zwi5.1736$pu4.172355@typhoon.ne.mediaone.net>
BUCK NAKED1 <dennis100@webtv.net> wrote:
> I overlooked that Net:FTP module does not work on Unix.
It works fine on my Linux and Solaris boxes. Maybe it's specific
to your installation.
------------------------------
Date: Fri, 4 Aug 2000 12:32:01 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: FormMail.pl problems
Message-Id: <Pine.GHP.4.21.0008041225001.13101-100000@hpplus03.cern.ch>
On Thu, 3 Aug 2000, Red Jackson hung upside-down from a convenient
nntp-server, and out popped this:
> Thanks for the tip! This is my first tangle with FormMail.
> Any suggestions for alternatives?
cgiemail seems to have a good reputation, though it isn't Perl.
http://web.mit.edu/wwwdev/cgiemail/
If that wasn't what you wanted, this page
http://web.mit.edu/wwwdev/cgiemail/webmaster.html
lists some alternatives.
------------------------------
Date: Fri, 04 Aug 2000 10:41:38 GMT
From: <newt@veko.ne.mediaone.net>
Subject: Re: Gee, thanks for all the help :-(
Message-Id: <C5xi5.1740$pu4.172355@typhoon.ne.mediaone.net>
Phil Hawkins <tarheel@sierratel.com> wrote:
> Nice group. Real f****** nice group.
I'm amazed that this actually got people to respond. But here I am ...
we'll be sure to put it all on your tab.
> ... It appears that there are two versions? One for NT
> and the other for Unix?
Perl is a program, as MS Word is a program. You wouldn't run the Mac
version of MS Word on your NT box.
> Huh? I have to write two different scripts for each server
> type? And what about the compiler?
Probobly not. Once you have (NT) Perl installed on NT and (Unix) Perl
installed on Unix, the same script is likely to run on both systems.
There are differences, though, so it's not a guarantee.
------------------------------
Date: Fri, 04 Aug 2000 12:08:38 GMT
From: aqutiv@my-deja.com
Subject: Re: get files from other servers
Message-Id: <8mebo2$j56$1@nnrp1.deja.com>
In article <8me1l1$cvp$1@news2.kornet.net>,
"Louie G. Kim" <gk@bncol.com> wrote:
> Is there any way to get files from other servers?
>
> When i am on server A, I want to get fileA from server B or
> I want to display fileA at server B.
>
> GK
>
>
use lwp...
for example:
use lwp::simple;
print get "http://redhat.com";
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 04 Aug 2000 14:04:54 +0300
From: Andreas Olofsson <olofsson@stam.com>
Subject: How do I convert a decimal number to a binary string??
Message-Id: <398AA355.F061E4D0@stam.com>
I there an easy way to convert a decimal number to a binary string in perl?
Regards,
Andreas
------------------------------
Date: Fri, 4 Aug 2000 15:41:04 +0200
From: "Brendon Caligari" <brendon@shipreg.com>
Subject: Re: How do I convert a decimal number to a binary string??
Message-Id: <8medom$34a$1@news.news-service.com>
"Andreas Olofsson" <olofsson@stam.com> wrote in message
news:398AA355.F061E4D0@stam.com...
> I there an easy way to convert a decimal number to a binary string in
perl?
>
unpack()
check docs for pack() and unpack()
print(unpack("B8", 'A')) worked for me, but I admit it's the
first time I've used unpack so I might be missing somthing.
Brendon
++++
------------------------------
Date: 04 Aug 2000 12:14:42 +0100
From: nobull@mail.com
Subject: Re: How to explain this expression?
Message-Id: <u9og392s7x.fsf@wcl-l.bham.ac.uk>
u8526505@ms27.hinet.net () writes:
> $_=<>;
> /hello/ and print "abc\n",print "ok\n";
> Is there a friendly way to rewrite it ?
What do you mean "friendly". Do you mean more reable by someone
less familar with Perl?
# ARGV is a virtual file made up of all the input files
$_ = readline(ARGV);
if ( $_ =~ m/hello/ ) { # $_ matches the pattern /hello/
my $ok = print("ok\n");
print("abc\n",$ok);
}
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 04 Aug 2000 10:41:22 GMT
From: "Chris Stone" <c-stone@att.net>
Subject: Re: How to open and append to a file
Message-Id: <m5xi5.4226$gW5.244814@bgtnsc04-news.ops.worldnet.att.net>
Thanks again for all your help with this. I took your advice about adding
features one step at a time, and it helps a lot. So far I've come up with a
script that will read an entire HTML file, then write it all back to the
screen. The other script reads the form data and then prints that out on
screen. I only have trouble when I try to put the two together, which I
think comes from searching for the <!--**--> string. (I'm sticking to my old
structure for now, at least until I can learn something more advanced)
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:398A77C3.F4C28472@stomp.stomp.tokyo...
(cut, cut)
> You will learn most of your programming by actually writing programs.
> Trial and Error is a fabulous teacher. Use pragma hints for awhile,
> if you think they will help. Stop using pragma hints as soon as possible.
> Pragma hints can lead to stagnation in programming techniques and usually
> lead to very mediocre programmers. Only imaginative critical thinkers
> become great programmers. Pragma hints will not do this for you.
Trial and error is definitely the best way to learn, in fact it's about the
only way I learn how to do anything, just doing it over and over till I get
it right. BTW, you lost me with term "pragma hint" what are these? They
sound bad.
> FORTRAN and Turbo Pascal is my background.
Just out of couriosity, are you in the programing proffesion, or the
teaching proffesion?
> You have some syntax errors. Part of this is in those missing
> quotes we both F'd up on. Hmm.. read up on "for" style loops.
Syntax fixed
> For a challenge, this script of mine will
> print each time a person enters for the first
> time. This can be changed with a bit of
> creativity, such as adding a hidden field
> to your form action, a control.
>
> NAME="Control" VALUE="control"....
>
> if ($in{Control})
> { well... do the right thing here... print? }
I'm not sure exactly what you're trying to do here
> Oh yes, before I forget, don't bother
> with file locking. Are you really
> expecting millions of hits per day?
> You will have better luck being struck
> by lightning than having two visitors
> make entries at the precise same moment.
Hehe, I'll be lucky to get two visitors in a single day, and I doubt either
of them would be kind enough to sign my guestbook <g>
> As your skills mature, not so much in
> programming but rather in dealing with
> Life, you will discover women are quite
> talented in many ways, especially in
> employing our feminine instincts,
> such as our inherent fickle nature,
> to.. hmm... take care of business.
You kind of lost me right about here
> Ain't I a stinker?
>
> Godzilla!
>
> You're no good but I will rock you.
> http://la.znet.com/~callgirl3/nogood.mid
But I won't back down.
http://la.znet.com/~callgirl3/backdown.mid
Some questions regarding your script:
(cut, cut)
> # FULL PATH NAME FOR YOUR LOG FILE:
>
> $log_path = "/var/ftp/home/...etc ...etc /gbentries.log";
should i put anything in this file to begin with, or will it create itself,
or should it just be blank?
(cut, cut)
> ## OPEN OLD ENTRIES LOG FILE:
>
> open (GBENTRIES, "+<$log_path"); ## add error check
what does "+<" do? is it similar to ">>" and ">" functions?
(cut, cut)
> ## PUSH NEW ENTRY INTO WORKING ARRAY:
>
> push (@Gbentries, $new_entry);
What does push do? Sounds useful
Thanks again for the code, I'm gonna try and work from it and someday maybe
end up with a script of my own. Sad thing is it probably won't get more then
10 hits. But then that's not really the point, I just want to figure out how
this stuff works.
------------------------------
Date: Fri, 04 Aug 2000 10:42:27 GMT
From: hugo.b@derivs.com
Subject: How to Send Data to another PC ??? Help Please !!!
Message-Id: <8me6mi$fkj$1@nnrp1.deja.com>
Hi.
I have received data from a HTML Page using a perl script.
Now I need to send this data to a nothe PC which is a NT Machine.
I need to send my data to Excel on this other PC that will do some
Calculations on the data then send it back which the script then will
send back to the HTML.
How could I do this ???
any Help will be much appreciated.
Thank You
Hugo.b@derivs.com
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 04 Aug 2000 12:32:24 +0100
From: john kelly <kellym36@drink.bt.co.uk>
Subject: my what?
Message-Id: <398AA9C8.3E7CBA4@drink.bt.co.uk>
morning :)
can someone clear this up for me?
is there a difference btween :
my $thingy = "isfat"
and
$thingy = "isfat"
- cheers
j
------------------------------
Date: Fri, 4 Aug 2000 13:05:15 +0100
From: "Greg Griffiths" <gregory_griffiths@cargill.com>
Subject: Re: my what?
Message-Id: <8mebeg$ust$1@mercury.cargill.com>
The first specifies the value and the variable for use with the STRICT
option, the other works fine, unless you use this approach.
john kelly <kellym36@drink.bt.co.uk> wrote in message
news:398AA9C8.3E7CBA4@drink.bt.co.uk...
> morning :)
>
> can someone clear this up for me?
>
> is there a difference btween :
>
> my $thingy = "isfat"
>
> and
>
> $thingy = "isfat"
>
> - cheers
> j
>
------------------------------
Date: Fri, 04 Aug 2000 08:15:57 -0400
From: Tom Kralidis <tom.kralidis@ccrs.nrcanDOTgc.ca>
Subject: Re: my what?
Message-Id: <398AB3FD.1A577C1B@ccrs.nrcanDOTgc.ca>
john kelly wrote:
>
> morning :)
>
> can someone clear this up for me?
>
> is there a difference btween :
>
> my $thingy = "isfat"
>
> and
>
> $thingy = "isfat"
>
> - cheers
> j
Here's the difference:
#!/usr/bin/perl -w
use strict;
my $thingy = "isfat";
print "$thingy\n";
do_func();
print "$thingy\n";
sub do_func()
{
my $thingy = "isskinny";
print "$thingy\n";
}
Hope this helps
..Tom
--
=================================
Tom Kralidis
Geo-Spatial Developer
Canada Centre for Remote Sensing
Tel: (613) 947-1828
Fax: (613) 947-1408
http://www.nrcan.gc.ca/~tkralidi/
=================================
------------------------------
Date: Fri, 4 Aug 2000 11:18:44 +0100
From: "Daniel Foster" <daniel@blackomega.com>
Subject: Re: need help running .pl files with Apache
Message-Id: <8me5os$63v$2@news7.svr.pol.co.uk>
Try adding the line
AddHandler cgi-script .cgi
to your httpd.conf if it's not already there.
As has been said before the directory they're in needs to have the
ExecCGI option enabled in httpd.conf
---
A living organism ... feeds upon negative entropy ... Thus the
device by which an organism maintains itself at a fairly high
level or orderliness (i.e. a fairly low level of entropy) really
consists of sucking orderliness from its environment.
- E. Schrodinger
Daniel Foster - daniel@blackomega.com
------------------------------
Date: Fri, 04 Aug 2000 10:47:36 GMT
From: Abel Almazan <abel@inlander.es>
Subject: New Perl upload sample code 2
Message-Id: <398A9F3D.64B599E8@inlander.es>
Sorry, i forgot:
The previous HTML form is something like that:
<html>
<head>
<title>Upload Form with description</title>
</head>
<body>
<form name="f1" action="upload.pl" method="POST"
ENCTYPE="multipart/form-data">
Send this file: <INPUT NAME="fichero" TYPE="file"><br>
Descripcion:<input type="text" name="descripcion"><br>
<input type="submit" value="Probar">
</form>
</body>
</html>
------------------------------
Date: Fri, 04 Aug 2000 10:44:29 GMT
From: Abel Almazan <abel@inlander.es>
Subject: New Perl upload sample code
Message-Id: <398A9E82.277EF07E@inlander.es>
Hi people
This is a sample code of how to upload a file with minimum code and
getting additional info with the upload, like file desciption, etc...
#!/usr/bin/perl
print "Content-type: text/html\n\n";
#!/usr/local/bin/perl
use CGI qw(:standard);
# Esborrar tots els fitxers temporals anteriors dels que s'ha fet upload
# ATENCIÓ: Això pot portar problemes de concurrència (un procés d'upload
esborra fitxers
# d'un altre upload).
# Tot i que és estrany que passi, probablement no els esborrarà
perque els deu
# trobar encara en us... (suposo que és per això que no
aconsegueix esborrar els
# fitxers dels que ha fet l'upload...).
# En cas que els esborrés, probablement l'altra procés donarà
un error i l'usuari
# s'enterarà pel que podrà repetir l'operació.
#unlink <C:\\TEMP\\CGItemp*>;
#unlink <\\TEMP\\CGItemp*>;
# Cojo que tipo de fichero me estan enviando
$fichero = param('fichero');
$descripcion=param('descripcion');
$tmpfile=tmpFileName($fichero);
open TMP,"$tmpfile";
binmode TMP;
@pathunix = split('/', $fichero);
@pathdos = split(/\\/, $fichero);
open OUT,"> ../htdocs/$pathdos[$#pathdos]";
binmode OUT;
while (<TMP>)
{
print OUT $_;
}
close TMP;
close OUT;
system("chmod 777 ../htdocs/$pathdos[$#pathdos]");
If u have troubles, send me a msg.
------------------------------
Date: Fri, 04 Aug 2000 13:10:51 +0100
From: Neil <neil@thump.org>
Subject: Re: Novice Question: Outputting an existing file
Message-Id: <u7KKOXGhnMtu0PWWXmv3Eq1p3u17@4ax.com>
On Fri, 4 Aug 2000 11:21:11 +0200, "Toni" <trioinfoQUITAESTO@trioinfografia.com>
wrote:
>Hello!
>I'm a beginner and I've this question
>How can I output an existing html file from my script to the browser? I've
>read about
> Location: URL
>but it gives me error.
print "location: $url" ;
------------------------------
Date: Fri, 04 Aug 2000 12:11:48 GMT
From: aqutiv@my-deja.com
Subject: Re: Novice Question: Outputting an existing file
Message-Id: <8mebu0$j7j$1@nnrp1.deja.com>
In article <8me1p5$jar57@SGI3651ef0.iddeo.es>,
"Toni" <trioinfoQUITAESTO@trioinfografia.com> wrote:
> Hello!
> I'm a beginner and I've this question
> How can I output an existing html file from my script to the browser?
I've
> read about
> Location: URL
> but it gives me error.
> THANKS!
>
>
why do that when you can simply do:
print "Content-type: text/html\n\n";
open F, "file.html" or die "Can't open file, $!";
print for <F>;
close F;
If you want location instead, just replace it with the content-type...
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 4 Aug 2000 11:11:32 +0100
From: "Daniel Foster" <daniel@blackomega.com>
Subject: Re: Perl and mSQL Database
Message-Id: <8me5or$63v$1@news7.svr.pol.co.uk>
> I coded my Perl script as follow
> #!/usr/local/bin/perl
>
> use Msql;
>
> $dbh = Msql->connect;
> $dbh->selectdb("nomedatabase");
What you need here is DBI the Perl DataBase Interface. Get DBI.pm,
Msql-Mysql-modules-1.2209.tar.gz (I think that's the latest) and
install them as per the docs - I think you need some other things to,
like maybe Data::Dumper and Data::ShowTable. There are plenty of good
guides to DBI on the web, just do a search from your favourite search
engine for 'DBI'.
Your code will come out looking more like this...
#!/usr/bin/perl
use DBI;
$dbh=DBI->connect('DBI:Msql:nomedatabase', 'username', 'password')
or die 'died on connect: ' . DBI::errstr';
.
.
.
And then you can go on to do all you SQL statements etc.
HTH
---
A living organism ... feeds upon negative entropy ... Thus the
device by which an organism maintains itself at a fairly high
level or orderliness (i.e. a fairly low level of entropy) really
consists of sucking orderliness from its environment.
- E. Schrodinger
Daniel Foster - daniel@blackomega.com
------------------------------
Date: Fri, 04 Aug 2000 10:23:42 GMT
From: Abel Almazan <abel@inlander.es>
Subject: Problems creating a file
Message-Id: <398A99A1.D30BE75B@inlander.es>
I use open OUT,"> ../htdocs/filename.txt"; to create the file
"filename.txt" into "htdocs" directory and then write info it, but...
this command doesn't create the file, but the documentation tells that
this have to create the file if it doesn't exist.
What happens?? What can i do??
Please, reply to my e-mail too.
Thanx.
------------------------------
Date: Fri, 04 Aug 2000 11:43:46 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Problems creating a file
Message-Id: <slrn8olbd9.c8h.rgarciasuarez@rafael.kazibao.net>
Abel Almazan wrote in comp.lang.perl.misc:
>I use open OUT,"> ../htdocs/filename.txt"; to create the file
>"filename.txt" into "htdocs" directory and then write info it, but...
>
>this command doesn't create the file, but the documentation tells that
>this have to create the file if it doesn't exist.
>
>What happens??
There are lots of possibilities. For example, permissions may disallow
creation of a file here.
>What can i do??
You can do:
open OUT,"> ../htdocs/filename.txt" or die "Can't create file: $!\n";
to have a more detailed error message that will explain you the problem.
--
Rafael Garcia-Suarez
------------------------------
Date: Fri, 04 Aug 2000 13:53:41 +0200
From: "Ellegiers, J. M. (Jens)" <jellegie@ford.com>
Subject: Re: Problems creating a file
Message-Id: <398AAEC5.6E6FBF4B@ford.com>
Abel Almazan wrote:
>
> I use open OUT,"> ../htdocs/filename.txt"; to create the file
> "filename.txt" into "htdocs" directory and then write info it, but...
>
> this command doesn't create the file, but the documentation tells that
> this have to create the file if it doesn't exist.
>
> What happens?? What can i do??
>
Do you have the permissions to write to that directory??
You better always catch any error messages opening files by writing
open OUT,"> ../htdocs/filename.txt" or die ( "../htdocs/filename.txt: "
. $! );
This will terminate the script in case of errors and tell you why it
does so.
> Please, reply to my e-mail too.
>
> Thanx.
--
Viele Gruesse, regards, saludos
Jens Ellegiers
---------------------------------------------------------------
FORD-Werke AG, Spessartstrasse, 50725 Koeln
Jens Ellegiers Email: jellegie@ford.com /"\
Engineer (I-Engine CAE) Phone: +49-221-90-31467 \ /
Mail Sym: D-ME/PN-S Fax : +49-221-90-33025 X
ASCII Ribbon campaign against HTML E-mail & Usenet News >------> / \
------------------------------
Date: Fri, 04 Aug 2000 03:59:30 -0700
From: asker <rich_guy@hotmail.com>
Subject: Re: Q: split on fixed length string
Message-Id: <398AA212.7B666166@hotmail.com>
Jeff Zucker wrote:
>
> asker wrote:
> >
> > ($val1, $val2, $val3, $val4) = (split(//, $string))[0, 1, 2 to 4, 5 to
> > 20];
>
> Wait, don't leave town, unpack!
>
> As in the Perl function unpack().
>
> For example:
>
> my $str = 'abcdefghijklmnopqrstuvwxyz';
> my $pattern = 'A1 A3 A*';
> my @ary = unpack( $pattern, $str );
> print "$_\n" for @ary;
>
> That prints out:
>
> a
> bcd
> efghijklmnopqrstuvwxyz
>
> Because the pattern said to get A1 (1 char), then A3 (3 chars), then A*
> (all the rest).
>
> --
> Jeff
Thank you, I ended up using something in a subroutine that used a few
substr's, but your idea is faster and more what I was looking for. :-)
------------------------------
Date: 4 Aug 2000 12:01:28 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: remove entry from file --anyone!!
Message-Id: <8mebao$n82$1@lublin.zrz.tu-berlin.de>
<hallian@hotmail.com> wrote in comp.lang.perl.misc:
>hi all,
>
>simple question:
>
>I need to replace the user fred from the magic file.
>File magic looks like this:
>
>jill:nothappy:9034: gill hill
>fred:happy:9012:hill road
>nill:pop:983:jd houise
>
>I need to remove fred from the file and move nill up so that it looks
>like this:
>
>jill:nothappy:9034: gill hill
>nill:pop:983:jd houise
If you had bothered to consult the perl FAQ you wouldn't have had
to ask.
perldoc -q 'delete a line'
Anno
------------------------------
Date: 4 Aug 2000 12:41:32 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: semijoin() - a better way?
Message-Id: <8medls$nb1$1@lublin.zrz.tu-berlin.de>
John M. Gamble <jgamble@ripco.com> wrote in comp.lang.perl.misc:
>"There's more than one way to do it." But i have an oft-used
>function that i feel could be better. It is named semijoin(),
>and it joins groups of items in a list together, creating a new
>list. It gets used a lot in our scripts that handle database lists.
>
>I'm pretty sure that it could be improved - i'm using array slices
>and a loop, which can't be the fastest way.
>
>So... any suggestions?
>
>=item semijoin()
>
> @newlist = semijoin($expr, $itemcount, @list);
>
> $expr - A string to be used in a join() call.
> $itemcount - The number of items in a list to be joined.
> It may be negative.
> @list - The list
>
>Create a new list by performing a join on I<$itemcount> elements at a
>time on the original list. Any leftover elements from the end of the
>list become the last item of the new list, unless I<$itemcount> is
>negative, in which case the first item of the new list is made from the
>leftover elements from the front of the list.
>
>=back
>
>=cut
>sub semijoin($$@)
>{
> my($jstr, $itemcount, @oldlist) = @_;
> my($idx);
> my(@newlist) = ();
[rest of code snipped]
Well without the frills about negative $itemcount, the basic function
is
push @newlist, join $jstr, splice( @oldlist, 0, $itemcount) while @oldlist;
Anno
------------------------------
Date: Fri, 4 Aug 2000 13:53:29 +0200
From: "Carola Begemann" <cbegemann@orga.com>
Subject: Re: SOLVED: Configure Win32::ODBC Connection to a SQL Server?
Message-Id: <8meb3h$r5r$1@relay1.orga.com>
Carola Begemann schrieb in Nachricht <8m3pgk$j1d$1@relay1.orga.com>...
>Hallo,
>I am trying to configure a new Connection to a database on a sql 7 server
>using the Win32::ODBC module.
After a lot of trial and Error the Solution was as simle as:
Win32::ODBC::ConfigDSN(ODBC_ADD_SYS_DSN,"SQL Server",
( "DSN=$dsn","Description= $condb automatisch generiert",
"Server=$server")
note : give only these attributes and use the rest in the connect string!
here attributes are separated by ;
$dbc=new Win32::ODBC( "DSN=$dsn; UID=$user; PWD=$passwd; Database=$condb ")
Just in case anyboy needs this
Carola
------------------------------
Date: 4 Aug 2000 10:39:19 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: split strings by number
Message-Id: <8me6gn$n2g$1@lublin.zrz.tu-berlin.de>
Larry Rosler <lr@hpl.hp.com> wrote in comp.lang.perl.misc:
>In article <8mc5si$l0v$1@lublin.zrz.tu-berlin.de> on 3 Aug 2000 16:16:18
>-0000, Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> says...
>> <oderus54@my-deja.com> wrote in comp.lang.perl.misc:
>> >How would i split strings by number, like for example;
>> >
>> >
>> >$blah = "abcdefghijklmn";
>> >#now i want $string1 = "abc", $string2 = "defgh", $string3 = "ijk",
>> >$string4 = "lmn"
>>
>> While the description you give is less than clear, it looks like
>> you want to split a string at given character positions. If so,
>> the substr function is what you are looking for. perldoc -f substr.
>>
>> As usual, there are more ways to do this. If you're really into
>> fun, try unpack.
>
>The unpack() function provides a far more appropriate solution to this
>problem than a sequence of substr()s.
>
> my @strings = unpack A3A5A3A3 => $blah;
>
>Now write the corresponding substr() solution, and you will see. It
>will be messy and hard to maintain.
my @strings = map substr( $blah, 0, $_, ''), 3, 5, 3, 3;
Longer, yes. Destructive to $blah, yes. Very probably slower too,
though I didn't check. But not really messy, and easily maintained.
Anno
------------------------------
Date: Fri, 04 Aug 2000 12:46:02 +0100
From: john kelly <kellym36@drink.bt.co.uk>
Subject: Re: stripping - ? html tags
Message-Id: <398AACFA.2DC6DA21@drink.bt.co.uk>
thanks to everyone who helped
- it works now
j
------------------------------
Date: 4 Aug 2000 10:27:06 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Subclassing an opaque class
Message-Id: <8me5pq$n14$1@lublin.zrz.tu-berlin.de>
Damian Conway <damian@cs.monash.edu.au> wrote in comp.lang.perl.misc:
>Bob Glickstein <bobg@moonbase.zanshin.com> writes:
>
>>When I subclass someone else's class, how can I add my own instance
>>variables?
>
>>When I subclass my own class, I simply do this:
> [SNIP]
>>because I know the composition of a MySuperclass object. But when the
>>superclass is someone else's, $self may not be a HASH reference at
>>all; and if it is, `sub_instance_var' may collide with a member
>>already in the HASH.
>
>You are correct. Unfortunately there is no sure-fire way to do
>inheritance of an arbitrary Perl class without knowing what's
>going on inside it.
>
>One way around the problem is to use aggregation rather than inheritance:
>
> package MySubclass;
>
> sub new {
> my ($class, @args) = @_;
> my $self = { base => new MySuperclass(@args) };
> $self->{sub_instance_var} = $whatever;
> bless $self, $class;
> }
>
> # Forward unknown methods to base class object...
> sub AUTOLOAD {
> my $self = shift;
> $AUTOLOAD =~ s/.*:://;
> $self->{base}->$AUTOLOAD(@_);
> }
>
This ingenious method has one little problem: During object destruction,
perl will try to call the DESTROY method in MySuperclass, which now
leads (through AUTOLOAD) to the unconditional call of the DESTROY
method in MySubclass. If you don't have one, perl will complain.
This is easily mended by inserting "return if $AUTOLOAD eq 'DESTROY';"
before the last line of AUTOLOAD.
Of course, the method call overhead will suffer a bit from the
roundabout way a method is found. (The overhead suffers? It's
growing fat!) Benchmarks indicate that a no-op method called via
the aggregate method takes about six times as long as the same
method called via direct inheritance (see below).
If you don't need the full semantics of inheritance, in particular
if you don't intend to change an @ISA at run time, it is tempting
to recover part of the overhead by caching the methods from
MySuperclass into MySubclass. This can be accomplished like
this:
sub AUTOLOAD {
my $self = shift;
$AUTOLOAD =~ s/.*:://;
return if $AUTOLOAD eq 'DESTROY';
if ( my $methcode = $self->{base}->can( $AUTOLOAD) ) {
no strict qw( refs); # just in case it's on
*{ 'MySubclass::' . $AUTOLOAD} =
sub { my $self = shift; $methcode->( $self->{base}, @_) };
$self->$AUTOLOAD( @_);
}
}
This reduces the factor from 6 to about 2. Of course, if the
methods involved do some real work, the overhead soon becomes
irrelevant, so caching will usually not be worth the hassle.
It is a good thing that Perl has methods to solve this common
problem with inheritance. But having to resort to AUTOLOAD in
this way, isn't it also a leetle bit icky?
Anno
---------------------------------------------------------------------
#!/usr/local/bin/perl -w
use strict;
use Benchmark;
package Superclass;
sub new { bless {}, shift}
sub meth {}
package Inherit;
@Inherit::ISA = qw( Superclass);
package Aggregate;
sub new {
my ($class, @args) = @_;
my $self = { base => new Superclass(@args) };
bless $self, $class;
}
# Forward unknown methods to base class object...
sub AUTOLOAD {
my $self = shift;
$Aggregate::AUTOLOAD =~ s/.*:://;
return if $Aggregate::AUTOLOAD eq 'DESTROY';
$self->{base}->$Aggregate::AUTOLOAD(@_);
}
package Cache;
sub new {
my ($class, @args) = @_;
my $self = { base => new Superclass(@args) };
bless $self, $class;
}
# Forward unknown methods to base class object, cache in package as we go
sub AUTOLOAD {
my $self = shift;
$Cache::AUTOLOAD =~ s/.*:://;
return if $Cache::AUTOLOAD eq 'DESTROY';
if ( my $methcode = $self->{base}->can( $Cache::AUTOLOAD) ) {
no strict qw( refs);
*{ 'Cache::' . $Cache::AUTOLOAD} =
sub { my $self = shift; $methcode->( $self->{base}, @_) };
$self->$Cache::AUTOLOAD( @_);
}
}
package main;
use vars qw( $inherit $aggregate $cache);
$inherit = new Inherit;
$aggregate = new Aggregate;
$cache = new Cache;
timethese ( 1 << ( shift || 0), {
inherit => '$inherit->meth',
aggregate => '$aggregate->meth',
cache => '$cache->meth',
});
__END__
Benchmark: timing 65536 iterations of aggregate, cache, inherit...
aggregate: 11 wallclock secs (11.98 usr + 0.00 sys = 11.98 CPU) @ 5470.45/s (n=65536)
cache: 5 wallclock secs ( 5.23 usr + -0.00 sys = 5.23 CPU) @ 12530.78/s (n=65536)
inherit: 1 wallclock secs ( 1.97 usr + 0.00 sys = 1.97 CPU) @ 33267.01/s (n=65536)
------------------------------
Date: Fri, 4 Aug 2000 13:34:58 +0200
From: "Aage Vaksdal" <Aage.Vaksdal@rasmus.uib.no>
Subject: SV: Loop for selecting text?
Message-Id: <8me9ot$2k86$1@toralf.uib.no>
Thank you very big, Stephen.
I finally got it right!!!
------------------------------
Date: Fri, 04 Aug 2000 08:50:51 -0400
From: H C <carvdawg@patriot.net>
Subject: Re: Tk module for Windows NT
Message-Id: <398ABC2A.52DB2704@patriot.net>
ppm install Tk
gopal_bhat@my-deja.com wrote:
> Hi,
> I got Active-Perl(5.006) for WinNT and I wanted to install Tk module
> (perl -e 'use Tk' should work first). Please post a reply to this
> posting if any of you know a place on the net, where I can download
> compiled Tk module for Win NT.
> thanks
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Fri, 04 Aug 2000 12:22:13 +0100
From: john kelly <kellym36@drink.bt.co.uk>
Subject: Re: uuuuuuuAaron Kulkis is a Communist Buttfucker
Message-Id: <398AA765.17EB0F7C@drink.bt.co.uk>
is that a valid RegExp?
------------------------------
Date: Fri, 04 Aug 2000 12:06:55 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: very cool routine
Message-Id: <slrn8old1f.up.tim@degree.ath.cx>
On Thu, 3 Aug 2000 12:11:50 -0600, Robin Bank <rbank@csf.edu> wrote:
>
> > But what makes you so superior to the skilled coders and developers
> > who pay attention and RTFM? If that's a geek, go ahead and label me.
>
> Hmmm...ever RTFM and missed one function and said hey, I wish they had that
> function, and realizing that they "don't" have it, decided to write their
> own. Not knowing one little routine doesn't make me a "not skilled"
> coder/developer. I'm sorry I don't know everything like you.
No, one overlooked function does not revoke a "skilled" status; telling
a newsgroup that you're right and they're wrong no matter what,
however...
I don't know everything. Far from it. But I know enough not to second
guess an entire newsgroup and then insult them. :)
> Anyone who stares
> at a computer screen long enough to reply to every single trvial post on a
> newsgroup would NOT look as good as that girl on the barstool.
Few people physically have time to read every "trivial" post on a
newsgroup (especially this one); that's what killfiles are for. Here;
meet mine...
--
-Tim Hammerquist <timmy@cpan.org>
640K ought to be enough for anybody.
-- Bill Gates (In 1981)
------------------------------
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 3912
**************************************