[15550] in Perl-Users-Digest
Perl-Users Digest, Issue: 2963 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 5 18:10:51 2000
Date: Fri, 5 May 2000 15:10:34 -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: <957564631-v9-i2963@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 5 May 2000 Volume: 9 Number: 2963
Today's topics:
Perl Lazy Matching edlong@yahoo.com
PLEASE HELP on Hash of Hash tvn007@my-deja.com
Re: prob installing DBI / DBD <makarand_kulkarni@My-Deja.com>
problems with $/ = "\r\n" (Windows text files and $INPU <psrchisholm@my-deja.com>
Re: problems with $/ = "\r\n" (Windows text files and $ <lr@hpl.hp.com>
Quality of perl implementations (Was: Re: if file alrea <lr@hpl.hp.com>
Re: re-initializing through each loop <lr@hpl.hp.com>
Reading delimited file into hash agodfrey1118@my-deja.com
regex question gbaker@cs.umb.edu
Re: regex question <aperrin@davis.DEMOG.Berkeley.EDU>
Super-Simple newbie question <jatill@acsu.buffalo.edu>
Re: Super-Simple newbie question <jeff@vpservices.com>
Re: Super-Simple newbie question <andrew.mcguire@walgreens.com>
Re: Super-Simple newbie question (James W. Sandoz)
Re: Super-Simple newbie question <jeff@vpservices.com>
Re: Super-Simple newbie question <latsharj@my-deja.com>
Variable Not Completely Passed <grichards@flashcom.net>
Re: Variable Not Completely Passed <tony_curtis32@yahoo.com>
Re: Variable Not Completely Passed <grichards@flashcom.net>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 05 May 2000 19:55:57 GMT
From: edlong@yahoo.com
Subject: Perl Lazy Matching
Message-Id: <8ev904$kv9$1@nnrp1.deja.com>
Hello,
The crux of the question, is there are multiple variables in my hash
that start similiar
(ie: ab, abc, abcd). And there are sections of text that I want to
replace
(ie: "This ab, is abc, the next abcd") And Perl picks up the first ab
and replaces it with the ab replacement, but I want Perl to match the
WHOLE string and replace the whole string with the correct replacement.
Thank you!
- Ed (edl@usa.com)
(Note: I don't think I can use ^ and $, because (I tried it) and these
string are anywhere in the text.
Example:
%myhash = ("[ec_order_header].sold_to_member_name","getSoldToMemberName
()","[ec_order_header].sold_to","getSoldTo()");
$tmpstr ='<Name xml:lang="en">
[ec_order_header].sold_to_member_name</Name>';
foreach $k (keys %myhash)
{
$currkey = quotemeta $k;
#print "CURRKEY: $currkey\n";
($tableid,$rest) = split("\\.",$k);
$prefix = $prefixhash{$tableid};
print ("CURRKEY: $currkey\nTABLEID: $tableid\nPREFIX:
$prefix\nHASH: $prefixhash{$tableid}\n");
$tmpstr =~ s/$currkey/\<\%=$prefix$myhash{$k}\%\>/g;
}
print $tmpstr;
This prints:
CURRKEY: \[ec_order_header\]\.sold_to
TABLEID: [ec_order_header]
PREFIX: oh.
HASH: oh.
CURRKEY: \[ec_order_header\]\.sold_to_member_name
TABLEID: [ec_order_header]
PREFIX: oh.
HASH: oh.
<Name xml:lang="en"><%=oh.getSoldTo()%>_member_name</Name>
Notice how it just grabed "Sold_to" but not the rest.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 05 May 2000 20:43:37 GMT
From: tvn007@my-deja.com
Subject: PLEASE HELP on Hash of Hash
Message-Id: <8evbpl$o8s$1@nnrp1.deja.com>
Hi,
Could someone please help me on this:
Below is my PERL script:
#!/usr/local/bin/perl
$data_file = 'test.out';
%hash;
open(DATA,$data_file) || die "cannot open\n";
while (<DATA>){
chomp;
($order,$item,$value) = split /:/,$_;
$hash{$order}{$item}=$value;
}
foreach $ok(keys %hash){
print "ok\n";
foreach $ok2( keys %{$hash{$ok}}){
print "$ok2\t";
$ok3= $hash{$ok}{$ok2};
print "$ok3\n";
}
}
INPUT FILE: 'test.out'
order#1:potato:100
order#2:potato:200
order#1:meat:20
order#2:meat:30
OUTPUT From the PERL script above:
order#1
meat 20
potato 100
order#2
meat 30
potato 200
###################################################
However, I would like the output to print as follow:
meat potato
order#1 20 100
order#2 30 200
Min. 20 100
Max. 30 200
Average 25 150
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 05 May 2000 12:05:51 -0700
From: Makarand Kulkarni <makarand_kulkarni@My-Deja.com>
Subject: Re: prob installing DBI / DBD
Message-Id: <39131B8F.1D7101B6@My-Deja.com>
> Do we need to install any other drivers?
yes. Some oracle client libs under $oracle_home/lib/
are required.
------------------------------
Date: Fri, 05 May 2000 19:23:56 GMT
From: Paul S R Chisholm <psrchisholm@my-deja.com>
Subject: problems with $/ = "\r\n" (Windows text files and $INPUT_RECORD_SEPARATOR)
Message-Id: <8ev73q$ipt$1@nnrp1.deja.com>
Consider the following Perl program that tries to use $/ (a.k.a. $RS,
a.k.a. $INPUT_RECORD_SEPARATOR):
use strict;
$^W = 1; # perl -w
$/ = "\r\n" if $^O eq 'MSWin32';
while (<>) {
print;
}
The goal was to have <> and chomp handle end-of-line appropriately for
Windows text files.
I have two data files. If I run it against the 23 megabyte file:
perl -w stupid.pl datafile1.txt
it catenates the 23 megabyte file to standard output, as you'd expect.
If I run it against the 43 megabyte file (same kinds of lines, call
detail records of a not particularly interesting format, each line less
than 256 characters long, the first very short):
perl -w stupid.pl datafile2.txt
it sits for about an hour and complains, "Out of memory!" If I run it
in the debugger, the following transpires:
main::(stupid.pl:3): $^W = 1; # perl -w
DB<1> n
main::(stupid.pl:5): $/ = "\r\n" if $^O eq 'MSWin32';
DB<1> n
main::(stupid.pl:7): while (<>) {
DB<1> n
and it sits there, burning CPU and memory, trying to evaluate the first
call to <>. If I comment out the line that sets $/ I don't see any
problems (but I can't call chomp() to get rid of the logical end-of-
line).
Microsoft Windows NT 4.0 SP 4; (ActiveState) Perl, version 5.005_03
built for MSWin32-x86-object.
Any ideas? --PSRC
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 5 May 2000 14:02:42 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: problems with $/ = "\r\n" (Windows text files and $INPUT_RECORD_SEPARATOR)
Message-Id: <MPG.137cd6c98e3fc35898aa0c@nntp.hpl.hp.com>
In article <8ev73q$ipt$1@nnrp1.deja.com> on Fri, 05 May 2000 19:23:56
GMT, Paul S R Chisholm <psrchisholm@my-deja.com> says...
> Consider the following Perl program that tries to use $/ (a.k.a. $RS,
> a.k.a. $INPUT_RECORD_SEPARATOR):
>
> use strict;
> $^W = 1; # perl -w
>
> $/ = "\r\n" if $^O eq 'MSWin32';
>
> while (<>) {
> print;
> }
>
> The goal was to have <> and chomp handle end-of-line appropriately for
> Windows text files.
You are doing the job that perl has already done for you. Unless you
take a positive action (calling the binmode() function), perl will
convert "\r\n" read from a file into the single character "\n", which is
the default setting for $/.
...
> ... If I comment out the line that sets $/ I don't see any
> problems (but I can't call chomp() to get rid of the logical end-of-
> line).
Of course you can. The 'logical end-of-line is "\n", which is the
default value for $/, which chomp() chomps.
...
I suggest you read the first section in perlport, headed 'Newlines'.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 5 May 2000 12:31:47 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Quality of perl implementations (Was: Re: if file already exists then remove...)
Message-Id: <MPG.137cc17b59c765498aa08@nntp.hpl.hp.com>
In article <htp-DCD0EA.19040405052000@news.metropolis.net.au> on Fri, 05
May 2000 19:04:04 +0930, Henry <htp@mac.com> says...
...
> What it means in practice is that NASA doesn't use Perl to calculate
> maneuver burns, orbit insertion trajectories, and other critical datum
> because if they did, they'd lose a heck of a lot more pilots and probes
> than they currently do.
>
> Look, don't get me wrong, I think Perl's great. It forgives me when I
> make mistakes, and I forgive it when it makes mistakes. That makes for
> a very warm and fuzzy relationship. Tolerance is, however, not a trait
> of mission-critical programming languages (and compilers) - they are
> cold, prickly, but can be relied upon when the <objectionable object>
> hits the fan.
What does this say about the quality of open-source compilers,
specifically or generally? Is gcc acceptable as a C compiler? If so,
why is the quality of the perl implementations so low that Perl is
unacceptable? How about comparisons with the quality of Linux, an open-
source operating system with many hands on the code?
I am troubled by your laissez-faire attitude with regard to perl.
Should encouraging willing contributors to invest more time on quality
of implementation become a higher priority than continually adding
features?
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 5 May 2000 13:25:09 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: re-initializing through each loop
Message-Id: <MPG.137ccdfe839148ad98aa0a@nntp.hpl.hp.com>
In article <slrn8h5o39.4k3.tadmc@magna.metronet.com> on Fri, 5 May 2000
10:53:29 -0400, Tad McClellan <tadmc@metronet.com> says...
> On Fri, 5 May 2000 02:18:19 -0400, Jonah <nomail@nomail.com> wrote:
>
> >Is there anything wrong with re-intializing a variable
> >through each loop.
...
> I think you meant "redeclaring" there instead of "re-intializing" ?
^^^
...
> [ questions should end with question marks ]
^^^
And declarative sentences should end with periods, not question marks.
See above for two failures. :-)
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 05 May 2000 21:21:38 GMT
From: agodfrey1118@my-deja.com
Subject: Reading delimited file into hash
Message-Id: <8eve0h$qtr$1@nnrp1.deja.com>
I need to read a text file (/share/answer.txt) into a hash. The file is
currently delimited with ~ but delimiting character could be changed if need
be. I can work out the rest of the script if I could get that file imported.
I have only written a few scripts before but I'm having trouble getting
started with this one b/c I can't figure out how to get that to work, even
after RTFM. TIA for any help.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 05 May 2000 20:27:25 GMT
From: gbaker@cs.umb.edu
Subject: regex question
Message-Id: <8evaqp$n7g$1@nnrp1.deja.com>
Hi,
I have a messy data set of street names with stuff like :
10 MAINST
15 LOCUST
7 1ST
55 PARK WEST
12 BALLASTST
15 EAST
22 NORWALLST
What I would like to do is replace /st$/ with " st"
if the two letters before it are not some of the common
ones that come up ( i.e. CU in Locust, WE in West, EA in East, ).
Any Suggestions?
Thanks, Gary
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 05 May 2000 13:50:28 -0700
From: Andrew Perrin - Demography <aperrin@davis.DEMOG.Berkeley.EDU>
Subject: Re: regex question
Message-Id: <u5k4s8c3enf.fsf@davis.DEMOG.Berkeley.EDU>
gbaker@cs.umb.edu writes:
>
> 10 MAINST
> 15 LOCUST
> 7 1ST
> 55 PARK WEST
> 12 BALLASTST
> 15 EAST
> 22 NORWALLST
>
> What I would like to do is replace /st$/ with " st"
> if the two letters before it are not some of the common
> ones that come up ( i.e. CU in Locust, WE in West, EA in East, ).
How about...
#!/usr/local/bin/perl -w
use strict;
my @common = qw/CU WE EA/;
my @addresses = ('10 MAINST',
'15 LOCUST',
'7 1ST',
'55 PARK WEST',
'12 BALLASTST',
'15 EAST',
'22 NORWALLST');
my $common = join('|',@common);
foreach (@addresses) {
s/(?<!$common)(st)$/ $1/gi;
}
print join("\n",@addresses), "\n";
>
> Any Suggestions?
> Thanks, Gary
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
--
---------------------------------------------------------------------
Andrew J. Perrin - aperrin@demog.berkeley.edu - NT/Unix Admin/Support
Department of Demography - University of California at Berkeley
2232 Piedmont Avenue #2120 - Berkeley, California, 94720-2120 USA
http://demog.berkeley.edu/~aperrin --------------------------SEIU1199
------------------------------
Date: Fri, 5 May 2000 14:15:41 -0400
From: Jeffrey A Till <jatill@acsu.buffalo.edu>
Subject: Super-Simple newbie question
Message-Id: <8ev2rh$dm4$1@prometheus.acsu.buffalo.edu>
All I am trying to do it get some Perl, ANY Perl to work...
I make a file, helloWorld.
I put in it...
#!/usr/bin/perl
print "Hello World"
then at the unix prompt I type 'chmod +x helloWorld'
And to run it, I type 'helloWorld', but I get the error:
'helloWorld: command not found'
What am I doing wrong?
~Jeff Till
jatill@acsu.buffalo.edu
------------------------------
Date: Fri, 05 May 2000 11:23:46 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Super-Simple newbie question
Message-Id: <391311B2.8D48E175@vpservices.com>
Jeffrey A Till wrote:
>
> All I am trying to do it get some Perl, ANY Perl to work...
>
> I make a file, helloWorld.
> I put in it...
> #!/usr/bin/perl
> print "Hello World"
> then at the unix prompt I type 'chmod +x helloWorld'
> And to run it, I type 'helloWorld', but I get the error:
> 'helloWorld: command not found'
Is the perl executable found in /usr/bin on your system? Use the "which
perl" command to find out where perl is actually located and change that
top line to reflect that location. Also check to make sure that there
are no extraneous characters on that first line (even ones that might
not be visible -- e.g. look at it in emacs and see if there is a ^M on
the line).
--
Jeff
------------------------------
Date: Fri, 05 May 2000 13:32:20 -0500
From: "Andrew N. McGuire" <andrew.mcguire@walgreens.com>
Subject: Re: Super-Simple newbie question
Message-Id: <391313B4.9C0E68E8@walgreens.com>
Jeff Zucker wrote:
>
> Jeffrey A Till wrote:
> >
> > All I am trying to do it get some Perl, ANY Perl to work...
> >
> > I make a file, helloWorld.
> > I put in it...
> > #!/usr/bin/perl
> > print "Hello World"
> > then at the unix prompt I type 'chmod +x helloWorld'
> > And to run it, I type 'helloWorld', but I get the error:
> > 'helloWorld: command not found'
>
> Is the perl executable found in /usr/bin on your system? Use the "which
> perl" command to find out where perl is actually located and change that
> top line to reflect that location. Also check to make sure that there
> are no extraneous characters on that first line (even ones that might
> not be visible -- e.g. look at it in emacs and see if there is a ^M on
> the line).
I would be willing to bet that helloWorld is not in his $PATH.
Try ./helloWorld.
Cheers,
anm
--
Andrew N. McGuire
andrew.mcguire@walgreens.com
------------------------------
Date: 5 May 2000 14:41:16 -0400
From: sandoz@umbc.edu (James W. Sandoz)
Subject: Re: Super-Simple newbie question
Message-Id: <8ev4kc$3spbu$1@umbc7.umbc.edu>
In article <391311B2.8D48E175@vpservices.com>,
Jeff Zucker <jeff@vpservices.com> wrote:
>Jeffrey A Till wrote:
>> And to run it, I type 'helloWorld', but I get the error:
>> 'helloWorld: command not found'
>
>Is the perl executable found in /usr/bin on your system? Use the "which
>perl" command to find out where perl is actually located and change that
>top line to reflect that location. Also check to make sure that there
>are no extraneous characters on that first line (even ones that might
>not be visible -- e.g. look at it in emacs and see if there is a ^M on
>the line).
Jeff Z. probably nailed the problem, but if your #! line is correct then
check you PATH environmental variable. If '.' isn't in the path, you
need to type ./helloWorld
--
Mr. James W. Sandoz, Instructor, UMBC Dept of Biol Sciences,
1000 Hilltop Circle
Catonsville, MD 21250
voice: (410) 455-3497; fax: 455-3875; net: sandoz@umbc.edu
------------------------------
Date: Fri, 05 May 2000 11:48:09 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Super-Simple newbie question
Message-Id: <39131769.26785A9@vpservices.com>
"Andrew N. McGuire" wrote:
>
> I would be willing to bet that helloWorld is not in his $PATH.
> Try ./helloWorld.
Ayep, that too. How easily we forget those simple show-stopping
mistakes :-)
--
Jeff
------------------------------
Date: Fri, 05 May 2000 18:50:13 GMT
From: Dick Latshaw <latsharj@my-deja.com>
Subject: Re: Super-Simple newbie question
Message-Id: <8ev54u$gku$1@nnrp1.deja.com>
In article <8ev2rh$dm4$1@prometheus.acsu.buffalo.edu>,
Jeffrey A Till <jatill@acsu.buffalo.edu> wrote:
> #!/usr/bin/perl
> print "Hello World"
> then at the unix prompt I type 'chmod +x helloWorld'
> And to run it, I type 'helloWorld', but I get the error:
> 'helloWorld: command not found'
Is the directory where you placed your helloWorld program in your path?
If not, try:
>./helloWorld
Is perl really in /usr/bin? Try:
>which perl
--
Regards,
Dick
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 5 May 2000 12:14:22 -0700
From: "Gabe" <grichards@flashcom.net>
Subject: Variable Not Completely Passed
Message-Id: <sh677mkugbn133@corp.supernews.com>
print "</td></tr><tr><td align=center><a
href=http://www.mopicmag.com/cgi-bin/findpic.cgi?req=$request&start=$start&t
ype=keyword>Next</a></td>";
The value of $request is 'orange show', yet that print statement yields the
link:
http://www.mopicmag.com/cgi-bin/findpid.cgi?req=orange&start=
What happened to the 'show'? The variable prints out correctly when not used
in the context of a hyperlink though!
Help! Thanks!
Gabe
------------------------------
Date: 05 May 2000 14:17:18 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Variable Not Completely Passed
Message-Id: <878zxog62p.fsf@shleppie.uh.edu>
>> On Fri, 5 May 2000 12:14:22 -0700,
>> "Gabe" <grichards@flashcom.net> said:
> print "</td></tr><tr><td align=center><a
> href=http://www.mopicmag.com/cgi-bin/findpic.cgi?req=$request&start=$start&t
> ype=keyword>Next</a></td>";
> The value of $request is 'orange show', yet that print
> statement yields the link:
> http://www.mopicmag.com/cgi-bin/findpid.cgi?req=orange&start=
> What happened to the 'show'? The variable prints out
> correctly when not used in the context of a hyperlink
> though!
You can't have a space in a URL.
perldoc URI::Escape
hth
t
------------------------------
Date: Fri, 5 May 2000 13:44:43 -0700
From: "Gabe" <grichards@flashcom.net>
Subject: Re: Variable Not Completely Passed
Message-Id: <sh6cgv68gbn145@corp.supernews.com>
Tony Curtis <tony_curtis32@yahoo.com> wrote in message
news:878zxog62p.fsf@shleppie.uh.edu...
> perldoc URI::Escape
>
> hth
> t
Awesome. Thank you.
Gabe
------------------------------
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 2963
**************************************