[9616] in Perl-Users-Digest
Perl-Users Digest, Issue: 3210 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 21 01:07:14 1998
Date: Mon, 20 Jul 98 22:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 20 Jul 1998 Volume: 8 Number: 3210
Today's topics:
Re: (Semi-)Repeatable SDBM problem in v5.004_04 and Sun <s-max@pacbell.net>
[Q] #$number #number? <ryan@steelplan.com.au>
Re: [Q] #$number #number? (Larry Rosler)
Re: [Q] #$number #number? (Martien Verbruggen)
Re: [Q] #$number #number? (Andrew M. Langmead)
Best perl book for web programming <cbob@isource.net>
Best perl book for web programming <cbob@isource.net>
Best perl book for web programming <cbob@isource.net>
Best perl book for web programming <cbob@isource.net>
Re: Bug in regex quantifiers? (Larry Rosler)
Re: Bug in regex quantifiers? (Ronald J Kimball)
Re: Bug in regex quantifiers? (Abigail)
Re: Cant figure pattern matching exp =~ (Martien Verbruggen)
Re: Cant figure pattern matching exp =~ (Larry Rosler)
Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. p <jdporter@min.net>
comp.lang.perl.announce redux #3 <gnat@frii.com>
copying data <ff@otis.arraycomm.com>
Fun with large hashes (Martin Gleeson)
Re: HELP : Integrating an Access DB with Perl <metcher@spider.herston.uq.edu.au>
Re: HELP: Internet Database Design questions... <sedgeco1@agso.gov.au>
Re: How to define a structure in PERL? (Gabor)
Re: how to pass by reference <mpersico@erols.com>
Re: How to tell if a scalar is a number? <ljz@asfast.com>
Re: Is 3484000000 a negative number ? <mpersico@erols.com>
Re: Is 3484000000 a negative number ? <ljz@asfast.com>
log file hell (j)
matching hash values Juli@my-dejanews.com
Re: matching hash values (Ronald J Kimball)
Re: matching hash values <thelma@alpha2.csd.uwm.edu>
need expert opinions (Zheng Yuan)
Re: need expert opinions (Ronald J Kimball)
Newbie question re: WWW & Databases (Marcia Josephson)
Re: novice Q; reading columns of numbers <mpersico@erols.com>
Re: Perl for IIS4 <mattdb@syntrillium.com>
Re: What is awk better at than perl? (Larry quote) <uri@sysarch.com>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Jul 1998 20:02:11 -0700
From: Scott Maxwell <s-max@pacbell.net>
Subject: Re: (Semi-)Repeatable SDBM problem in v5.004_04 and SunOS 5.5.1
Message-Id: <m3n2a39aa4.fsf@localhost.localdomain>
John Porter <jdporter@min.net> writes:
> Scott Maxwell wrote:
> >
> > I'm getting a semi-repeatable error (happens almost always, but not
> > always) using SDBM_File with Perl 5.004_04 and SunOS 5.5.1.
> >[...]
>
> Looks o.k. to me, and running it on my machine (SunOS 2.4) had
> no problems.
*Sigh* ... well, thanks for looking over it. More investigation
suggests that the problem occurs only when the file grows, so maybe
it's something in the combination of tmpfs and files with holes.
> > sub CountKeys {
> > return scalar(@{ [ keys %Db ] });
> > }
>
> That's horrible. It returns a list of all the keys, then gets
Ah, I'd confused evaluating a hash in a scalar context with evaluating
keys() in a scalar context. (I though keys() in a scalar context
returned the "used/total" string.) Thanks for setting me straight.
--
-------------------------+-----------------------------------------------------
R H L U Scott Maxwell: | perl -e '$\=".\n";Just();sub another{Perl()}sub Just
E A I X s-max@ | {another()}sub Perl{hacker()}sub hacker{$,=" ";print
D T N 5 pacbell.net | reverse map{$_=(caller($_))[3];s/.*:://;$_}(0..3)}'
------------------------------
Date: Tue, 21 Jul 1998 09:38:36 +0800
From: Ryan Snowden <ryan@steelplan.com.au>
Subject: [Q] #$number #number?
Message-Id: <35B3F11C.46DC9220@steelplan.com.au>
I saw this example a while back which was able to get the NUMBER of
characters stored in a variable by puching a hash in front of it (which
makes sense being a number hash).
I want to make everything 3-digit. That is, if $number is 1, I want to
make it 00$number (or 001). If $number was 22, I want to make it
0$number (or 022), etc etc. I was planning on doing this with
successive if () { } statements.. I only need 3 so it's not so bad.
Can anyone tell me how to get the number of characters of a variable?
Thanks
Ryan Snowden
------------------------------
Date: Mon, 20 Jul 1998 19:16:56 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: [Q] #$number #number?
Message-Id: <MPG.101d99efc4b1723d989733@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a courtesy copy sent to Ryan Snowden
<ryan@steelplan.com.au>.]
In article <35B3F11C.46DC9220@steelplan.com.au> on Tue, 21 Jul 1998
09:38:36 +0800, Ryan Snowden <ryan@steelplan.com.au> says...
> I saw this example a while back which was able to get the NUMBER of
> characters stored in a variable by puching a hash in front of it (which
> makes sense being a number hash).
This makes no sense. You may have seen something about the length of an
array.
> I want to make everything 3-digit. That is, if $number is 1, I want to
> make it 00$number (or 001). If $number was 22, I want to make it
> 0$number (or 022), etc etc. I was planning on doing this with
> successive if () { } statements.. I only need 3 so it's not so bad.
>
> Can anyone tell me how to get the number of characters of a variable?
The length() function will do that, but why bother? What you want (pad
to three digits with leading zeros) is done trivially by sprintf().
$result = sprintf '%.3d', $number;
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 21 Jul 1998 02:39:17 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: [Q] #$number #number?
Message-Id: <6p0v0l$1lm$2@nswpull.telstra.net>
In article <35B3F11C.46DC9220@steelplan.com.au>,
Ryan Snowden <ryan@steelplan.com.au> writes:
> I saw this example a while back which was able to get the NUMBER of
> characters stored in a variable by puching a hash in front of it (which
> makes sense being a number hash).
Not right. You can get the index of the last element of an array by
putting $# in front of the array identifier, like this:
my @array = qw( foo bar dada lala boo );
print "Last element at: $#array\n";
(I will not talk about the effect of $[, you can read about it if you
must)
The number of elements is available as @array in a scalar context.
The number of characters in a scalar can be found with the length builtin
> I want to make everything 3-digit. That is, if $number is 1, I want to
> make it 00$number (or 001). If $number was 22, I want to make it
> 0$number (or 022), etc etc. I was planning on doing this with
> successive if () { } statements.. I only need 3 so it's not so bad.
Don't! Do something like this instead:
my $num = 1;
my $formatted_num = sprintf("%03d", $num);
Suggested literature:
# perldoc -f length
# perldoc -f sprintf
# perldoc perldata
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 21 Jul 1998 04:09:24 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: [Q] #$number #number?
Message-Id: <EwFFJo.L05@world.std.com>
Ryan Snowden <ryan@steelplan.com.au> writes:
>I want to make everything 3-digit. That is, if $number is 1, I want to
>make it 00$number (or 001). If $number was 22, I want to make it
>0$number (or 022), etc etc. I was planning on doing this with
>successive if () { } statements.. I only need 3 so it's not so bad.
>Can anyone tell me how to get the number of characters of a variable?
For formatted numbers, think of using the printf or sprintf functions.
printf '%03d', $number;
I was just going to refer you to the perlfunc man page for the
function that returns the length of a scalar, but then I realized
there was nothing in your article to imply that you even know what
functions are. If thats true, you are probably do very welll for
yourself if you picked up a perl tutorial book like "Learning
Perl". On the other hand, if you do know what a function is, its easy
enough to read the perlfunc man page to find one to do whatever you
want it to.
--
Andrew Langmead
------------------------------
Date: Mon, 20 Jul 1998 22:53:46 -0500
From: John <cbob@isource.net>
Subject: Best perl book for web programming
Message-Id: <35B410CA.B700BE49@isource.net>
Programming Perl is the only book that I've looked at, and it seems ok.
How does it compare to the other books on the market. If all I'm going
to be doing is web programming, should I spend my money on this book or
on a different "aftermarket" book more tailored to the internet?
------------------------------
Date: Mon, 20 Jul 1998 22:57:43 -0500
From: John <cbob@isource.net>
Subject: Best perl book for web programming
Message-Id: <35B411B7.6ECE3E1B@isource.net>
Programming Perl is the only book that I've looked at, and it seems ok.
How does it compare to the other books on the market. If all I'm going
to be doing is web programming, should I spend my money on this book or
on a different "aftermarket" book more tailored to the internet?
------------------------------
Date: Mon, 20 Jul 1998 22:55:18 -0500
From: John <cbob@isource.net>
Subject: Best perl book for web programming
Message-Id: <35B41125.6AA85A77@isource.net>
Programming Perl is the only book that I've looked at, and it seems ok.
How does it compare to the other books on the market. If all I'm going
to be doing is web programming, should I spend my money on this book or
on a different "aftermarket" book more tailored to the internet?
------------------------------
Date: Mon, 20 Jul 1998 22:59:26 -0500
From: John <cbob@isource.net>
Subject: Best perl book for web programming
Message-Id: <35B4121D.E9FA1329@isource.net>
Programming Perl is the only book that I've looked at, and it seems ok.
How does it compare to the other books on the market. If all I'm going
to be doing is web programming, should I spend my money on this book or
on a different "aftermarket" book more tailored to the internet?
------------------------------
Date: Mon, 20 Jul 1998 19:11:24 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Bug in regex quantifiers?
Message-Id: <MPG.101d98a81091cf60989732@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and a courtesy copy sent to Matt Pryor
<matt@whiterabbit.co.uk>.]
In article <35B3EE57.70459BA2@whiterabbit.co.uk> on Tue, 21 Jul 1998
02:26:47 +0100, Matt Pryor <matt@whiterabbit.co.uk> says...
> And my reply (to give Randal the opportunity of slapping my wrists)
Why Randal? I'll be glad to (very gently, because it is OK). :-)
> Bryan Miller wrote:
>
> > but what if my string looks like
> >
> > $patch_num = "PHKL_12345"
>
> Then you'd use something like /^[a-zA-Z]{4}_[\d]{5}$/
/^[a-zA-Z]{4}_\d{5}$/
\d is the same as [\d] or [0-9]
> or if a possible number was contained within a larger string:
>
> $patchnum = "My number is MATT_00491. Is that correct?";
> print "You entered:\n$patchnum\n\n";
> $useful_bit = $patchnum; # in case we want to keep the orig.
> if ($useful_bit =~ s/.*?([a-zA-Z]{4}_[\d]{5}).*/$1/) {
> print "Your number is $useful_bit.\n";
if ($patchnum =~ /[a-zA-Z]{4}_(\d{5})/) {
print "Your number is $1.\n";
with ^ and $ anchors if desired. Why copy and mash $patchnum if you
don't need to? (I've placed the parentheses to capture the number part
only.)
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 21 Jul 1998 00:14:21 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Bug in regex quantifiers?
Message-Id: <1dchp5e.u9d06s2m2th8N@bay1-103.quincy.ziplink.net>
Bryan Miller <millerb@millerb.fc.hp.com> wrote:
> my $patch_num = "123456789";
>
> if ($patch_num !~ /[0-9]{3,4}/) {
> print "Patch number too small/big.\n",
> }
Here's another solution...
if ($patch_num !~ /(?:^|\D)\d{3,4}(?:\D|$)/) {
Match either the beginning of the string or a non-digit, followed by 3
or 4 digits, followed by a non-digit or the end of the string.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 21 Jul 1998 04:21:35 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Bug in regex quantifiers?
Message-Id: <6p150f$msc$1@client3.news.psi.net>
Matt Pryor (matt@whiterabbit.co.uk) wrote on MDCCLXXXV September MCMXCIII
in <URL: news:35B3EE57.70459BA2@whiterabbit.co.uk>:
++ And my reply (to give Randal the opportunity of slapping my wrists)
++
++ Bryan Miller wrote:
++
++ > but what if my string looks like
++ >
++ > $patch_num = "PHKL_12345"
++
++
++ Then you'd use something like /^[a-zA-Z]{4}_[\d]{5}$/
++
++ or if a possible number was contained within a larger string:
++
++ $patchnum = "My number is MATT_00491. Is that correct?";
++ print "You entered:\n$patchnum\n\n";
++ $useful_bit = $patchnum; # in case we want to keep the orig.
++ if ($useful_bit =~ s/.*?([a-zA-Z]{4}_[\d]{5}).*/$1/) {
++ print "Your number is $useful_bit.\n";
++ } else {
++ print "Your number isn't recognised.\n";
++ }
But that assumes the specific 'ABCD_" prefix, and it will still
match ABCD_123456789, because "ABCD_12345" matches [a-zA-Z]{4}_[\d]{5}.
If you want to match 100 - 9999 in a string, and you don't know what
else can be there:
1) The two stepped approach:
/(\d+)/ && 100 <= $1 && $1 < 10000
2) A variation:
/(\d{3,})/ && $1 < 10000
3) The single regex:
/(?:\A|\D)\d{3,4}(?!\d)/
Which means "match 3 to 4 digits that follow either a non-digit
or the beginning of the string, and which aren't followed by a
digit".
4) The mixed approach:
/(\d{3,5})/ && $1 < 10000;
This has the advantage over the first approach that it doesn't
spend too much time making a long match if the string to match
contains hundreds of digits.
5) Two regexes:
/\d{3,4}/g && ! /\G\d/g;
This doesn't rely on any special meaning of digits and can easily
be adapted for matching 3 or 4 successive vowels or other chars.
Note however, that certain approaches might give false negatives,
depending on what you want.
Method
String 1 2 3 4 5
23 foo 234 No Yes Yes Yes No
12345 foo 234 No No Yes No No
Before choosing what method to use to determine whether a string contains
the appropriate number, one should also answer the question what the
method should yield on strings like "23 foo 234". Another thing that can
influence the right approach is whether pos() is going to be used or not.
#!/usr/local/bin/perl -w
use strict;
my @strings = ("23 foo 234", "12345 foo 234");
my @pats = (sub {local $_ = shift; /(\d+)/ && 100 <= $1 && $1 < 10000},
sub {local $_ = shift; /(\d{3,})/ && $1 < 10000},
sub {local $_ = shift; /(?:\A|\D)\d{3,4}(?!\d)/},
sub {local $_ = shift; /(\d{3,5})/ && $1 < 10000},
sub {local $_ = shift; /\d{3,4}/g && ! /\G\d/g});
my ($format1, $format2) = (" %-20s", "%3s ");
printf $format1, "";
printf " Method";
print "\n";
printf $format1, "String";
foreach (1 .. @pats) {printf $format2, $_}
print "\n\n";
foreach my $str (@strings) {
printf $format1, $str;
foreach my $pat (@pats) {
printf $format2, $pat -> ($str) ? "Yes" : "No";
}
print "\n";
}
__END__
--
perl -wleprint -eqq-@{[ -eqw+ -eJust -eanother -ePerl -eHacker -e+]}-
------------------------------
Date: 21 Jul 1998 02:32:44 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Cant figure pattern matching exp =~
Message-Id: <6p0ukc$1lm$1@nswpull.telstra.net>
In article <6p0rh1$ao1$1@winter.news.erols.com>,
"David Waffen" <dmwaff@erols.com> writes:
> while (<IN>) {
> if (/^realname: /) { $realname=(split("realname: ",$_))[1]; }
> $_ =~ s? ??g;
> if (/^uid:/) { $uid=(split(":",$_)) [1]; }
> elsif (/^gid:/) { $gid=(split(":",$_)) [1]; }
> elsif (/^home:/) {$homedir=(split(":",$_)) [1]; }
> }
This might win the prize for ugliest and nastiest code of this year :).
> I understand the begin with realname, uid, gid, home and split is storing
> values in variables,
> BUT what is happening with the $_ =~ s? ??g;
This is equivalent to
s/ //g;
or
s| ||g;
I guess that is where your confusion originates. You are not
_matching_, you are replacing.
it simply replaces all occurrences of a space with nothing.
An aside: You are aware that you will have the end-of-line character
in the variables after this?
Suggested literature:
# perldoc perlop
# perldoc perlre
# perldoc perlfunc
Martien
PS. Now, I wonder why the author of that piece of perl had no problem
implicitly matching, but did have problems implicitly replacing in $_,
or splitting $_.
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Mon, 20 Jul 1998 20:16:25 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Cant figure pattern matching exp =~
Message-Id: <MPG.101da7e7f6220241989771@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc; copy mailed to Martien Verbruggen
<mgjv@comdyn.com.au>.]
In article <6p0ukc$1lm$1@nswpull.telstra.net> on 21 Jul 1998 02:32:44
GMT, Martien Verbruggen <mgjv@comdyn.com.au> says...
...
> > BUT what is happening with the $_ =~ s? ??g;
>
> This is equivalent to
>
> s/ //g;
> or
> s| ||g;
Almost equivalent :-). It can match only once, unless/until 'reset' is
executed in the same package. See a recent thread on this bit of arcana.
'perlop' says "This usage is vaguely deprecated, and may be removed in
some future version of Perl." but I doubt it.
--
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Mon, 20 Jul 1998 21:07:14 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Coding Quiz (was Re: efficiency: print<<"xxx" vs. print)
Message-Id: <35B3B305.59F1@min.net>
> >Bonus: What is the OPPOSITE of spaghetti code?
Lisp.
--
John Porter
------------------------------
Date: 20 Jul 1998 21:49:40 -0600
From: Nathan Torkington <gnat@frii.com>
Subject: comp.lang.perl.announce redux #3
Message-Id: <5qn2a3kgmj.fsf@prometheus.frii.com>
So, the vocal comp.lang.perl.misc folks seem to have several
attributes:
- want commercial vs non-commercial tagged
- want productivity vs misc. application tagged
- don't want to see CGI programs
Bear in mind that tagging really only works on *either* productivity
*or* commercial. If you can suggest a way for both to be tagged,
without massively long subject lines, please do.
So, how about a questionnaire? I don't care if you mail 'em to
me or post 'em to the group. I'll summarize those I get in email.
I just want to see how (most?) people feel.
I want the comp.lang.perl.announce moderator to:
Tag Commercial Posts [ ]
Tag Unproductive :-) Posts [ ]
Not Approve CGI Posts [ ]
Cheers;
Nat
(Just Get On With It Already [X])
------------------------------
Date: Tue, 21 Jul 1998 03:51:37 GMT
From: Farhad Farzaneh <ff@otis.arraycomm.com>
Subject: copying data
Message-Id: <vu90ln6euu.fsf@otis.arraycomm.com>
Hello,
What's a good way to do multi-dimensional array copies?
Here's a snippet that confused me:
----------------------------------------
@b = ( [1, 2, 3], [2, 3, 4] );
print "b = ",@b,"\n";
$d = new();
print "d = ",@$d,"\n";
$d->[1][0] = 20;
print "b[1][0] = ",$b[1][0],"\n";
sub new {
my @c = @b;
return \@c;
}
----------------------------------------
When run, this prints :
b = ARRAY(0x9b050)ARRAY(0x9ab04)
d = ARRAY(0x9b050)ARRAY(0x9ab04)
b = 20
At some level this does make sense, because the contents of b are of course
pointers to anonymous arrays. But I want to copy the whole array. Do I
have to loop to do this?
--
Farhad
------------------------------
Date: Tue, 21 Jul 1998 13:33:16 +1000
From: gleeson@unimelb.edu.au (Martin Gleeson)
Subject: Fun with large hashes
Message-Id: <gleeson-ya02408000R2107981333160001@news.unimelb.edu.au>
Hi Folks,
I'm working with some large hashes, which are created by tie'ing
to Berkeley DB's. My problem is that I'm getting a strange error when
stepping through them. Here's an example of the code (it does something
other than print, but that's not the problem):
#!/usr/local/bin/perl -s
use Fcntl;
use DB_File;
use strict;
my $db_file = $ARGV[0];
my (%db, $key, $val);
tie %db, 'DB_File', $db_file, O_RDONLY, 0644, $DB_HASH
or die "Couldn't tie to $db_file: $!\n";
while(($key,$val) = each %db) {
print "Key: [$key] Val: [$val]\n";
}
untie %db;
exit(0);
Running this gives the error:
Allocation too large at ./foo.pl line 13.
Line 13 is the 'while' line. It got 35,097 items through the hash before
dying with this error. The error is described in the blue camel as
"You can't allocate more than 64K on an MS-DOS machine". Well, I'm
not on an MS-DOS machine (nor am I likely to ever be :), and perl -v
says: "This is perl, version 5.004_04 built for alpha-dec_osf". It's on
an AlphaServer 4100.
I changed the while line to the older, nastier way of traversing a
hash, and it works fine! Prints out all 55,000+ items.
- while(($key,$val) = each %db) {
+ foreach $key (keys(%db)){
+ $val = $db{$key};
I'm using the while/each convention because the blue camel told me to
prefer 'each' to 'keys' for space efficiency when order doesn't matter
(p543). It even cites this specific situation in the second paragraph
on p310.
Any ideas? Is there anything else I should look at, have I provided enough
info, am I missing something, or is it just me?
Cheers,
Marty.
--
Martin Gleeson
** Personal opinion only **
Webmaster, The University of Melbourne, Australia.
Imagine, if you will, a world without hypothetical situations...
------------------------------
Date: Tue, 21 Jul 1998 13:33:00 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: HELP : Integrating an Access DB with Perl
Message-Id: <35B40BEC.7C44FB5F@spider.herston.uq.edu.au>
No, no! Sorry Sean, but somebody before you posted the correct answer -
Win32::ODBC. You could write a script using ODBC in the same time that
you took writing the script to parse the ASCII file - *and* you'd save
yourself the import/export time and aggravation.
Aside:
If you really like ASCII files (and, let's face it, who doesn't?), why
not leave the table in ASCII format? Perl is happy, and Access will
cope with linking to an ASCII file.
--
Jaime Metcher
Sean P. Sitter wrote:
>
> This post is a bit alte, but....
> I just did a similiar thing (acces DB with perl). The easiest way to go
> about this is to have access export the DB file into an ascii field
> delimited file. I like to use semicolon's as the delimiter. Then, each
> field of the DB is on one line and each separated value represents a
> field. Then, if you want your perl script to write to the DB, you can
> simply use the same delimiters and have it print values into a single
> line where the fields are separated by these delimiters. Then simply
> import the delimited file into access if you want to view it or use it
> outside of the script. E-mail me if you're confused
>
> -Sean
------------------------------
Date: Tue, 21 Jul 1998 13:14:56 +1000
From: Suzanne Edgecombe <sedgeco1@agso.gov.au>
Subject: Re: HELP: Internet Database Design questions...
Message-Id: <35B407B0.3AB80496@agso.gov.au>
- wrote:
> No, I don't make fun of the silly users, as long as they don't try to
> make technical decisions and I don't try to make unqualified decisions
>
> about their jobs, we get along quite nicely. Of course, drawing an
> annual salary well beyond that of most of the "users" makes it a bit
> easier to stomach some of the ridiculous stuff I encounter on a daily
> basis. I never dreamed I'd be earning WELL over 150K a year before I
> even turned 30. And as for lonely, well.... If I was, I don't think
> I would be for long with the kind of money I'm making. After 28
> months at this ungodly salary, I still have trouble believing it, or
> even spending it all.
hmm.... your "ungodly salary" may well reflect not the level of your
abilities and intelligence, but rather the naivity of the person paying
your way. And despite your "wealth" you still have alot to learn. Grow
up little boy!!
------------------------------
Date: 21 Jul 1998 02:03:12 GMT
From: gabor@vmunix.com (Gabor)
Subject: Re: How to define a structure in PERL?
Message-Id: <slrn6r7tqh.60.gabor@localhost.vmunix.com>
In comp.lang.perl.misc, Meena Chockalingam <cmeena@hotmail.com> wrote :
# Hi All,
#
# I have the following structure defined in C.
#
# typedef struct
# {
# int i_name;
# char slot0[20];
# char slot1[20];
# .... ......
# char slot23[20];
# }iNameSlot;
# ;
# iNameSlot interface[80]
#
# How can I do this in PERL?
Use an array of hashes.
------------------------------
Date: Mon, 20 Jul 1998 22:29:16 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: how to pass by reference
Message-Id: <35B3FCFC.775B5BB7@erols.com>
M.J.T. Guy wrote:
>
> [snip]
> Shhh! Don't tell anyone, but the secrets of the Temple Lore have been
> revealed in perlsub:
>
> [snip]
> The array @_ is a local array, but its elements are aliases for
> the actual SCALAR (emphasis Matthew O. Persico) parameters.
Which does SQUAT if you want to pass an array or hash. Then, you need to
pass and explicit reference. Otherwise, the array or hash will be
flattened out.
------------------------------
Date: 21 Jul 1998 00:17:30 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: How to tell if a scalar is a number?
Message-Id: <ltpvezvnvp.fsf@asfast.com>
eharley@pacbell.net (Eric Harley) writes:
> In article <6oti81$i48$1@csnews.cs.colorado.edu>, tchrist@mox.perl.com
> (Tom Christiansen) wrote:
>
> Try that regexp on for size.
>
> while (<>) {
> chomp;
> if (/^[-+]?(([0-9]+)|([0-9]*\.[0-9]+)([eE][+-]?[0-9]+)?)$/) {
> print "$_ number\n";
> } else {
> print "$_ not number\n";
> }
> }
Well, the original poster asked for a test to see if a scalar consists
of all digits. Your regexp attempts to see if it's in the form of any
kind of number. But if this is what you actually want to test for,
then how about something like the following? ...
sub isNumber {
my $n = shift;
local $noError = 1;
local $SIG{__WARN__} = sub { $noError = undef };
eval { my $x = $n + 0 };
return ($noError);
}
This only works when the `-w' flag is set, by the way.
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: Mon, 20 Jul 1998 22:00:38 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
To: Michael Pavlov <misha@etsd.ml.com>
Subject: Re: Is 3484000000 a negative number ?
Message-Id: <35B3F646.3CD90F01@erols.com>
No, you've just exceeded the maximum allowed integer value. An int is
(usually) represented by n-1 bits of an n-bit word with the remaining
bit reserved for the sign. Let's take a simple example:
8bits: 128 64 32 16 8 4 2 1
0 0 0 0 0 0 0 0 0
127 0 1 1 1 1 1 1 1
-127 1 1 1 1 1 1 1 1
-1 1 0 0 0 0 0 0 1
If you don't allow for negatives (unsigned in languages like 'C') then
129 is represented as:
129 1 0 0 0 0 0 0 1 (128 + 1)
You did the equivilient of sticking a 129 into an 8-bit signed int. It
dutifully set the bits on the way in, but the interpretation is
different on the way out.
Michael Pavlov wrote:
>
> Here is a quick one:
>
> #!/usr/local/etsd/ged/bin/perl
> $x = 3484000000;
> if ($x < 0 )
> {
> print("is negative\n");
> }
> else
> {
> print("it is pos\n");
> }
>
> $x = 348000;
>
> if ($x < 0 )
> {
> print("is negative\n");
> }
> else
> {
> print("it is pos\n");
> }
>
>
> Produced on machine with perl 5.02
>
> is negative
> it is pos
>
> Produced on machine with perl 5.04
> it is pos
> it is pos
>
> Is this a bug ?
------------------------------
Date: 20 Jul 1998 22:50:33 -0400
From: Lloyd Zusman <ljz@asfast.com>
Subject: Re: Is 3484000000 a negative number ?
Message-Id: <lt3ebvx6h2.fsf@asfast.com>
"Matthew O. Persico" <mpersico@erols.com> writes:
> No, you've just exceeded the maximum allowed integer value. An int is
> (usually) represented by n-1 bits of an n-bit word with the remaining
> bit reserved for the sign. Let's take a simple example:
>
> [ ... deleted to save space ... ]
That's an excellent explanation, but unfortunately, it doesn't account
for why Mr. Pavlov got different results using different versions of
Perl, as he mentioned:
> Michael Pavlov wrote:
> >
> > [ ... ]
> >
> > Produced on machine with perl 5.02
> >
> > is negative
> > it is pos
> >
> > Produced on machine with perl 5.04
> > it is pos
> > it is pos
> >
> > [ ... ]
There might a difference between the Perl versions 5.002 and 5.004
(note the double zeros in the version numbers) in terms of how they
each handle large numbers. Is this possible?
Were the two tests run on different machines with different
architectures? If so, which two machines and OS's? Could this
account for the anomaly?
--
Lloyd Zusman ljz@asfast.com
perl -e '$n=170;for($d=2;($d*$d)<=$n;$d+=(1+($d%2))){for($t=0;($n%$d)==0;
$t++){$n=int($n/$d);}while($t-->0){push(@r,$d);}}if($n>1){push(@r,$n);}
$x=0;map{$x+=(($_>0)?(1<<log($_-0.5)/log(2.0)+1):1)}@r;print"$x\n"'
------------------------------
Date: Tue, 21 Jul 1998 02:29:21 GMT
From: jjones@nospam.elementdesign.com (j)
Subject: log file hell
Message-Id: <35b3fbbe.185910@nntp.best.com>
I'm tinkering with an apache logfile parser/stats script...
Works great, if the access.log is small, like under 3 or 4 megs.
Earlier, I tried using it on an access.log that was about 30 megs...
it still worked, but it took quite a long time and took up almost all
of my system resources.
The way I'm reading from these logfiles may be a bit silly, but it's
the only way I know how right now, and was wondering if some of you
could shed some light on how I can speed it up a bit, and have it not
take up so many system resources.
The way I'm reading the access.log files right now is just like this:
open(LOG, "access.log") or die "cannot open access.log: $!";
while (<LOG>) {
do stuff...
...
...
...
}
close(LOG);
How could I make this more efficient? Any help appreciated.
Thanks.
j
------------------------------
Date: Tue, 21 Jul 1998 03:27:30 GMT
From: Juli@my-dejanews.com
Subject: matching hash values
Message-Id: <6p11r2$nsj$1@nnrp1.dejanews.com>
while (defined ($line = <FILE>) ) {
foreach $key (keys %in) {
if ($key =~ /\bfoo\b/) {
if ($in{$key} =~ /$line/ ) {
push (@thefile, $line);
}
}
}
}
What I am doing is reading in a file, line by line
The key/value pairs are coming from a form
Foreach key in %in
If the key matches the pattern foo
If the value of that key matches a line in the file
write line to the array......
The first key match works fine,
but I am not able to match the value
Any help is appreciated.
Juli@my-dejanews.com
Ex:
File - while (defined ($line = <FILE>) ) {
CIA OPEN BLUE foreach $key (keys %in) {
FBI UP GREEN if ($key =~ /\bMAN\b/) {
Key / Value pair - if ($in{$key} =~ /$line/ ) {
MAN=CIA push (@thefile, $line);
DOOR=OPEN
COLOR=GREEN
So if the key is MAN, the value is CIA, CIA matches CIA on the line, so the
entire line should be pushed to the array, but I'm having a real hard time
with the value......
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Tue, 21 Jul 1998 00:14:25 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: matching hash values
Message-Id: <1dchpfa.1w11o424peyoN@bay1-103.quincy.ziplink.net>
[posted and mailed]
<Juli@my-dejanews.com> wrote:
> while (defined ($line = <FILE>) ) {
> foreach $key (keys %in) {
> if ($key =~ /\bfoo\b/) {
> if ($in{$key} =~ /$line/ ) {
> push (@thefile, $line);
> }
> }
> }
> }
> [...]
> but I am not able to match the value
Do you want to match newlines in the values? If not, try inserting
chomp($line);
as the first line in the while loop. That will remove the newline
character from the end of $line.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: 21 Jul 1998 04:32:31 GMT
From: Thelma Lubkin <thelma@alpha2.csd.uwm.edu>
Subject: Re: matching hash values
Message-Id: <6p15kv$ogc$1@uwm.edu>
Juli@my-dejanews.com wrote:
: while (defined ($line = <FILE>) ) {
: foreach $key (keys %in) {
: if ($key =~ /\bfoo\b/) {
: if ($in{$key} =~ /$line/ ) { <---------------------------
: push (@thefile, $line); \
: } \
: } ||
: } ||
: } \/
This looks for $line within
key--you'd like
$line =~ $in{key}: lines
that contain the value of key.
--thelma
: Juli@my-dejanews.com
: -----== Posted via Deja News, The Leader in Internet Discussion ==-----
: http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: 20 Jul 1998 23:28:44 -0400
From: zyuan@hercules.acsu.buffalo.edu (Zheng Yuan)
Subject: need expert opinions
Message-Id: <6p11tc$sp7$1@hercules.acsu.buffalo.edu>
I have a very large database which people access via a perl script. The
problem is that when there are 25 people accessing this database at the
same time the server chokes: If accessed by one person the system is very
quick at retrieving the results, but when more try searching, it seems
there are so many processes going on, the server slows to almost a stand
still.
Right now when searching in the database I am doing this:
open(LINK, "<myfile.dat");
while ($item = <LINK>) {
#search for a specific string
}
close LINK;
Because my database is over 150000 records and 50 megs, this process can
take a very long time which I wish I could speed up as well. I can't
simply read all this into an array as it would eat up all memory.
Any suggestions?
Thanks in advance for your help,
Jenn
------------------------------
Date: Tue, 21 Jul 1998 00:14:27 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: need expert opinions
Message-Id: <1dchpjv.y80bhevnyezkN@bay1-103.quincy.ziplink.net>
Zheng Yuan <zyuan@hercules.acsu.buffalo.edu> wrote:
> Because my database is over 150000 records and 50 megs, this process can
> take a very long time which I wish I could speed up as well. I can't
> simply read all this into an array as it would eat up all memory.
Look up the tie function and the AnyDBM_File module, and see if they
suit your needs.
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Tue, 21 Jul 1998 04:12:23 GMT
From: mjedc@netcom.com (Marcia Josephson)
Subject: Newbie question re: WWW & Databases
Message-Id: <mjedcEwFFon.51s@netcom.com>
I am working with a static database backing a web page. Portability
(hopefully back to UNIX :-) is an issue, but it must work on NT. The
question is should I use Berkley DB (or SDBM since its static) or use
DBI? How fast would SDBM be for databases upto about 5-10MB on the web
server? Since I am locked into MS SQL Server 6.5, how reliable is the ODBC
driver for DBI on Win32? I would greatly appreciate any comments,
suggestions...
------------------------------
Date: Mon, 20 Jul 1998 22:10:48 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
To: isifuelo@my-dejanews.com
Subject: Re: novice Q; reading columns of numbers
Message-Id: <35B3F8A8.5659A044@erols.com>
Way too complicated. I give you pseudo-code, you track down the real
calls (cause I don't have Perl docs on this machine):
For each line read in {
substitiute nothing for the commas (read the RegExp docs)
@array = split the line on whitespace (read the split docs)
$newLine = join /,/, @array ## This puts them back together
push @lines, $newLine ## This saves the line
}
Now the sort is tricky because the date is wrong for ordering. Can't
code it, again, without my handy-dandy docs. In theory, you could simply
change the fist column to YY/MM/DD format. Then a simple sort would
work. But you probably want to keep the old format.
So maybe you dup col#1 to the end of the line, change col#1, sort and
then restore.
Anyone else got any brighter ideas?
Yes, there are probably more terse ways of doing this, but let's walk
before we run.
isifuelo@my-dejanews.com wrote:
>
> I'm trying to read html file which contains 6 columns seperated by spaces
> [deleted html stuff]
> A B C D E F
> 1/05/98 25.545 25.875 26.225 25.323 2,790,245
> 1/02/98 25.000 25.375 25.750 25.063 2,566,445
> 12/31/97 25.225 24.938 25.545 24.625 3,242,645
> ^--------------------------------^ move here
> I'd like to reformat above so numbers are seperated using commas,
> commas removed from numbers (1,234,567 -> 1234567), column B moves
> after E, and dates reveresed (line with old date at the beginning of file).
>
> output should look like:
> 12/31/97......
> 1/02/98,25.875,26.225,26.225,25.000,2790245
> 1/05/98,...
>
> I'm trying to match...
> (\d(\d)?)/(\d(\d)?)/(\d\(d)?)\s([0-9]+(\.[0-9]*)?)\s([0-9]+(\.[0-9]*)?)\s([0-
> 9]+(\.[0-9]*)?)\s([0-9]+(\.[0-9]*)?)\s([0-9]*) i dont know how to do last
> column (number with commas) is that right? what other stuff i need to make it
> a perl program (using perl on win95).
>
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Mon, 20 Jul 1998 20:50:08 -0700
From: Matt Bieber <mattdb@syntrillium.com>
Subject: Re: Perl for IIS4
Message-Id: <35B40FF0.4D778AE9@syntrillium.com>
Perhaps if you posted some sample of what you're doing we could help. Your
problem can have many causes...
Matt
Mike Wesolowski wrote:
> Has anybody gotten I/O redirection working in Perl for IIS4 running on a NT
> box?
>
> I am having trouble passing webform data back to perl to process. My
> webform ask for info and I want to store that info in a file on the NT box
> but it seems the the i/o direction isn't being passed back as the values are
> null.
>
> Can anyone help me out?
>
> Thanks
>
> Mike Wesolowski
> Systems Admin
> Milwaukee Housing Authority
> mwesol@hacm.org
------------------------------
Date: 20 Jul 1998 22:59:53 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: What is awk better at than perl? (Larry quote)
Message-Id: <x7af63nc2e.fsf@sysarch.com>
>>>>> "TC" == Tom Christiansen <tchrist@mox.perl.com> writes:
TC> [courtesy cc of this posting sent to cited author via email]
TC> In comp.lang.perl.misc,
TC> Uri Guttman <uri@sysarch.com> writes:
TC> :this wish has been discussed before. since perl's re can do so many
TC> :powerful things, it can lead into deep re recursion that will not return
TC> :in your lifetime.
TC> Recursion in not necessary for that. Solving regexes with backreferences
TC> is an exponential problem, which is itself a problem.
TC> --tom
but managing backreferences would involve going up/down the backtracking
tree which is (real or logical) recursion. so it is a question of
choosing terms rather than anything else.
and anyhow ilya (IIRC) has said that this feature will be in 5.005, so
it is moot about how deep perl will go with $/ being a regex. it will go
as deep as you tell it to.
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed 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 V8 Issue 3210
**************************************