[6337] in Perl-Users-Digest
Perl-Users Digest, Issue: 959 Volume: 7
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Feb 16 16:17:14 1997
Date: Sun, 16 Feb 97 13:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 16 Feb 1997 Volume: 7 Number: 959
Today's topics:
Re: CGI.pm dynamic tables? <merlyn@stonehenge.com>
Re: Comparing two dates (Dave Thomas)
Re: difference btw s/// & tr/// (Matthew Ahrens)
GDBM_File on BSDI (Mike Heins)
Re: HELP loop prob (Tor Iver Wilhelmsen)
Here's a good perl resource... <dave@inquiry.com>
Re: Learning perl from scratch <99borns@ionaprep.pvt.k12.ny.us>
Re: Learning perl from scratch <sjohnson@ibm.net>
Re: learning perl (Bertil Wennergren)
Module installation in $HOME and dependences <kent@erlang.ericsson.se>
Re: Module installation in $HOME and dependences (Brian L. Matthews)
Re: overwriting in-memory password <merlyn@stonehenge.com>
Perl/Tk for Win95 (David Grove)
Re: Perl/Tk for Win95 (Nathan V. Patwardhan)
Pig Latin <99borns@ionaprep.pvt.k12.ny.us>
Re: Pig Latin (Chris Schleicher)
Re: Pig Latin (Mike Fessler)
Re: Pig Latin (Nathan V. Patwardhan)
Re: Pig Latin (Greg Bacon)
Printing an array in Perl <halo@asu.edu>
Re: Printing an array in Perl (Chris Schleicher)
Re: PROGRAM: how to check for nice/valid email address (Tad McClellan)
Reading directly into array is slow, why? (Bertil Wennergren)
Re: Reading directly into array is slow, why? (Mike Heins)
Re: Reading directly into array is slow, why? <dsb3@earthlink.net>
Re: using "$var" considered harmful?! (was Re: Q: openi (Chris Schleicher)
Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 16 Feb 1997 11:26:59 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
Subject: Re: CGI.pm dynamic tables?
Message-Id: <8chgjczjws.fsf@gadget.cscaper.com>
>>>>> "Lincoln" == Lincoln Stein <lstein@logo> writes:
Lincoln> In article <wjkohdyn8q2.fsf@bitsrfr.cnd.hp.com>,
Lincoln> Jacob Miner <jacob@bitsrfr.cnd.hp.com> wrote:
>> Is there any way to create a dynamic table using the CGI.pm
>> module, and it's syntax?
>> print table(
>> Tr(
>> foreach $entry ('one','two') {
>> td("entry");
>> }
>> )
>> )
Lincoln> Try something like this:
Lincoln> foreach $entry ('one','two') {
Lincoln> push(@cells,td($entry));
Lincoln> }
Lincoln> print table(Tr(@cells));
Or even:
print table(Tr(map {td $_} qw(one two)));
Map is your friend. Use map!
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 561 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 16 Feb 1997 16:23:30 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Comparing two dates
Message-Id: <slrn5gecuu.u5e.dave@fast.thomases.com>
On Sun, 16 Feb 1997 00:15:38 -0800, basj@cyber.xs4all.nl <basj@cyber.xs4all.nl> wrote:
> How can I compare the two dates so that I can fill an array with new
> documents since the user's last visit. Is store the two dates in the
> following format: Sat Feb 15 23:11:21 PST 1997
You could convert the dates into a better format for comparison:
my %mon = ( Jan => 1, Feb => 2, Mar => 3, Apr => 4 ); # etc....
$date = "Sat Feb 15 23:11:21 PST 1997";
$date =~ s/^....(\w{3})\s+(\d+)\s+(\d{1,2}):(\d\d):(\d\d)\s+(\w+)\s(\d{4})/
sprintf("%4d%02d%02d%02d%02d%02d", $7, $mon{$1}, $2, $3, $4, $5)/e;
print "$date\n";
These can then be compared as strings.
Dave
--
_________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
------------------------------
Date: Sun, 16 Feb 1997 16:32:29 GMT
From: matt@callnet.com (Matthew Ahrens)
Subject: Re: difference btw s/// & tr///
Message-Id: <330834dd.47360032@news.alt.net>
On 15 Feb 1997 13:58:12 -0800, Elton Kong <fkong@scf.usc.edu> wrote:
>Thanks for the replies! In fact I have looked into the perlop and perlre
>manual pages, and (I think) I know perfectly well the difference between
>the 2 operators. I just wonder when both can be used, which one is more
>efficient?
>
>You see, below is my problem. I have an input file with a certain
>character which I want to get rid of. So I can use either of the forms
>below.
>
>s/\cM//g;
>tr/\cM//d;
>
>Thus my question is: which is more efficient?
use the Benchmark library to find out for yourself. (perldoc Benchmark;)
>
>BTW, is there any difference if I don't put a "g" after the s/// opeator?
>I can't see the difference after trying.
RTFM! : from 'man perlop':
g Replace globally, i.e. all occurrences.
so if your string is "hi\cMthere\cMElton" it will kill all occurences of \cM
in your string. if you did not use /g then only the first occurrence would
be replaced. (duh!)
------------------------------
Date: 16 Feb 1997 16:35:44 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: GDBM_File on BSDI
Message-Id: <5e7d10$2ei@vixen.cso.uiuc.edu>
I believe I am having some locking problems with DB_File on a BSDI 2.1
system (and probably others using DB_File). I would like to test
with GDBM_File, which has integral locking, but can't get Perl to
build with it.
I built the library OK, though the test programs ('make progs') would
not all compile, and a quick test with 'testgdbm' appears to work.
But when I build the library into Perl (both 5.003_00 and 5.003_26)
the lib/gdbm test fails on test 5 (and 6 and 7, when run manually
from the test directory). All other tests pass.
Searches for 'bsd gdbm' on DejaNews and perusal of the appropriate
FAQs/docs appear to offer nothing. If anyone has done this successfully,
I would appreciate some help.
--
Regards, ___ ___
Mike Heins http://www.iac.net/~mikeh|_ _|____ |_ _|
Internet Robotics | || _ \ | |
This post reflects the Oxford, OH 45056 | || |_) || |
opinion of my employer. <mikeh@iac.net> |___| _ <|___|
513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: 16 Feb 1997 16:26:05 GMT
From: toriver@pvv.ntnu.no (Tor Iver Wilhelmsen)
Subject: Re: HELP loop prob
Message-Id: <5e7cet$qs4@due.unit.no>
lewis@thereel.com writes:
>I have tried to emulate the following code:
>
>print OUTPUT ":$FORM{'qu1'}";
>print OUTPUT ":$FORM{'qu2'}";
>print OUTPUT ":$FORM{'qu3'}";
>print OUTPUT ":$FORM{'qu4'}";
>etc ...
>
for (1..4) { print OUTPUT ":$FORM{'qu'.$_}" }
- Tor Iver
--
Substitute Assistant CEO of Opening Tins of Dog Food of the DNRC.
toriver@pvv.org * http://www.pvv.org/%7Etoriver * Rush: Cut to the Chase
"I'm old enough not to care too much about what you think of me
But I'm young enough to remember the future and the way things ought to be"
------------------------------
Date: Sun, 16 Feb 1997 07:23:41 -0800
From: Dave Wagner <dave@inquiry.com>
Subject: Here's a good perl resource...
Message-Id: <3307267D.28E9@inquiry.com>
Here's a place to get answers to perl questions:
http://www.inquiry.com/techtips/web_pro/
--
____________________ Answers for IT Professionals ____________________
Dave Wagner | 415-655-2828 | 415-655-2820 FAX | dave@inquiry.com
____________________ http://www.inquiry.com/search ___________________
------------------------------
Date: Sun, 16 Feb 1997 13:15:23 -0800
From: "!Stephen!" <99borns@ionaprep.pvt.k12.ny.us>
To: posenj@lancet.co.za
Subject: Re: Learning perl from scratch
Message-Id: <330778EB.30AD@ionaprep.pvt.k12.ny.us>
Hi!
If you go to http://www.waite.com/ezone you can learn PERL, HTML, C++,
and many more languages completely from scratch! That's what I'm doing
now! Hope that helps!
--
!Stephen!
Try the *new* incredibly fantastic HTML contest!
http://home1.gte.net/spantz
------------------------------
Date: 16 Feb 1997 20:10:49 GMT
From: "Scott T. Johnson" <sjohnson@ibm.net>
Subject: Re: Learning perl from scratch
Message-Id: <01bc1c45$600b5d90$8c4a48a6@scott>
Go out and get a good book like Perl 5 Interactive Course by Waite Group
Press. Great book. Perl is complicated which makes it very powerful and
this book really helps you learn.
> /^\d+$/;
Means: Starting at the beginning of the line (^), look for at least one to
many digits (\d+) to the end of the line ($). No other characters (or
decimals) are allowed)
Hope that helps.
Scott
Kevin Posen <posenj@lancet.co.za> wrote in article
<5e71ga$ge7@news1.saix.net>...
> Hi.
>
> I've recently started to learn Perl using an HTML manual that I received
with the Perl5 .zip file
> (it contains perl.html, perltoc.html, perldata.html, etc.). The problem
is that, although I have
> been programming for about 5 years, I have only used Pascal and BASIC for
DOS -- never Unix, sed,
> awk or C. The manual assumes a fair amount of background from those and
so I have run into many
> incomplete explanations and I'm finding it very difficult to follow the
manual.
>
> Does anyone know of a manual that would be better? Or can anyone suggest
a route/method for me to go
> about learning it more easily?
>
> (One of the things I'm having trouble on is why does
> /^\d+$/;
> check if something is a whole number?)
>
> Thanks a lot.
>
> Kevin Posen
>
>
------------------------------
Date: 16 Feb 1997 00:49:13 GMT
From: bw@mail2.tripnet.se (Bertil Wennergren)
Subject: Re: learning perl
Message-Id: <5e5li9$n8k@minox.tripnet.se>
En la afisxo <33038601.12843692@news.ultranet.ca> Helen skribis:
: I'm in a similar position myself. I found that both Camel books
: (Learning Perl being one of them, Programming Perl being the other)
: became clearer as I learned more unix. They assume a unix background
: in the reader. Not to have done so would have made them twice as
: thick. Fortunately, unix isn't that hard to pick up. Learning unix is
: useful even if you plan to use Perl on NT or whatever.
True. Almost allmaterial on Perl that I have come across has assumed a
knowledge of C(++). This has been a major obstacle in my Perl learning
since I don't know _any_ programming language, least of all C. Is there
any material out there that does not start every other sentence with "this
is mostly like C except for..."?
----------------------------------------------
Bertilo Wennergren
<bw@tripnet.se>, <bertilow@hem1.passagen.se>
<http://hem1.passagen.se/bertilow/bertilo.htm>
----------------------------------------------
------------------------------
Date: 16 Feb 1997 17:18:22 +0100
From: Kent Boortz <kent@erlang.ericsson.se>
Subject: Module installation in $HOME and dependences
Message-Id: <d2eneg4tdd.fsf@erlang.ericsson.se>
I don't have root access on my computer at work and don't want to
bother the system administrator for every module or new version of a
module I want to install. So I do local installations under my
$HOME. I have created bin, lib, man and var directorys and it usually
works well. If the module is independent that is.
But now I tried to install the libwww library that needed a newer Net
and FTP that needed a newer IO. This was hard. I know I can specify search
paths for other libraries on the command line with "-I" but it doesn't
work very well if scripts call other scripts as in the case where
the Makefile.PL calls Configure in the libnet installation.
So why no Unix environment variable with additional paths to search?
I searched the FAQ and perlrun man-page but couldn't find anything.
The only solution I can think of is to install my own copy of Perl
but i would prefer not to. Especially since I have lots of scripts
that begin with "#!/usr/local/bin/perl".
/kgb
======================================================================
I had to use lines like
% perl -I/home/kent/lib/perl5 -I/home/kent/lib/perl5/sun4-solaris/5.003 \
Makefile.PL
I also had to modify the source to Configure in Net becuase it was run
from Makefile.PL but INC wasn't passed.
BEGIN {unshift(@INC,
"/home/kent/lib/perl5",
"/home/kent/lib/perl5/sun4-solaris/5.003",
)}
To make the test of the libwww library I had to do
% make test PREFIX=/home/kent FULLPERL="perl -I/home/kent/lib/perl5 \
-I/home/kent/lib/perl5/sun4-solaris/5.003"
------------------------------
Date: 16 Feb 1997 12:03:49 -0800
From: blm@halcyon.com (Brian L. Matthews)
Subject: Re: Module installation in $HOME and dependences
Message-Id: <5e7p76$9m2$1@halcyon.com>
In article <d2eneg4tdd.fsf@erlang.ericsson.se>,
Kent Boortz <kent@erlang.ericsson.se> wrote:
|I don't have root access on my computer at work and don't want to
|bother the system administrator for every module or new version of a
|module I want to install.
If I understand you correctly, PERLLIB and PERL5LIB may help. They're
documented in the main perl man page.
Brian
--
Brian L. Matthews Illustration Works, Inc.
For top quality, stock commercial illustration, visit:
http://www.halcyon.com/artstock
------------------------------
Date: 16 Feb 1997 11:23:41 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: fine@net.ohio-state.edu ("Thomas A. Fine")
Subject: Re: overwriting in-memory password
Message-Id: <8ck9o8zk2a.fsf@gadget.cscaper.com>
>>>>> ""Thomas" == "Thomas A Fine" <fine@net.ohio-state.edu> writes:
"Thomas> nvp@shore.net (Nathan V. Patwardhan) writes:
>> Thomas A. Fine (fine@net.ohio-state.edu) wrote:
>> : than necessary. What's the correct way to _guarantee_ that I've removed
>> : it from memory after use?
>>
>> undef $varname;
"Thomas> What I want is to have some great wizard of the internals of perl come along
"Thomas> and say "Blessed art the ways of substr()", or some such nonsense.
I'd bet that tr/\0-\377/x/ would do it. Tr doesn't like malloc unless
it's absolutely necessary.
But I know painfully little about Perl internals. I'm *much* better
versed at the uses and abuses of the externals. :-)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 561 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 16 Feb 97 17:14:55 GMT
From: pete@dave-world.net (David Grove)
Subject: Perl/Tk for Win95
Message-Id: <3307408f.0@nt.dave-world.net>
Does anybody know where I can get PERL/Tk for Win95?
PLEEZE HELP!
pete@dave-world.net
------------------------------
Date: 16 Feb 1997 19:29:20 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Perl/Tk for Win95
Message-Id: <5e7n6g$1jg@fridge-nf0.shore.net>
David Grove (pete@dave-world.net) wrote:
: Does anybody know where I can get PERL/Tk for Win95?
You can't to my knowledge, as such a beast doesn't exist. :-) You might
look into Tcl/Tk for Windows if you're interested in GUIs based on a
scripting language.
--
Nathan V. Patwardhan
nvp@shore.net
"[news:alt.fan.jwz]"
------------------------------
Date: Sun, 16 Feb 1997 13:23:28 -0800
From: "!Stephen!" <99borns@ionaprep.pvt.k12.ny.us>
Subject: Pig Latin
Message-Id: <33077AD0.2C44@ionaprep.pvt.k12.ny.us>
Hi!
I've just finished writing a very useful PERL program. It takes
whatever the user types in and converts it to Pig Latin. I've tried
setting it up so that if someone types in exit, then the program will
quit. Unfortunately, all it does is print exitay. What's wrong? Here's
the code I used.
#!perl
LOOP: while (<>) {
s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;
print "$_ \n" ;
goto LOOP;
}
if (<> =="exit") {
die
}
Thanx in advance!
--
!Stephen!
Try the *new* incredibly fantastic HTML contest!
http://home1.gte.net/spantz
------------------------------
Date: 16 Feb 1997 11:29:17 -0800
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: Pig Latin
Message-Id: <5e7n6d$2i2@psychotix.cs.uoregon.edu>
In article <33077AD0.2C44@ionaprep.pvt.k12.ny.us>,
!Stephen! <99borns@ionaprep.pvt.k12.ny.us> wrote:
>LOOP: while (<>) {
> s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;
> print "$_ \n" ;
> goto LOOP;
>}
>if (<> =="exit") {
> die
>}
Ugh. A classic case a naughty goto. ;-) Just how do you expect
to ever reach that if statement?
Lose the LOOP, and test for "exit" before you translate to pig latin:
while (<>) {
die "Exiting!" if /^exit$/;
s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;
print;
}
or, even lazier:
[~] 7 % perl -lpe 'die "Exiting!" if /^exit$/; \
? s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;'
Hope this helps,
--Chris
--
Chris Schleicher Office: 541/346-3998
Univ of Oregon CIS GTF email: chrissch@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~chrissch/
------------------------------
Date: Sun, 16 Feb 1997 19:24:41 GMT
From: mef@netaxs.com (Mike Fessler)
Subject: Re: Pig Latin
Message-Id: <33075ec3.9751272@netnews.netaxs.com>
"!Stephen!" <99borns@ionaprep.pvt.k12.ny.us> wrote:
: Hi!
: I've just finished writing a very useful PERL program. It takes
: whatever the user types in and converts it to Pig Latin. I've tried
: setting it up so that if someone types in exit, then the program will
: quit. Unfortunately, all it does is print exitay. What's wrong? Here's
: the code I used.
: #!perl
: LOOP: while (<>) {
: s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;
: print "$_ \n" ;
: goto LOOP;
: }
: if (<> =="exit") {
: die
: }
Um, you're checking the value of the current line *after* you do the
substitution -- either put the check before the substitution, or check for
"exitay"...
------------------------------
Date: 16 Feb 1997 19:33:17 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Pig Latin
Message-Id: <5e7ndt$1jg@fridge-nf0.shore.net>
!Stephen! (99borns@ionaprep.pvt.k12.ny.us) wrote:
: I've just finished writing a very useful PERL program. It takes
: whatever the user types in and converts it to Pig Latin. I've tried
: setting it up so that if someone types in exit, then the program will
That's a brilliant idea - I'm laughing out loud. If you were a woman, I'd
ask for your hand in marriage. :-)
Maybe someone will write a pig latin extension to Perl, called PlPerl.
Example:
intpray("atwhay isway ouryay amenay? ");
opchay(ingstray_amenay = <INSTDAY>);
intpray("Ellohay, ingstray_amenay.\n");
--
Nathan V. Patwardhan
nvp@shore.net
"[news:alt.fan.jwz]"
------------------------------
Date: 16 Feb 1997 20:27:17 GMT
From: gbacon@cs.uah.edu (Greg Bacon)
To: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: Pig Latin
Message-Id: <5e7qj5$3n6@info.uah.edu>
[Posted and mailed]
In article <5e7n6d$2i2@psychotix.cs.uoregon.edu>,
chrissch@cs.uoregon.edu (Chris Schleicher) writes:
: while (<>) {
: die "Exiting!" if /^exit$/;
: s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;
: print;
: }
A couple of TPJs ago (if you don't know what I'm talking about, check
out <http://tpj.com/>) in his "Understanding Regular Expressions"
column, Jeffrey Friedl pointed out the frequency of the above
phenomenon: namely, people can't seem to get out of regex gear and back
to the plain Jane string compare that we used to do before we had Perl.
I'm not pointing an accusatory finger, mind you. I'm often guilty of
the same myself. I just find it interesting.
Perhaps a better way would be
while (<>) {
chomp;
exit 0 if $_ eq 'exit';
s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;
print;
}
Even better might be
while (<>) {
exit 0 if index($_, "exit") == 0;
s/\b([^aeiouy]*)(\S+)\s?/$2$1ay /gi;
print;
}
FWIW:
oreo% cat test.pl
#! /usr/bin/perl
use Benchmark;
timethese(100000,
{
'regex' => '$_ = "exit\n"; $a = /^exit$/',
'cmp' => '$_ = "exit\n"; chomp; $a = $_ eq "exit"',
'index' => '$_ = "exit\n"; $a = (index $_, "exit" == 0)',
'substr' => '$_ = "exit\n"; $a = (substr($_, 0, 4) eq "exit")',
}
);
oreo% test.pl
Benchmark: timing 100000 iterations of cmp, index, regex, substr...
cmp: 3 secs ( 2.89 usr 0.00 sys = 2.89 cpu)
index: 3 secs ( 1.94 usr 0.00 sys = 1.94 cpu)
regex: 3 secs ( 3.79 usr 0.00 sys = 3.79 cpu)
substr: 4 secs ( 3.01 usr 0.00 sys = 3.01 cpu)
Greg
--
Greg Bacon <gbacon@cs.uah.edu>
Unix / Perl Consultant
Perl Institute Partner - http://www.perl.org/
------------------------------
Date: Sun, 16 Feb 1997 11:39:14 -0700
From: Halo <halo@asu.edu>
Subject: Printing an array in Perl
Message-Id: <33075452.330D@asu.edu>
Hi,
I have a databse with names and addresses of people. Each address and
name is on a single line. The first field is the state followed by the
zip code and then the name and the rest of the address. I want to print
the Name and address on one line and the State and zip code on the next.
A sample record looks like this
WY 82070 Tomane James 3307 Alta Vista D Laramie
I was doing it in the following way
for($i=2; $i < $a; $i++)
{
printf "%s", $words[i];
}
where words is my array.
my result looks loke this
WYWYWYWYWYWYWY
If some one can hep I'd appreciate it.
Thnaks
Soma ghosh
email Soma.Ghosh@asu.edu
------------------------------
Date: 16 Feb 1997 11:13:00 -0800
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: Printing an array in Perl
Message-Id: <5e7m7s$2g1@psychotix.cs.uoregon.edu>
[mailed and posted]
In article <33075452.330D@asu.edu>, Halo <halo@asu.edu> wrote:
>A sample record looks like this
>WY 82070 Tomane James 3307 Alta Vista D Laramie
>I was doing it in the following way
> for($i=2; $i < $a; $i++)
> {
> printf "%s", $words[i];
> }
>
>where words is my array.
>my result looks loke this
>WYWYWYWYWYWYWY
Well you don't tell us how you're getting @words, or where $a comes
from for that matter. Regardless, it shouldn't be too hard to get what
your after. Here are a couple quick and dirty examples:
$rec = 'WY 82070 Tomane James 3307 Alta Vista D Laramie';
@words = split(/\s+/, $rec);
$state = shift @words;
$zip = shift @words;
print "@words\n$state, $zip\n";
or
$rec = 'WY 82070 Tomane James 3307 Alta Vista D Laramie';
($state, $zip, $rest) = $rec =~ /^(\w+) (\d+) (.+)$/;
print "$rest\n$state, $zip\n";
Do those help?
Regards,
--Chris
--
Chris Schleicher Office: 541/346-3998
Univ of Oregon CIS GTF email: chrissch@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~chrissch/
------------------------------
Date: Sun, 16 Feb 1997 10:57:02 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: PROGRAM: how to check for nice/valid email address
Message-Id: <u8e7e5.3e1.ln@localhost>
DUPLANTIER Bastien (duplanti@enstb.enst-bretagne.fr) wrote:
: where could i get the Tom Christiansen's article about this subject?
: 'cause i'm a new news reader, so i can't get it...
: thank you for reply...
You can look up any Usenet posting at http://www.dejanews.com
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 16 Feb 1997 15:19:41 GMT
From: bw@mail2.tripnet.se (Bertil Wennergren)
Subject: Reading directly into array is slow, why?
Message-Id: <5e78id$97o@minox.tripnet.se>
I am puzzled by the time differences in the following simple code.
Reading a file directly into an array is much slower (on larger files)
than reading it indirectly through more lines of code. Why is this?
I'm running Perl on an Atari ST, which is of course in itself a _very_
slow machine. To duplicate my results on a faster machine much bigger
files would be needed, I suppose.
-------------------------------------------------------------
$"="";
@files=("small","medium","large"); # "small" = 1319 bytes
# "medium" = 26700 bytes
# "large" = 106800 bytes
foreach $file(@files)
{
#FIRST TRY - READING INDIRECTLY INTO ARRAY
$start=time;
open(TXT,"$file");
while($line=<TXT>) # THIS
{ # IS
push(@text,$line); # FAST
} # (ON LARGER FILES)
$stop=time;
$duration=$stop-$start;
print "\"$file\" first try: $duration second(s)\n";
close(TXT);
#SECOND TRY - READING DIRECTLY INTO ARRAY
$start=time;
open(TXT,"$file");
@text=<TXT>; # THIS IS SLOW (ON LARGER FILES)
$stop=time;
$duration=$stop-$start;
print "\"$file\" second try: $duration second(s)\n";
close(TXT);
}
-------------------------------------------------------------
This prints out:
"small" first try: 0 second(s)
"small" second try: 0 second(s)
"medium" first try: 4 second(s)
"medium" second try: 8 second(s)
"large" first try: 16 second(s)
"large" second try: 102 second(s)
Is this a fault in the Atari ST version of Perl, or is there another
explanation?
"perl -v" gives the following:
This is perl, version 4.0
$RCSfile: perl.c,v $$Revision: 4.0.1.7 $$Date: 92/06/08 14:50:39 $
Patch level: 35
Copyright (c) 1989, 1990, 1991, Larry Wall
atariST series port, ++jrb bammi@cadence.com
----------------------------------------------
Bertilo Wennergren
<bw@tripnet.se>, <bertilow@hem1.passagen.se>
<http://hem1.passagen.se/bertilow/bertilo.htm>
----------------------------------------------
------------------------------
Date: 16 Feb 1997 18:49:20 GMT
From: mheins@prairienet.org (Mike Heins)
Subject: Re: Reading directly into array is slow, why?
Message-Id: <5e7krg$7qj@vixen.cso.uiuc.edu>
Bertil Wennergren (bw@mail2.tripnet.se) wrote:
: I am puzzled by the time differences in the following simple code.
: Reading a file directly into an array is much slower (on larger files)
: than reading it indirectly through more lines of code. Why is this?
:
: I'm running Perl on an Atari ST, which is of course in itself a _very_
: slow machine. To duplicate my results on a faster machine much bigger
: files would be needed, I suppose.
:
I think you are running into a classic allocation problem that
can be solved by pre-extending an array (i.e. $#text = 10_000;).
The push() function very efficiently extends the array by one
when adding an element. When you just read into an array, and
Perl doesn't know how much is to come, it is constantly finding
there is not enough allocation and having to allocate more
memory.
--
Regards,
Mike Heins [mailed and posted] http://www.iac.net/~mikeh ___ ___
Internet Robotics |_ _|____ |_ _|
If you think nobody cares if 131 Willow Lane, Floor 2 | || _ \ | |
you're alive, try missing a couple Oxford, OH 45056 | || |_) || |
of car payments. <mikeh@iac.net> |___| _ <|___|
-- Earl Wilson 513.523.7621 FAX 7501 |_| \_\
------------------------------
Date: Sun, 16 Feb 1997 12:50:14 -0600
From: Dave Baker <dsb3@earthlink.net>
To: Bertil Wennergren <bw@mail2.tripnet.se>
Subject: Re: Reading directly into array is slow, why?
Message-Id: <330756E6.1B12@earthlink.net>
Bertil Wennergren wrote:
>
> I am puzzled by the time differences in the following simple code.
> Reading a file directly into an array is much slower (on larger files)
> than reading it indirectly through more lines of code. Why is this?
>
> I'm running Perl on an Atari ST, which is of course in itself a _very_
> slow machine. To duplicate my results on a faster machine much bigger
> files would be needed, I suppose.
[snip]
> open(TXT,"$file");
> while($line=<TXT>) # THIS
> { # IS
> push(@text,$line); # FAST
> } # (ON LARGER FILES)
> open(TXT,"$file");
> @text=<TXT>; # THIS IS SLOW (ON LARGER FILES)
[snip]
My interpretation of this would be as follows:
the first method takes one line at a time and throws it (again line at a
time)
into the array. the second method reads the whole thing into an
internal
structure and then copies the whole thing to the array ...
imagine moving 100 bowling balls and having the choice of carrying them
one
at a time, or holding them all at once ...
$0.02
dave
------------------------------
Date: 16 Feb 1997 10:43:20 -0800
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: using "$var" considered harmful?! (was Re: Q: opening a file RW without deleting it.)
Message-Id: <5e7kg8$2e8@psychotix.cs.uoregon.edu>
[mailed and posted]
In article <5e4us9$4ke$2@csnews.cs.colorado.edu>,
Tom Christiansen <tchrist@mox.perl.com> wrote:
>For example:
>
> f([a, b, c]);
>
> sub g {
> my $stuff = shift;
> print "@stuff\n";
> }
>
> sub f {
> my $arg = shift;
> g("$arg"); # WRONG BAD OUCH
> }
Did you mean?
sub g {
my $stuff = shift;
print "@{$stuff}\n"; # or perhaps just $stuff
}
As written, g() isn't much use in illustrating you've stringified
that array reference.
--Chris
--
Chris Schleicher Office: 541/346-3998
Univ of Oregon CIS GTF email: chrissch@cs.uoregon.edu
URL: http://www.cs.uoregon.edu/~chrissch/
------------------------------
Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Jan 97)
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.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
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 V7 Issue 959
*************************************