[18941] in Perl-Users-Digest
Perl-Users Digest, Issue: 1136 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 14 18:05:44 2001
Date: Thu, 14 Jun 2001 15:05:11 -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: <992556311-v10-i1136@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 14 Jun 2001 Volume: 10 Number: 1136
Today's topics:
Re: 2 questions about flock <skilchen@swissonline.ch>
Re: 2Gb+ files (was: can you do while (<HANDLE>) inside <Gala@nonono.com>
Re: accuracy on $i on for($i=0;$i<=1;$i++) (zero the hero)
Re: accuracy on $i on for($i=0;$i<=1;$i++) (isterin)
Re: accuracy on $i on for($i=0;$i<=1;$i++) <bart.lateur@skynet.be>
Re: An ever unwanted growing array??? (zero the hero)
Re: Foreach Not Behaving Properly (Barry Allwood)
hash resources <rrauer@mitre.org>
Re: hash resources <bart.lateur@skynet.be>
Re: Help with split?vvp (Steven)
Re: initialising multi-dimensional array <m.grimshaw@salford.ac.uk>
Re: initialising multi-dimensional array <m.grimshaw@salford.ac.uk>
Re: initialising multi-dimensional array (Ben Okopnik)
Looking for good tutorial/book on Perl programming. <ufnitehawk@yahoo.com>
Re: Looking for good tutorial/book on Perl programming. (E.Chang)
Re: Looking for good tutorial/book on Perl programming. <EvR@compuserve.com>
Re: Memory Issues/File Slurping (Doug McGrath)
Re: Multiplexing stdin and stderr to screen and logfile <nospam@hotmail.com>
Re: Negative lookahead not working (Sweth Chandramouli)
Re: Negative lookahead not working <morgan@hahaha.org>
Re: Negative lookahead not working <joe+usenet@sunstarsys.com>
Re: Negative lookahead not working <joe+usenet@sunstarsys.com>
Re: new to perl need help with concordance <iliilllli1@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 14 Jun 2001 22:05:49 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: 2 questions about flock
Message-Id: <9gbafq$7uv2i$1@ID-13368.news.dfncis.de>
"Mark Grimshaw" <m.grimshaw@salford.ac.uk> schrieb im Newsbeitrag
news:3B28C7D0.FB922302@salford.ac.uk...
> Anyone for the sync() question at the bottom?
>
> > my $db = new my_DB;
SoĻ$db holds a reference to an instance of your package my_DB;
> > $db->sync(); # flush output to DB
You probably have no sync() method defined in your package my_DB. So you
call an undefined method which causes your script to abort.
> > open_db() is a db tie method I've defined in an external package:
> >
> > sub open_db # tie %DB to db with supplied mode
> > {
> > shift;
> > my @input = @_;
> > my %DB;
> > tie(%DB, 'DB_File', $input[0], $input[1]) or return 0;
Here you need to store a copy of the object returned from the tie.
(See the section "THE API INTERFACE" in the DB_File manpage)
my $db_obj = tie(%DB, 'DB_File', $input[0], $input[1]) or return 0;
> > return \%DB;
and return it together with the tied hash reference
return ($db_obj, \%DB);
and then change your call to db_obpen to
($db_obj, $DB) = $db->open_db($db_file, O_RDWR|O_CREAT)))
then you should be able to call:
$db_obj->sync()
another possibility would go along these lines:
- store the object returned from tie in your my_DB instance
- implement a proxy method sync() in your my_DB package which
forwards the sync() call to the object returned from tie and
stored in the my_DB instance.
something like:
sub open_db # tie %DB to db with supplied mode
{
my $self = shift;
my ($file, $flags) = @_;
my %DB;
$self->{DB_OBJ} = tie(%DB, 'DB_File', $file, $flags) or return;
return \%DB;
}
sub sync()
{
my $self = shift;
return ${self->{DB_OBJ}}->sync();
}
> > Any idea what's up?
You might want to take a look at the BerkeleyDB module which gives you
access to the transactional and the builtin locking features of newer
Berkeley DB versions.
------------------------------
Date: Thu, 14 Jun 2001 20:31:38 GMT
From: "Gala" <Gala@nonono.com>
Subject: Re: 2Gb+ files (was: can you do while (<HANDLE>) inside opening a file twice?)
Message-Id: <Ka9W6.92532$%i7.67405785@news1.rdc1.sfba.home.com>
Ok I stand corrected. I guess I didnt think about all these big businesses/chain sotres/etc that could have massive
databases. It seems engines like MS Access and others can handle multi gig/terabyte DBs rather well. I'm guessing a simple
flat file of that size would be would be a lot more difficult to handle. Then again I could be wrong (wouldn't be the first
time ;p). Do you know???
I think its cool unix is getting ready for 64 bit! I am actually thinking about setting up a linux box. Prolly go with
RedHat. Or is there a better one?
To be honest I think I was a little arrogant to assume all that I did. I stand corrected.
Gala
"Andrew Hamm" <ahamm.NO$PAM@sanderson.NO$PAM.net.au> wrote in message news:3b26d927$1@news.iprimus.com.au...
> Gala wrote in message ...
> >
> >Ok.. a long is a 32 bit number, therefor goes up to of 4,294,967,295 -
> >about 4 gigs (unsigned), or, 2,147,483,647 - about 2 gigs (singed). Now
> >lets be realistic here. Is there a computer out there that has a file
> >thats 4 or 2 gigs big?
> >
> Oh, I could think of several dozen under my administration. A multi-gig
> space is routine these days in a large database system. Terabyte
> databases are now in existence and becoming more common. Places like KFC
> and Pizza Hut collect daily records from all the stores in a district.
> These records include cash register activity to the minute and include
> details such as what was purchased, how much was spent, the time of the
> day, whether any special deal vouchers were used to make the purchases,
> whether any specific "deal" was asked for and so on.
>
> I was told several years ago thru a loose connection to the place, that
> KFC even analyses details such as whether having a slide in the child-
> ren's playground has an effect on the profitability of the store.
>
> >(Damn that'd be a huge file!!! Bleh, just thinking about itterating
> >through a file that big just makes my stomach turn ;p)
> >
> This information is collected into huge "database warehouses" and
> analysed in an attempt to see which deals and vouchers work the best on
> which days and where. These databases are huge and a typical query
> against a warehouse will completely scan multiple tables and bang them
> together to get the results they are looking for.
>
> Apart from the fast food vendors, you can be sure that banks, insurance
> companies, financial institutions, etc etc etc etc etc are using huge
> databases of multi-gigabyte and even multi-terabyte sizes. Needless to
> say the data is grouped into files or spaces exceeding 2Gb.
>
> Tax departments and insurance companies are using terabyte database
> warehouses to detect patterns which suggest fraudulent activities are
> taking place. Medical research centres are using terabyte warehouses to
> detect adverse drug interactions. Health authorities are using terabyte
> warehouses to detect over-prescription and other medical crimes.
>
> Even disregarding the common-place activity of sequentially scanning
> large databse tables, intelligent database engine software is extremely
> powerful and capable of selecting individual records out of millions.
> And, certain other processes do run through large amounts of space
> sequentially. When you can achieve transfer rates of at least several
> Mb/sec INCLUDING the processing work going on, it doesn't take too much
> time. Archiving the database to tape is one example of this happening.
> If you setup a machine with striped sets of disks, you can multiply this
> transfer rate to whatever degree you need for your system.
>
> >No, really, I really doubt are files of that size.
> >
> On a home pc, sure, I'd agree with that.
>
> >My god, do you have any idea how slow a server would be if were to
> >process that file over and over (in for example a site where many users
> >visit, each calling the cgi that processes that file). I think a word
> >for that would be INSANE.
> >
> So you think the whole world is limited to web sites? Think again! Even
> with web sites, as those sites become larger and more mission critical
> to a business, the database engines I've mentioned are becoming more and
> more essential to maintain performance on the sites as more and more
> information and transactions are performed.
>
> >In over words I very much doublt anyone would have any trobble with
> >a file size bigger then a long can hold. Not to mention, most server
> >providers usally dont give more then 100 megs, or sometimes less,
> >depending on the provider and service, but theres no way in the 7th
> >circle of hell you are going to get anything even remotely close to
> >2 gigs. Unless you happen to own/host your own server with a big
> >hard drive.
> >
> Well, like I've already proven, files greater than 2G are trivial to
> create. I haven't got immediate access to a Linux system right now (I'm
> rebuilding my personal machine) but if you do, have a look at the
> definitions of the fpos_t datatypes. If you have sufficiently modern
> Linux, you'll find that it's now a structure that's bigger than a long.
> Hence, even a Perl long will soon be unsuitable to hold the return value
> from ftell. Very soon the Perl Porters will deal with this and we'll all
> have to adapt if the language is shifted that way.
>
> This change in the structure of fpos_t is because Linux is being
> prepared for 64 bit addressing. I hear that Linux is considered
> ready for the Intel 64 bit processor. HP-UX, DG/UX, AIX and many
> other professional UNIX have been made 64 bit ready and functional
> for a few years now. You can only buy a 64 bit processor from many
> of these vendors.
>
> >Even so, god forbid trying to display the entire file!!!!!!!
> >
> Yes, that would be a silly, breathless thing to do...
>
> --
> "Dis act ain't about lafter - it's about comedy" - Andrew Dice Clay
>
>
>
>
>
------------------------------
Date: 14 Jun 2001 11:22:24 -0700
From: christopher_brien@hotmail.com (zero the hero)
Subject: Re: accuracy on $i on for($i=0;$i<=1;$i++)
Message-Id: <3bcda11.0106141022.2d7ca5ec@posting.google.com>
Frederic Magnard <magnard@iap.fr> wrote in message news:<Pine.OSF.4.33.0106141633080.10445-100000@hautbrion>...
> Hello,
>
> As I type
> $ perl -e 'for ($i=0.1; $i<=1; $i+=0.01) {print "$i\n";}'
> I'm surprised to read the last lines on an DEC-osf machine:
> 0.690000000000001
> ...
> 0.??0000000000001
> ...
> 0.990000000000001
>
> and these lines on a linux (pentium 3) machine:
> 0.889999999999999999
> ...
> 0.??9999999999999999
> ...
> 0.999999999999999999
>
> What kind of error is that ? Or do I do something wrong ?
It's a "thinking that floating point numbers are accurate" error.
You can't get more accurate than a few about a dozen significant
digits when using floats. Which is why 1.0000001 - 0.0000001 !=
1.000000. It will also depend on the machines implementation of
floats.
If you can, try using integer arithmetic, at least for the loop
counter. Failing that, fixed point using some scaling factor should
work. I think there's a module somewhere (on CPAN) that will do that
for you.
Is there any reason why you need to use .001 increments?
------------------------------
Date: 14 Jun 2001 12:16:13 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: accuracy on $i on for($i=0;$i<=1;$i++)
Message-Id: <db67a7f3.0106141116.20730718@posting.google.com>
I believe that's the way your system represents floating numbers.
Each architecture has a little bit different output. Use sprintf
before outputting to limit the decimal points and therefore the result
should come out the same.
This is actually an expected bahavior.
HTH
Ilya
Frederic Magnard <magnard@iap.fr> wrote in message news:<Pine.OSF.4.33.0106141633080.10445-100000@hautbrion>...
> Hello,
>
> As I type
> $ perl -e 'for ($i=0.1; $i<=1; $i+=0.01) {print "$i\n";}'
> I'm surprised to read the last lines on an DEC-osf machine:
> 0.690000000000001
> ...
> 0.??0000000000001
> ...
> 0.990000000000001
>
> and these lines on a linux (pentium 3) machine:
> 0.889999999999999999
> ...
> 0.??9999999999999999
> ...
> 0.999999999999999999
>
> What kind of error is that ? Or do I do something wrong ?
>
> Thanks for any help,
>
> Fred.
>
> My perl version :
> $ perl -V
> Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
> Platform:
> osname=dec_osf, osvers=4.0, archname=alpha-dec_osf-thread-multi
> uname='osf1 trimoulet v4.0 1229 alpha '
> config_args='-Dprefix=/home/seguret4/groupamax/usr/perl'
> hint=recommended, useposix=true, d_sigaction=define
> usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
> useperlio=undef d_sfio=undef uselargefiles=define usesocks=undef
> use64bitint=define use64bitall=define uselongdouble=define
> Compiler:
> cc='cc', ccflags ='-pthread -std -fprm d -ieee -D_INTRINSICS -I/usr/local/include -DLANGUAGE_C',
> optimize='-O4',
> cppflags='-pthread -std -ieee -D_INTRINSICS -I/usr/local/include -DLANGUAGE_C'
> ccversion='V5.9-008', gccversion='', gccosandvers=''
> intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
> d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=8
> ivtype='long', ivsize=8, nvtype='long double', nvsize=8, Off_t='off_t', lseeksize=8
> alignbytes=8, usemymalloc=n, prototype=define
> Linker and Libraries:
> ld='ld', ldflags ='-L/home/seguret4/groupamax/usr/osf/lib -L/usr/local/lib'
> libpth=/home/seguret4/groupamax/usr/osf/lib /usr/local/lib /usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /var/shlib
> libs=-lgdbm -ldbm -ldb -lm -liconv -lutil -lpthread -lexc
> perllibs=-lm -liconv -lutil -lpthread -lexc
> libc=/usr/shlib/libc.so, so=so, useshrplib=false, libperl=libperl.a
> Dynamic Linking:
> dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' '
> cccdlflags=' ', lddlflags='-shared -expect_unresolved "*" -O4 -msym -std -s -L/home/seguret4/groupamax/usr/osf/lib -L/usr/local/lib'
>
>
> Characteristics of this binary (from libperl):
> Compile-time options: MULTIPLICITY USE_ITHREADS USE_64_BIT_INT USE_64_BIT_ALL USE_LARGE_FILES PERL_IMPLICIT_CONTEXT
> Built under dec_osf
> Compiled at Apr 13 2001 19:16:57
> %ENV:
> PERLLIB="/tmp_mnt/home/seguret4/groupamax/soft/lheasoft/OSF1_4.0_alpha/scripts"
> @INC:
> /tmp_mnt/home/seguret4/groupamax/soft/lheasoft/OSF1_4.0_alpha/scripts
> /home/seguret4/groupamax/usr/perl/lib/5.6.1/alpha-dec_osf-thread-multi
> /home/seguret4/groupamax/usr/perl/lib/5.6.1
> /home/seguret4/groupamax/usr/perl/lib/site_perl/5.6.1/alpha-dec_osf-thread-multi
> /home/seguret4/groupamax/usr/perl/lib/site_perl/5.6.1
> /home/seguret4/groupamax/usr/perl/lib/site_perl
> .
------------------------------
Date: Thu, 14 Jun 2001 20:04:37 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: accuracy on $i on for($i=0;$i<=1;$i++)
Message-Id: <8v5iitgu2ff4cf5d4v8kpcd4ukdbg1066r@4ax.com>
Frederic Magnard wrote:
>As I type
>$ perl -e 'for ($i=0.1; $i<=1; $i+=0.01) {print "$i\n";}'
>I'm surprised to read the last lines on an DEC-osf machine:
>0.690000000000001
You are? Hmmm...
What would you expect here?
for ($i=0; $i<=1; $i+=1/3) {print "$i\n";}
I don't think anybody expects exact results here. And why not? Because
1/3 can not be represented exactly in base 10 numbers. In base 3 or a
multiple thereof, representation COULD be exact.
So, what happens in your case, is that FP numbers that are negative
exponents of 10, can not be represented exactly in a base 2 system,
which is what the computer uses internally. So, with finite precision,
you get some rounding, away from the number you'd like to represent.
For better results, use an integer (which CAN be represented exactly)
for the loop counter, and divide it by 100. That result won't be exact,
but at least you won't get an accumulation of errors.
And oh, yes, this is in the FAQ. But other people will already have
pointed that out to you.
--
Bart.
------------------------------
Date: 14 Jun 2001 11:37:05 -0700
From: christopher_brien@hotmail.com (zero the hero)
Subject: Re: An ever unwanted growing array???
Message-Id: <3bcda11.0106141037.788c8e1b@posting.google.com>
Mark Stellaard wrote
>my @files = ();
>
>sub func_1 {
> my @list = ();
> @list = recursive($bar);
>}
>
>sub recursive($foo){
> if ($bla) { &recursive($temp); }
> else { push (@files, $foo); }
>
>return @files; # files array contains all found files in directory
structure.
>}
You REALLY shouldn't be using globals for a recursive function.
As far as I can tell, you want to check for some condition, and if
true, then return the value passed to the recursive function.
Otherwise return the value after reiterating. Like this:
sub func_1 {
my @list = ();
@list = recursive($bar);
}
sub recursive($foo){
if ($bla){my @list = &recursive ($temp)}
else {return $foo);
}
Or maybe not. It's not entirely clear what you're trying to. Posting
something less obfuscated might help?
------------------------------
Date: 14 Jun 2001 21:38:48 GMT
From: barryallwood@aol.com (Barry Allwood)
Subject: Re: Foreach Not Behaving Properly
Message-Id: <20010614173848.14608.00003988@ng-mm1.aol.com>
Oki, here is the sub, and the AID is a specific article, if you do this in the
Url ?AID=2 it will show article 2
sub NewsTemplate {
$_ = ($NewsAID, $NewsTitle, $NewsText, $NewsPerson, $NewsDate, $Display, $Bump)
= split /:x:/;
open(TEMPLATE, "article.tmpl") or die "can't open article.tmpl: $!";
local($/) = undef;
my $ArticleOut = <TEMPLATE>;
close(TEMPLATE);
$ArticleOut =~ s/\$BP_NewsText/$NewsText/g;
$ArticleOut =~ s/\$BP_NewsDate/$NewsDate/g;
$ArticleOut =~ s/\$BP_NewsPerson/$NewsPerson/g;
$ArticleOut =~ s/\$BP_NewsTitle/$NewsTitle/g;
print $ArticleOut;
}
EB
------------------------------
Date: Thu, 14 Jun 2001 14:23:42 -0400
From: Ron Auer <rrauer@mitre.org>
Subject: hash resources
Message-Id: <3B29012E.F28F3B98@mitre.org>
If you create a large hash then when you finish with it you set it to
null (%hash="";), will perl release the resources it was using?
Thanks
Ron
------------------------------
Date: Thu, 14 Jun 2001 18:47:21 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: hash resources
Message-Id: <ce1iit856kub07i362nhsk4mt02k35trdm@4ax.com>
Ron Auer wrote:
>If you create a large hash then when you finish with it you set it to
>null (%hash="";), will perl release the resources it was using?
You shouldn't do that. You'd be assigning an "odd number of arguments"
to the hash.
Use
%hash = ();
or
undef %hash;
instead.
Would it release resources? In case of memory, I'd say "yes". Other
resources, no. If there were other references to parts of the hash, it
won't realese as much. It will never release memory back to the system,
perl never does that. And in case of the undef(), it would probably
release a bit morethan in case of %hash=(). You need Ilya Z. to give you
a fully detailed (and correct) answer.
--
Bart.
------------------------------
Date: 14 Jun 2001 13:04:20 -0700
From: steve.busiello@gs.com (Steven)
Subject: Re: Help with split?vvp
Message-Id: <fa45b871.0106141204.2c8653d@posting.google.com>
For the data and explanation that was given it was
-Steven
Bart Lateur <bart.lateur@skynet.be> wrote in message news:<q8ffit8rjki14vsorr2urmqa8tqk198a5g@4ax.com>...
> Steven wrote:
>
> >I still think this is the best way
> >
> >$line = "a|b|c|d|e|f|g";
> >substr($line,0,1) = "0";
> >print "$line \n";
> >
> >simple and nice
>
> Oh yeah?
>
> $line = "first field|b|c|d|e|f|g";
> substr($line,0,1) = "0";
> print "$line\n";
> -->
> 0irst field|b|c|d|e|f|g
>
> I don't think that is even close.
------------------------------
Date: Thu, 14 Jun 2001 19:52:03 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: initialising multi-dimensional array
Message-Id: <3B2907D3.BD4DD80@salford.ac.uk>
Ben Okopnik wrote:
>
> Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote in message news:<3B28D0CF.9878E9B2@salford.ac.uk>...
>
> > I simply print the element value
> > back to a browser. If it's undef it prints nothing. I want it to print
> > 0. I can do this one of several ways but it's likely to involve a loop
> > (or loop within that) hunting out and checking each element for undef.
>
>
> unless ( defined $h{$x} ) { print 0; } else { print $h{$x}; }
>
> Ben Okopnik
> -=-=-=-=-=-
Isn't that a hash?
------------------------------
Date: Thu, 14 Jun 2001 20:01:14 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: initialising multi-dimensional array
Message-Id: <3B2909FA.555EF458@salford.ac.uk>
nobull@mail.com wrote:
>
> Mark Grimshaw <m.grimshaw@salford.ac.uk> writes:
>
> > How do I initialise everything in a multi-dimensional array to 0 (or any
> > variable for that matter)? Currently, all rows/column elements are
> > undef.
>
> Perhaps a more interesting question than "how" would be "why". As a
> rule it is better to write your code to expect the array to start out
> empty.
>
> Rather than creating a big array of zerors consider peppering your
> code with judicious use of "no warnings 'uninitialized'" or "|| 0".
>
> If you really want to pre-populate a multi-dimensional array then
> suppose you want @array to be a 3D array with elements $array[0][0][0]
> to $array[5][4][3] all 0.
>
> my @array = map { [ map { [ (0) x 4 ] } 1 .. 5 ] } 1 .. 6;
>
> or if you value symmetry over efficiency:
>
> my @array = map { [ map { [ map {0} 0 .. 3 ] } 0 .. 4 ] } 0 .. 5;
OK - I asked the wrong question it seems. It was never my intention to
start out with an array of a _set_ size all set to 0. As another of my
posts corrected it, I really wanted to know how to specify (if possible)
that prior to any population of the multi-dimensional array, any
non-populated elements (skipped over in my script as the array grew)
would be 0 instead of undef. The answer, it seems is no.
Isn't 'no warnings' perl 5.6? I'm using 5.005 (or whatever).
Not used map yet so I'll have a look at it.
------------------------------
Date: 14 Jun 2001 14:05:46 -0700
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: initialising multi-dimensional array
Message-Id: <be30c829.0106141305.7a78f35b@posting.google.com>
Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote in message news:<3B2907D3.BD4DD80@salford.ac.uk>...
> Ben Okopnik wrote:
> >
> > Mark Grimshaw <m.grimshaw@salford.ac.uk> wrote in message news:<3B28D0CF.9878E9B2@salford.ac.uk>...
> >
> > > I simply print the element value
> > > back to a browser. If it's undef it prints nothing. I want it to print
> > > 0. I can do this one of several ways but it's likely to involve a loop
> > > (or loop within that) hunting out and checking each element for undef.
> >
> >
> > unless ( defined $h{$x} ) { print 0; } else { print $h{$x}; }
>
>
> Isn't that a hash?
A hash element. You can replace it with whatever you need to check; the idea
remains the same.
Ben Okopnik
-=-=-=-=-=-
------------------------------
Date: Thu, 14 Jun 2001 15:10:54 -0400
From: "Axiom" <ufnitehawk@yahoo.com>
Subject: Looking for good tutorial/book on Perl programming.
Message-Id: <9gb0cb$jlq$1@node21.cwnet.roc.gblx.net>
I'm a windows user. If you have any information on a good tutorial/book that
i can use to learn please inform me. I am wanting to get into Perl
programming and using it on web design.
Thanks in advance for any help,
Malcolm Taylor
------------------------------
Date: Thu, 14 Jun 2001 18:59:27 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Looking for good tutorial/book on Perl programming.
Message-Id: <Xns90C098F36DE36echangnetstormnet@207.106.93.86>
"Axiom" <ufnitehawk@yahoo.com> wrote in
<9gb0cb$jlq$1@node21.cwnet.roc.gblx.net>:
> I'm a windows user. If you have any information on a good
> tutorial/book that i can use to learn please inform me. I am
> wanting to get into Perl programming and using it on web design.
A search in the comp.lang.perl.misc archives on groups.google.com for
"good book" turned up 5400 articles. I am certain you will find some
good recommendations among those discussions, as well as discover an
excellent source of information.
--
EBC
------------------------------
Date: Thu, 14 Jun 2001 13:34:13 -0600
From: "Richard A. Evans" <EvR@compuserve.com>
Subject: Re: Looking for good tutorial/book on Perl programming.
Message-Id: <9gb3ii$hf7$1@sshuraab-i-1.production.compuserve.com>
My preferences would be...
"Learning Perl " or "Learning Perl on Win32 Systems" (basic) (basically the
same book, flavored for the OS)
"Programming Perl" (more advanced)
"CGI Programming with Perl"
All of these are O'Reilly books. They have others that are excellent, but
these should get you started.
Regards,
Rick Evans
"Axiom" <ufnitehawk@yahoo.com> wrote in message
news:9gb0cb$jlq$1@node21.cwnet.roc.gblx.net...
> I'm a windows user. If you have any information on a good tutorial/book
that
> i can use to learn please inform me. I am wanting to get into Perl
> programming and using it on web design.
>
> Thanks in advance for any help,
> Malcolm Taylor
>
>
------------------------------
Date: 14 Jun 2001 13:59:54 -0700
From: doug.mcgrath@us.telegyr.com (Doug McGrath)
Subject: Re: Memory Issues/File Slurping
Message-Id: <a4e10296.0106141259.78c9ff9d@posting.google.com>
> One thing to watch out for is that you are letting a reference to the
> data held by the lexical variable survive the scope of the variable.
> When this happens, the lexical is reallocated at the next "my". If
> the reference counts never go to zero, then this just keeps happening.
>
> Ah, so you already thought of that. If the module returns an object,
> doesn't that imply that a reference is surviving?
Yes, it is, but the reference returned is used in a loop, and then
that variable is reused for the next file. I implemented a DESTROY
method in module to confirm that the previous reference was being
destroyed, and it was. I can't find any dangling references to the
hash that might be keeping parts of it around.
For my original request, I thought that the code was too lengthy and
complex to post. My first hope was for some general ideas on Perl's
memory management.
However, further experiments and judicious "ps" commands embedded in
the code reveal that the virtual memory is jumping by leaps and bounds
as a result of pattern matching. Essentially what I'm doing is
slurping an RCS repository file, and then parsing it with a series of
regular expressions. The end result is an object that encapsulates all
of the history information, but without the actual working file
contents.
Some of our RCS files are quite large; the biggest one is 25 MB, but
what I'm seeing is that pattern matching is sucking up a lot of memory
even on the small files. Some of the expressions in question are
below; the file contents are in $line. I suspect that once I
understand why any one of them takes so much memory, then I'll be able
to rework all of them to hopefully reduce the impact.
In most cases, I pick up the desired information from the grouping. I
use the positional qualifier to skip over the part of the file that's
already been matched.
if ($line =~ m/^\s*head\s+(.*?);/oscg)
<snip>
if ($line =~ m/\G\s*branch\s+(.*?);/oscg)
<snip>
if ($line =~ m/\G\s*access\s*(.*?);/oscg)
<snip>
if ($line =~ m/\G\s*symbols\s*(.*?);/oscg)
<snip>
if ($line =~ m/\G\s*locks\s*(.*?);/oscg)
<snip>
$line =~ m/\G\s*strict\s*;/scg;
if ($line =~ m/\G\s*comment\s+(\@.*?[^\@]\@)?;/oscg)
<snip>
if ($line =~ m/\G\s*expand\s+(.*?);/oscg)
<snip>
Hopefully, these snippets will be enough detail. What it looks like to
me is either that the regular expression engine isn't freeing its
memory, or that the expressions I'm using are causing a lot of memory
fragmentation so that the free pool can't be reused efficiently.
If I have to, I can go back to re-reading the repository file line by
line, but the slurping method got a 50% performance increase for most
of our operations, and this is stuff that we use constantly. Some of
the scripts that rely on this module were taking an hour and a half to
run; with the new method, they run in under 10 minutes, so the savings
are considerable.
Thank you,
Doug McGrath
------------------------------
Date: Thu, 14 Jun 2001 14:32:55 -0500
From: Mr. SunRay <nospam@hotmail.com>
Subject: Re: Multiplexing stdin and stderr to screen and logfile
Message-Id: <Hj8W6.557$b6.192853@news.uswest.net>
I wrote:
> [sorry to answer my own message]
>
> Well-well-well.. It seems to be that I haven't looked "deep" enough...
> My test program used "print" also. I somehow figured that, being on the
> other side of the pipes and in a seperate process, this non-logger
> wouldn't have to use syswrite and friends.
>
> This is really annoying! Does that mean that *any* perl program that
> uses select() can't read from pipes that are stdio-buffered???
>
> I am confused.
I'm not an expert, but no one else responded and I do own "Network Programming
with Perl" by Lincoln Stein (though I didn't stay at a Holiday Inn last
night). If you own it, look at Chapters 12 (Multiplexed applications) and
Chapter 13 (Nonblocking I/O).
There's a module that Lincoln creates called IO::Getline within the book that
probably handles the situation you're describing. I'm not going to deprive
Lincoln of his royalties and publish it here (though he may if he sees this
post).
I can give you a clue, though. Look at the Errno module (EWOULDBLOCK).
Otherwise, buy the book. It's well worth it.
Regards,
Mr. Sunray
------------------------------
Date: Thu, 14 Jun 2001 18:27:11 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Negative lookahead not working
Message-Id: <3m7W6.80869$G5.17270074@news1.rdc1.md.home.com>
In article <87snh3ru2x.fsf@hahaha.org>,
Morgan Fletcher <morgan@hahaha.org> wrote:
>That was a typo, I meant to type print unless /\@thing\s+\w+(?!XYZ)/;
>
>If I change it to be print unless /\@thing\s\w*?(?!XYZ)/; I get all @thing
>lines, with and without XYZ at the end.
>
>Here is a more literal set of examples:
>
>@thing mSysErrGeneral
>@thing mNumErrXYZ
>@thing mSysErrWrongKey
>@thing mNoRespXYZ
>
>I'd want everything but the mSysErrGeneral an mSysErrWrongKey lines
>printed. Some of those pairs are separated by tabs, not spaces.
Much better; now we know exactly what you are trying to
do. The trick is that you are matching word characters before the
lookahead; \w+ thus matches the m<message> string, and the negative
lookahead succeeds because there _isn't_ anything after that string
and thus the string you are looking for isn't found. Try
/^\@thing\s+(?!mSysErr)\w+$/ (note also the addition of anchors).
-- Sweth.
--
Sweth Chandramouli ; <sweth+perl@gwu.edu>
------------------------------
Date: Thu, 14 Jun 2001 18:40:18 GMT
From: Morgan Fletcher <morgan@hahaha.org>
Subject: Re: Negative lookahead not working
Message-Id: <87bsnqrjl9.fsf@hahaha.org>
Thanks for the help. My statement now works, and I can successfully use the
negative lookahead:
print unless /^\@\s*thing(?!.*XYZ)/
morgan
------------------------------
Date: 14 Jun 2001 15:04:34 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Negative lookahead not working
Message-Id: <m34rtic27x.fsf@mumonkan.sunstarsys.com>
Morgan Fletcher <morgan@hahaha.org> writes:
> Thanks for the help. My statement now works, and I can successfully
> use the negative lookahead:
>
> print unless /^\@\s*thing(?!.*XYZ)/
Congratulations?! Now anything with "XYZ" after "thing" won't print (Z*).
Are you just looking to learn how to use negative lookahead (Y*),
or are you actually trying to solve your original problem (X*)?
[*] - see http://perl.plover.com/Questions.html
--
Joe Schaefer "If you were plowing a field, which would you rather use? Two
strong oxen or 1024 chickens?"
-- Seymour Cray
------------------------------
Date: 14 Jun 2001 15:13:12 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Negative lookahead not working
Message-Id: <m3zobaan93.fsf@mumonkan.sunstarsys.com>
Joe Schaefer <joe+usenet@sunstarsys.com> writes:
> Morgan Fletcher <morgan@hahaha.org> writes:
>
> > Thanks for the help. My statement now works, and I can successfully
> > use the negative lookahead:
> >
> > print unless /^\@\s*thing(?!.*XYZ)/
>
>
> Congratulations?! Now anything with "XYZ" after "thing" won't print (Z*).
^^^^^
will
Oops- logic error: unless(), not if(): d'oh!
--
Joe Schaefer "Heavier than air flying machines are impossible."
-- William Thomson (Lord Kelvin)
------------------------------
Date: Thu, 14 Jun 2001 11:20:06 -0700
From: "IlIIllllI1" <iliilllli1@hotmail.com>
Subject: Re: new to perl need help with concordance
Message-Id: <tii03ej06b7d14@corp.supernews.com>
"Stefan Weiss" <der.prinz@gmx.net> wrote in message
news:3b288bda$1@e-post.inode.at...
> IlIIllllI1 <iliilllli1@hotmail.com> wrote:
>
> > I cant figure out how to finish this exercise
> > http://www.comp.leeds.ac.uk/Perl/split.html#exercise ive been trying for
2
> > hours.
>
<snip>
> The following loop will do what you want:
>
> for (my $i=1; $i < @splittext; $i++) {
> my $before = substr((' 'x10).$splittext[$i-1],-10,10);
> my $after = substr($splittext[$i].' 'x10,0,10);
> print $before, $string, $after, "\n";
> }
>
thats what i was looking for thanks.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1136
***************************************