[22245] in Perl-Users-Digest
Perl-Users Digest, Issue: 4466 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 25 18:08:35 2003
Date: Sat, 25 Jan 2003 15:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 25 Jan 2003 Volume: 10 Number: 4466
Today's topics:
Re: binmode() please help me <family2@aracnet.com>
Re: binmode() please help me <jurgenex@hotmail.com>
DBD::CSV help <will@com.yahoo>
Re: DBD::CSV help <jeff@vpservices.com>
fork confusion <phwashington@attbi.com>
Re: fork confusion <tassilo.parseval@post.rwth-aachen.de>
Re: How can a SMTP mail be deleted from a Unix mailbox <LuigiDunbar@hotmail.com>
How to format Interlinear text for Windows <russjohnson@frontiernet.net>
Re: How to format Interlinear text for Windows <jurgenex@hotmail.com>
Re: mod_rewrite: On-the-fly Content-Regeneration with A (Markus Elfring)
Perl say that 100.01 is greater than 100.01 !!!!!!!! (ilbeduino)
Re: Perl say that 100.01 is greater than 100.01 !!!!!!! (Anno Siegel)
Re: Perl say that 100.01 is greater than 100.01 !!!!!!! (h\)
Re: Perl say that 100.01 is greater than 100.01 !!!!!!! <jurgenex@hotmail.com>
Re: Perl say that 100.01 is greater than 100.01 !!!!!!! (Anno Siegel)
Perl script to access directory <alex@alexbanks.com>
Re: Perl script to access directory <jurgenex@hotmail.com>
Re: Perl script to access directory <alex@alexbanks.com>
Re: Perl script to access directory <dha@panix2.panix.com>
Re: Question about "our" (Rich Wales)
Re: Reverse Inheritance? (Ben Morrow)
Re: Split question (Anno Siegel)
Re: Splitting a configuration file into a hash <knewman00@earthlink.net>
Re: Splitting a configuration file into a hash <knewman00@earthlink.net>
Re: Splitting a configuration file into a hash <knewman00@earthlink.net>
To create a static html page with perl script from the (Chas Friedman)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 25 Jan 2003 09:52:28 -0600
From: Abernathey Family <family2@aracnet.com>
Subject: Re: binmode() please help me
Message-Id: <3E32B2BC.76E6E09D@aracnet.com>
"Jürgen Exner", recent graduate of the
perldoc_is_revelation_from_a_deity seminary wrote:
>
> [Please do not post Jeopardy style; posting repaired]
> Adam Trotter wrote:
> > "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> > news:MPqY9.480$3E6.246@nwrddc01.gnilink.net...
> >> Adam Trotter wrote:
> >>> I'm trying to modify a perl script for my college's net admin....
> >>> most of it works right, except for when it comes to the upload
> >>> functions on windows boxes. I'm trying to fix that, and I know the
> >>> answer lies somewhere in binmode(), and I've tried putting it
> >>> everywhere that seems logical and I can not get it to work right :(
> >>
> >> What exactly is unclear with the second paragraph of the binmode man
> >> page and needs improvement?
> >
--snip--
<gag> I can't believe the vitrol that provided in place of help. If you
don't want to answer somebody's question - don't.
-Don
------------------------------
Date: Sat, 25 Jan 2003 19:33:53 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: binmode() please help me
Message-Id: <BEBY9.10$qb1.9@nwrddc01.gnilink.net>
Abernathey Family wrote:
> "Jürgen Exner", recent graduate of the
>> Adam Trotter wrote:
>>> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
>>> news:MPqY9.480$3E6.246@nwrddc01.gnilink.net...
>>>> What exactly is unclear with the second paragraph of the binmode
>>>> man page and needs improvement?
>>>
> --snip--
> <gag> I can't believe the vitrol that provided in place of help. If
> you don't want to answer somebody's question - don't.
If you are so enlighted as to know what the OP didn't understand about the
second paragraph of "perldoc -f binmode" then please be so kind and share
this knowlegde with all of us so that we can improve that section.
jue
------------------------------
Date: Sat, 25 Jan 2003 19:58:58 GMT
From: w i l l <will@com.yahoo>
Subject: DBD::CSV help
Message-Id: <40r53v0gn46dn8sk0voj6t36o6mls99tus@4ax.com>
All I want to do is be able to work with a csv file (seperated by ',')
and use it like a database.
=========contents of csvdb=========================
id,name
111,one
222,two
333,three
============end=================================
and here is my script...... I got the example from the perldoc, but
this doesn't seem to be printing anything to the screen.
what am i doing wrong?
-Will
use strict;
use warnings;
use DBI;
my $dbh = DBI->connect(qq{DBI:CSV:csv_sep_char=,});
$dbh->{'csv_tables'}->{'info'} = { 'file' => 'csvdb'};
my($query) = "SELECT * FROM csvdb ";
my($sth) = $dbh->prepare($query);
$sth->execute();
while (my $row = $sth->fetchrow_hashref) {
print("Found result row: id = ", $row->{'id'},
", name = ", $row->{'name'});
}
$sth->finish();
------------------------------
Date: Sat, 25 Jan 2003 13:15:43 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: DBD::CSV help
Message-Id: <3E32FE7F.3000203@vpservices.com>
[posted to newsgroup and mailed to will]
w i l l wrote:
> my $dbh = DBI->connect(qq{DBI:CSV:csv_sep_char=,});
You don't need to specify comma as the csv_sep_char, it is the default.
> $dbh->{'csv_tables'}->{'info'} = { 'file' => 'csvdb'};
This specifies that the *table* called "info" is found in the *file*
called "csvdb".
> my($query) = "SELECT * FROM csvdb ";
This mistakenly uses the *file* name rather than the *table* name.
Change it to:
my($query) = "SELECT * FROM info ";
> print("Found result row: id = ", $row->{'id'},
The current version of SQL::Statement has a bug such that the hash keys
returned from this query need to be in upper case : $row->{ID}. This
will be fixed in version 1.006 of SQL::Statement which will be available
next week.
--
Jeff (maintainer of DBD::CSV and SQL::Statement)
------------------------------
Date: Sat, 25 Jan 2003 21:17:55 GMT
From: Philip Washington <phwashington@attbi.com>
Subject: fork confusion
Message-Id: <3E330004.5070900@attbi.com>
I have the following code where I am trying to run a program for a given
length of time. Kill it, run another program and restart the original.
The first progam will run indefinitely if allowed. I have not added the
second program because I thus far have not been able to cleanly kill the
first.
The programs which are run under exec(" ") or system(" ") appear to
create another child, but when I run
kill "INT",$kidpid
they do not seem to be affected.
Any better ideas on how to accomlish this will be gratefully accepted.
#!/usr/bin/perl
my $kidpid;
if (!defined($kidpid = fork())) {
#fork returned undef, so failed
die "Cannot fork: $!";
} elsif ($kidpid == 0) {
# fork returned 0, so this branch is child
exec("sh Runfilter.sh");
# if exec fails, fall through to the next statement
die "can't exec date: $!";
} else {
# fork returned 0 nor undef
# so this branch is parent
sleep(10);
my $result=kill "INT",$kidpid;
print "Killed child process $kidpid (result $result)\n";
}
------------------------------
Date: 25 Jan 2003 21:31:20 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: fork confusion
Message-Id: <b0uvn8$1dl$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Philip Washington:
> I have the following code where I am trying to run a program for a given
> length of time. Kill it, run another program and restart the original.
> The first progam will run indefinitely if allowed. I have not added the
> second program because I thus far have not been able to cleanly kill the
> first.
>
> The programs which are run under exec(" ") or system(" ") appear to
> create another child, but when I run
> kill "INT",$kidpid
> they do not seem to be affected.
>
> Any better ideas on how to accomlish this will be gratefully accepted.
>
>
> #!/usr/bin/perl
> my $kidpid;
>
> if (!defined($kidpid = fork())) {
> #fork returned undef, so failed
> die "Cannot fork: $!";
> } elsif ($kidpid == 0) {
> # fork returned 0, so this branch is child
> exec("sh Runfilter.sh");
> # if exec fails, fall through to the next statement
> die "can't exec date: $!";
> } else {
> # fork returned 0 nor undef
> # so this branch is parent
> sleep(10);
> my $result=kill "INT",$kidpid;
Out of curiosity, why are you sending sigint (keyboard interrupt)?
sigterm would seem more plausible to me.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sat, 25 Jan 2003 21:17:52 GMT
From: "Al Dunbar" <LuigiDunbar@hotmail.com>
Subject: Re: How can a SMTP mail be deleted from a Unix mailbox by a script?
Message-Id: <4aDY9.117834$sV3.4480815@news3.calgary.shaw.ca>
"Markus Elfring" <Markus.Elfring@web.de> wrote in message
news:40ed1d8f.0301250006.589d9810@posting.google.com...
> > Bill, over an RFC1149 gateway.
>
> Do you really suggest the "Standard for the Transmission of IP
> Datagrams on Avian Carriers" as a gateway service? ;-)
> - http://ietf.org/rfc/rfc1149.txt
> - Let us perform the POP3 protocol with birds
> http://www.blug.linux.no/rfc1149/
"Avian carriers", "birds", "penguins". What, are we going to convert the
whole internet from the usual IP to one based on homing pigeons? ;-)
/Al
------------------------------
Date: Sat, 25 Jan 2003 14:47:16 -0500
From: "Russell L Johnson" <russjohnson@frontiernet.net>
Subject: How to format Interlinear text for Windows
Message-Id: <v35q6ismr4se31@corp.supernews.com>
I have some information which I'd like to print out as interlinear text,
using MORE THAN 1 NON-PROPORTIONAL font.
Interlinear text is text in which lines of related information are printed
out so that the corresponding information is on adjacent lines. Below, I
show some interlinear text using 1 SINGLE PROPORTIONAL font. The text shown
is Chapter 1, Verse 1 from the Textus Receptus -- the Greek text behind the
King James Version New Testament.
Line 1 is a transliteration of the Greek word (a representation of it
using the Roman alphabet).
Line 2 is the Strong's number (an index to the corresponding word in
the book "A Concise Dictionary of the Words in the Greek New Testament ...",
by James Strong).
Line 3 is a grammatical code for the Greek word ("PREP" is the code for
"preposition").
Line 4 is the English gloss (1 or more words in English which literally
mean the same thing as the Greek word[
On a Microsoft Windows PC, how could I line up the corresponding words,
numbers, codes, and glosses using a non-proportional font (such as Arial or
Times New Roman), or ideally, using MORE THAN 1 NON-PROPORTIONAL font.
(Instead of using transliterations of the Greek words, I'd like to use a
font which represents the accented Greek characters.)
Thanks for any information you can provide.
- Russ Johnson
JohnsonRuss@NetZero.com
Terre Hill, PA USA
[FOR THE FOLLOWING TEXT TO DISPLAY PROPERLY, IT MUST BE DISPLAYED USING A
PROPORTIONAL FONT, SUCH AS COURIER. On a Microsoft Windows PC, pasting it
into Notepad is one quick, easy way to do this.]
< The Gospel according to St. John>
1:1 En arch hn o logov kai o logov hn
1722 746 2258 3588 3056 2532 3588 3056 2258
PREP N-DSF V-IXI-3S T-NSM N-NSM CONJ T-NSM N-NSM V-IXI-3S
In [the] beginning was the Word and the Word was
prov ton yeon kai yeov hn o logov.
4314 3588 2316 2532 2316 2258 3588 3056
PREP T-ASM N-ASM CONJ N-NSM V-IXI-3S T-NSM N-NSM
with the God and God was the Word.
------------------------------
Date: Sat, 25 Jan 2003 20:04:07 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to format Interlinear text for Windows
Message-Id: <X4CY9.210$Gj3.207@nwrddc02.gnilink.net>
Russell L Johnson wrote:
[...]
> On a Microsoft Windows PC, how could I line up the corresponding
> words, numbers, codes, and glosses using a non-proportional font
> (such as Arial or Times New Roman), or ideally, using MORE THAN 1
> NON-PROPORTIONAL font. (Instead of using transliterations of the
> Greek words, I'd like to use a font which represents the accented
> Greek characters.)
Maybe you can look at it from a different perspective. What you really got
here is a table with 4 rows and many columns (as many as you have words).
If you approach your problem that way then you can either create a real
table (what kind of output medium are you using? HTML? RTF? PDF? PS?) and
leave the actual aligning and padding to the proper engine. Or you can use
the proper width function for each cell of your table for your output medium
(if available) and do the necessary calculations and padding yourself.
jue
------------------------------
Date: 25 Jan 2003 10:39:40 -0800
From: Markus.Elfring@web.de (Markus Elfring)
Subject: Re: mod_rewrite: On-the-fly Content-Regeneration with Apache
Message-Id: <40ed1d8f.0301251039.6581c72a@posting.google.com>
3. I am interested in the following setting.
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^.+ regenerate.php
[T=application/php,L]
The documentation for Apache seems to omit which properties the
specified file must have.
3.1 The original example specifies the file "page.cgi".
I guess that it does not be marked as executable. (Otherwise, the file
should have got the extension "bat", "com" oder "exe" under Windows.)
3.2 In which directory must the file that will be called here be
stored?
3.3 Will the usual settings for MIME types and file extensions be
applied to this file so that it will be executed by a PHP interpreter?
Which software component will be responsible for the execution of the
script file?
------------------------------
Date: 25 Jan 2003 09:21:31 -0800
From: giulio@forteyang.com (ilbeduino)
Subject: Perl say that 100.01 is greater than 100.01 !!!!!!!!
Message-Id: <203a632d.0301250921.38e5a5eb@posting.google.com>
#!/usr/bin/perl
#
# I'VE TRIED THIS SCRIPT ON 2 COMPUTERS:
#
# v5.6.1 built for MSWin32-x86-multi-thread
# v5.6.1 built for i386-linux
#
# AND THE RESULT IS ALWAYS THE SAME:
#
# !!! 100.01 > 100.01 !!!
#
# ANYONE HAVE SUGGESTION???
#
$A = 100.01;
$b1 = 354.25;
$b2 = 254.24;
$B = $b1 - $b2; # $B now should be 100.01
if ($A == $B){ print "$A = $B";
} elsif($A < $B) { print "$A < $B";
} elsif($A > $B) { print "$A > $B";
} else { print "Aloa!";}
------------------------------
Date: 25 Jan 2003 17:38:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl say that 100.01 is greater than 100.01 !!!!!!!!
Message-Id: <b0ui2e$pi7$1@mamenchi.zrz.TU-Berlin.DE>
ilbeduino <giulio@forteyang.com> wrote in comp.lang.perl.misc:
> #!/usr/bin/perl
> #
> # I'VE TRIED THIS SCRIPT ON 2 COMPUTERS:
> #
> # v5.6.1 built for MSWin32-x86-multi-thread
> # v5.6.1 built for i386-linux
> #
> # AND THE RESULT IS ALWAYS THE SAME:
> #
> # !!! 100.01 > 100.01 !!!
> #
> # ANYONE HAVE SUGGESTION???
> #
Yes. Calm down.
The result you see is to be expected. Floating point arithmetic is only
approximate and the results can be surprising. See "perldoc -q number"
for a longer explanation. If you want to see what values the computer
(not only Perl) works with, try this:
perl -e 'printf "%.16f\n", 100.01'
perl -e 'printf "%.16f\n", 354.25 - 254.24'
You will note that one number is indeed greater than the other.
Anno
------------------------------
Date: Sat, 25 Jan 2003 19:07:33 +0100
From: "Michael Peuser \(h\)" <post@mpeuser.de>
Subject: Re: Perl say that 100.01 is greater than 100.01 !!!!!!!!
Message-Id: <b0ujn9$cu4$00$1@news.t-online.com>
"ilbeduino" <giulio@forteyang.com> schrieb im Newsbeitrag
news:203a632d.0301250921.38e5a5eb@posting.google.com...
> #!/usr/bin/perl
> #
> # I'VE TRIED THIS SCRIPT ON 2 COMPUTERS:
> #
> # v5.6.1 built for MSWin32-x86-multi-thread
> # v5.6.1 built for i386-linux
> #
> # AND THE RESULT IS ALWAYS THE SAME:
> #
> # !!! 100.01 > 100.01 !!!
> #
> # ANYONE HAVE SUGGESTION???
> #
>
> $A = 100.01;
>
> $b1 = 354.25;
> $b2 = 254.24;
> $B = $b1 - $b2; # $B now should be 100.01
>
> if ($A == $B){ print "$A = $B";
> } elsif($A < $B) { print "$A < $B";
> } elsif($A > $B) { print "$A > $B";
> } else { print "Aloa!";}
Anno explained the situation some minutes ago - there is a clumpsy
work-around described in perlop (Floting-point Arithmetic). You probably
have noteted that in your example $A-$B is something of the order 10^-14.
This fact can also be utilized.
instead of $A == $B abs ($A-$B) < $eps
$A < $B ($B-$A) > $eps
$A > $B ($A-$B) > $eps
It is not very good of Perl to round real numbers for print; but this
behaviour is found on most calculators as well....
Kindly
Mike
------------------------------
Date: Sat, 25 Jan 2003 18:14:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl say that 100.01 is greater than 100.01 !!!!!!!!
Message-Id: <luAY9.1969$Ec.205@nwrddc02.gnilink.net>
ilbeduino wrote:
> #!/usr/bin/perl
> # AND THE RESULT IS ALWAYS THE SAME:
> #
> # !!! 100.01 > 100.01 !!!
> #
> # ANYONE HAVE SUGGESTION???
Please see my answer in the other NG.
AND STOP MULTIPOSTING!
jue
------------------------------
Date: 25 Jan 2003 18:19:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl say that 100.01 is greater than 100.01 !!!!!!!!
Message-Id: <b0ukgb$pi7$2@mamenchi.zrz.TU-Berlin.DE>
Michael Peuser \(h\) <post@mpeuser.de> wrote in comp.lang.perl.misc:
> "ilbeduino" <giulio@forteyang.com> schrieb im Newsbeitrag
> news:203a632d.0301250921.38e5a5eb@posting.google.com...
[...]
> > # !!! 100.01 > 100.01 !!!
[...]
>
> Anno explained the situation some minutes ago - there is a clumpsy
> work-around described in perlop (Floting-point Arithmetic). You probably
> have noteted that in your example $A-$B is something of the order 10^-14.
> This fact can also be utilized.
>
> instead of $A == $B abs ($A-$B) < $eps
> $A < $B ($B-$A) > $eps
> $A > $B ($A-$B) > $eps
A far better workaround is to avoid floating point arithmetic if at all
possible. Most prominently, this can be done with currency calculations
by transforming to the lowest unit (cents) on input and calculating the
conventional amount (in $) only on output.
If floating point arithmetic can't be avoided, some epsilon fuzz like
above is mandatory.
Anno
------------------------------
Date: Sat, 25 Jan 2003 17:59:30 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Perl script to access directory
Message-Id: <3e32d088$0$240$cc9e4d1f@news.dial.pipex.com>
I host my website through a shared hosting package which allows me to
password protect my directories. This is done through a CPANEL 5 console, to
change the config of Apache webserver. I simply create a username, password
and a resource name for my directory and then anytime anybody accesses that
directory through a browser they have to enter a password. The password is
remembered for the length of time that their browser remains open (session).
First questions:
Is this SSL?
How secure is this?
My plan is to use this method as a 'functional id' - an id and password that
a server-side Perl script can use to unlock the directory after it aurhoises
users based on password/username held in my database. The problem is I have
no idea how to write the code to access the directory in Perl - please can
someone show me some sample code for doing this?
Thanks lots,
Alex
------------------------------
Date: Sat, 25 Jan 2003 18:16:04 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl script to access directory
Message-Id: <EvAY9.2879$3E6.2779@nwrddc01.gnilink.net>
Alex Banks wrote:
> I host my website through a shared hosting package which allows me to
[...]
There must be an outbreak of a new multiposting epidemy. Could you please
stop that?
jue
------------------------------
Date: Sat, 25 Jan 2003 18:34:44 -0000
From: "Alex Banks" <alex@alexbanks.com>
Subject: Re: Perl script to access directory
Message-Id: <3e32d8ca$0$233$cc9e4d1f@news.dial.pipex.com>
i know. sorry. in fact i'm so desperate to get an answer that i may even
post it in the alt.chips.salt-n-vinegar newsgroup...
anybody help?
"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:EvAY9.2879$3E6.2779@nwrddc01.gnilink.net...
> Alex Banks wrote:
> > I host my website through a shared hosting package which allows me to
> [...]
>
> There must be an outbreak of a new multiposting epidemy. Could you please
> stop that?
>
> jue
>
>
------------------------------
Date: Sat, 25 Jan 2003 21:28:01 +0000 (UTC)
From: "David H. Adler" <dha@panix2.panix.com>
Subject: Re: Perl script to access directory
Message-Id: <slrnb360b1.lg6.dha@panix2.panix.com>
In article <3e32d8ca$0$233$cc9e4d1f@news.dial.pipex.com>, Alex Banks wrote:
> i know. sorry. in fact i'm so desperate to get an answer that i may even
> post it in the alt.chips.salt-n-vinegar newsgroup...
Ah, but that's just *off-topic* posting.
I'm pretty sure Jürgen meant that you posted multiple times to multiple
groups, rather than cross-posting a single message.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Its a whole new kind of boredom.
- Ash (The ICT Tech with a soul)
------------------------------
Date: Sat, 25 Jan 2003 17:11:04 +0000 (UTC)
From: richw@richw.org (Rich Wales)
Subject: Re: Question about "our"
Message-Id: <20030125165315.D06283.richw@jessejames.Stanford.EDU>
"YiWei" wrote:
> I'm learning Perl now and I'm having problems with the
> keyword "our". . . . I can't see any practical use of it.
"our" is useful if you want a module to "use strict" and still be
able to have a non-private global variable.
If "use strict" is in effect, every global variable in a module
should be declared with either "my" (if you want it to be private)
or "our" (if you want code outside the module to access it).
Before "our" existed, you would have had to list non-private global
variables in a "use vars" statement, or else "use strict" would
generate a "global symbol requires explicit package name" error.
Rich Wales richw@richw.org http://www.richw.org
------------------------------
Date: Sat, 25 Jan 2003 16:02:26 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Reverse Inheritance?
Message-Id: <b0ucei$k5l$1@wisteria.csv.warwick.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>Well, after this discussion it appears that string-evaled require is
>indeed the most expedient way to load a module chosen at run time.
>
>I still don't like it.
No, nor do I. Is it worth suggesting to p5p that
require "Foo::Bar";
be made to do the right thing? If you actually need to load a file called
'Foo::Bar' you can use
require "./Foo::Bar";
. Along, of course, with the corollary, which is that %INC should have an entry
for Foo::Bar as well as for Foo/Bar.pm.
Anyone know how practical/well received that suggestion might be?
Ben
------------------------------
Date: 25 Jan 2003 14:27:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Split question
Message-Id: <b0u6sh$j8q$2@mamenchi.zrz.TU-Berlin.DE>
Thomas Brooks <tombrooks.nospam@hotmail.com> wrote in comp.lang.perl.misc:
> I am doing some splitting in perl
> --------------------------------------
> $data = "domain-user";
>
> @fields = split /-/, $data;
>
> print "domain is $fields[0]\n";
> print "username is $fields[1]\n";
> --------------------------------------
>
> As you see it is simply splitting the input where the left is the domain and
> the right is the username. My only problem is if a user wants a dash in his
> or her username.
If "domain" means what it appears to mean, this is not your only problem.
A domain name can contain "-" too. If it does, you're stuck; the line
just isn't uniquely parseable. Choose a different delimiter.
> So if $data = "domain-ima-user";
It's worse when
$data = 'my-domain-ima-user';
Anno
------------------------------
Date: Sat, 25 Jan 2003 18:55:00 GMT
From: Kevin Newman <knewman00@earthlink.net>
Subject: Re: Splitting a configuration file into a hash
Message-Id: <84BY9.2629$U27.266632@newsread2.prod.itd.earthlink.net>
Uri Guttman wrote:
>>>>>>"KN" == Kevin Newman <knewman00@earthlink.net> writes:
[snip]
>
>
> KN> key1a=value1a | key1b=value1b | key1c=value1c
> KN> key2a=value2a | key2b=value2b | key2c=value2c
>
> please give a very clear definition of those keys and values. are the
> keys single word tokens (\w+)? are the values also single strings
> without spaces? (\S+)? are there spaces around all the | chars? if those
> constraints are solid then you can do some neat tricks. you can slurp
> the whole file in (choose a method for that) and then:
>
> my %config = $file_text =~ /(\w+)=(\S+)/g ;
>
> done.
This works great.
>
> if some of those constraints aren't solid, then you have to do more work.
>
[snip]
>
> KN> my @config = (split /\|/, $record[$i]) ;
>
> don't use array indexing unless you really need to. a while/for loop
> would be simpler and faster. depending on the loop construct you can
> also do neat tricks.
Okay.
> also there is no need for the () around the whole split expression. the
> @config provides list context all by itself.
>
>
> KN> foreach my $thing (@config) {
>
> you don't need the temp var @config either. just use the split
> expression:
>
> foreach my $thing (split /\|/, $record[$i]) {
>
>
> KN> my ($key, $value) = split (/\s*=\s*/,$thing,2) ;
>
> that split expression tells me more about the config format. but you
> don't need the 2 there as you only have 2 elements on the left and split
> shouldn't find more than 2 parts if your format is correct.
Noted.
>
> KN> $config{$key} = $value;
> KN> }
>
> let's now assume a line by line read loop and the lesser contraints as
> shown above. (you still need to nail down the config format specs.)
>
> while( my $conf_line = <CONF> ) {
>
> foreach my $key_val (split /\|/, $conf_line ) {
>
> my ($key, $value) = split( /\s*=\s*/, $key_val ) ;
> $config{$key} = $value;
> }
> }
>
> but if the key=val has some constraints like no spaces (you seem to
> allow spaces around the =) then you can simplify it as above:
>
>
> while( my $conf_line = <CONF> ) {
>
> while( $conf_line =~ /(\S+)\s*=\s*(\S+)/ ) {
> $config{$1} = $2 ;
> }
> }
>
> so as you can see you must specify your config (or other) formats very
> carefully. the tighter the specs, the easier it is to parse out the
> key/value pairs. just showing examples is not the same as a proper
> specification.
Thanks Uri.
kln
------------------------------
Date: Sat, 25 Jan 2003 19:03:20 GMT
From: Kevin Newman <knewman00@earthlink.net>
Subject: Re: Splitting a configuration file into a hash
Message-Id: <YbBY9.2643$U27.266901@newsread2.prod.itd.earthlink.net>
Tad McClellan wrote:
> Kevin Newman <knewman00@earthlink.net> wrote:
>
>>I'm attempting to optimize/shorten a split statement that acts on a
>
>
> [snip data, repeated below]
>
>
>>Here is the current statement that works okay, but I'm sure that there
>>is a simpler why to do this:
>>
>> my @config = (split /\|/, $record[$i]) ;
>
>
>
> Do you really want space characters at the start of some of the keys
> and at the end of some of the values?
>
>
>
>> foreach my $thing (@config) {
>> my ($key, $value) = split (/\s*=\s*/,$thing,2) ;
>
> ^^^ ^^^
> ^^^ ^^^
>
> My guess is you've gotten those flipped around with the split pattern.
>
> Is this your real code?
>
>
>
>> $config{$key} = $value;
>> }
>>
>>
>>Any suggestions on how to improve this code?
>
>
>
> This in not "optimized" nor "simpler" nor "improved" but
> it _is_ shorter. :-)
>
> -------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> my %config;
> while ( <DATA> ) {
> chomp;
> my %h = /(.*?)=(.*?)(?:\||$)/g; # m//g in list context
> @config{keys %h} = values %h; # hash slice
> }
>
> print "$_ ==> $config{$_}\n" for sort keys %config;;
>
> __DATA__
> key1a=value1a | key1b=value1b | key1c=value1c
> key2a=value2a | key2b=value2b | key2c=value2c
> -------------------------
>
>
> But we're not playing golf here...
>
> I like your way much better. You for sure could eliminate the
> temporary @config array. You might want to use m// in list
> context instead of split. Different guts for the while above:
>
> -------------------------
> chomp;
> foreach my $thing ( split /\|/ ) {
> my ($key, $value) = $thing =~ /(.*?)=(.*)/;
> $config{$key} = $value;
> }
> -------------------------
>
>
Thanks Tad. I'll add this to my personal "How can I split ..." FAQ file.
kln
------------------------------
Date: Sat, 25 Jan 2003 19:05:36 GMT
From: Kevin Newman <knewman00@earthlink.net>
Subject: Re: Splitting a configuration file into a hash
Message-Id: <4eBY9.2649$U27.266901@newsread2.prod.itd.earthlink.net>
Harald H.-J. Bongartz wrote:
> Uri Guttman wrote:
>
>>>>>>>"KN" == Kevin Newman <knewman00@earthlink.net> writes:
>>
>> KN> my ($key, $value) = split (/\s*=\s*/,$thing,2) ;
>>
>>that split expression tells me more about the config format. but you
>>don't need the 2 there as you only have 2 elements on the left and
>>split shouldn't find more than 2 parts if your format is correct.
>
>
> When I saw this line, I thought that Kevin introduced the '2' to allow
> values that contain a '=' themselves, like
>
> key = value=1
>
> But of course, we don't have a spec ...
>
>
>>while( $conf_line =~ /(\S+)\s*=\s*(\S+)/ ) {
>
> ^ /g
> Won't work without the /g, IMHO.
>
> Ciao,
> Harald
Adding it now.
Thanks,
kln
------------------------------
Date: Sat, 25 Jan 2003 17:16:38 +0000 (UTC)
From: friedman@math.utexas.edu (Chas Friedman)
Subject: To create a static html page with perl script from the command line...
Message-Id: <b0ugpm$h6t$1@geraldo.cc.utexas.edu>
__________
You wrote:
...............
>What I want is the following:
>
>When I execute "test.pl" from my command line prompt, it should give
>me the same output in an html page. I mean, when I run the "test.pl"
>command form the CMD, the html page should pop up with the same output
>that I am getting now with the URL address.
>
>How can I go about to achieve this little task?
>
>Thanks in advance,
>Jimmy
You could write a new script "test2.pl" which you call from the command
prompt. This script would write the html to a local file and then call
the IE browser on that local file (e.g. using "system"). (I think that's
what you seem to want.)
[By the way, in your code:
foreach (@array)
{
($key, $files);
($key,$files) = split (/\t/);
......
what is the purpose of the first line in the block?]
chas
------------------------------
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 4466
***************************************