[6895] in Perl-Users-Digest
Perl-Users Digest, Issue: 520 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 23 05:07:23 1997
Date: Fri, 23 May 97 02:00:28 -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 Fri, 23 May 1997 Volume: 8 Number: 520
Today's topics:
Re: \b refuses to work properly (Tad McClellan)
changing values in forked subroutine (user)
formmail.pl question <richard.ells@anet.co.uk>
Re: help - grep lines between two line patterns <merlyn@stonehenge.com>
Re: Help with delimited fields... (Tim Gim Yee)
Re: how do I format text (Chipmunk)
Looking for sh to perl convert program (Ken Hargreaves)
Re: mktemp for perl (Mike Stok)
Re: News::NNTPCLient trouble with NEWNEWS <jeremy@exit109.com>
Re: OO Perl instance variables and lists (Jonathan King)
Problem with anonymous array as instance variable? (Mark Doyle)
Re: Q: Untainting an environment variable without chang (Tim Gim Yee)
Re: questions about chop (Tad McClellan)
Reading info from animated gif (Hans Kind)
Re: Reading the last line of a file <ray@icix.net>
Re: Reading the last line of a file (Bob Shair)
Re: Reading the last line of a file (Tad McClellan)
Re: Reading the last line of a file (Craig Berry)
Re: Seraching Large Files <toml@synnet.com>
Re: Size of simple scalar values (Jonathan King)
Re: split'\|'; except when preceded by '/' <merlyn@stonehenge.com>
Re: The perl way? What is it really? (Clay Irving)
Re: Transformation of string into a variable in Perl? (Chipmunk)
Tricky Searching Problem (Matthew D. Healy)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 22 May 1997 23:59:10 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: \b refuses to work properly
Message-Id: <u683m5.vda.ln@localhost>
zingbust@montana.com wrote:
: Hi, I'm trying to write a search tool for my web site, such that
: if someone searches on some words that are on a line or lines of
: my database, the corresponding lines where a match occurs will be
: returned to their browser. I want all searched words to be
: boolean AND automatically. I don't want partial words to match,
: so I have this snippet of code...
: line: while ($string = <CITYFILE>) {
: foreach $term (@terms) {
: if ($string =~ /\b$term\b/i) {
With $string = "Cleveland Robert" the above test passes.
Then, 1) s/Cleveland/<B>Cleveland</B>/ and
2) s/Rober/<B>Rober</B>/
both happen, because your using the 'g' modifier, and you're *not*
using \b in this substitution.
: $string =~ s#$highlight#<B>$&</B>#gio;
^^ ^^
through some \b's in there.
: } # $highlight was earlier assigned the list of
: # terms separated by a |, and surrounded by ()
: else {
: next line;
: }
: }
: print "$string";
: }
: ... This works fine for the first search term. The \b's prevent
: a match on "clevelan" if the term is "cleveland". But, my
: understanding of this stuff tells me it should also work on all
: the terms. For example, the terms "Cleveland and "Robert"
: are both on one line of my database. A search on "cleveland" and
: "rober" returns a match when it shouldn't, yet reversing the order of
: the two terms ("rober" first and then "cleveland) does not return a
: match (as expected). Where has my thinking gone afoul?
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 23 May 1997 06:25:36 +0200
From: user@topnet.de (user)
Subject: changing values in forked subroutine
Message-Id: <5m3680$pe8@news.frankfurt.topnet.de>
Keywords: perl, fork, variables, share
Hi.
I must do some work in the background while the main program does some
other work. The background program changes a few variables which I want
to evaluate in the main programm. Best solution is to share all variables
so the all value changes in the main or sub get immediately changes in the
other parts, too.
With fork, the sub program gets all values from the main program,
but does not give back any value to the main.
I am using perl 5.003 on a 386-40. The program does some timecritical
serial IO, i.e. do some output, wait a welldefined time, and the
immediately do some other output. While waiting do read serial input
and immediately react on some value.
Is there a way to spawn several processes which share all variable values?
krd.
------------------------------
Date: 23 May 97 08:08:40 GMT
From: "Richard" <richard.ells@anet.co.uk>
Subject: formmail.pl question
Message-Id: <01bc6750$29c2ad00$74fe4ac2@rick>
Hi!
I am using a copy of FormMail.pl and using
a a page with loads of 'fillerinable' items.
For some reason, when I get the emailed response
from this form, all of the items are in a strange
order, nothing like the order they appear in HTML.
Does anyone know the logic used in FormMail.pl so
I can attempt to get the results back in the correct
order???
If anyone can help me, please email me direct on:
richard.ells@anet.co.uk
Anyone finding the answer for me will be hailed a
GOD and given immortality. Probably.
Cheers,
Rick.
------------------------------
Date: 23 May 1997 00:44:56 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: gossamer@glasswings.com.au (Bek Oberin)
Subject: Re: help - grep lines between two line patterns
Message-Id: <8cpvui7htz.fsf@gadget.cscaper.com>
>>>>> "Bek" == Bek Oberin <gossamer@glasswings.com.au> writes:
>> Or you can write:
>> [\s\S]*?
>> for that. I often do.
Bek> Hmmm. Would [\w\W]* or [\d\D]* both have the same effect?
Bek> I'm not sure why but I'd find the \w\W combination far more
Bek> 'intuitive' than the others ..
Of course. If you wanted to go really overboard, put them *all* in:
[\s\S\w\W\d\D]*
:-)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 466 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: Fri, 23 May 1997 03:49:37 GMT
From: tgy@chocobo.org (Tim Gim Yee)
Subject: Re: Help with delimited fields...
Message-Id: <33850f81.73531372@news.seanet.com>
On 21 May 1997 23:43:10 GMT, campbell@getnet.com (Paul W. Campbell)
wrote:
>I want to take this:
>--------------------
>
>login|98-P49344W|CFI_FB3.0|1.1|96/10/02 04:08:23||96/10/0215:29:46|sgc/bin/login|1.1|96/10/02 04:08:23||sgc/bin/login||0644||||||||||||||||||||
>cshrc|98-P49344W|CFI_FB3.0|1.3|96/10/02 04:02:44||97/02/2005:28:48|sgc/bin/cshrc|1.3|96/10/02 04:02:44||sgc/bin/cshrc||0644||||||||||||||||||||
>
>
>And make it look like:
>----------------------
>
>1.1 sgc/bin/login
>1.3 sgc/bin/cshrc
Somthing similar to this should work...
foreach (<FILE>) {
printf "%2.1f %s\n", (split /\|/)[8,7];
}
-- Tim Gim Yee tgy@chocobo.org
http://www.dragonfire.net/~tgy/moogle.html
"Will hack perl for a moogle stuffy, kupo!"
------------------------------
Date: 23 May 1997 05:15:07 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: how do I format text
Message-Id: <5m394r$86r$1@dartvax.dartmouth.edu>
In article <33838B3C.6B44@wwide.com>
Scott <Scott@wwide.com> writes:
> what I want to do is separate out the 9 fields and make them into a
> table. Then display the table..
>
> any ideas?
Use split to separate each row into a list of 9 fields. Store each row
list as an array ref in another array.
Use formats and write to output the table neatly.
Chipmunk
------------------------------
Date: Thu, 22 May 97 22:29:06 GMT
From: ken@zadall.com (Ken Hargreaves)
Subject: Looking for sh to perl convert program
Message-Id: <5m2h43$orv$1@zadallv.zadall.com>
Is there any kind of utility to convert bourne shell scripts to perl scripts?
Thanks.
------------------------------
Date: 23 May 1997 02:48:19 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: mktemp for perl
Message-Id: <5m30hj$j0v@news-central.tiac.net>
In article <3384AB86.7EFD@pop.jpl.nasa.gov>,
Chris Cowan <cowan@pop.jpl.nasa.gov> wrote:
>Is there a perl version of the C call mktemp() in the core perl
>distribution? Or some module off of CPAN?
perl -MPOSIX -e 'print tmpnam'
says /tmp/00669aaa on my system, so there's a tmpnam in the POSIX module
distributed with perl 5.
Hope this helps,
Mike
--
mike@stok.co.uk | The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/ | PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/ | 65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com | Pencom Systems Administration (work)
------------------------------
Date: 23 May 1997 04:58:05 GMT
From: Jeremy <jeremy@exit109.com>
Subject: Re: News::NNTPCLient trouble with NEWNEWS
Message-Id: <5m384t$1d8$1@news1.exit109.com>
Danny Aldham <danny@hendrix.postino.com> wrote:
>I have just started using the News::NNTPCLient module, and have tried
>the example out of the man page as below:
>#!/usr/local/bin/perl -w
> require News::NNTPClient ;
> $c = new News::NNTPClient("hendrix.postino.com") ;
> foreach ($c->newnews("test", time - 3600)) {
> print $c->body($_);
> }
> __END__
>This gives me an error: NNTPERROR: 500 "NEWNEWS" not implemented; try "help".
>I am running Inn1.5.1 , and do have a test newsgroup.
But you have the NEWNEWS command disabled, which as I recall is the
default in 1.5.1 (or if it isn't, it ought to be).
--
Jeremy | jeremy@exit109.com
The customer is always right, until he tries to say something.
------------------------------
Date: 23 May 1997 05:22:07 GMT
From: king@cogsci.ucsd.edu (Jonathan King)
Subject: Re: OO Perl instance variables and lists
Message-Id: <5m39i0$32p$1@news1.ucsd.edu>
In article <5lv6oc$jgf@vixen.cso.uiuc.edu>
harrison@cs.uiuc.edu (William L Harrison) writes:
> I'm hoping someone can answer a (hopefully not too simple)
>question about lists and OO Perl instance variables.
Well, it's sort of simple...
>Specifically, I want to have an instance variable that contains
>a list.
No you don't. :-) Or if you do, you can't have one (but read on)
>So, for example, if I say:
>
> $self->{Foo} = ("blah", "blah", "herman");
>
>then "$self->{Foo}" is set to the last value of "herman" instead of to
>the whole list (which is what I want). Is there some way of having
>"$self->{Foo}" set to the whole list?
Three points here.
The first point is that this isn't really a question about OO
instance variables, but what kind of things you can put into a hash,
since you're using (a reference to) a hash to model your object
here.
The second point is what I find when I look in the index to my Blue
Camel for "hash"; the first mention is on page 7:
Hashes. A hash is an unordered set of scalars, accessed by some
string value that is associated with each scalar. [etc.]
See? It says the word "scalar" twice. And a list (or array) is not
a scalar value. What is a scalar value? Look on page 38 where it
tells you what a scalar value is:
This value may be a number, a string, or a reference to another
piece of data.
So you *can* have a reference to a something, even an array as the
value indexed by a hash. How do you do that? Looking for
"references" in the index brings you to pages 244ff, and the
goldmine on page 246 where you find out you can do this:
$self->{Foo} = ["blah", "blah", "herman"];
Square brackets will compose an anonymous array for you, and hand
you a reference...that you can put down as the value of that hash.
So how do we get at the array again? Well, that's on page 249ff,
and especially on p. 266ff.
Short answer:
One item:
$self->{Foo}->[1] # will give you blah
$self->{Foo}[1] # same thing; arrow is optional here
Whole thing:
@{$self->{Foo}} # looks tricky, but is just the array value
# of the reference to an array
>I've consulted the camel book and some humongous Waite group
>tome, but they're somewhat scant on details about OO.
I'd use the Waite-y tome to kill insects if I were you, but there's
plenty of good stuff in the Blue Camel. Including the answer to
your question.
>Anyhow, any help you give me I'd appreciate.
A pleasure, I'm sure.
>If you could respond via e-mail, I'd appreciate that, too.
And I'd apprecieate lots of money. :-)
jking
ps--The third point is that the reason you got the last item of the
array in your hash is because you were using the comma operator to
make a list on the fly, but the comma operator returns the final
item in a SCALAR context, like the one you had. So you never had a
list in the first place there...
------------------------------
Date: 23 May 1997 03:24:31 GMT
From: doyle@aps.org (Mark Doyle)
Subject: Problem with anonymous array as instance variable?
Message-Id: <5m32lf$lmd@sun20.ccd.bnl.gov>
Hi all,
I can't quite figure out why this doesn't work the way I expect it to.
Perhaps it is a perl bug, but presumably it is more likely that I have a
simple misunderstanding. Below is a simple program that creates two Foo
objects and then prints them out. One of the instance variables is
initialized as an anonymous array while the other is just a scalar. The
program sets some values for these instance variables for each object and
then simply prints the two objects out.
So what's the problem? I would have thought each instance of Foo would have
had its own hash %ivar, but it seems that the same array is used for both
objects while different scalars are used. So instead of getting output that
looks like
Fred and Barney
Bedrock
Homer
Springfield
I get
Fred and Barney and Homer
Bedrock
Fred and Barney and Homer
Springfield
I find this behavior in both perl 5.003 and perl 5.004. Am I missing
something here, or is this a perl bug? Why wouldn't the scalar and the array
at least be on the same footing?
Cheers,
Mark
#!/usr/local/bin/perl -w
use strict;
use Carp;
{
package Foo;
use strict;
use Carp;
use vars qw($AUTOLOAD);
my %ivars = (hometown=> undef,
characters => [],
);
sub new {
my $that = shift;
my $class = ref($that) || $that;
my $self = { %ivars };
bless ($self, $class);
return $self;
}
sub print_info {
my $self = shift;
my $type = ref($self)
or croak "$self is not an object";
print "\n", join(" and ", @{$self->characters}), "\n";
print "$self->{hometown}\n\n";
}
sub add_character {
my $self = shift;
my $type = ref($self)
or croak "$self is not an object";
my $character = shift;
push @{$self->{characters}}, $character;
warn "pushed character $#{$self->{characters}} $character onto
$self->{characters} for $self\n";
}
sub AUTOLOAD {
my $self = shift;
my $type = ref($self)
or croak "$self is not an object";
my $name = $AUTOLOAD;
$name =~ s/.*://; # strip fully-qualified portion
unless (exists $self->{$name} ) {
croak "Can't access `$name' field in class $type";
}
if (@_) {
return $self->{$name} = shift;
} else {
return $self->{$name};
}
}
} # End of Foo
my $fooone;
my $footwo;
$fooone = new Foo;
$fooone->add_character('Fred');
$fooone->add_character('Barney');
$fooone->hometown('Bedrock');
$footwo = new Foo;
$footwo->add_character('Homer');
$footwo->hometown('Springfield');
$fooone->print_info;
$footwo->print_info;
------------------------------
Date: Fri, 23 May 1997 04:09:33 GMT
From: tgy@chocobo.org (Tim Gim Yee)
Subject: Re: Q: Untainting an environment variable without changing it
Message-Id: <3385152b.74981117@news.seanet.com>
On 22 May 1997 01:41:30 GMT, "Andrew Pollock" <apollock@bit.net.au>
wrote:
>Heaven forbid that I've asked a FAQ here, but...
>
>I'm writing a setuid CGI script that needs access to $ENV{'REMOTE_USER'}.
>How can I untaint this environment variable? A perl -T is spewing when I
>make a system call using this variable as a parameter.
$ENV{'REMOTE_USER'} =~ /(.*)/;
$remote_user = $1; # Untainted but still insecure.
See the perlsec man pages.
-- Tim Gim Yee tgy@chocobo.org
http://www.dragonfire.net/~tgy/moogle.html
"Will hack perl for a moogle stuffy, kupo!"
------------------------------
Date: Thu, 22 May 1997 23:21:32 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: questions about chop
Message-Id: <c063m5.n7a.ln@localhost>
Scott (Scott@wwide.com) wrote:
: I have text file full of lines that look like this:
: blah stuff hmmm hello fred joe blue dd cc
: I need to chop off the dd and cc on the end of all of them.. (they don't
: really all say dd and cc, this is an example)
: here is what I have:
: while (<FILE>) { # reads into $_
: print OUTFILE "<tr>";
s/(\s+\S+){2}$//; # delete the last two fields
OR
s/\s+\S+\s+\S+$//; # delete the last two fields
OR
$_ = join ' ', (split)[0..6]; # keep the first seven fields
Then split as below...
: foreach $field (split) { # split splits up $_ by
: default
: {
: print OUTFILE "<td>$field</td>";
: }
: }
: print OUTFILE "</tr>\n";
: }
: print OUTFILE "</table>\n";
: close(FILE);
: how do I use the chop command (or whatever one is necessary) to remove
: the end of each line?
: Is their a command to chop say 7 lines off of the end of every line?
^^^^^^^^^^^ ^^^^^^^^^^
resulting in a negative six lines?
I don't think you can do that, even with Perl. ;-)
$_ = substr($_, 0, -7); # remove the last seven _characters_ from a line
OR
s/.......$//; # remove the last seven _characters_ from a line
OR
s/.{7}$//; # remove the last seven _characters_ from a line
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: Fri, 23 May 1997 07:42:37 GMT
From: hans@kindserver.com (Hans Kind)
Subject: Reading info from animated gif
Message-Id: <33854a30.10558301@news.pi.net>
Hi,
I'm looking for a cgi/perl routine that can read the info like pixel
size, comment tag etc, stored within a animated gif, in a way that can
be used to display this on a html page. Anyone out here that can help
me out?
rgds
Hans Kind
The Dutchy
hans@kindserver.com
------------------------------
Date: Thu, 22 May 1997 10:30:55 -0400
From: Ramon Castillo <ray@icix.net>
Subject: Re: Reading the last line of a file
Message-Id: <33845899.1438@icix.net>
Everything is too complicate this is more easy for me.
open (LAST , "tail -1 $file |");
while (<LAST>)
{print "$_\n"}
The result will be the last record.
RC
------------------------------
Date: 23 May 1997 05:30:22 GMT
From: rmshair@uiuc.edu (Bob Shair)
Subject: Re: Reading the last line of a file
Message-Id: <5m3a1e$jvg@vixen.cso.uiuc.edu>
gml4410@ggr.co.uk (Lack Mr G M) writes:
>In article <338383C8.856D7023@inigo.us.dg.com>, Bob Maillet <rmaillet@inigo.us.dg.com> writes:
>|> I am trying to get my program to read the last line of a file..
>|> I have tried a loop but had no luck..does anyone have any suggestions?
...
>|> open (FILE, $database);
>|> @file = (<FILE>);
>|> close(FILE);
This is fine for a tiny file, such as the 30-liner he's actually faced with.
> This means that you allocate memory for all of the file. If it is
>big, you will need the memory. Somewhat wastefull of resources.
>
> chomp($last_line = $_) while(<FILE>);
This is fine for a medium-sized file.
If you have a large file (say multiple GB), you'd better do something like:
#
open (FILE, $database) || die "cannot open:$!\n";
$filesize = -s FILE;
$start = $filesize - 512; #or some number you're SURE will have >1 line
seek (FILE,$start,0) || die "cannot seek:$!\n";
chop($last_line = $_) while(<FILE>);
--
Bob Shair Open Systems Consultant
1018 W. Springfield Avenue rmshair@uiuc.edu
Champaign, IL 61821 217/356-2684
< Not employed by or representing the University of Illinois >
------------------------------
Date: Fri, 23 May 1997 00:12:27 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Reading the last line of a file
Message-Id: <rv83m5.gga.ln@localhost>
Ramon Castillo (ray@icix.net) wrote:
: Everything is too complicate this is more easy for me.
^^^^^^^^^^ ^^^^^^^^^^^^^
Including yours ;-)
: open (LAST , "tail -1 $file |");
: while (<LAST>)
: {print "$_\n"}
print `tail -1 $file`;
: The result will be the last record.
--
Tad McClellan SGML Consulting
Tag And Document Consulting Perl programming
tadmc@flash.net
------------------------------
Date: 23 May 1997 06:00:44 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Reading the last line of a file
Message-Id: <5m3bqc$mel$1@marina.cinenet.net>
Joel Graber (jgraber@daldd.sc.ti.com) wrote:
:
: In article <5m22m7$9su$1@marina.cinenet.net> cberry@cinenet.net
: (Craig Berry) writes:
:
: > As near as I can tell from reading the 'perldata' doc, $list[$#list] and
: > $list[-1] are entirely equivalent expressions.
:
: I didn't see that in man perldata, and it isn't (entirely) true.
: perl -e '$[=-4; @l=qw(a b c d e f g h); print " $l[$#l] , $l[-1] : @l\n";'
: h , d : a b c d e f g h
Yeah, I thought of this too, and almost posted a followup to point it out
-- but after all, $[ is deprecated, so I don't feel *too* bad about
ignoring it. And the statement itself isn't in perldata, but you can
infer it from how $#list and $list[-1] are defined.
---------------------------------------------------------------------
| Craig Berry - cberry@cinenet.net
--*-- Home Page: http://www.cinenet.net/users/cberry/home.html
| Member of The HTML Writers Guild: http://www.hwg.org/
"Every man and every woman is a star."
------------------------------
Date: Tue, 20 May 1997 10:39:34 -0400
From: Tom Lynch <toml@synnet.com>
Subject: Re: Seraching Large Files
Message-Id: <3381B7A6.35DE@synnet.com>
Jahwan Kim wrote:
>
> On Fri, 09 May 1997 08:29:41 -0400, Tom Lynch <toml@synnet.com> wrote:
> [snip]
> > while (<VER>){
> > chop;
> > @y = $_;
> > @y = split;
> > while (($vkey,$vvalue) = each %signal) {
> > if (/$vkey/){
> > $vtmp = "$y[1] $vkey $vvalue";
> > push(@vline, $vtmp);
> > }
> > }
> > }
> [snip]
> Wouldn't it be faster to use 'eq' comparison instead of m//, if
> that's what you want?
>
> @all_vkeys = keys %signal;
> while(<VER>) {
> @_ = split chop;
> shift; $y1 = shift; shift;
> OUTER: foreach $vkey (@all_vkeys) {
> foreach (@_) {
> if ( $vkey eq $_ ) {
> $vtmp = "$y1 $vkey %signal{$vkey}";
> push(@vline, $vtmp);
> last OUTER;
> }
> }
> }
> }
>
> Jahwan
Yes this would be true if I knew where $vkey was on the line, but
it could be anywhere except the first three columns. So I have to
use m// to go throuh the entire line.
Tom
------------------------------
Date: 23 May 1997 05:41:24 GMT
From: king@cogsci.ucsd.edu (Jonathan King)
Subject: Re: Size of simple scalar values
Message-Id: <5m3am4$363$1@news1.ucsd.edu>
In article <33833F96.608B@lanl.gov>
"Douglas A. Smith" <douglas@lanl.gov> writes:
>
>I've gone through various books, and I can't find a answer to this
>problem:
Throw out the various books, and buy the second edition of
Programming Perl instead. :-)
>I have a script which adds large sets of data and compares small
>differences in these sets. The problem comes when the sums start
>to get larger than 2.14 billion.
Actually, I'll make a wild guess the problem actually crops up at
2,147,483,648 or so...
>Is there a way to get perl to force the use of more bytes used in
>integer scalars? I don't want to force the use of floating point
>numbers since I need the absolute accuracy of the integer sum.
Let's look in that index for "integer"...
Page 180? Nope. Page 455? Nope. Page 460...yes!
Math::BigInt -- Arbitrary length Integer Math Package
That should do the trick. You may now continue to count your
money. :-) At least I hope it was only money you were counting...
jking
------------------------------
Date: 23 May 1997 00:43:49 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: danboo@ixl.com
Subject: Re: split'\|'; except when preceded by '/'
Message-Id: <8csoze7hvu.fsf@gadget.cscaper.com>
>>>>> "Dan" == Dan Boorstein <danboo@ixl.com> writes:
Dan> A string with: no linefeeds
Dan> fields separated by |
Dan> nested |'s are escaped with \ (i.e., \|)
Dan> I want to split this string on unescaped |'s, removing
Dan> the \'s preceding the escaped |'s. I thought this would
Dan> be a 2 line split-regex block, but has turned into
Dan> something much less elegant which I pieced together
Dan> from various FAQ's and Dejanews articles. Behold:
[7 lines of slightly scary code deleted :-]
Dan> It does everything I wanted it to do, but not as cleanly as I'd
Dan> hoped. Any ideas on how to clean up this process (not necessarily
Dan> my coding style)?
Sometimes, the most straightforward way is the most straightforward way:
## presume data in $_:
s/\\\|/\0/g; # hide any non-delimiters from the following:
@list = split /\|/; # split on real delimiters
for (@list) { tr/\0/|/; } # and put back non-delimiters (unescaped now)
Next? :-)
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 466 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: 22 May 1997 23:05:00 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: The perl way? What is it really?
Message-Id: <5m31gs$g45@panix.com>
In <5m257s$mbi@grok.adb.gu.se> niklas@grok.adb.gu.se (Niklas Paulsson) writes:
....
>My first impression was "What a sick and perverted brain has put
>together this pile of mud?", but I keept hacking, and slowly, more and
>more I began to like perl more and more.
>When I finally read the book "mastering regular expresions" I feel in
>love with perl. Today I use perl for a wide variety of tasks in my
>everyday job, and most of all I think it is great fun hacking in perl.
Heh. Welcome to the club.
....
>But people keep refering to "the perl way of doing things", and I
>really wonder what is "the perl way of doing things"...
I think the "Perl way of doing things" is "There's always more than one
way to do things."
--
Clay Irving See the happy moron,
clay@panix.com He doesn't give a damn,
http://www.panix.com/~clay I wish I were a moron,
My God! Perhaps I am!
------------------------------
Date: 23 May 1997 04:50:26 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: Transformation of string into a variable in Perl?
Message-Id: <5m37mi$eqv$1@dartvax.dartmouth.edu>
In article <3383F575.BE37AD7@wettzell.ifag.de>
Hayo Hase <hase@wettzell.ifag.de> writes:
> Or in other words, how can I transform strings into variables?
$foo = "bar";
$$foo = "baz";
print "$bar\n";
> ...
>
> for ($i=0; $i<52; $i++) { # still faulty!
> $frame = sprintf("\$f_1%02x", $i);
>
> $adflag[$i] = $w_0->Checkbutton();
> $adflag[$i] -> pack(-side=>'left', -in=>"$frame");
What you want to do here is:
$adflag[$i] -> pack(-side=>'left', -in=>$$frame);
> }
Chipmunk
------------------------------
Date: Thu, 22 May 1997 20:42:38 -0500
From: Matthew.Healy@yale.edu (Matthew D. Healy)
Subject: Tricky Searching Problem
Message-Id: <Matthew.Healy-2205972042380001@pudding.med.yale.edu>
Suppose we have a *BIG* text file that is in an unstructured format.
I want an efficient way of extracting all groups of lines meeting the
following conditions:
1. Each group BEGINS with a line containing $STRING_1, and may well
contain more lines containing that string.
2. SOMEWHERE within the group of lines can be found a line containing
$STRING_2
3. Each group of lines ENDS with a line containing $STRING_3
I cannot figure out how to do this without some incredibly messy
logic, involving multiple nested loops.
Note that it is condition #2 that has me stonkered. If I just wanted
every group of lines delimited by $STRING_1 and $STRING_3, then I
could say something like `sed -n /$STRING_1/,/$STRING_3/,p` or its
equivalent in pure Perl. It is the added condition that somewhere
between the begin/end delimiters must be at least one line meeting
a third condition that has me stonkered. There will most probably
be multiple chunks beginning and ending with delimiter lines, some
of which contain the second string and some of which do not. The
strings in question may or may not be at the beginning of a line,
but in any case I want to include the entire beginning line and
the entire ending line.
Also, $STRING_1, $STRING_2, and $STRING_3 are from user input, so
few assumptions can be made about them. I will filter out all but
alphanumerics and certain punctuation.
By *BIG* file, I mean, it is not acceptable to slurp the entire
file, or any significant fraction thereof, into memory at once.
HOWEVER, it CAN be assumed that either (1) any line containing
$STRING_1 will soon be followed by a line containing $STRING_3
or else the user has committed an error and should be warned.
Thus, if there are more than, say, 150 lines not containing
$STRING_3 following a line containing $STRING_1, then the program
should die with an appropriate error message instead of continuing
processing.
---------
As of 21 May 1997, 954 days till Y2K....
Matthew.Healy@yale.edu
http://paella.med.yale.edu/~healy
"But I thought it was pointed at the rabbit *between* my feet!"
---------
Help a victim of severe email harrassment, see
http://www.geocities.com/~hitchcockc/story.html#fund
---------
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 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.
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 520
*************************************