[15951] in Perl-Users-Digest
Perl-Users Digest, Issue: 3363 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 14 21:10:35 2000
Date: Wed, 14 Jun 2000 18:10:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <961031416-v9-i3363@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 14 Jun 2000 Volume: 9 Number: 3363
Today's topics:
Perl 5.6.0 & SCO <tekwiz@home.com>
Re: Perl 5.6.0 & SCO <rootbeer@redcat.com>
Re: Perl 5.6.0 & SCO (Jerome O'Neil)
Re: perl returning hash of my variables <rootbeer@redcat.com>
Re: regular expression help (matching exactly n times) <ppith@my-deja.com>
Re: sorting an array <jeff@vpservices.com>
split on comma seperated fields, with quoted fields all r37347@my-deja.com
Re: split on comma seperated fields, with quoted fields <jeff@vpservices.com>
Re: split on comma seperated fields, with quoted fields <lr@hpl.hp.com>
Re: split on comma seperated fields, with quoted fields <chrisda@optushome.com.au>
Re: split on comma seperated fields, with quoted fields <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Splitting a script into multiple files <rootbeer@redcat.com>
substitutions when vars contain regexp symbols <elf@ee.ryerson.ca>
Re: substitutions when vars contain regexp symbols <rootbeer@redcat.com>
Re: substitutions when vars contain regexp symbols <tina@streetmail.com>
Re: textfile reading template <Jonathan.L.Ericson@jpl.nasa.gov>
Re: Using a hash with popup_menu <rootbeer@redcat.com>
view HTTP Headers <none@none.ca>
Re: view HTTP Headers (brian d foy)
Re: works without strict but not with why ???? <danielxx@bart.nl>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 14 Jun 2000 22:39:29 GMT
From: "Robert Young" <tekwiz@home.com>
Subject: Perl 5.6.0 & SCO
Message-Id: <BQT15.1573$7I1.53811@news1.rdc2.on.home.com>
I compiled the 5.6.0 stable src with SCO OpenServer 5.0.5 and get to the
"make test" part, where several errors occur. If I run the "./perl harness"
functionality, I get a core dump. I haven't looked at the fns that didn't
work yet. Anyone have any comments?
------------------------------
Date: Wed, 14 Jun 2000 16:24:02 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Perl 5.6.0 & SCO
Message-Id: <Pine.GSO.4.10.10006141622550.5301-100000@user2.teleport.com>
On Wed, 14 Jun 2000, Robert Young wrote:
> I compiled the 5.6.0 stable src with SCO OpenServer 5.0.5 and get to
> the "make test" part, where several errors occur. If I run the "./perl
> harness" functionality, I get a core dump. I haven't looked at the fns
> that didn't work yet. Anyone have any comments?
It's not compiled correctly. :-)
You may wish to wait for 5.6.1 to see which bugs it fixes. But chances are
that your configuration wasn't correct and that you could fix part of this
on your own by trying again. Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 14 Jun 2000 23:06:56 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: Perl 5.6.0 & SCO
Message-Id: <keU15.1362$li3.32169@news.uswest.net>
"Robert Young" <tekwiz@home.com> elucidates:
> I compiled the 5.6.0 stable src with SCO OpenServer 5.0.5 and get to the
> "make test" part, where several errors occur. If I run the "./perl harness"
> functionality, I get a core dump. I haven't looked at the fns that didn't
> work yet. Anyone have any comments?
>
SCO Marketing Blurbs...
SCO! It's marginaly better than NT!
SCO! You'll never bitch about Solaris again.
SCO! Think of the stories you'll tell.
SCO! Hair on your chest.
You have my sympathies.
------------------------------
Date: Wed, 14 Jun 2000 15:54:09 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: perl returning hash of my variables
Message-Id: <Pine.GSO.4.10.10006141544370.5301-100000@user2.teleport.com>
On Wed, 14 Jun 2000 tlars@my-deja.com wrote:
> I'd like to write a perl module such that I can copy the values of all
> package level "my" variables (assume module has only one package) into
> a hash and return a ref to the hash.
You seem to be confused about lexical ("my") variables and packages -
Lexicals aren't in any package. But you can store any number of scalar
values into a hash, and then return a reference to the hash.
> package Test;
>
> my one = "hello";
> my two = "hi";
> my three = "howdy";
>
> sub returnAllVariables {
> ...code here...
> }
Of course, you've omitted the dollar sign in front of those scalars'
names. And the only thing you're showing in package Test is the sub,
Test::returnAllVariables. But that's all right....
sub return_all_variables {
{
one => $one,
two => $two,
three => $three,
}
}
> I really don't need to use "my" variables. I could use package scoped
> dynamic vars. However, I'd like to make the variables invisible
> outside the package or make the variables constants.
Of course, the hash contains a _copy_ of the variables. Modifying an
element of the hash won't modify the lexical. (You could store a reference
to the lexical, if that were desired, but I'm not sure that's what you
want.) Each call to the sub will return a new copy. If that's not desired,
you could use something like this:
my $hash;
BEGIN {
$hash = {
one => $one,
two => $two,
three => $three,
};
}
sub return_all_variables {
$hash;
}
> I know that my is any easy way to make the variables invisible. Not
> sure how to make the vars constant. "use constant" did not seem like
> it would work in this case.
No, that declares package-level constants. That may be what you want, but
I don't think so.
I'm not sure what you're trying to accomplish. Although you could use the
code I've given above, it seems complex. Perhaps you want to make a module
and export some global variables? Or you want to export some constants?
Constants from 'use constant' should be exportable.
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Thu, 15 Jun 2000 00:23:41 GMT
From: Howard Jow <ppith@my-deja.com>
Subject: Re: regular expression help (matching exactly n times)
Message-Id: <8i97m0$pdl$1@nnrp1.deja.com>
Thanks for your help everyone, I needed to use $string =~ m/^\w{5}$/;
I should have been more specific about what I was trying to do. I had
hoped the comments gave it away (the if statement succeeds if and only
if we matched exactly 5 characters...see the carding joke below.
otherwise go to the else) Time to move on...
In article <3945aa68.3bc$3e3@news.op.net>,
mjd@plover.com (Mark-Jason Dominus) wrote:
> In article <8i44u1$2mp$1@nnrp1.deja.com>,
> Howard Jow <ppith@my-deja.com> wrote:
> >$string = "abddba";
> >if($string =~ m/([\w]{5}?)/) { # match exactly 5 characters
(non-greedy)
> > print "we matched exactly 5 characters\n";
> >}
>
> ``Hi, you need to show some ID.''
>
> ``Here is my driver's license.''
>
> ``I'm sorry, but you have to be 21 to drink.''
>
> ``But I'm 35!''
>
> ``As I said, you need to be 21 to drink, and you're not 21.''
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 14 Jun 2000 15:53:49 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: sorting an array
Message-Id: <39480CFD.6E4CCC04@vpservices.com>
Larry Rosler wrote:
>
> Instead of using the SQL 'ORDER BY' capability -- which imposes the
> computational burden on the database daemon (which may be on a separate
> machine, and may be handling several requests simultaneously)
> -- I prefer to sort in the application that requests the data.
> I know how to do sorting in Perl efficiently (-:) and more flexibly
> than SQL can.
In cases where efficiency and flexibility are the key requirements,
you're probably right. For many straight-forward sorting tasks,
however, using SQL has the advantage of cleaner and more maintainable
code (at least to my eyes).
> I would be interested in other experiences with this kind of tradeoff
> between the Perl program and the database server.
This doesn't have to be a tradeoff. As I move DBD::RAM and
SQL::Statement towards pure Perl and as the pure Perl perlDB project
ramps up (http://perldb.sourceforge.net/), one will be able to specify a
request in SQL and get the work done by Perl. I would value any
suggestions on that. I would value even more if you (Larry) want to
help implement the sorting for it. :-)
At any rate, I would see there being a number of features of an
application that could be combined in almost any way:
query is processed
a) from a request using SQL syntax or a request using Perl syntax
b) by a Perl script/db-engine or by a non-Perl script/db-engine
c) on the same machine or on a different machine as the script
Each of those choices has separate tradeoffs; so I don't see it as a
Perl vs SQL thing.
--
Jeff
------------------------------
Date: Wed, 14 Jun 2000 23:05:25 GMT
From: r37347@my-deja.com
Subject: split on comma seperated fields, with quoted fields allowed
Message-Id: <8i933a$m47$1@nnrp1.deja.com>
I'm new at regular expressions and I've been trying to figure out how
I can split a line of text that has comma seperated fields without
splitting on the commas that appear in quoted fields.
For example, the following string:
12,567,"hello",992,"this has a, comma",200,"not this"
Should be split into:
12 567 "hello" 992 "this has a,comma" 200 "not this"
Any help is much appreciated!
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 14 Jun 2000 16:28:50 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: split on comma seperated fields, with quoted fields allowed
Message-Id: <39481532.F0F51716@vpservices.com>
r37347@my-deja.com wrote:
>
> I'm new at regular expressions and I've been trying to figure out how
> I can split a line of text that has comma seperated fields without
> splitting on the commas that appear in quoted fields.
>
> For example, the following string:
>
> 12,567,"hello",992,"this has a, comma",200,"not this"
>
> Should be split into:
>
> 12 567 "hello" 992 "this has a,comma" 200 "not this"
There is an entire section on exactly this topic in perlfaq4. It lists
a regular expression that can fit simple cases. The book on Regexen by
Friedl has an extended discussion of it. Also the Text::CSV_XS and
Text::ParseWords modules handle this and the DBD::CSV and DBD::RAM
modules let you access or create files of similar strings as database
records.
--
Jeff
------------------------------
Date: Wed, 14 Jun 2000 16:35:58 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: split on comma seperated fields, with quoted fields allowed
Message-Id: <MPG.13b1b6b5404cbb7898ab81@nntp.hpl.hp.com>
In article <8i933a$m47$1@nnrp1.deja.com> on Wed, 14 Jun 2000 23:05:25
GMT, r37347@my-deja.com <r37347@my-deja.com> says...
> I'm new at regular expressions and I've been trying to figure out how
> I can split a line of text that has comma seperated fields without
> splitting on the commas that appear in quoted fields.
>
> For example, the following string:
>
> 12,567,"hello",992,"this has a, comma",200,"not this"
>
> Should be split into:
>
> 12 567 "hello" 992 "this has a,comma" 200 "not this"
>
> Any help is much appreciated!
Thy help cometh from the FAQ.
perlfaq4: "How can I split a [character] delimited string except when
inside [character]? (Comma-separated files)"
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 14 Jun 2000 23:50:25 GMT
From: "chris dawson" <chrisda@optushome.com.au>
Subject: Re: split on comma seperated fields, with quoted fields allowed
Message-Id: <5TU15.1304$FO1.1367@news1.rochd1.qld.optushome.com.au>
<r37347@my-deja.com> wrote in message news:8i933a$m47$1@nnrp1.deja.com...
> I'm new at regular expressions and I've been trying to figure out how
> I can split a line of text that has comma seperated fields without
> splitting on the commas that appear in quoted fields.
>
> For example, the following string:
>
> 12,567,"hello",992,"this has a, comma",200,"not this"
>
> Should be split into:
>
> 12 567 "hello" 992 "this has a,comma" 200 "not this"
>
> Any help is much appreciated!
First of all apologies if this message is in some weird Micros~1 Outlook
format, I don't normally use it.
I don't know how to solve this problem using regular expressions only, I'll
be loooking to see if some guru has a solution. What you could do is split
the line up by commas initially
my @line = split /,/, $line;
and then loop throught that array to reunite any fields that were
accindentaly split
for (my $i=0;$i<=$#line;$i++) {
if (/^".*/) {
$fields[$i] = ( $line[$i] . $line[++$i] );
}
else { $fields[$i] = $line[$i];}
}
( Note I'm not sure if the autoincrementing ++$i will work that way, sorry I
can't check and again I hope someone corrects me. )
------------------------------
Date: Wed, 14 Jun 2000 17:24:41 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: split on comma seperated fields, with quoted fields allowed
Message-Id: <39482249.A523A1A7@jpl.nasa.gov>
chris dawson wrote:
> <r37347@my-deja.com> wrote in message news:8i933a$m47$1@nnrp1.deja.com...
> > I'm new at regular expressions and I've been trying to figure out how
> > I can split a line of text that has comma seperated fields without
> > splitting on the commas that appear in quoted fields.
> >
> > For example, the following string:
> >
> > 12,567,"hello",992,"this has a, comma",200,"not this"
> >
> > Should be split into:
> >
> > 12 567 "hello" 992 "this has a,comma" 200 "not this"
>
> First of all apologies if this message is in some weird Micros~1 Outlook
> format, I don't normally use it.
It looks ok to me, but why didn't you send a test post to a test post
newsgroup to see for yourself (alt.test for instance)?
> I don't know how to solve this problem using regular expressions only, I'll
> be loooking to see if some guru has a solution. What you could do is split
> the line up by commas initially
>
> my @line = split /,/, $line;
>
> and then loop throught that array to reunite any fields that were
> accindentaly split
>
> for (my $i=0;$i<=$#line;$i++) {
> if (/^".*/) {
> $fields[$i] = ( $line[$i] . $line[++$i] );
> }
> else { $fields[$i] = $line[$i];}
> }
>
> ( Note I'm not sure if the autoincrementing ++$i will work that way, sorry I
> can't check and again I hope someone corrects me. )
First, the question would be better answered by referencing the FAQ
(perldoc -q split). Second, your code doesn't work on the test data
that was provided. Third, if you don't have access to perl (and why
not?) don't post answers. Please see the other answers to this post.
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Wed, 14 Jun 2000 15:30:56 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Splitting a script into multiple files
Message-Id: <Pine.GSO.4.10.10006141529240.5301-100000@user2.teleport.com>
On Wed, 14 Jun 2000, Trevor Sky Garside wrote:
> What is the best method for splitting a script into multiple files,
> such that some variables can be made available to all of the subs from
> all of the files? I asked this awhile ago (my news server has since
> lost the thread), and was told to "require" the external files. This
> works except for the variables.
Variables which will be shared among several files need to be global
variables. If your code will always be run under Perl 5.6 or later, see
the docs for the 'our' directive. Otherwise, see the docs for the 'use
vars' directive. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 14 Jun 2000 19:52:59 -0400
From: Luis Fernandes <elf@ee.ryerson.ca>
Subject: substitutions when vars contain regexp symbols
Message-Id: <x0snufom5g.fsf@ee.ryerson.ca>
How do I perform an in-place substitution when the variable
containing the old string contains regexp chars? (I looked through the
_Perl Cookbook_ to no avail.)
For example, if you run this program...
#!/usr/local/bin/perl
#replace what's in $symbol with nothing
$symbol="Z";
$string="ZXCV^BNM";
print STDERR "$string\n";
$string=~ s/$symbol//;
print STDERR "$string\n";
The output is (as expected the Z is zapped):
ZXCV^BNM
XCV^BNM
------------------------------------------------------------------------
But, if you run this program:
#!/usr/local/bin/perl
#replace what's in $symbol with nothing
$symbol="^"; # This was "Z" before
$string="ZXCV^BNM";
print STDERR "$string\n";
$string=~ s/$symbol//;
print STDERR "$string\n";
The output is (unexpectedly):
ZXCV^BNM
ZXCV^BNM
When I expect the ^ to be zapped:
ZXCVBNM
------------------------------
Date: Wed, 14 Jun 2000 17:23:36 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: substitutions when vars contain regexp symbols
Message-Id: <Pine.GSO.4.10.10006141722550.5301-100000@user2.teleport.com>
On 14 Jun 2000, Luis Fernandes wrote:
> How do I perform an in-place substitution when the variable
> containing the old string contains regexp chars?
I believe you want the \Q (quotemeta) escape. Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: 15 Jun 2000 00:57:17 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: substitutions when vars contain regexp symbols
Message-Id: <8i99lc$4c9s7$3@fu-berlin.de>
hi,
Luis Fernandes <elf@ee.ryerson.ca> wrote:
> How do I perform an in-place substitution when the variable
> containing the old string contains regexp chars? (I looked through the
> _Perl Cookbook_ to no avail.)
> #replace what's in $symbol with nothing
> $symbol="^"; # This was "Z" before
> $string="ZXCV^BNM";
> $string=~ s/$symbol//;
> ZXCV^BNM
> When I expect the ^ to be zapped:
> ZXCVBNM
use
$symbol="\Q^\E";
and look at
perldoc perlre
for the meaning of \Q and \E
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Wed, 14 Jun 2000 15:05:20 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: textfile reading template
Message-Id: <394801A0.52070C1F@jpl.nasa.gov>
[jeopardy quote of the original problem fixed]
Manny wrote:
> Manny wrote:
>
> > Needs to read huge text file in series of records. Folliwing text file:
> >
> > test.txt
> >
> > field1 : value1
> > field2 : value2
> > field3 : value3
> >
> > field1 : 1
> > field2 : 2
> > field3 : 3
> > =============
> >
> > I needs to read in
> > $value1,$value2,$value3 as record 1. and write it to other text file.
> > example:
> >
> > test.out
> > value1,value2,value3
> > 1,2,3
> > and so on.
>
> I have been doing following so far:
>
> open(INF, $inf) || die "";
You could put $! and $inf somewhere in your error message. Perhaps a
small explaination would help too.
> while(<INF>) {
>
> if ( $_ =~ "field1" ) {
It would be cleaner (and perl idiomatic) to write:
if (/field1/){
> ($field1token, $field1value) = split(/\:/);
No need to escape that colon.
> } elsif ....
You might want to stuff these pairs into a hash somewhere in this loop.
$record{$field1token} = $field1value;
instead of having a bunch of scalars floating around. You could even
simplify to:
my %record;
my $inf = 'somefile';
open INF, $inf or die "can't open $inf: $!";
while (<INF>){
my ($key, $value) = split ':';
$record{$key} = $value;
};
> better way to do this?
I have been fiddling around with the DBD::RAM DBI driver, and it seems
like a perfect solution for this sort of thing. (It could also be
massive overkill unless the file really is 'huge'.)
Jon
--
Knowledge is that which remains when what is
learned is forgotten. - Mr. King
------------------------------
Date: Wed, 14 Jun 2000 15:34:24 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Using a hash with popup_menu
Message-Id: <Pine.GSO.4.10.10006141533550.5301-100000@user2.teleport.com>
On Wed, 14 Jun 2000, Edward Waldspurger wrote:
> print $menu->popup_menu(-name=>'selection_name',
> -values=>\@array,
> -lables=>\%hash);
How do you spell 'label'? :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Wed, 14 Jun 2000 19:24:56 -0300
From: "k" <none@none.ca>
Subject: view HTTP Headers
Message-Id: <AzT15.10195$qS3.27016@tor-nn1.netcom.ca>
How do you read and display the HTTP Headers of the current Request of a
script?
Thanks,
kh
------------------------------
Date: Wed, 14 Jun 2000 18:41:14 -0500
From: brian@smithrenaud.com (brian d foy)
Subject: Re: view HTTP Headers
Message-Id: <brian-1406001841150001@176.sanjose-06-07rs16rt.ca.dial-access.att.net>
In article <AzT15.10195$qS3.27016@tor-nn1.netcom.ca>, "k" <none@none.ca> wrote:
>How do you read and display the HTTP Headers of the current Request of a
>script?
see the HTTP::Headers module documentation.
good luck :)
--
brian d foy
Perl Mongers <URI:http://www.perl.org>
CGI MetaFAQ
<URI:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
------------------------------
Date: Wed, 14 Jun 2000 22:10:30 GMT
From: "Daniel van den Oord" <danielxx@bart.nl>
Subject: Re: works without strict but not with why ????
Message-Id: <qpT15.1320$%h3.27161@Typhoon.bART.nl>
works just fine with me !!!!
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3363
**************************************