[16782] in Perl-Users-Digest
Perl-Users Digest, Issue: 4194 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 31 21:05:30 2000
Date: Thu, 31 Aug 2000 18: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: <967770313-v9-i4194@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 31 Aug 2000 Volume: 9 Number: 4194
Today's topics:
Re: Array Compare <bart.lateur@skynet.be>
Re: Continuation format danraymond@my-deja.com
Re: Creating a subroutine library for PerlScript <davidbullock@tech-center.com>
Re: Creating a subroutine library for PerlScript <flavell@mail.cern.ch>
Re: Creating a subroutine library for PerlScript <miltginsburg@email.com>
DBD::ODBC and date/time field overflow (David Wall)
Re: Distributed System <bkennedy@hmsonline.com>
IPC::Shareable not sharing tied hashes <jthomas@woodland.org>
local install of DBI on web host cquirion@my-deja.com
local install of DBI on web host cquirion@my-deja.com
local install of DBI cquirion@my-deja.com
local install of DBI cquirion@acromap.com
Re: Local install of perl modules (Alastair)
My Perl looks like C! <spragg@cs.ucdavis.edu>
Re: My Perl looks like C! (Marcel Grunauer)
Re: My Perl looks like C! <uri@sysarch.com>
Re: My Perl looks like C! (Jakob Schmidt)
Re: My Perl looks like C! (Abigail)
Re: My Perl looks like C! (Tim)
Re: My Perl looks like C! <taboo@comcen.com.au>
Re: My Perl looks like C! <smerr612@mailandnews.com>
Re: My Perl looks like C! <anmcguire@ce.mediaone.net>
Re: open web file <tony_curtis32@yahoo.com>
Re: open web file (Abigail)
Re: open web file (David Wall)
Re: open web file (Steven M. O'Neill)
Re: open web file <tony_curtis32@yahoo.com>
Re: output fun <jerry@j3iss.com>
Parsing text file not working properly <nakroshis@smart.net>
Re: Parsing text file not working properly <lr@hpl.hp.com>
Re: Parsing text file not working properly <stephenk@cc.gatech.edu>
Re: Parsing text file not working properly <taboo@comcen.com.au>
Re: Perl/ODBC/SQL Wierdness? (Malcolm Dew-Jones)
Re: Q. relating to perlfaq(4) / sort <ren.maddox@tivoli.com>
Sample Makefiles <umrigas@cc.umanitoba.ca>
Re: Sorting a Tab Delimited Text File By Second Field <bart.lateur@skynet.be>
Thank you!! (from a newbie) (Warren)
url correcting help? ptomsic@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 31 Aug 2000 23:18:05 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Array Compare
Message-Id: <8hptqs82g1tuhf3686bqlfh0bh9seddac3@4ax.com>
marxjkj123@my-deja.com wrote:
>Hello all, I have a bit of a problem. I have two arrays(array X &
>array Y) and need to compare them against one another. If my array(X)
>element is equal to an element in array(Y), do nothing. But if an
>element in array(X) is not equal to any of the array(Y) elements append
>array(X) element results into a third array(Z).
I'll use a hash, not a third array, if you don't mind.
my %z;
@z{@x} = ();
delete @z{@y};
my @z = keys %z; # the result, in pseudo-random order.
print "@z\n";
If you really insist on having the elements in the original order:
my %z;
@z{@x} = 1 .. @x;
delete @z{@y};
my @z = sort { $z{$a} <=> $z{$b} } keys %z;
--
Bart.
------------------------------
Date: Thu, 31 Aug 2000 23:00:29 GMT
From: danraymond@my-deja.com
Subject: Re: Continuation format
Message-Id: <8omo22$no1$1@nnrp1.deja.com>
> > Try doing that with the command input operator:
> >
> > print `ls
> > /usr/local`;
> >
> > It won't work. A single backslash won't help
>
> It still works. Perl does the right thing, and passes the string off
> to the shell. It's just that the shell doesn't want that newline in
> there.
>
> > either. A double backslash seems to work
> > but I'm not sure exactly why. Anyone know?
>
> Strings in backquotes are interpolated as a double-quoted string,
> meaning that a backslash is the escape character. You need to use two
> to end up with one in the string that gets passed off to the shell.
One might argue that if "\" is the escape character then Perl should
treat a "\<newline>" differently than just a "<newline>". Ie. strip out
any "\<newline>" it encounters. That would be the intuitive result.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 16:01:42 -0700
From: David Bullock <davidbullock@tech-center.com>
Subject: Re: Creating a subroutine library for PerlScript
Message-Id: <anntqs4hn7s5658hku6j2offde09ocqc23@4ax.com>
>On Thu, 31 Aug 2000, Milt Ginsburg wrote:
>
>> > : I am designing a web-site using PerlScript for ASP.
>>
>> I thought only VBScript and Javascript worked in ASP?
Here's an article on using Perl in ASP.
http://www.asptoday.com/articles/19990716.htm
You may also want to check out http://www.activestate.com
Activestate has done a couple of neat open source ports, including
ActivePerl, ActivePython, and they're working on a Visual Perl, and
VisualPython.
Hope this helped.
On Thu, 31 Aug 2000 23:39:44 +0200, "Alan J. Flavell"
<flavell@mail.cern.ch> wrote:
>Yeah, that figures, from one with your proven ability.
Alan:
If you are incapable of making a positive contribution, maybe you
should go get a breath of fresh air and come back when you feel a
little more... human. If you're unwilling to make a positive
contribution, well that speaks for itself.
------------------------------
Date: Fri, 1 Sep 2000 01:54:19 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Creating a subroutine library for PerlScript
Message-Id: <Pine.GHP.4.21.0009010151010.20824-100000@hpplus03.cern.ch>
On Thu, 31 Aug 2000, David Bullock wrote:
> Alan:
> If you are incapable of making a positive contribution,
Sorry about that. When I see someone hectoring the other usenauts on
WWW topics, and then proving to the assembled multitude that they're
incapable of using a search engine, frustration has been known to
break out. It's OK, I'm unsubscribing from the WWW group now.
------------------------------
Date: Thu, 31 Aug 2000 20:59:37 -0400
From: "Milt Ginsburg" <miltginsburg@email.com>
Subject: Re: Creating a subroutine library for PerlScript
Message-Id: <8omv0q$3ph$3@slb6.atl.mindspring.net>
David Bullock <davidbullock@tech-center.com> wrote in message
news:anntqs4hn7s5658hku6j2offde09ocqc23@4ax.com...
>
> Here's an article on using Perl in ASP.
>
> http://www.asptoday.com/articles/19990716.htm
Thanks.
Did Alan say something?
------------------------------
Date: 31 Aug 2000 20:32:41 -0400
From: darkon@one.net (David Wall)
Subject: DBD::ODBC and date/time field overflow
Message-Id: <8FA1D331Ddarkononenet@206.112.192.118>
When I run the program below, I get an error. But if I set
$placeholders=0, it will run correctly and I can print out the results of
the query.
The error is
DBD::ODBC::st execute failed: [Microsoft][ODBC Microsoft Access 97
Driver]Datetime field overflow (SQL-22008)(DBD: st_execute/SQLExecute
err=-1) at C:\PerlProg\hhe-query\try-q.pl line 29.
I've searched the Perl/DBI book, the DBI and DBD::ODBC docs, and several
Dejanews and web searches, but I can't find any information on what I'm
doing wrong. I've found a few places where someone asked a similar
question, but I've yet to see a reply that had an answer.
If I've missed something I should have noticed, a pointer to the correct
docs would be appreciated. I'm not sure what I'm doing wrong.
#!/usr/bin/perl -w
use strict;
use DBI qw(:sql_types);
my $placeholders=1;
my $statement = qq|select OPEN_DATE FROM combined
WHERE (OPEN_DATE Between #1/1/1999# And #2/1/1999#)
ORDER BY OPEN_DATE; | ;
$statement = qq|select OPEN_DATE from combined
where (OPEN_DATE between ? and ?)
ORDER BY OPEN_DATE|
if $placeholders;
my @query_parms=('#1/1/1999#', '#2/1/1999#');
my $dbh = DBI->connect('DBI:ODBC:HHElocal', '', '',
{RaiseError=>1, LongReadLen=>1000} );
my $sth = $dbh->prepare( $statement )
or die "Can't prepare SQL statement: ", $dbh->errstr(), "\n";
if ($placeholders) {
for (my $i=0; $i < @query_parms; $i++) {
$sth->bind_param($i+1, $query_parms[$i], SQL_DATE) or die $!;
$sth->bind_param($i+1, $query_parms[$i], SQL_DATE) or die $!;
}
}
my $rv = $sth->execute()
or die "Cannot execute SQL: ", $dbh->errstr(), "\n";
--
David Wall
darkon@one.net
------------------------------
Date: Thu, 31 Aug 2000 23:06:55 GMT
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Distributed System
Message-Id: <jyBr5.3858$AW2.42721@news1.rdc2.pa.home.com>
"Matthias Jaekle" <ntw6maja@fht-esslingen.de> wrote in message
news:39ACD45D.9547C195@fht-esslingen.de...
> Are there allready Perl modules for this tasks, or perl
> modules which make it simple to programm a load distributing
> system like this ?
The Schedule::Load module may be what you need, see the distribution at
www.cpan.org
--Ben Kennedy
------------------------------
Date: Thu, 31 Aug 2000 15:21:58 -0700
From: "Joe Thomas" <jthomas@woodland.org>
Subject: IPC::Shareable not sharing tied hashes
Message-Id: <sqtmilh7c5d142@news.supernews.com>
I'm having trouble sharing hashes between forked processes using
IPC::Shareable. Tied scalars are shared correctly, but tied hashes seem to
maintain separate states after being forked. I see this behavior with
IPC::Shareable 0.51 and Perl 5.005_03 on both Red Hat Linux 6.1 and Solaris
7.
Anyone have any ideas on this?
Thanks,
Joe Thomas
Here's my test script:
#!/usr/bin/perl -w
use strict;
use IPC::Shareable;
use vars qw($counter %hash);
tie %hash, 'IPC::Shareable', undef, {create => 'yes', destroy => 'yes'};
tie $counter, 'IPC::Shareable', undef, {create => 'yes', destroy => 'yes'};
$| = 1;
for (my $i = 0; $i < 3; $i++) {
sleep 1;
next if fork();
hashcount(3, 3);
exit;
}
while (1) {
last if wait() == -1;
}
sub hashcount {
my ($loops, $sleeptime) = @_;
for (my $i = 0; $i < $loops; $i++) {
(tied $counter)->shlock;
(tied %hash)->shlock;
$hash{++$counter} = $$;
print "Process $$ sees:\n";
for my $key (sort keys %hash) {
print "\$hash{$key} = $hash{$key}\n";
}
(tied %hash)->shunlock;
(tied $counter)->shunlock;
sleep $sleeptime;
}
}
exit;
The results I get:
[jthomas@server ~]$ ./ipctest.pl
Process 3737 sees:
$hash{1} = 3737
Process 3738 sees:
$hash{2} = 3738
Process 3739 sees:
$hash{3} = 3739
Process 3737 sees:
$hash{1} = 3737
$hash{4} = 3737
Process 3738 sees:
$hash{2} = 3738
$hash{5} = 3738
Process 3739 sees:
$hash{3} = 3739
$hash{6} = 3739
Process 3737 sees:
$hash{1} = 3737
$hash{4} = 3737
$hash{7} = 3737
Process 3738 sees:
$hash{2} = 3738
$hash{5} = 3738
$hash{8} = 3738
Process 3739 sees:
$hash{3} = 3739
$hash{6} = 3739
$hash{9} = 3739
------------------------------
Date: Thu, 31 Aug 2000 22:15:27 GMT
From: cquirion@my-deja.com
Subject: local install of DBI on web host
Message-Id: <8omldd$kba$1@nnrp1.deja.com>
I've read in several posts on various Perl
newsgroups that you can install DBI locally
(i.e., as a subdirectory off your cgi-bin, for
example) if your ISP does not have the module
installed.
To test this scenario, I've copied the DBD/DBI
Perl files to a local directory (cgi-bin/lib) on
our intranet - this works fine.
I only have FTP access to my web host. When I FTP
the files across to my ISP, our scripts (which
use DBI) do not work. I wrote a small script
which simply tries to access DBI (and writes 1
line to the browser) - I get an internal server
error when the 'use DBI' line is in. If I remove
that line the script works. Obviously, it is not
finding or isn't allowed to find the DBI module.
My question is ... is it okay to simply copy
these files (without going through the actual
installation)? I had actually installed DBI on
our local machine - then I uninstalled it to test
local module usage. Perhaps I am missing a vital
file? Or, maybe permissions are set incorrectly
at the ISP?
If someone out there has gone through this
exercise, I'd appreciate knowing which
files/directories are required... and what you
had to do to get this to work.
thanks...
--cheryl
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 22:15:26 GMT
From: cquirion@my-deja.com
Subject: local install of DBI on web host
Message-Id: <8omldb$kb9$1@nnrp1.deja.com>
I've read in several posts on various Perl
newsgroups that you can install DBI locally
(i.e., as a subdirectory off your cgi-bin, for
example) if your ISP does not have the module
installed.
To test this scenario, I've copied the DBD/DBI
Perl files to a local directory (cgi-bin/lib) on
our intranet - this works fine.
I only have FTP access to my web host. When I FTP
the files across to my ISP, our scripts (which
use DBI) do not work. I wrote a small script
which simply tries to access DBI (and writes 1
line to the browser) - I get an internal server
error when the 'use DBI' line is in. If I remove
that line the script works. Obviously, it is not
finding or isn't allowed to find the DBI module.
My question is ... is it okay to simply copy
these files (without going through the actual
installation)? I had actually installed DBI on
our local machine - then I uninstalled it to test
local module usage. Perhaps I am missing a vital
file? Or, maybe permissions are set incorrectly
at the ISP?
If someone out there has gone through this
exercise, I'd appreciate knowing which
files/directories are required... and what you
had to do to get this to work.
thanks...
--cheryl
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 22:17:35 GMT
From: cquirion@my-deja.com
Subject: local install of DBI
Message-Id: <8omlhb$kju$1@nnrp1.deja.com>
I've read in several posts on various Perl newsgroups that you can
install DBI locally (i.e., as a subdirectory off your cgi-bin, for
example) if your ISP does not have the module installed.
To test this scenario, I've copied the DBD/DBI Perl files to a local
directory (cgi-bin/lib) on our intranet - this works fine.
I only have FTP access to my web host. When I FTP the files across to
my ISP, our scripts (which use DBI) do not work. I wrote a small script
which simply tries to access DBI (and writes 1 line to the browser) - I
get an internal server error when the 'use DBI' line is in. If I remove
that line the script works. Obviously, it is not finding or isn't
allowed to find the local DBI module. Note that it does find it on our
local server.
My question is ... is it okay to simply copy these files (without going
through the actual installation)? I had actually installed DBI on our
local machine - then I uninstalled it to test local module usage.
Perhaps I am missing a vital file? Or, maybe permissions are set
incorrectly at the ISP?
If someone out there has gone through this exercise, I'd appreciate
knowing which files/directories are required... and what you had to do
to get this to work.
thanks...
--cheryl
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 22:17:44 GMT
From: cquirion@acromap.com
Subject: local install of DBI
Message-Id: <8omlhk$kk5$1@nnrp1.deja.com>
I've read in several posts on various Perl newsgroups that you can
install DBI locally (i.e., as a subdirectory off your cgi-bin, for
example) if your ISP does not have the module installed.
To test this scenario, I've copied the DBD/DBI Perl files to a local
directory (cgi-bin/lib) on our intranet - this works fine.
I only have FTP access to my web host. When I FTP the files across to
my ISP, our scripts (which use DBI) do not work. I wrote a small script
which simply tries to access DBI (and writes 1 line to the browser) - I
get an internal server error when the 'use DBI' line is in. If I remove
that line the script works. Obviously, it is not finding or isn't
allowed to find the local DBI module. Note that it does find it on our
local server.
My question is ... is it okay to simply copy these files (without going
through the actual installation)? I had actually installed DBI on our
local machine - then I uninstalled it to test local module usage.
Perhaps I am missing a vital file? Or, maybe permissions are set
incorrectly at the ISP?
If someone out there has gone through this exercise, I'd appreciate
knowing which files/directories are required... and what you had to do
to get this to work.
thanks...
--cheryl
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 22:43:23 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Local install of perl modules
Message-Id: <slrn8qtnsq.sk.alastair@warp.demon.co.uk>
Mark Williams <mark@orctel.co.uk> wrote:
>Is it possible to install perl modules in a local directory?
>My problem is my cgi host will not install modules that I need. Can I
>install modules on my local machine in a local directory and copy them
>up to my host into a local directory?
>Am I talking rubbish?
Yes, this seems to be possible and workable. One method is ;
1) For install
give the 'LIB=' argument when making i.e.
perl Makefile.PL LIB=/<path>/<to>/<module>/<dir>
make
make test
make install
2) For use ;
use lib '/<path>/<to>/<module>/<dir>';
use <MODULE>;
--
Alastair |
alastair@calliope.demon.co.uk |
http://www.calliope.demon.co.uk | PGP Key : A9DE69F8
-------------------------------------------------------------------
------------------------------
Date: 31 Aug 2000 22:11:20 GMT
From: Adam Trace Spragg <spragg@cs.ucdavis.edu>
Subject: My Perl looks like C!
Message-Id: <8oml68$s35$1@mark.ucdavis.edu>
Hey all... long time lurker, first time poster.
I've been using Perl professionally for about a year or so. I've completed
some good projects, and have really fallen in love with the language. I feel
I'm pretty competent, but also that I have a lot to learn.
One of my biggest concerns is that my Perl code looks like C code. When I
look at what Real Perl Hackers write, it doesn't look like C at all.
How can I reconcile this difference?
Thanks!
Adam
------------------------------
Date: Thu, 31 Aug 2000 22:20:58 GMT
From: marcel@codewerk.com (Marcel Grunauer)
Subject: Re: My Perl looks like C!
Message-Id: <slrn8qtmgi.1uu.marcel@gandalf.local>
On 31 Aug 2000 22:11:20 GMT, Adam Trace Spragg <spragg@cs.ucdavis.edu> wrote:
>I've been using Perl professionally for about a year or so. I've completed
>some good projects, and have really fallen in love with the language. I feel
>I'm pretty competent, but also that I have a lot to learn.
>
>One of my biggest concerns is that my Perl code looks like C code. When I
>look at what Real Perl Hackers write, it doesn't look like C at all.
>
>How can I reconcile this difference?
Learn idiomatic Perl. Embrace hashes, map, grep, references, closures,
regexes and all the other things that make Perl what it is. Apart
from studying other people's code I can recommend "Effective Perl
Programming" by Joseph Hall and Randal L. Schwartz. You may have heard
of the Schwartzian Transform, which is another piece of idiomatic Perl.
--
Marcel Gr\"unauer - Codewerk plc . . . . . . . . . . . <http://www.codewerk.com>
Perl Consulting, Programming, Training, Code review . . . <marcel@codewerk.com>
mod_perl, XML solutions - email for consultancy availability
sub AUTOLOAD{($_=$AUTOLOAD)=~s;^.*::;;;y;_; ;;print} Just_Another_Perl_Hacker();
------------------------------
Date: Thu, 31 Aug 2000 22:22:14 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: My Perl looks like C!
Message-Id: <x7vgwhoyuh.fsf@home.sysarch.com>
>>>>> "ATS" == Adam Trace Spragg <spragg@cs.ucdavis.edu> writes:
ATS> Hey all... long time lurker, first time poster.
this is a newsgroup, not a call in radio show. :)
ATS> I've been using Perl professionally for about a year or so. I've
ATS> completed some good projects, and have really fallen in love with
ATS> the language. I feel I'm pretty competent, but also that I have
ATS> a lot to learn.
well, if you still code like c in perl, then i wouldn't rate you as
pretty competent. that is a hallmark of a beginner perl hacker.
ATS> One of my biggest concerns is that my Perl code looks like C
ATS> code. When I look at what Real Perl Hackers write, it doesn't
ATS> look like C at all.
ATS> How can I reconcile this difference?
start to think in perl and not in c.
best thing would be for you to post some of your code here. then let the
collective mind shred it and show you how to code it in a more perlish
way. if your ego can handle it, it is a great way to learn stuff.
we have seen many c style posts and all can be easily improved a great
deal in both style and usually speed. c in perl typically is much slower
as it doesn't take advantage of perl's strengths and usually relies on
its weaknesses. i once rewrote a large parsing and munging script
written by idjits. they were reading in a 5MB file using getc (which is
a slow operator called for each char instead of record i/o) in perl!!
and doing that 5 times after creating some temp files. my rewrite was
over 60 times faster.
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: Fri, 1 Sep 2000 00:26:25 +0200
From: sumus@aut.dk (Jakob Schmidt)
Subject: Re: My Perl looks like C!
Message-Id: <1eg979e.1ito4051h7oeteN@[192.168.88.117]>
Adam Trace Spragg <spragg@cs.ucdavis.edu> wrote:
> One of my biggest concerns is that my Perl code looks like C code. When I
> look at what Real Perl Hackers write, it doesn't look like C at all.
>
> How can I reconcile this difference?
Hard to say when we don't know exactly what your code looks like really.
I have some guesses though:
- stop using the C-style for-loop (it's rarely the best choice)
- get used to thinking of lists and arrays in a certain Perly way :-)
- use grep and map, use splice and substr as an lvalue
- use slices of hashes and arrays at least once a day
- read the perlstyle manpage and live by it
- don't use parens around parameter lists when you don't have to
- read a lot of c.l.p.m articles and be careful to notice the syntax
used.
Guess I'm not a "Real" Perl Hacker (yet?) but I think some of the above
pieces of advice may help free you from the lack of style (or at least
the lack of color) that characterizes C (compared to Perl).
Jakob
--
$_="rka rPrhoatuJs nte elHce\n";0while[$s=-int.5
-.5*length]&&s&(.{$s})(.)(.{$s})&$1$3&s&&print$2
------------------------------
Date: 31 Aug 2000 22:28:18 GMT
From: abigail@foad.org (Abigail)
Subject: Re: My Perl looks like C!
Message-Id: <slrn8qtmug.8ac.abigail@alexandra.foad.org>
Adam Trace Spragg (spragg@cs.ucdavis.edu) wrote on MMDLVII September
MCMXCIII in <URL:news:8oml68$s35$1@mark.ucdavis.edu>:
"" Hey all... long time lurker, first time poster.
""
"" I've been using Perl professionally for about a year or so. I've completed
"" some good projects, and have really fallen in love with the language. I feel
"" I'm pretty competent, but also that I have a lot to learn.
""
"" One of my biggest concerns is that my Perl code looks like C code. When I
"" look at what Real Perl Hackers write, it doesn't look like C at all.
""
"" How can I reconcile this difference?
There are two options:
- Shoot all Real Perl Hackers, so everyone will code Perl as in C.
- Get a different book.
Abigail
--
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
print+Just (), another (), Perl (), Hacker ();'
------------------------------
Date: Thu, 31 Aug 2000 22:30:46 GMT
From: SPAM+indigo@dimensional.com (Tim)
Subject: Re: My Perl looks like C!
Message-Id: <8FA1A0A13indigodimcom@166.93.207.145>
spragg@cs.ucdavis.edu (Adam Trace Spragg) wrote in
<8oml68$s35$1@mark.ucdavis.edu>:
>Hey all... long time lurker, first time poster.
>
>I've been using Perl professionally for about a year or so. I've
>completed some good projects, and have really fallen in love with the
>language. I feel I'm pretty competent, but also that I have a lot to
>learn.
>
>One of my biggest concerns is that my Perl code looks like C code. When
>I look at what Real Perl Hackers write, it doesn't look like C at all.
>
>How can I reconcile this difference?
I bring this up in code reviews all the time. First thing is to realize
that "looking too much like C" is not so bad thing, compared to the
"looking too much like crap" criticism I have to level far too often.
Knowing how to program is more important than knowing how to program in
Perl.
A few pointers to get away from that C-in-Perl doldrums:
o Avoid "for ($i=0;$i<$n;$i++)". Perl for loops rarely use iterators.
o Use hashes. A lot.
o Use logical operators. this() or die; is a lot cleaner than
if (this()) { die; }. Same with $x = $this || $that;
o Use unless and until instead of negated if and while.
o Use EXPR if COND if your consequence is more important than your
condition.
o Master regular expressions.
o Understand $_, and know its power.
o Think in terms of lists and list manipulation, instead of arrays
and indexing. Be comfortable with map and grep.
o Be comfortable using hashes and arrays to build complex data structures
on the fly.
o Strings and file I/O are a pain in C. Don't be afraid to go crazy with
them in Perl.
-T
------------------------------
Date: 31 Aug 2000 22:04:56 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: My Perl looks like C!
Message-Id: <39ae3bd8$1_3@nexus.comcen.com.au>
Adam Trace Spragg <spragg@cs.ucdavis.edu> wrote:
>Hey all... long time lurker, first time poster.>
>I've been using Perl professionally for about a year or so. I've completed
>some good projects, and have really fallen in love with the language. I feel
>I'm pretty competent, but also that I have a lot to learn.
>
>One of my biggest concerns is that my Perl code looks like C code. When I
>look at what Real Perl Hackers write, it doesn't look like C at all.
>
>How can I reconcile this difference?
>
>Thanks!
>Adam
read http://www.perl.org/press/style-guide.html
------------------------------
Date: Thu, 31 Aug 2000 23:19:32 GMT
From: Steven Merritt <smerr612@mailandnews.com>
Subject: Re: My Perl looks like C!
Message-Id: <8omp5i$p1o$1@nnrp1.deja.com>
In article <8oml68$s35$1@mark.ucdavis.edu>,
Adam Trace Spragg <spragg@cs.ucdavis.edu> wrote:
> One of my biggest concerns is that my Perl code looks like C code.
When I
> look at what Real Perl Hackers write, it doesn't look like C at all.
That's ok, my C looks like Perl. And I bet it's a helluva lot harder to
maintain than your Perl.
Steven
--
King of Casual Play
The One and Only Defender of Cards That Blow
My newsreader limits sigs to four lines, but I cleverly bypassed this by
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 31 Aug 2000 19:51:23 -0500
From: "Andrew N. McGuire " <anmcguire@ce.mediaone.net>
Subject: Re: My Perl looks like C!
Message-Id: <Pine.LNX.4.21.0008311928220.28172-100000@hawk.ce.mediaone.net>
On Thu, 31 Aug 2000, Tim quoth:
~~ Date: Thu, 31 Aug 2000 22:30:46 GMT
~~ From: Tim <SPAM+indigo@dimensional.com>
~~ Newsgroups: comp.lang.perl.misc
~~ Subject: Re: My Perl looks like C!
~~
~~ spragg@cs.ucdavis.edu (Adam Trace Spragg) wrote in
~~ <8oml68$s35$1@mark.ucdavis.edu>:
~~
~~ >Hey all... long time lurker, first time poster.
~~ >
~~ >I've been using Perl professionally for about a year or so. I've
~~ >completed some good projects, and have really fallen in love with the
~~ >language. I feel I'm pretty competent, but also that I have a lot to
~~ >learn.
~~ >
~~ >One of my biggest concerns is that my Perl code looks like C code. When
~~ >I look at what Real Perl Hackers write, it doesn't look like C at all.
~~ >
~~ >How can I reconcile this difference?
~~
~~ I bring this up in code reviews all the time. First thing is to realize
~~ that "looking too much like C" is not so bad thing, compared to the
~~ "looking too much like crap" criticism I have to level far too often.
~~ Knowing how to program is more important than knowing how to program in
~~ Perl.
I disagree, a HUGE part of knowing how to program is mastering the
idioms of the language you are programming in.
~~ A few pointers to get away from that C-in-Perl doldrums:
~~
~~ o Avoid "for ($i=0;$i<$n;$i++)". Perl for loops rarely use iterators.
~~ o Use hashes. A lot.
Based on what premise? A hash is not the end all data structure.
Use the appropriate data structure for the task you are trying to
accomplish!
~~ o Use logical operators. this() or die; is a lot cleaner than
~~ if (this()) { die; }. Same with $x = $this || $that;
I usually use:
$x ||= $that;
most often to set defaults after a GetOptions(). It is a matter of
style, I suppose.
[ snip ]
~~ o Understand $_, and know its power.
And limitations!
(read: where it can and cannot be used, and when it adds to and
takes away from readability)
[ snip ]
~~ o Strings and file I/O are a pain in C. Don't be afraid to go crazy with
~~ them in Perl.
Indeed, "have the appropriate amount of fun".
anm
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~ Andrew N. McGuire ~
~ anmcguire@ce.mediaone.net ~
~ "Plan to throw one away; you will, anyhow." - Frederick P. Brooks, Jr. ~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: 31 Aug 2000 17:05:23 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: open web file
Message-Id: <87aedtgk7w.fsf@limey.hpcc.uh.edu>
>> On Thu, 31 Aug 2000 15:07:07 -0700,
>> "Sean Scannell" <sean@access-management.com> said:
> Why does the following die: open (TEMP,
> 'http://www.foo.com/bar.html') || die
This will die if you don't have a readable file called
bar.html in the directory hierarchy
./http://www.foo.com
i.e. in the current directory.
> I guess I can fetch the file via LWP, but just
> wondering.
Web resources are not files. open() doesn't understand
any remote HTTP/FTP/... semantics.
hth
t
--
"I'm not easily impressed. Wow! A blue car!"
Homer Simpson
------------------------------
Date: 31 Aug 2000 22:18:19 GMT
From: abigail@foad.org (Abigail)
Subject: Re: open web file
Message-Id: <slrn8qtmbp.8ac.abigail@alexandra.foad.org>
Sean Scannell (sean@access-management.com) wrote on MMDLVII September
MCMXCIII in <URL:news:ZBAr5.85$WH4.68667@news.pacbell.net>:
|| Why does the following die:
||
|| open (TEMP, 'http://www.foo.com/bar.html') || die
Why do you ask? Perl has a useful mechanism that tells you why
something failed. Why don't you use it instead of asking here?
|| I guess I can fetch the file via LWP, but just wondering.
open() has lots of magic, but only C-API specific and, unfortunally,
no HTTP semantics. It would be useful though.
Abigail
--
perl -e 'for (s??4a75737420616e6f74686572205065726c204861636b65720as?;??;??)
{s?(..)s\??qq \?print chr 0x$1 and q ss\??excess}'
------------------------------
Date: 31 Aug 2000 20:17:50 -0400
From: darkon@one.net (David Wall)
Subject: Re: open web file
Message-Id: <8FA1C23F7darkononenet@206.112.192.118>
I wrote:
>
>open() is for opening files. http://www.foo.com/bar.html isn't a file.
>
Well, plus a few other things like pipes, but mainly files. ok? :-)
--
David Wall
darkon@one.net
------------------------------
Date: 31 Aug 2000 20:29:39 -0400
From: steveo@panix.com (Steven M. O'Neill)
Subject: Re: open web file
Message-Id: <8omt9j$im1$1@panix6.panix.com>
David Wall <darkon@one.net> wrote:
>I wrote:
>
>>
>>open() is for opening files. http://www.foo.com/bar.html isn't a file.
HTML files are not files?
--
Steven O'Neill steveo@panix.com
------------------------------
Date: 31 Aug 2000 19:32:24 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: open web file
Message-Id: <877l8xgdev.fsf@limey.hpcc.uh.edu>
>> On 31 Aug 2000 20:29:39 -0400,
>> steveo@panix.com (Steven M. O'Neill) said:
> David Wall <darkon@one.net> wrote:
>> I wrote:
>>
>>> open() is for opening files.
>>> http://www.foo.com/bar.html isn't a file.
> HTML files are not files? -- Steven O'Neill
URLs are not files. There's a big, big difference.
hth
t
-
"I'm not easily impressed. Wow! A blue car!"
Homer Simpson
------------------------------
Date: Thu, 31 Aug 2000 19:01:16 -0500
From: Jerry Jorgenson <jerry@j3iss.com>
Subject: Re: output fun
Message-Id: <2F8B873414B79812.C5510C376575303E.D6A7AD15A8908A0B@lp.airnews.net>
Here's my version:
#!/usr/sbin/perl
# spaces.pl
# Program to print out a palindrome in a pattern
use diagnostics;
use strict;
my $startText;
my $character;
my @characters;
@characters = qw(G F E D C B A);
$startText = "ABCDEFGFEDCBA";
print $startText, "\n";
foreach $character (@characters) {
$startText =~ s/$character/ /g;
print $startText, "\n";
}
exit;
ankban4@my-deja.com wrote:
--
Jerry Jorgenson
jerry@j3iss.com
http://www.j3iss.com/
------------------------------
Date: Thu, 31 Aug 2000 19:03:32 -0400
From: Rick Nakroshis <nakroshis@smart.net>
Subject: Parsing text file not working properly
Message-Id: <39AEE444.A98D0BED@smart.net>
What am I doing wrong? When I run this program, it prints "BB AA 111"
on three seperate lines, when I was expecting "BB BB 222". What am I
doing wrong here? I'm new to Perl, and this looks like it ought to work
correctly.
#!/usr/bin/perl -w
# Activestate Perl v5.60 on Win NT 4.0 WS
#
$search = "BB";
open (DATAFILE, "data.dat") or die "Can't open the data file: $!";
while (<DATAFILE>) {
if (index (<DATAFILE>, $search) eq 0) {
($field1, $field2) = split (/,/);
print ("$search\n");
print ("$field1\n");
print ("$field2\n");
}
}
close (DATAFILE) or die "Couldn't close the DATAFILE: $!";
Data file contents is:
AA,111<carriage return>
BB,222<carriage return>
CC,333<carriage return>
DD,444<carriage return>
<carriage return>
Searching for AA or CC returns nothing; BB and DD returns the previous
record.
I welcome any helpful suggestions and hints. Any recommended books,
besides the pair of Camel books?
Rick
--
_\\|//_
( O-O )
-------------------------o00--(_)--00o---------------------------
Rick Nakroshis nakroshis@smart.net
And remember, another day ends:
All targets met...
All systems working and customers satisfied...
All staff eager and enthusiastic...
All pigs fed, watered, and ready to fly.
-----------------------------------------------------------------
------------------------------
Date: Thu, 31 Aug 2000 16:39:13 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Parsing text file not working properly
Message-Id: <MPG.14188c8194434b7798ad11@nntp.hpl.hp.com>
In article <39AEE444.A98D0BED@smart.net> on Thu, 31 Aug 2000 19:03:32 -
0400, Rick Nakroshis <nakroshis@smart.net> says...
> What am I doing wrong? When I run this program, it prints "BB AA 111"
> on three seperate lines, when I was expecting "BB BB 222". What am I
> doing wrong here? I'm new to Perl, and this looks like it ought to work
> correctly.
>
> #!/usr/bin/perl -w
A good start. Next learn to add 'use strict;' and declare variables.
> # Activestate Perl v5.60 on Win NT 4.0 WS
> #
my
> $search = "BB";
> open (DATAFILE, "data.dat") or die "Can't open the data file: $!";
Excellent diagnostic!
> while (<DATAFILE>) {
> if (index (<DATAFILE>, $search) eq 0) {
The contents of the first line read from the file are now in $_. But
this use of <DATAFILE> reads the second line from the file.--
Although it changes nothing, I would use the following form to avoid
indenting the rest of the loop. I would also use the proper operator
for numerical comparison:
next unless index($_, $search) == 0;
or (shorter but somewhat more obscure):
next if index $_, $search;
> ($field1, $field2) = split (/,/);
my ($field1, $field2) = split /,/;
> print ("$search\n");
> print ("$field1\n");
> print ("$field2\n");
Don't forget that $field2 still has a trailing newline. You could use
this:
chomp;
before doing the split, to extract just the field. If all you are going
to do is print it with a newline following, don't bother with the
chomp().
> }
> }
> close (DATAFILE) or die "Couldn't close the DATAFILE: $!";
>
> Data file contents is:
See below.
while (<DATA>) {
next unless index($_, $search) == 0;
chomp;
my ($field1, $field2) = split /,/;
print $search, "\n", $field1, "\n", $field2, "\n";
# print "$search\n$field1\n$field2\n"; # An alternate way
}
close DATA or die "Couldn't close the DATAFILE: $!";
__END__
AA,111
BB,222
CC,333
DD,444
> Searching for AA or CC returns nothing; BB and DD returns the previous
> record.
Because that is what is in $_, as shown above.
> I welcome any helpful suggestions and hints. Any recommended books,
> besides the pair of Camel books?
What pair of Camel books? 'Camel' ne 'Llama'.
Go here for recommendations:
http://www.sysarch.com/
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 31 Aug 2000 19:43:52 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Parsing text file not working properly
Message-Id: <39AEEDB8.9E46B42D@cc.gatech.edu>
Rick Nakroshis wrote:
> What am I doing wrong? When I run this program, it prints "BB AA 111"
> on three seperate lines, when I was expecting "BB BB 222". What am I
> doing wrong here? I'm new to Perl, and this looks like it ought to work
> correctly.
>
> #!/usr/bin/perl -w
> # Activestate Perl v5.60 on Win NT 4.0 WS
> #
> $search = "BB";
> open (DATAFILE, "data.dat") or die "Can't open the data file: $!";
> while (<DATAFILE>) {
>
> if (index (<DATAFILE>, $search) eq 0) {
Your problem is right here. <DATAFILE> reads and returns the next line in
the file, while you are iterating over it. This line should be:
if (index ($_, $search) eq 0) {
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: 31 Aug 2000 22:51:47 +1100
From: "Kiel Stirling" <taboo@comcen.com.au>
Subject: Re: Parsing text file not working properly
Message-Id: <39ae46d3$1_1@nexus.comcen.com.au>
Rick Nakroshis <nakroshis@smart.net> wrote:
>What am I doing wrong? When I run this program, it prints "BB AA 111">on three seperate lines, when I was expecting "BB BB 222". What am I
>doing wrong here? I'm new to Perl, and this looks like it ought to work
>correctly.
>
>#!/usr/bin/perl -w
># Activestate Perl v5.60 on Win NT 4.0 WS
>#
>$search = "BB";
>open (DATAFILE, "data.dat") or die "Can't open the data file: $!";
>while (<DATAFILE>) {
> if (index (<DATAFILE>, $search) eq 0) {
> ($field1, $field2) = split (/,/);
> print ("$search\n");
> print ("$field1\n");
> print ("$field2\n");
> }
>}
>close (DATAFILE) or die "Couldn't close the DATAFILE: $!";
>
>Data file contents is:
>
>AA,111<carriage return>
>BB,222<carriage return>
>CC,333<carriage return>
>DD,444<carriage return>
><carriage return>
I would do this
open FILE, "file.dat" or die "FILE->read: $!";
$search = "BB";
while (<FILE>) {
($field1, $field2) = split "," $_ if /^$search/;
# split $_ if the value of $search is at the start
# of the line
print $field1,$field2,"\n";
}
close FILE or die "FILE->close: $!";
-Kiel Stirling
------------------------------
Date: 31 Aug 2000 16:06:25 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Perl/ODBC/SQL Wierdness?
Message-Id: <39aee4f1@news.victoria.tc.ca>
Stephan Gross (sg@loralskynet.com) wrote:
: Problem: my perl program returns different data than Access does
: running the same SQL statement.
: I have two tables in Access. Each contains a field with same name
: (FIELD1) but different values. The tables are joined by another
: common field (COMMON). I use the Access Query Design to get rows I
: want, then switch to the SQL view and get the SQL statement, which
: looks something like this:
: "SELECT TABLE1.CUSTOMER, TABLE1.FIELD1, TABLE2.FIELD1
: FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.COMMON = TABLE2.COMMON"
: When I run this in Access, I get unique values for TABLE1.FIELD1 and
: TABLE2.FIELD1.
: I then cut and paste the exact same SQL statement into my perl ODBC
: program. When I run the program, TABLE1.FIELD1 returns the same value
: as TABLE2.FIELD1.
: Any ideas on what to do about this?
Try assigning unique names to the columns.
SELECT TABLE1.CUSTOMER Tab1_Cust,
TABLE1.FIELD1 Tab1_Fld1,
TABLE2.FIELD1 Tab2_fld2
FROM TABLE1 INNER JOIN TABLE2 ON TABLE1.COMMON = TABLE2.COMMON"
------------------------------
Date: 31 Aug 2000 17:31:52 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Q. relating to perlfaq(4) / sort
Message-Id: <m3aedt3vvr.fsf@dhcp11-177.support.tivoli.com>
Larry Rosler <lr@hpl.hp.com> writes:
> As for negative numbers (more precisely, signed numbers), there is some
> discussion of that in the place referenced by Abe Timmerman:
>
> For more information: "A Fresh Look at Efficient Perl Sorting"
> (Appendix B:)
>
> http://www.hpl.hp.com/personal/Larry_Rosler/sort/sorting.html
I read through this again (though I didn't go through the slides
again), and I didn't see anything about arbitrary length signed
"string" numbers. I suppose it would be simple to just make it a
two-key sort. Sort by sign, then by magnitude. Throwing in decimal
places would, I suppose, necessitate either some clever handling to
get the length right, or simply split the fractional portion into a
third key.
Nope, not good enough... negative values need to be reverse sorted by
magnitude. Perhaps preprocessing into two lists, one for negative
values and one for non-negative values. Sort both lists and then just
combine them.
Haven't quite got it working yet, but it's time to leave....
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 31 Aug 2000 18:12:20 -0500
From: Nektarios Rigas <umrigas@cc.umanitoba.ca>
Subject: Sample Makefiles
Message-Id: <39AEE654.8B673A4B@cc.umanitoba.ca>
Hi Everyone,
Are there any sample perl makefiles out there that I may read?
I need one that successfully loads external windows libraries.
I've searched and have not found any yet.
I am on Win NT and have the most current version of Perl.
Just to let you know:
I have read the man page on ExtUtils::MakeMaker and I am obviously
not doing something right.
--
============================
Thank You
N. Rigas
------------------------------
Date: Thu, 31 Aug 2000 23:00:27 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Sorting a Tab Delimited Text File By Second Field
Message-Id: <fmotqs0dhagvnrvtlkrkj7sdct6914d91r@4ax.com>
Shawn M. Crowley wrote:
>What is the best way to sort a tab delimited file with many records by the
>second field, in this situation a date?
Extract the second field, a simple (split/\t/, $_, 3)[1] will do; and
use a Schwartzian Transform (AKA the "map sort map" thing) to use this
to sort the lines.
@sorted = map { $_->[0] } sort { $a->[1] cmp $b->[1] }
map { [ $_, (split /\t/, $_, 3)[1] ] } <>;
--
Bart.
------------------------------
Date: Fri, 01 Sep 2000 00:47:57 GMT
From: warren@desertwolf.com (Warren)
Subject: Thank you!! (from a newbie)
Message-Id: <39aefd4b.109676786@news.gte.net>
To those who helped me out with my simple little problem, thanks! It
is very refreshing to find the courteous, helpful responses that I
found on this forum.
Thanks again,
Warren
------------------------------
Date: Thu, 31 Aug 2000 22:47:08 GMT
From: ptomsic@my-deja.com
Subject: url correcting help?
Message-Id: <8omn96$mo0$1@nnrp1.deja.com>
I'm certain this has been done before, but I don't know where to look,
so could someone please point me in the direction of something that
would run thru a directory tree, find URLS that are not full-urls'
(../../picture.gif) and replace it with the actual URL
(http://www.foo.com/images/new_images/picture.gif)
I believe the difficult part of this would be once you get a few sub-
levels deep into the site and it starts referencing one or two levels
above, or simply using a slash to run to the top of the tree.
Is there something out there that would do this?
Thanks
PJT
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
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 4194
**************************************