[9614] in Perl-Users-Digest
Perl-Users Digest, Issue: 3208 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 20 19:07:24 1998
Date: Mon, 20 Jul 98 16:00:25 -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 Mon, 20 Jul 1998 Volume: 8 Number: 3208
Today's topics:
Re: Array element translation <jdporter@min.net>
Re: Array element translation <merlyn@stonehenge.com>
Re: beginner: better code for word separation combinati <jdporter@min.net>
Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. p (Stefaan A Eeckels)
Re: compare arrays <jdporter@min.net>
Re: compare arrays (Larry Rosler)
dumb questions Re: Problem with DBD::Oracle <kucerar@hhmi.org>
Re: Failed to compile perl because make does not how to (M.J.T. Guy)
Finding new files (create after a time stamp) drubin@gatekeeper.cb.att.com
Re: Finding new files (create after a time stamp) (Brian Wheeler)
Geography.pm <paula@2lm.com>
Is 3484000000 a negative number ? <misha@etsd.ml.com>
newbie <jerrball@rust.net>
Re: newbie (Kelly Hirano)
Re: newbie <jdporter@min.net>
Re: Overriding builtin functions <yary@apicom.com>
Re: Perl Beautifier Home Page (William R. Ward)
Regular Exp. Question <JLEHMANN@dsccc.com>
Re: Regular Exp. Question (Brian Wheeler)
Re: Regular Exp. Question (Larry Rosler)
Re: Regular Exp. Question <jdporter@min.net>
Re: Simple problem with perl script. (Neil Neely)
split function on CR/LF <Barney@tdrake.demon.co.uk>
Re: split function on CR/LF (Brian Wheeler)
Tcl is better than Perl (Kin-Koi Lo)
temp directory for both unix and windows platform <balaji@emicx.mentorg.com>
Re: Turning 13 lines of text into one (Abigail)
Re: Wierd behaviour of .. operator <Richard@waveney.demon.co.uk>
Wrong Line # <shenge@ece.ucdavis.edu>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 20 Jul 1998 21:04:55 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Array element translation
Message-Id: <35B3B27A.2B22@min.net>
Larry Rosler wrote:
>
> In article <6ovudv$pq9$1@news-1.news.gte.net> on Mon, 20 Jul 1998
> 11:26:26 -0600, Kirk D. Haines <khaines@oshconsulting.com> says...
> > @seq = grep {tr/0123/3210/} @comp;
>
> Wrong. That changes @comp, which is clearly not desired. It also loses
> any element that happens not to have a 0 1 2 or 3 in it.
>
> @seq = map { local $_ = $_; tr/0123/3210/; $_ } @comp;
>
> Randal's solution, which is computational instead of by mapping, is
> neat(er?).
They are not equivalent, and it's because the original question was
ambiguous as to whether he had a string of [0123] characters, or an
array of strings from the set qw[ 0 1 2 3 ]. Randal's solution
assumes the latter, your solution assumes the former.
--
John Porter
------------------------------
Date: Mon, 20 Jul 1998 22:12:37 GMT
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: Array element translation
Message-Id: <8cogukw4s5.fsf@gadget.cscaper.com>
>>>>> "Abigail" == Abigail <abigail@fnx.com> writes:
Abigail> map {tr/0123/3210/} @seq = @comp;
Ewww. Void use of map. Five yard penalty.
(I bet you did it just to see if I'd notice, eh? :-)
for (@seq = @comp) { tr/0123/3210/ }
print "Just another 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: Mon, 20 Jul 1998 20:57:22 GMT
From: John Porter <jdporter@min.net>
Subject: Re: beginner: better code for word separation combinations
Message-Id: <35B3B0B4.675@min.net>
Ralph Brands wrote:
>
> I have a program that searches for examples of a first word followed by a
> second word in text.
>
> If the program finds a section of text with more than one example of one
> or both words, I want to indicate the number of words between the first
> and second search words in all possible combinations of those words.
>
> For example, if "cat" is the first search word and "dog" is the second
> search word, I want to do this:
>
> $matchstring = There is a cat and cat but also a dog and the another cat
> and dog and cat in this sentence.
>
> words that are cat:
> 4
> 6
> 14
> 18
>
> words that are dog:
> 10
> 16
>
> For each dogvalue
> For each catvalue
> if dogvalue > catvalue
> wordseparationvalue = dogvalue - catvalue + 1
> ->
>
> 3, 5
> 1, 9, 11
I think there must be a bug in your ("horrible") solution,
because if there's a separation value of 1, then there is
an occurence of "dog" and "cat" at the exact same position.
Anyway, here's my version, which gives (I believe) the
right results:
my $data = 'There is a cat and cat but also a dog and the
another cat and dog and cat in this sentence.';
my %found;
my @data = split /\W+/, $data;
for my $i ( 0 .. $#data ) {
push @{$found{$data[$i]}}, $i;
}
my $var3 = 'cat'; # or whatever
my $var4 = 'dog';
for my $x ( @{$found{$var3}} ) {
print join ', ', map { $x<$_ ? ($_-$x+1) : () } @{$found{$var4}};
print "\n";
}
It produces this output:
7, 13
5, 11
3
--
John Porter
------------------------------
Date: 20 Jul 1998 12:56:59 GMT
From: Stefaan.Eeckels@ecc.lu (Stefaan A Eeckels)
Subject: Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. print)
Message-Id: <6oveqr$ffh$1@justus.ecc.lu>
In article <x7sok1m7ai.fsf_-_@sysarch.com>,
Uri Guttman <uri@sysarch.com> writes:
OK, without looking at the others ;-)
> all of the questions have very short answers (about one word each) which,
> hopefully, will open exploration of large areas of programming terra
> incognita. the bonus answer is cute and copyrighted by me.
>
> 1. Who is main the PERSON you should think about while you are writing code?
Yourself (as you're the most likely maintainer).
>
> 2. Other than comments, what is the most important HUMAN aspect of code?
Readability (but I'd disagree with the first part of the sentence).
>
> 3. What is the main PURPOSE of comments?
Structure through whitespace ;-)
>
> Bonus: What is the OPPOSITE of spaghetti code?
Lasagna code, obviously!
--
Stefaan
whose Perl programs are more like pita code, really :-)
--
PGP key available from PGP key servers (http://www.pgp.net/pgpnet/)
___________________________________________________________________
Perfection is reached, not when there is no longer anything to add,
but when there is no longer anything to take away. -- Saint-Exupery
------------------------------
Date: Mon, 20 Jul 1998 21:32:22 GMT
From: John Porter <jdporter@min.net>
Subject: Re: compare arrays
Message-Id: <35B3B8E8.41F1@min.net>
Dominic Dunlop wrote:
>
> Stale thread, but WTH, I'll jump in anyway...
Just douse with water, and put in warm oven for a few minutes.
> Craig Berry <cberry@cinenet.net> wrote in respose to a question from
> Alberto Brosich <brosich@univ.trieste.it>:
> > : How can i compare two arrays other then with a loop?
> > Short answer: You can't do it without looping.
>
> Umm, yes you can. For a straight equality check of two arrays, @x and
> @y,
>
> "@x" eq "@y"
No, that is even worse. It still has to loop, in order to get every
element of the array and stringize it. But it's worse, because it
always loops over the entire array, rather than jumping out at the
earliest possible opportunity. (Plus all the other reasons you
mentioned for eschewing this technique.)
--
John Porter
------------------------------
Date: Mon, 20 Jul 1998 15:14:46 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: compare arrays
Message-Id: <MPG.101d6136874df5e798972e@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a courtesy copy sent to John Porter
<jdporter@min.net>.]
In article <35B3B8E8.41F1@min.net> on Mon, 20 Jul 1998 21:32:22 GMT, John
Porter <jdporter@min.net> says...
...
> > "@x" eq "@y"
>
> No, that is even worse. It still has to loop, in order to get every
> element of the array and stringize it. But it's worse, because it
> always loops over the entire array, rather than jumping out at the
> earliest possible opportunity. (Plus all the other reasons you
> mentioned for eschewing this technique.)
That is way overstated. If the arrays match, the stringizing approach is
about twice as fast as the loop. If the first mismatch is halfway
through, they are about the same. So on average they are about the same.
I posted the benchmarks on July 14.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 20 Jul 1998 17:06:56 -0400
From: Richard J Kucera <kucerar@hhmi.org>
Subject: dumb questions Re: Problem with DBD::Oracle
Message-Id: <35B3B16F.9E8AE95@hhmi.org>
Why aren't there pre-built DBD's for major vendors and platforms?
It seems like Perl would take off in popularity if there were just some pre-built
packages...
especially a pre-built Apache + mod_perl + Oracle DBD...
I would gladly switch to Apache & DBI from Java Web Server & Oracle type 4 JDBC
but I simply don't have the time for such mucking around with running gcc anymore
(I'd love to do it, but I'd get in trouble).
Also, if Perl networking is so great, why don't they write network drivers like
they've done with Java, rather than continue to rely on native drivers? It seems
like
it would make life simpler.
... if I could just get a pre-built DBD
I could start using it immediately for some quick CGI jobs where servlets are
cumbersome, rather than keep proliferating Java.
-R Kucera, Web Apps Developer.
Eric Zylberstejn wrote:
> Ralf Orlowski wrote:
> > As I could need some data from the Oracle-Database in this scripts I tried
> > to install the DBI and the DBD-Oracle module to access the Database from
> > within perl.
> > But during the installation of the DBD module I had to recognize that this
> > module needs some header files from oracle for the installation that are
> > not included in my runtime Version of Oracle.
>
> Hi,
>
> I think you need Oracle's Pro*C module, because DBD::Oracle is partly written
> in C. Once you get Pro*C on your computer everything will run correctly. I have
> been using DBI and DBD::Oracle for quite some time now.
>
> Take a look at:
> http://www.hermetica.com/technologia/perl/DBI/index.html
>
> Eric
>
> ------------------------------------------------------------------------
>
> Eric Zylberstejn <Eric.Zylberstejn@wanadoo.com>
> FTI
>
> Eric Zylberstejn
> FTI <Eric.Zylberstejn@wanadoo.com>
> 41 r Camille Desmoulins Work: 01 41 33 94 59
> Issy-les-Moulineaux Netscape Conference Address
> 92130 Netscape Conference DLS Server
> France
> Additional Information:
> Last Name Zylberstejn
> First Name Eric
> Version 2.1
------------------------------
Date: 20 Jul 1998 21:05:46 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Failed to compile perl because make does not how to make README file
Message-Id: <6p0bfa$4nc$1@pegasus.csx.cam.ac.uk>
chuanlarp satchavarodom <chuanlarp@bigfoot.com> wrote:
>dear all.
>
> I recently downloaded perl5 and tried to compile it on DynixPTX Pentium
>machine. the configure ran fine, but when I tried to make it. The make
>stopped suddenly after start saying that make does not how to make README.
>Please help me.
You'll have to provide rather more information if you seriously expect
to get any help. In particular, please provide the *output* of the
./myconfig script (as instructed in INSTALL), the exact commands that you
typed and the errors you got.
Mike Guy
------------------------------
Date: Mon, 20 Jul 1998 20:35:06 GMT
From: drubin@gatekeeper.cb.att.com
Subject: Finding new files (create after a time stamp)
Message-Id: <6p09lq$j8j$1@nnrp1.dejanews.com>
Hello,
What is the best way (using ksh or perl) to find all files in a directory
created after a timedate stamp (such as 07/20/98:10:10)? I was hoping this
would be simple, but I keep coming up with very messy solutions.
Thanks for any suggestions.
- Dan
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 20 Jul 1998 21:32:31 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: Re: Finding new files (create after a time stamp)
Message-Id: <6p0d1f$dcv$2@flotsam.uits.indiana.edu>
use the find command. 'man find' should give you enough details.
In article <6p09lq$j8j$1@nnrp1.dejanews.com>,
drubin@gatekeeper.cb.att.com writes:
> Hello,
>
> What is the best way (using ksh or perl) to find all files in a directory
> created after a timedate stamp (such as 07/20/98:10:10)? I was hoping this
> would be simple, but I keep coming up with very messy solutions.
>
> Thanks for any suggestions.
>
> - Dan
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Mon, 20 Jul 1998 14:40:15 -0700
From: Paula Gibb <paula@2lm.com>
Subject: Geography.pm
Message-Id: <35B3B93F.1556@2lm.com>
Hello,
I am looking for a Perl module called Geography; does anyone know the
whereabouts of this module? BTW, I have already searched for the module
via CPAN, but have come up empty-handed.
Thanks for any information you can provide.
Paula G.
------------------------------
Date: Mon, 20 Jul 1998 17:58:09 -0400
From: Michael Pavlov <misha@etsd.ml.com>
Subject: Is 3484000000 a negative number ?
Message-Id: <35B3BD71.C033965A@etsd.ml.com>
This is a multi-part message in MIME format.
--------------26795BB3DF662BF70B900F76
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Here is a quick one:
#!/usr/local/etsd/ged/bin/perl
$x = 3484000000;
if ($x < 0 )
{
print("is negative\n");
}
else
{
print("it is pos\n");
}
$x = 348000;
if ($x < 0 )
{
print("is negative\n");
}
else
{
print("it is pos\n");
}
Produced on machine with perl 5.02
is negative
it is pos
Produced on machine with perl 5.04
it is pos
it is pos
Is this a bug ?
--------------26795BB3DF662BF70B900F76
Content-Type: text/x-vcard; charset=us-ascii; name="vcard.vcf"
Content-Transfer-Encoding: 7bit
Content-Description: Card for misha@etsd.ml.com Pavlov
Content-Disposition: attachment; filename="vcard.vcf"
begin: vcard
fn: misha@etsd.ml.com Pavlov
n: Pavlov;misha@etsd.ml.com
org: Merrill Lynch
adr: 2 World Financial Center;;6th Floor, room 06-259;New York;New York;10080;USA
email;internet: misha@etsd.ml.com
title: Systems Engineer
tel;work: (212)236-2062
tel;fax: (212)236-2399
x-mozilla-cpt: ;0
x-mozilla-html: TRUE
version: 2.1
end: vcard
--------------26795BB3DF662BF70B900F76--
------------------------------
Date: Mon, 20 Jul 1998 17:18:59 -0400
From: "Jerry Chapman" <jerrball@rust.net>
Subject: newbie
Message-Id: <6p0ces$iut$1@news2.ispnews.com>
Well,
This is my first newsgroup - anything!
I am as new as it gets.
However, I am trying to learn perl - especially from the server side. What
I need is a step by step process to get the server running. I have
installed win32 - perl. I think it works, but when I try to link with html
the .pl files basically prints out without executing. What am I doing wrong
------------------------------
Date: 20 Jul 1998 14:33:31 -0700
From: hirano@Xenon.Stanford.EDU (Kelly Hirano)
Subject: Re: newbie
Message-Id: <6p0d3b$ou5@Xenon.Stanford.EDU>
In article <6p0ces$iut$1@news2.ispnews.com>,
Jerry Chapman <jerrball@rust.net> wrote:
>Well,
>This is my first newsgroup - anything!
>I am as new as it gets.
>However, I am trying to learn perl - especially from the server side. What
>I need is a step by step process to get the server running. I have
>installed win32 - perl. I think it works, but when I try to link with html
>the .pl files basically prints out without executing. What am I doing wrong
you need to configure your server to let it know that .pl files are scripts,
not text documents. but this discussion belongs in a different newsgroup as
it has nothing to do with the perl language -- it has to do with win32 server
configuration.
--
Kelly William Hirano Stanford Athletics:
hirano@cs.stanford.edu http://www.gostanford.com/
hirano@alumni.stanford.org (WE) BEAT CAL (AGAIN)! 100th BIG GAME: 21-20
------------------------------
Date: Mon, 20 Jul 1998 21:46:18 GMT
From: John Porter <jdporter@min.net>
Subject: Re: newbie
Message-Id: <35B3BC2A.4AE5@min.net>
Jerry Chapman wrote:
>
> However, I am trying to learn perl - especially from the server side.
Um, there is no "server side" to perl. You're learning two different
things at once. Here in this group, we'll help you learn how to
program in perl. Server stuff is dealt with elsewhere.
> What I need is a step by step process to get the server running.
> I have installed win32 - perl. I think it works, but when I try to link with html
> the .pl files basically prints out without executing. What am I doing wrong
God knows, but you might check out some of the helpful information
which is available on-line at
http://language.perl.com/CPAN/doc/FAQs/cgi/idiots-guide.html
--
John Porter
------------------------------
Date: Mon, 20 Jul 1998 13:21:27 -0700
From: Yary H <yary@apicom.com>
Subject: Re: Overriding builtin functions
Message-Id: <35B3A6C6.7EB9@apicom.com>
]Those that return a negative number in the C-language keyword()
]function in the toke.c file in your Perl source kit may be overridden.
]Keywords that cannot be overridden are chop, defined, delete, ...
A request to the perl-maintianers:
Have a descriptive warning when the program tries to override one of
those functions.
and, let me override anything if I rilly rilly wanna! (without
recompiling perl).
bye
-y
------------------------------
Date: 20 Jul 1998 14:08:40 -0700
From: hermit@cats.ucsc.edu (William R. Ward)
Subject: Re: Perl Beautifier Home Page
Message-Id: <waau34cxmav.fsf@ese.UCSC.EDU>
Russ Allbery <rra@stanford.edu> writes:
> Zenin <zenin@bawdycaste.org> writes:
> > $VERSION = do { my @r = (q$Revision: 2.0 $ =~ /\d+/g); sprintf '%d.%03d'.'%02d' x ($#r-1), @r};
>
> > Try putting that on multiple lines. Hint: check with MakeMaker.
>
> That's unnecessarily long for most people's version numbers. Try this
> instead. :)
>
> ($VERSION = (split (' ', q$Revision: 1.2 $ ))[1]) =~ s/\.(\d)$/.0$1/;
This is even shorter:
$VERSION = ((q$Revision: 2.19 $ =~ /([\d.]+)/)[0]);
--Bill.
--
William R Ward Bay View Consulting http://www.bayview.com/~hermit/
hermit@bayview.com 1803 Mission St. #339 voicemail +1 408/479-4072
hermit@cats.ucsc.edu Santa Cruz CA 95060 USA pager +1 408/458-8862
PGP Key 0x2BD331E5; Public key at http://www.bayview.com/~hermit/pubkey.txt
-----------------------------------------------------------------------------
"Language is a virus from outer space." --William S. Burroughs
------------------------------
Date: Mon, 20 Jul 1998 15:59:43 -0500
From: JLEHMANN <JLEHMANN@dsccc.com>
Subject: Regular Exp. Question
Message-Id: <35B3AFBF.3B879EDD@dsccc.com>
I'm a beginner at this so this is probably obvious.
In a while loop scanning through a text file, I have this RE:
if (/\d{9,}\|$email\|.+/i) { ... }
the text file is in the format:
123456789|email@host.com|collegename|password
123456789|email@host.com|collegename|password
123456789|email@host.com|collegename|password
123456789|email@host.com|collegename|password
So my RE is trying to find if the email is in the file. Problem is, the
email string: "|||||" matches every single line in the file. How could
the RE be written better?
Thanks,
John
------------------------------
Date: 20 Jul 1998 21:41:23 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: Re: Regular Exp. Question
Message-Id: <6p0di3$dcv$4@flotsam.uits.indiana.edu>
In article <35B3AFBF.3B879EDD@dsccc.com>,
JLEHMANN <JLEHMANN@dsccc.com> writes:
> I'm a beginner at this so this is probably obvious.
> In a while loop scanning through a text file, I have this RE:
>
> if (/\d{9,}\|$email\|.+/i) { ... }
>
> the text file is in the format:
>
> 123456789|email@host.com|collegename|password
> 123456789|email@host.com|collegename|password
> 123456789|email@host.com|collegename|password
> 123456789|email@host.com|collegename|password
>
> So my RE is trying to find if the email is in the file. Problem is, the
> email string: "|||||" matches every single line in the file. How could
> the RE be written better?
>
> Thanks,
> John
Well, you could skip using a regular expression and use:
foreach (@array) {
my($id,$email,$collegename,$password)=split(/\|/);
if($email eq $email_I_am_testing_for) {
# do something
last; # stop checking.
}
}
or, you can use a regular expression to escape \ | + * { } ( ), etc
and then do the match.
Brian Wheeler
bdwheele@indiana.edu
------------------------------
Date: Mon, 20 Jul 1998 14:40:20 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Regular Exp. Question
Message-Id: <MPG.101d591ef55a94ea98972d@nntp.hpl.hp.com>
[This followup was posted to comp.lang.perl.misc and a copy was sent to
the cited author.]
In article <35B3AFBF.3B879EDD@dsccc.com> on Mon, 20 Jul 1998 15:59:43 -
0500, JLEHMANN <JLEHMANN@dsccc.com> says...
> I'm a beginner at this so this is probably obvious.
> In a while loop scanning through a text file, I have this RE:
>
> if (/\d{9,}\|$email\|.+/i) { ... }
>
> the text file is in the format:
>
> 123456789|email@host.com|collegename|password
> 123456789|email@host.com|collegename|password
> 123456789|email@host.com|collegename|password
> 123456789|email@host.com|collegename|password
>
> So my RE is trying to find if the email is in the file. Problem is, the
> email string: "|||||" matches every single line in the file. How could
> the RE be written better?
Almost always, when you substitute a string into a regex you want to
suppress the magic meaning of any characters in it. I think if you
surround the substitution by \Q and \E all will go well:
if (/\d{9,}\|\Q$email\E\|./i) { ... }
I've dropped the trailing '+' which doesn't do anything.
You are off to a very good start for a beginner (for example, escaping
the | you could see in your regex). Read further about \Q and\E in
perlre and quotemeta in perlfunc.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 20 Jul 1998 21:42:44 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Regular Exp. Question
Message-Id: <35B3BB56.BD7@min.net>
JLEHMANN wrote:
>
> if (/\d{9,}\|$email\|.+/i) { ... }
> the text file is in the format:
> 123456789|email@host.com|collegename|password
> So my RE is trying to find if the email is in the file. Problem is, the
> email string: "|||||" matches every single line in the file. How could
> the RE be written better?
You need to "quotemeta" any strings, such as the contents of $email;
that keeps any special chars in it from having their special meaning.
put \Q before it and \E after it:
if (/\d{9,}\|\Q$email\E\|.+/i) { ... }
--
John Porter
------------------------------
Date: 20 Jul 1998 22:10:25 GMT
From: neil@elara.frii.com (Neil Neely)
Subject: Re: Simple problem with perl script.
Message-Id: <6p0f8h$bvq$1@europa.frii.com>
Nico van Leeuwen (webmaster@acidhouse.com) wrote:
: # Sub routine check_user
: sub check_user {
: # Retrieve Data file contents
: open (DATAFILE, "$data_file") || die "Can't open $data_file: $!\n";
: @lines = <DATAFILE>;
: close (DATAFILE);
[snip]
It looks like your just basically trying to see if the user currently
exists, this can be accomplished very simply with the following:
if (check_user($username)) {
print "HTML stuff saying user already exists\n";
} else {
print "HTML stuff saying user does not exist\n";
}
sub &check_user {
my $username = shift;
if (defined getpwnam($username)) {
return 1;
} else {
return 0;
}
}
getpwnam used in scalar context returns the uid of the username specified
and returns nothing if the uid does not exist, the 'defined' check is in
there to avoid the logic error of 'root's uid being 0 (and thus 'false').
Regards,
Neil Neely
Systems Administrator
------------------------------
Date: Mon, 20 Jul 1998 22:14:28 +0100
From: Barney Tyrwhitt-Drake <Barney@tdrake.demon.co.uk>
Subject: split function on CR/LF
Message-Id: <rRtjEFA0M7s1Ew5e@tdrake.demon.co.uk>
I am trying to convert multiline text retrieved from an HTML Form's
textarea component into a single string where a comma and space replace
the CR/LF at the end of each line. My script runs:
...
# Remove CR/LFs in Address and replace them with comma+space
@lines = split(/\n/,$multilinetext);
$commatext = join(", ",@lines);
print FILE "\""."$commatext"."\",";
...
However, something is wrong in the /\n/ regular expression in the split
function as it only seems to remove one byte of the original hex 0D 0A
pair that is in $multilinetext.
What regular expression should I use in the split function to remove
both bytes of the CR/LF pair?
--
Barney Tyrwhitt-Drake
------------------------------
Date: 20 Jul 1998 21:35:05 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: Re: split function on CR/LF
Message-Id: <6p0d69$dcv$3@flotsam.uits.indiana.edu>
In article <rRtjEFA0M7s1Ew5e@tdrake.demon.co.uk>,
Barney Tyrwhitt-Drake <Barney@tdrake.demon.co.uk> writes:
> I am trying to convert multiline text retrieved from an HTML Form's
> textarea component into a single string where a comma and space replace
> the CR/LF at the end of each line. My script runs:
>
> ...
> # Remove CR/LFs in Address and replace them with comma+space
> @lines = split(/\n/,$multilinetext);
> $commatext = join(", ",@lines);
> print FILE "\""."$commatext"."\",";
> ...
>
> However, something is wrong in the /\n/ regular expression in the split
> function as it only seems to remove one byte of the original hex 0D 0A
> pair that is in $multilinetext.
>
> What regular expression should I use in the split function to remove
> both bytes of the CR/LF pair?
\n is only the linefeed, not the carriage return and linefeed.
Try this:
$multilinetext=~s/\r\n/, /g;
\r is the carriage return, \n the linefeed. which get replaced with a
comma and a space.
Brian Wheeler
bdwheele@indiana.edu
------------------------------
Date: 20 Jul 1998 22:10:31 GMT
From: kinkoi@leland.Stanford.EDU (Kin-Koi Lo)
Subject: Tcl is better than Perl
Message-Id: <6p0f8n$3ks$1@nntp.Stanford.EDU>
Hi,
I am going to write script programe so that the server can talk to my client programe. People told me it is better to use Tcl instead of Perl. I only know Perl and know nothing about Tcl. Would anyone tell me which is better?
Thanks,
Kinkoi
------------------------------
Date: Mon, 20 Jul 1998 15:16:57 -0700
From: Anandan Balaji <balaji@emicx.mentorg.com>
Subject: temp directory for both unix and windows platform
Message-Id: <35B3C1D9.7874@emicx.mentorg.com>
Hi,
I am writing some perl scripts, which can run on both unix and
windows platform. Does any one have solution for how to take
care /tmp directory in the scripts?
Thanks in advance,
-Balaji
------------------------------
Date: 20 Jul 1998 21:12:02 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Turning 13 lines of text into one
Message-Id: <6p0br2$ic1$1@client3.news.psi.net>
Larry (larryq@nospam.tuttle.com) wrote on MDCCLXXXIV September MCMXCIII
in <URL: news:6p01b1$179$1@nnrp2.crl.com>:
++
++ Hi everyone,
++
++
++ I'm just feeling my way around here, and have a little project
++ I'm trying to get a bead on. I've got a text file that contains about
++ 10,000 records in it, each record consisting of 13 lines of text, while each
++ line is exactly 80 characters long. I need to take each "record", and turn
++ the 13 lines of text into one really long line. What's the best way to do
++ so? Thanks for any and all suggestions!
my $block_size = 13 * 80;
open IN, "< infile" or die $!;
open OUT, "> outfile" or die $!;
while (!eof IN) {
my $block_size = $block_size;
local $_ = "";
while ($block_size) {
my $bytes = sysread IN, $_, $block_size;
die "Eeeps" unless defined $bytes;
$block_size -= $bytes;
}
s/\n(?=.)//sg;
print;
}
Abigail
--
perl -wle '$, = " "; sub AUTOLOAD {($AUTOLOAD =~ /::(.*)/) [0];}
print+Just (), another (), Perl (), Hacker ();'
------------------------------
Date: Mon, 20 Jul 1998 22:13:21 +0100
From: Richard Proctor <Richard@waveney.demon.co.uk>
Subject: Re: Wierd behaviour of .. operator
Message-Id: <ant202121bc8Rr9i@waveney.demon.co.uk>
In article <MPG.101d2a108a4bcc03989729@nntp.hpl.hp.com>, Larry Rosler
<URL:mailto:lr@hpl.hp.com> wrote:
> > foreach('A1'..'A13') ...
> >
> > And had expected the loop to operate with A1, A2, A3, A4, A5, A6, A7, A8, A9,
> > A10, A11, A12 and A13. BUT was rather surprised to find it generate A1..A9,
> > then B0..B9 ... Z9 then continue with AA0..AA9 ... ZZ0..ZZ9! Thus
> > generating 7019 values rather than the 13 I had expected (it never did
> > generate A10 .. A13). 'A1'..'A9' behaves as expected.
> >
> > Now when I realised what had happend, I trivially corrected the problem,
> > however could somebody explain why it did this? Is it a bug? Should
> > it generate a warning? (I did use -w before you ask)
>
> It is a 'magic' feature, not a bug, and is very explicitly documented in
> perlop under 'Autoincrement and Decrement': "If, however, the variable
> has only been used in string contexts since it was set, and has a value
> that is not null and matches the pattern /^[a-zA-Z]*[0-9]*$/, the
> increment is done as a string, preserving each character within its
> range, with carry: ..."
Yes I read that, but if I had asked for 'A1' .. 'ZZ9' the result would have
been what I had expected. The autoincrement here never does generate the
end case. If the end of the range is never going to be generated, should
this be warned against? (the result in my case was a very LARGE file, that
had SOME of what I wanted as the first 9 entries).
Should the magicness, have recognised that the end pattern had more digits
than the start pattern? It could then have incremented the numerical
component of the string, up to the numerical endpoint before incrementing the
alpha part of it.
Basicly I think what it did was not what exactly 'right', Perl should either
do it 'right' or at least have given a warning that the endpoint was never
reached.
>
> I presume your trivial fix was to change 'A1' to 'A01'.
>
No, that would not have given what I wanted, I eventually did:
for $Seas ('A'..'D') {
foreach(1..13) {
$Prog= $Seas . $_;
print "\nProgram: $Prog\n";
print join(', ',@$Prog);
...
}
}
The example I had given was the essence of the problem not the detail.
--
Richard@waveney.demon.co.uk
split//,'ecHle etn sJutaohrPr akr';print splice@_,$#_/2,1while(@_)
------------------------------
Date: 20 Jul 1998 22:06:32 GMT
From: Eric Sheng <shenge@ece.ucdavis.edu>
Subject: Wrong Line #
Message-Id: <6p0f18$lo8$1@mark.ucdavis.edu>
Hi all,
I am having a problem with the PERL compiler/interpreter. I have noticed that the warning/error messages during run
time is inaccurate. For example, "use of uninitialized value @ line ##" does not refer to the correct line that generated the
warning. In my PERL script, I have some pretty long lines for printing. I was wondering if these long lines are the cause of
the wrong line # on perl warning messages.
--Eric
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V8 Issue 3208
**************************************