[19954] in Perl-Users-Digest
Perl-Users Digest, Issue: 2149 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 17 14:10:31 2001
Date: Sat, 17 Nov 2001 11:10:13 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006024213-v10-i2149@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 17 Nov 2001 Volume: 10 Number: 2149
Today's topics:
Re: Median of Three <nobody@nowhere.com>
Re: Median of Three <nobody@nowhere.com>
Re: Median of Three (Peter J. Acklam)
Re: Median of Three <tsee@gmx.net>
Re: Median of Three <godzilla@stomp.stomp.tokyo>
Re: Median of Three <godzilla@stomp.stomp.tokyo>
Re: Median of Three (James Wetterau)
Re: Median of Three (James Wetterau)
Re: Median of Three <tony_curtis32@yahoo.com>
Re: Median of Three <godzilla@stomp.stomp.tokyo>
Need Help On An Assignment <danieldicenso@mediaone.net>
Re: Need Help On An Assignment <Tassilo.Parseval@post.rwth-aachen.de>
Re: Need Help On An Assignment (Clinton A. Pierce)
Newbie: Please Kindly Help With Reading File <AlexBB2001USA@yahoo.com>
Re: Newbie: Please Kindly Help With Reading File <Laocoon@eudoramail.com>
Re: Newbie: Please Kindly Help With Reading File (Garry Williams)
no more than 128 symbles <dolgopa@co.ru>
Please Kindly Help With DBI <AlexBB2001USA@yahoo.com>
Re: Please Kindly Help With DBI (Garry Williams)
Re: Regex help (Garry Williams)
Re: Sorting observation (Clinton A. Pierce)
Re: Which ISPs support perl scripts? <parmeet@emirates.net.ae>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 17 Nov 2001 18:21:36 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Median of Three
Message-Id: <w3pJ7.334985$8x1.95060@newsfeeds.bigpond.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3BF6115D.97063DE1@stomp.stomp.tokyo...
> Mark Jason Dominus wrote:
>
> (snipped)
>
> > Suppose you want to find the median of three values instead of the
> > minimum. Is there an analogous short version?
>
> For a number set containing three entries, the median is always
> the second number in the set. No math is needed to find it.
Your response is total gibberish.
gtoomey
------------------------------
Date: Sat, 17 Nov 2001 18:24:10 +1000
From: "Gregory Toomey" <nobody@nowhere.com>
Subject: Re: Median of Three
Message-Id: <W5pJ7.334987$8x1.95146@newsfeeds.bigpond.com>
"Mark Jason Domains" <mjd@plover.com> wrote in message
news:3bf5e50b.3d71$11@news.op.net...
>
>
> Suppose you want to find the median of three values instead of the
> minimum. Is there an analogous short version?
>
The way to determine the complexity of median algorithms is the number of
comparisons. The naive method is to sort and find the value in the middle of
the sorted data. This is O(n log n).
There are linear i.e. O(n) algorithms. See Dor & Zwick, Selecting the
Median, Siam Jour. Comp 28(5),pp 2722-1758, 1999.
There is an approximate algorithm at www.cs.wpi.edu/~hofri/medsel.pdf
gtoomey
------------------------------
Date: 17 Nov 2001 09:00:12 +0100
From: pjacklam@online.no (Peter J. Acklam)
Subject: Re: Median of Three
Message-Id: <8zd5ddyr.fsf@online.no>
"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> For a number set containing three entries, the median is always
> the second number in the set. No math is needed to find it.
No. That is only true if the set is ordered.
Peter
--
#!/local/bin/perl5 -wp -*- mode: cperl; coding: iso-8859-1; -*-
# matlab comment stripper (strips comments from Matlab m-files)
s/^((?:(?:[])}\w.]'+|[^'%])+|'[^'\n]*(?:''[^'\n]*)*')*).*/$1/x;
------------------------------
Date: Sat, 17 Nov 2001 11:36:50 +0100
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Median of Three
Message-Id: <9t5eil$6up$07$1@news.t-online.com>
"Godzilla!" <godzilla@stomp.stomp.tokyo> schrieb im Newsbeitrag
news:3BF6115D.97063DE1@stomp.stomp.tokyo...
| Additionally it is inappropriate to cross-post to a
| moderated newsgroup. This is unfair to a moderator;
| she or he is instantly mail bombed.
|
| I do not condone mail bombing a newsgroup moderator.
http://www.plover.com/clpm/moderators
Have you realized MJD is a moderator?
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm
------------------------------
Date: Sat, 17 Nov 2001 08:04:48 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Median of Three
Message-Id: <3BF68AA0.692170A5@stomp.stomp.tokyo>
Steffen Müller wrote:
> Godzilla! wrote:
(snipped)
> | I do not condone mail bombing a newsgroup moderator.
> http://www.plover.com/clpm/moderators
> Have you realized MJD is a moderator?
Your rationale is related to something intelligent
in what way?
You are certainly free to mail bomb Mr. Plover
based on your logic, whatever the heck it is.
It is my choice to not mail bomb others.
* wonders if this bozo's brain is on vacation *
Godzilla!
------------------------------
Date: Sat, 17 Nov 2001 08:11:26 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Median of Three
Message-Id: <3BF68C2E.5D86A77F@stomp.stomp.tokyo>
Peter J. Acklam wrote:
> Godzilla! wrote:
(snipped)
> > For a number set containing three entries, the median is always
> > the second number in the set. No math is needed to find it.
> > @Array = (3, 5, 7);
> No. That is only true if the set is ordered.
Your enrollment in and successful completion of an
elementary Algebra class could benefit you greatly.
Godzilla!
------------------------------
Date: 17 Nov 2001 11:27:11 -0500
From: jwjr@panix.com (James Wetterau)
Subject: Re: Median of Three
Message-Id: <9t634v$rdk$1@panix2.panix.com>
In article <3bf5e50b.3d71$11@news.op.net>,
Mark Jason Dominus <mjd@plover.com> wrote:
> ...They point out that you can make the code much shorter and simpler
>like this:
>
> $min = $x;
> if ($min > $y) { $min = $y }
> if ($min > $z) { $min = $z }
>
>This also generalizes better to more than three items.
>
>Suppose you want to find the median of three values instead of the
>minimum. Is there an analogous short version?
In the case of three values the median is guaranteed to be closest to
the mean, so we can take the mean of the absolute value of the diffs
from the mean and then use that. Something like.
sub median
{
my $mean;
map { $mean += $_ / 3 } @_;
my @difs = map { abs($_ - $mean) } @_;
my $difmin = $difs[0]; my $med = $_[0];
if ($difmin > $difs[1]) { $difmin = $difs[1]; $med = $_[1]; }
if ($difmin > $difs[2]) { $difmin = $difs[2]; $med = $_[2]; }
$med;
}
This doesn't work for more values, alas.
--
James Wetterau, Jr. jwjr@panix.com (h) james@surgam.net (w)
"Well, enough of these vague generalities. On to the vague specifics."
- Larry Wall, in "Apocalypse 3".
------------------------------
Date: 17 Nov 2001 11:28:26 -0500
From: jwjr@panix.com (James Wetterau)
Subject: Re: Median of Three
Message-Id: <9t637a$rhc$1@panix2.panix.com>
In article <8945t9.vbs.ln@wombat.san-francisco.ca.us>,
Keith Keller <kkeller@speakeasy.net> wrote:
...
>This should work, but I don't think it's easily generalizable:
>
> $i = $x; $j = $y;
> if ($x > $y) {$i = $y; $j = $x;}
> if ($i > $z) { $med = $i }
> if ($j > $z) { $med = $z }
> $med = $j;
This code gives $med = 5 for $x = 3, $y = 5, $z = 4, so it's wrong.
--
James Wetterau, Jr. jwjr@panix.com (h) james@surgam.net (w)
"Well, enough of these vague generalities. On to the vague specifics."
- Larry Wall, in "Apocalypse 3".
------------------------------
Date: Sat, 17 Nov 2001 10:33:36 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Median of Three
Message-Id: <873d3d2w7z.fsf@limey.hpcc.uh.edu>
>> On 17 Nov 2001 11:27:11 -0500,
>> jwjr@panix.com (James Wetterau) said:
> In the case of three values the median is guaranteed to
> be closest to the mean, so we can take the mean of the
> absolute value of the diffs from the mean and then use
> that. Something like.
> ...
> This doesn't work for more values, alas.
Statistics::Descriptive has a "median" method. Seems
easiest unless you're explicitly looking for interesting
ways of finding the median.
--
Oh! I've said too much. Smithers, use the amnesia ray.
------------------------------
Date: Sat, 17 Nov 2001 10:07:08 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Median of Three
Message-Id: <3BF6A74C.D5E79C9C@stomp.stomp.tokyo>
Ben Pfaff wrote:
> Mark Jason Dominus wrote:
> > In an early article about programming style, Kernighan and Plaugher
> > look at an example where the programmer is trying to compute the
> > minimum of three values
(snipped)
> Second (really just a restatement of the first): There are six
> possible orderings for a triple of different real numbers:
> x < y < z x < z < y z < x < y
> y < x < z y < z < x z < y < x
Ten.
There is no rule entries in a number set must be different.
x = y = z
x = y
x = z
y = z
I will leave further permutations on these for enjoyment of the reader.
> This looks to me like further evidence that median is more
> complex than minimum, even among only three choices.
> *shrug* At this point I'm pretty convinced that there's no
> simple solution. Maybe someone cleverer than me can come up
> with one. I'd be surprised, but in a pleasant way.
I have removed your cross-posting for reasons cited
in another article of mine.
A most clever method is to simply to use this method
developed thousands of years back, as I exemplified.
Quite analogous to Plover's example, certainly. I suspect
though, few recognize the analogy because my method does
not "look" the same; different variable names, different
format. A final analysis, however, demonstrates it is a
comparative methodology, a comparision of a single number,
a desired median, to all others of a given number set of
three or more.
It could be argued by a clever person a number set
consisting of only two numbers does indeed have a
median value. However, this would cause statisticians
to grit their teeth and tug at their hair.
* considers parallel lines *
Still, in the case of infinity, where parallel lines
intersect, this could lead to a median actually being
an infinite number set. Ahh.. but is so metaphysical.
Nonetheless, I do have something clever to add after
reading all responses to Plover's articles, with almost
all responses mail bombing a newsgroup moderator.
For these posted formulas, for these posted calculations,
wouldn't it be rather clever of an intellectually annoying
person such as myself, to suggest using this number set:
[0 0 0]
Kinda causes the gears of series comparative operators to grind
and grind and grind ... ad infinitum.
* wonders which of those zeroes is the true median *
For another reader, this word "median" directly indicates
an ordered number set is being used. This is a logical
presumption, a mathematical caveat, amongst those of us
familiar with the language of mathematics, clever or not.
Godzilla!
------------------------------
Date: Sat, 17 Nov 2001 16:33:31 GMT
From: "Daniel DiCenso" <danieldicenso@mediaone.net>
Subject: Need Help On An Assignment
Message-Id: <vjwJ7.1623$eh7.852151@typhoon.ne.mediaone.net>
Let me introduce my self. I'm a student currently taking a night school
course in basic Perl scripting towards my Webmaster certification.
This is my homework assignment due this Monday.
-----------------------------------------------------------
Write a perl program that takes a first and last name as input and outputs
the name properly formatted. Also ask for age and output the number of days
old they are.
Here's what it should look like:
First Name: homer
Last Name: sIMPson
Age: 42
Your full name is: Homer Simpson
You are approximately 15330 days old.
----------------------------------------
Here's the code I created...
-----------------------------------------
#!/usr/local/bin/perl
#Enter first name field;
print "Enter your first name:";
$firstname = <STDIN>;
chomp ($firstname);
#Enter last name field;
print "Enter your last name:";
$lastname = <STDIN>;
chomp ($lastname);
#Array function for putting the first and last name together;
$fullname = lc("$firstname $lastname");
#Mathmateic function for computing the age;
$a = 365;
print "Enter your age:";
$c = <STDIN>;
$d = $a * $c;
#Print function results;
print "Your full name is $fullname.\n";
print "You are approximately $d days old.";
----------------------------------------------------
The code works fine, but what do I need to do or add to the code to create
the final result?
e-mail me at danieldicenso@mediaone.net if anybody's got an answer.
------------------------------
Date: Sat, 17 Nov 2001 17:57:37 +0100
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Need Help On An Assignment
Message-Id: <9t64u1$tun$02$1@news.t-online.com>
On Sat, 17 Nov 2001 16:33:31 GMT, Daniel DiCenso wrote:
> Let me introduce my self. I'm a student currently taking a night school
> course in basic Perl scripting towards my Webmaster certification.
>
> This is my homework assignment due this Monday.
[snipped]
> The code works fine, but what do I need to do or add to the code to create
> the final result?
You are not expecting us to do your homework, are you?
Anyway, since I did not exclusively want to flame, here is my personal
easter-egg search for you:
Look up the info on several string-related Perl-functions. This
especially includes ucfirst(). Hint: You can nest function calls in Perl:
print ucfirst lc for qw/stRANGelY foRmatED StRINg laCKING wHITesPaces/;
> e-mail me at danieldicenso@mediaone.net if anybody's got an answer.
Ask here, read here.
Tassilo
--
Magpie, n.:
A bird whose theivish disposition suggested to someone that it
might be taught to talk.
-- Ambrose Bierce, "The Devil's Dictionary"
------------------------------
Date: Sat, 17 Nov 2001 17:07:01 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Need Help On An Assignment
Message-Id: <VOwJ7.30398$RI2.14180535@news2>
[Posted and mailed]
In article <vjwJ7.1623$eh7.852151@typhoon.ne.mediaone.net>,
"Daniel DiCenso" <danieldicenso@mediaone.net> writes:
> Let me introduce my self. I'm a student currently taking a night school
> course in basic Perl scripting towards my Webmaster certification.
>
> This is my homework assignment due this Monday.
Then you might want to look at ucfirst() in the manual page. Quickly.
> Last Name: sIMPson
>
> Your full name is: Homer Simpson
> You are approximately 15330 days old.
What about names like McCain?
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Sat, 17 Nov 2001 06:29:56 -0500
From: "Alex Bright" <AlexBB2001USA@yahoo.com>
Subject: Newbie: Please Kindly Help With Reading File
Message-Id: <9t5gv1$u8e$1@slb0.atl.mindspring.net>
I execute my C program at the prompt with:
prog employee
prog = the C program executable (i.e. prog.exe)
employer = the database used with the program
The C program will create an output file named prog.txt. The output file is
formatted as:
enum esalary edob # each field is separated by space, each horizontal
line is a record
My goal is to capture/use the C program's output file for my perl program.
I wrote:
system( `prog employee`)
my $eFile = "prog.txt";
open EDATA, "<$eFile"
or die "Can't open $eFile: $!\n";
my ($enum, $esalary, $edob);
while (<EDATA>)
{
($enum, $esalary, $edob) = split(' ', $_);
}
I have compiler and other errors (too many to list here). Please kindly
check what's wrong with my script?
Thank you very much for your kindness in advance.
The C program is OK.
------------------------------
Date: Sat, 17 Nov 2001 12:38:26 +0100
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Newbie: Please Kindly Help With Reading File
Message-Id: <Xns915C809C9B889Laocooneudoramailcom@62.153.159.134>
"Alex Bright" <AlexBB2001USA@yahoo.com> wrote in
news:9t5gv1$u8e$1@slb0.atl.mindspring.net:
> I execute my C program at the prompt with:
> prog employee
>
> prog = the C program executable (i.e. prog.exe)
> employer = the database used with the program
>
> The C program will create an output file named prog.txt. The output
> file is formatted as:
> enum esalary edob # each field is separated by space, each
> horizontal line is a record
>
> My goal is to capture/use the C program's output file for my perl
> program.
>
> I wrote:
>
> system( `prog employee`)
Missing ;
> my $eFile = "prog.txt";
>
> open EDATA, "<$eFile"
> or die "Can't open $eFile: $!\n";
>
> my ($enum, $esalary, $edob);
>
> while (<EDATA>)
> {
> ($enum, $esalary, $edob) = split(' ', $_);
Do you just throw away the data or did you just omit the rest?
> }
Lao
------------------------------
Date: Sat, 17 Nov 2001 13:10:13 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Newbie: Please Kindly Help With Reading File
Message-Id: <slrn9vcodo.4je.garry@zfw.zvolve.net>
On Sat, 17 Nov 2001 06:29:56 -0500, Alex Bright <AlexBB2001USA@yahoo.com> wrote:
[ snip ]
> My goal is to capture/use the C program's output file for my perl program.
>
> I have compiler and other errors (too many to list here).
That's interesting because I got exactly one error compiling this
program:
$ perl -c try
syntax error at try line 3, near ")
my "
There will be run-time errors, if that error is fixed, but it was only
one error in compiling.
> Please kindly
> check what's wrong with my script?
> Thank you very much for your kindness in advance.
>
> I wrote:
#!/usr/bin/perl -w
use strict;
Get all the help you can when developing Perl programs.
> system( `prog employee`)
Wrong quotes. See the perlop manual page for the explanation of qx//
operator. See the perlfunc manual page for an explanation of the
system() function. The backtics do not return the string inside --
they return the output of the result of running the command line.
That said, you should probably check the result of running the
external program:
system "prog employee" and die "prog ended with status $?\n";
> my $eFile = "prog.txt";
>
> open EDATA, "<$eFile"
> or die "Can't open $eFile: $!\n";
>
> my ($enum, $esalary, $edob);
>
> while (<EDATA>)
> {
> ($enum, $esalary, $edob) = split(' ', $_);
> }
It appears that the scope of $enum, $esalary and $edob could be
limited to the while block. Maybe you want to declare them inside the
block. The default behavior of split() is just what you want here.
It will split the $_ variable on white space. See the split() section
of the perlfunc manual page.
while (<EDATA>) {
my ($enum, $esalary, $edob) = split;
}
--
Garry Williams
------------------------------
Date: Sat, 17 Nov 2001 21:26:58 +0300
From: "Godhead" <dolgopa@co.ru>
Subject: no more than 128 symbles
Message-Id: <9t6a1c$6er$1@octopus.co.ru>
Hi!
I'm a lumer....
Could anybody make me expression which can accept a string 128 symbles
lenght and deny more than 128 !!!
Thanks a lot!!!
------------------------------
Date: Sat, 17 Nov 2001 09:00:03 -0500
From: "Alex Bright" <AlexBB2001USA@yahoo.com>
Subject: Please Kindly Help With DBI
Message-Id: <9t5pob$598$1@slb1.atl.mindspring.net>
(I posted earlier under different subject but didn't specifically say that I
want to use the DBI module. I want to thank Gary Williams and Laocoon for
your kindness and time.)
For simplicity:
I execute my C program at the prompt with:
prog employee
prog = the C program executable (i.e. prog.exe)
employer = the database used with the program
The C program will create an output file named prog.txt,
which is formatted as:
enum elname efname
Each field is separated by space, and each horizontal line is a record
My goal is to capture/use the C program's output file for my perl
program and use the DBI module for queries.
#!/bin/perl -w
use strict;
use DBI;
system(`prog employee`) or die "Can't run prog"; # die here doesn't seem
matter
my $employerFile = "prog.txt";
### Open the data file for reading, and die upon failure
open EMPLOYEEDATA, "<$employeeFile"
or die "Can't open $employeeFile: $!\n";
### Declare our row field variables
my ( $enum, $elname, $efname);
### Scan through all the entries for the desired site
while ( <EMPLOYEEDATA> ) {
### Remove the newline that acts as a record-delimiter
chomp;
### Break up the record data into separate fields
( $enum, $elname, $efname) = split;
print "$enum $elname $efname\n"; #Yes reading alright
}
### Close the employee data file
close EMPLOYEEDATA;
exit;
However, the following statements of DBI create compiler errors among
others. How do use the DBI correctly in my
case? I read the DBI module doc but still have no clue.
SELECT elname, efname
FROM employeeFile
WHERE enum = 123
(Want to display the elname and efname for employee number 123)
Please kindly help. Thank you very much in advance.
------------------------------
Date: Sat, 17 Nov 2001 16:52:41 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Please Kindly Help With DBI
Message-Id: <slrn9vd5es.4mj.garry@zfw.zvolve.net>
[ Your E-mail address is invalid. I attempted to respond via E-mail
and it bounced. If it's not a typo, you should *not* cause yahoo's
mail server to have to indicate it. There is a domain name reserved
for that purpose that *no* server has to be bothered by. See RFC
2606. ]
On Sat, 17 Nov 2001 09:00:03 -0500, Alex Bright <AlexBB2001USA@yahoo.com> wrote:
> (I posted earlier under different subject but didn't specifically say that I
> want to use the DBI module. I want to thank Gary Williams and Laocoon for
> your kindness and time.)
>
> For simplicity:
>
> I execute my C program at the prompt with:
> prog employee
>
> prog = the C program executable (i.e. prog.exe)
> employer = the database used with the program
>
> The C program will create an output file named prog.txt,
> which is formatted as:
> enum elname efname
>
> Each field is separated by space, and each horizontal line is a record
>
> My goal is to capture/use the C program's output file for my perl
> program and use the DBI module for queries.
>
> #!/bin/perl -w
>
> use strict;
> use DBI;
>
> system(`prog employee`) or die "Can't run prog"; # die here doesn't seem
^ ^ ^^
^ ^ ^^
> matter
Your word-wrap creates a compile-time error.
You *still* have a run-time error (actually two!) because you still
are using the backtick operator inappropriately. Please read the
perlop manual page about the backtick operator (qx//).
The return from system() is not what you seem to think. The system()
function returns the exit status of the program that it executes.
Conventionally, successful completion is indicated by returning an
exit status od zero. Therefore, if you correct the quoting, the die()
will be executed whenever the prog program returns zero. This is
probably not what you want.
system "prog employee" and die "prog returned status $?\n";
or more C-style
if ( system("prog employee") != 0 ) {
die "prog returned status $?\n";
}
Please read the system() section of the perlfunc manual page.
> my $employerFile = "prog.txt";
>
> ### Open the data file for reading, and die upon failure
> open EMPLOYEEDATA, "<$employeeFile"
> or die "Can't open $employeeFile: $!\n";
>
> ### Declare our row field variables
> my ( $enum, $elname, $efname);
>
>
> ### Scan through all the entries for the desired site
> while ( <EMPLOYEEDATA> ) {
>
> ### Remove the newline that acts as a record-delimiter
> chomp;
>
> ### Break up the record data into separate fields
> ( $enum, $elname, $efname) = split;
>
> print "$enum $elname $efname\n"; #Yes reading alright
> }
>
> ### Close the employee data file
> close EMPLOYEEDATA;
> exit;
>
> However, the following statements of DBI create compiler errors among
> others. How do use the DBI correctly in my
> case? I read the DBI module doc but still have no clue.
>
> SELECT elname, efname
> FROM employeeFile
> WHERE enum = 123
These are *not* Perl statements. This text will not compile in a Perl
program.
The DBI module is probably one of the best-documented modules on CPAN.
There is a wealth of information for effective use of the module.
It's first section points out the dbi-users mailing list for getting
help. I would recommend that you subscribe to the list and lurk for a
month if you're going to develop applications with the DBI module.
The "Outline Usage" section of the DBI manual page clearly describes
how to use DBI. May I quote?
Outline Usage
To use DBI, first you need to load the DBI module:
use DBI;
use strict;
(The "use strict;" isn't required but is strongly
recommended.)
Then you need to the connect entry elsewhere in this
document to your data source and get a handle for that
connection:
$dbh = DBI->connect($dsn, $user, $password,
{ RaiseError => 1, AutoCommit => 0 });
I don't see anything like this in the code you posted above.
Further, to actually execute a query, this section goes on to explain
the steps.
Please re-read the DBI manual page.
> (Want to display the elname and efname for employee number 123)
I don't understand why you want to re-display the very information
that the external program prog seems to be printing for you. But if
you must,
[ untested ]
my $dbh = DBI->new($dsn, $user, $passwd,
{ RaiseError => 1, AutoCommit => 0 });
my $sth = $dbh->prepare(q{SELECT elname, efname
FROM employeeFile
WHERE enum = ?});
while (<EMPLOYEEDATA>) {
chomp;
($enum) = split;
$sth->execute($enum);
print join("\t", $enum, $sth->fetchrow_array()), "\n";
}
--
Garry Williams
------------------------------
Date: Sat, 17 Nov 2001 13:16:33 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: Regex help
Message-Id: <slrn9vcopl.4je.garry@zfw.zvolve.net>
On 16 Nov 2001 13:35:48 -0800, Jack Altradmon <gjchap99@my-deja.com> wrote:
> I want to send a file name to my script (on Win32) so I can split it
> into mode (read/write/append), drive, path and file name.
>
> My script has to be able to handle the following variations:
>
> "> test.log"
> "> test*"
> "> c:\temp\example\test.log"
> "> c:\temp\example\test*"
> "> \\server\c$\temp\example\test.log"
> "> \\server\c$\temp\example\test*"
> "> .\temp\example\test.log"
> "> .\temp\example\test*"
use File::Basename;
--
Garry Williams
------------------------------
Date: Sat, 17 Nov 2001 00:46:57 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Sorting observation
Message-Id: <9t5vjh$ehf$1@news.Stanford.EDU>
In article <3bf4d4c0.2009$1e2@news.op.net>,
mjd@plover.com (Mark Jason Dominus) writes:
> Then you no longer need Perl's special three-way '<=>' and 'cmp'
> operators, because you just use the regular '<' and 'lt' operators
> instead:
Praise be. I really, really hate explaining <=> and cmp to students.
So I usually wind up hand-waving until I have to explain how to write
a custom sort. Then I have to confront the weirdness head on.
A sort-sub that returns true/false would make this so much easier,
I think.
> The reason I bring this up is I've just discovered the following trick:
>
> print qsort sub { $a == $b }, 1,4,2,8,5,4,7,1,4,2,8,5,3,7;
>
> With the qsort implementation above, the output is 11444228855773.
> Items in appear in the same order in the input as in the output, (for
> example, the first 4 precedes the first 8 in the input, so the 4s
> precede the 8s in the output) but with equal items grouped. There is
> no analog of this with three-way comparators.
Oh my. I had an application for something like this a few weeks
ago. I had a series of different XML elements, all children of the
same parent element that I wanted to group together. However: I
couldn't change the relative order of the like items within its group.
(And a sort wasn't necessary.)
I wound up benching a decorate-sort-undecorate technique (a stable
sort) against just pushing the elements into a hash-of-lists and settled
on the latter. But that little trick would've been a clever solution.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Sat, 17 Nov 2001 21:45:49 +0400
From: "Parmeet" <parmeet@emirates.net.ae>
Subject: Re: Which ISPs support perl scripts?
Message-Id: <9t67f9$nm65@news.emirates.net.ae>
www.f2s.com
--
--------------------------------------------
Parmeet.S.Khurana
email::parmeet@emirates.net.ae
-http://www.cgi.sphosting.com
-http://cloud9.nethop.com
--------------------------------------------
-http://www.shekharrahate.com
-http://www.ultimate-fashions.com
"Chris Clarke" <mad-biker@couplands-well.freeserve.co.uk> wrote in message
news:9t4duk$f9k$1@news8.svr.pol.co.uk...
> As an absolute perl beginner... how do I find an ISP which supports perl
> scripts? I am currently with Freeserve, and the ISP would have to be
free.
> I tried a search with Ask Jeeves for ISPs, to no avail. I know you guys
are
> WAY ahead of me technical-wise, but I've done some programming, and would
> like to learn perl. Freeserve doesn't have the facility for CGI or perl
> scripts. Are there any (free) ISPs that you know of who do?
>
> TIA,
>
> Chris.
>
>
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.
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 V10 Issue 2149
***************************************