[16387] in Perl-Users-Digest
Perl-Users Digest, Issue: 3799 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 25 14:10:30 2000
Date: Tue, 25 Jul 2000 11:10:19 -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: <964548619-v9-i3799@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 25 Jul 2000 Volume: 9 Number: 3799
Today's topics:
Re: popup.pm <bert@scanlaser.nl>
Re: question on lists of lists... of lists! <rwilliamson@uno.gers.com>
Re: question on lists of lists... of lists! (Greg Bacon)
Random Passwd Generator Needed <john@thinman.com>
Re: Random Passwd Generator Needed (Randal L. Schwartz)
Re: READING hashes eats memory!? <kenneth.c.barr.nospam@intel.com>
regexp to find two ip's in a line <russ_jones@rac.ray.com>
Re: regexp to find two ip's in a line (Cameron Kennedy)
Re: regexp to find two ip's in a line <brendon@shipreg.com>
Re: regexp to find two ip's in a line <russ_jones@rac.ray.com>
Re: regexp to find two ip's in a line (Greg Bacon)
Re: Safe.pm question nobull@mail.com
Re: Sending email with attachment <asg@natlib.udm.ru>
Re: sort with use strict nobull@mail.com
Re: Suggestion for syntax change <keithmur@mindspring.com>
Re: Suggestion for syntax change <keithmur@mindspring.com>
thread support <bobby@devos.org>
Re: Why won't "use strict;" work? (Lou Hevly)
Re: Why won't "use strict;" work? <bart.lateur@skynet.be>
Re: Yet another Regexp problem (sorry about the prev. p (Greg Bacon)
Yet another Regexp problem (sorry about the prev. post! <jimmy.lantz@ostas.lu.se>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Jul 2000 19:16:58 +0200
From: Bert IJff <bert@scanlaser.nl>
Subject: Re: popup.pm
Message-Id: <397DCB8A.CF8FB23E@scanlaser.nl>
fatdaz64@my-deja.com wrote:
>
> Hi Folks
>
> I am trying to get a piece of perl tk code working and I am running
> into a problem with a "require popup.pm". I have searched Active State
> and CPAN for this module but I can't find any reference to it.
>
> Can anybody shed any light on this?
Darren,
I didn't find a "require popup.pm" in any of my (standard) Tk modules.
Did you write this perl tk code yourself or did you download it,
and possibly didn't download all the files?
hth
Bert
>
> Cheers
>
> Darren
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Tue, 25 Jul 2000 17:33:23 GMT
From: "Rusty Williamson" <rwilliamson@uno.gers.com>
Subject: Re: question on lists of lists... of lists!
Message-Id: <Dbkf5.335$wn.12934@typhoon.san.rr.com>
Abigail!
Thank you for your reply! I think my problem is that I don't know how to
'access' the data. How would you loop through the keys to print this hash
out?
Thanks!
------------------------------------------------------------
Rusty Williamson
Systems Programmer
GERS Retail Systems
http://www.gers.com/
The Object Workshop
http://home.san.rr.com/williamson/
Home Page
http://www.znet.com/~rusty/
------------------------------------------------------------
"Abigail" <abigail@foad.org> wrote in message
news:slrn8nr5v1.vcg.abigail@alexandra.foad.org...
> Rusty Williamson (rwilliamson@uno.gers.com) wrote on MMDXX September
> MCMXCIII in <URL:news:o59f5.318$wn.11510@typhoon.san.rr.com>:
> [] Hello,
> []
> [] The following is working well for me...
> []
> [] $netTot{"$date"} = {
> [] "average" => $data1,
> [] "med" => $data2,
> [] "max" => $data3,
> [] "min" => $data4
> [] };
> []
> [] ... but, now I need to put this structure with a list. I've been
looking
> [] but the above is as far as my books take it. How could I take this one
> [] level further? In other words, now structure above must be repeated
for
> [] each $month. The following syntax doesn't seem to work but will
illustrate
> [] the point:
> []
> [] $netTot{"$month"}{"$date"}={
> [] "average" => $data1,
> [] "med" => $data2,
> [] "max" => $data3,
> [] "min" => $data4
> [] };
> []
> [] The above looks right to me but doesn't seem to work (I wish I knew
PERL
> [] better!). Does anyone know the proper syntax for what I'm trying to do
(and
> [] if you want to same me an addition post... how would I reference it
:-) )?
>
>
> That surprises me as it works for me. Perhaps you should be a bit more
> specific than "doesn't work".
>
>
> #!/opt/perl/bin/perl -w
> use strict;
>
> use Data::Dumper;
>
> my ($month,$date, %netTot) = ("foo", "bar");
> my ($data1, $data2, $data3, $data4) = qw /aap noot mies wim/;
>
> $netTot{"$month"}{"$date"}={
> "average" => $data1,
> "med" => $data2,
> "max" => $data3,
> "min" => $data4
> };
>
> print Dumper \%netTot;
>
> __END__
> $VAR1 = {
> 'foo' => {
> 'bar' => {
> 'average' => 'aap',
> 'min' => 'wim',
> 'max' => 'mies',
> 'med' => 'noot'
> }
> }
> };
>
> --
> package Just_another_Perl_Hacker; sub print {($_=$_[0])=~ s/_/ /g;
> print } sub __PACKAGE__ { &
> print ( __PACKAGE__)} &
> __PACKAGE__
> ( )
------------------------------
Date: Tue, 25 Jul 2000 17:48:01 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: question on lists of lists... of lists!
Message-Id: <snrkmhu43j164@corp.supernews.com>
In article <Dbkf5.335$wn.12934@typhoon.san.rr.com>,
Rusty Williamson <rwilliamson@uno.gers.com> wrote:
: Thank you for your reply! I think my problem is that I don't know how to
: 'access' the data. How would you loop through the keys to print this hash
: out?
man perllol
man perldsc
Greg
--
There's a lovely paper which compares Unix to Zork in both cognitive and user
motivational terms. Maybe you like Unix because it's an adventure game?
Still, I just don't think Unix will succeed as a theme park (some small
fraction of :-) -- Bruce Cohen
------------------------------
Date: Tue, 25 Jul 2000 17:09:55 GMT
From: John van V <john@thinman.com>
Subject: Random Passwd Generator Needed
Message-Id: <8lkhkv$t2b$1@nnrp1.deja.com>
Hi, Is there a script out there somewhere that I could use to give users
passwds so that I can enable them thru a cgi.
--
##############################################
# CXN, Inc. Contact: john@thinman.com #
# Proud Sponsor of Perl/Unix of NY #
# http://puny.vm.com #
##############################################
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 25 Jul 2000 10:36:10 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Random Passwd Generator Needed
Message-Id: <m1g0oykt85.fsf@halfdome.holdit.com>
>>>>> "John" == John van V <john@thinman.com> writes:
John> Hi, Is there a script out there somewhere that I could use to give users
John> passwds so that I can enable them thru a cgi.
Ahh... sounds almost precisely like what I wrote for my last
few WT columns, at
http://www.stonehenge.com/merlyn/WebTechniques/
check out columns 49 and 50.
print "Just another Perl hacker and web whacker,"
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Tue, 25 Jul 2000 10:14:55 -0700
From: "Ken Barr" <kenneth.c.barr.nospam@intel.com>
Subject: Re: READING hashes eats memory!?
Message-Id: <8lkht3$l7o@news.or.intel.com>
The answer (Michael Carman wins for pointing me in the right direction):
hidden in the "Boolean context" section of the Camel book, I see "An
undefined null scalar may become defined the first time you use it as if it
were defined."
Had I wanted to allocate memory for a 2^32 x 2^32 array, I would have made
it an ARRAY not a hash (which I obviously didn't because 2^64 bytes of
memory is a lot)!
So the solution is to test for "defined" before doing the read (or with
exists(), if you prefer):
foreach $src (keys(%src)){
foreach $dst (keys(%dst)){
**** if(defined($cell{$src}{$dst}){
$i=$cell{$src}{$dst}{packets}
}
}
}
"Ken Barr" <kenneth.c.barr.nospam@intel.com> wrote in message
news:8l84he$96o@news.or.intel.com...
> I have a huge hash-of-hash table (with 1st and 2nd level keys that are 32
> bit ints, if that matters). It gets created in about 2-3 megs of
memory...
> When I start to access the table in a loop, however, memory usage
> BALLOONS!!! Reading from the table once it exists in memory shouldn't
> require more than one extra word of memory (which I would happily reuse
each
> iteration of the loop). How can I do:
>
> foreach $src (keys(%src)){
> foreach $dst (keys(%dst)){
> $i=$cell{$src}{$dst}{packets}
> }
> }
>
> without running out of memory? BTW, swapping the foreach/keys with
> while/each doesn't help.
>
> Thank you,
> Ken
>
>
>
>
------------------------------
Date: Tue, 25 Jul 2000 10:23:25 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: regexp to find two ip's in a line
Message-Id: <397DB0ED.BA7EA5A1@rac.ray.com>
I'm reading an input file that has a bunch of crap in it that I don't
care about, and some lines that have two ip addresses. There might be
leading and trailing white space, and the ip's are separated by white
space. So I wrote this to select the ones I wanted:
/^\s*\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s+\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s*$/
Then I got cute and trimmed it to this:
/^\s*(\d{1,3}.){3}\d{1,3}\s+(\d{1,3}.){3}\d{1,3}\s*$/
Can anyone golf it down shorter? I like with mine, since it works, but
I'd love to see what the real Tigers in this group can do.
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Tue, 25 Jul 2000 08:58:08 -0800
From: kenned57@NoSpam.edu (Cameron Kennedy)
Subject: Re: regexp to find two ip's in a line
Message-Id: <kenned57-2507000858080001@alexthinkpad.salk.edu>
> Then I got cute and trimmed it to this:
>
> /^\s*(\d{1,3}.){3}\d{1,3}\s+(\d{1,3}.){3}\d{1,3}\s*$/
>
> Can anyone golf it down shorter?
@ips=map{/\s*(\d{1,3}(?:\.\d{1,3}){3})\s*/g}<INPUT>;
Cameron
------------------------------
Date: Tue, 25 Jul 2000 19:14:12 +0200
From: "Brendon Caligari" <brendon@shipreg.com>
Subject: Re: regexp to find two ip's in a line
Message-Id: <8lkefe$qoo$1@news.news-service.com>
"Russ Jones" <russ_jones@rac.ray.com> wrote in message
news:397DB0ED.BA7EA5A1@rac.ray.com...
> I'm reading an input file that has a bunch of crap in it that I don't
don't all input files!!
> care about, and some lines that have two ip addresses. There might be
> leading and trailing white space, and the ip's are separated by white
> space. So I wrote this to select the ones I wanted:
>
>
/^\s*\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s+\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s*$/
does't '.' match any character....i believe '.' has to be escaped \. ??
>
> Then I got cute and trimmed it to this:
>
> /^\s*(\d{1,3}.){3}\d{1,3}\s+(\d{1,3}.){3}\d{1,3}\s*$/
/((^\s*|\s+)(\d{1,3}\.){3}\d{1,3}){2}\s*$/
I'm only 20% convinced about this but it it seems to have worked in the
following script
#!/usr/bin/perl -w
use strict;
while (<STDIN>) {
if (m/((^\s*|\s+)(\d{1,3}\.){3}\d{1,3}){2}\s*$/) {
print("match\n");
}
}
exit(0);
The Brendon
------------------------------
Date: Tue, 25 Jul 2000 12:09:20 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: regexp to find two ip's in a line
Message-Id: <397DC9C0.D63EFEFD@rac.ray.com>
Cameron Kennedy wrote:
>
> > Then I got cute and trimmed it to this:
> >
> > /^\s*(\d{1,3}.){3}\d{1,3}\s+(\d{1,3}.){3}\d{1,3}\s*$/
> >
> > Can anyone golf it down shorter?
>
> @ips=map{/\s*(\d{1,3}(?:\.\d{1,3}){3})\s*/g}<INPUT>;
>
Lets in lines with only one IP, lets in lines with text on them. The
only valid line is (optional white space, valid IP, white space, valid
IP, optional white space).
--
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747
Quae narravi, nullo modo negabo. - Catullus
------------------------------
Date: Tue, 25 Jul 2000 17:59:12 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: regexp to find two ip's in a line
Message-Id: <snrlbgeq3j1121@corp.supernews.com>
In article <397DB0ED.BA7EA5A1@rac.ray.com>,
Russ Jones <russ_jones@rac.ray.com> wrote:
: I'm reading an input file that has a bunch of crap in it that I don't
: care about, and some lines that have two ip addresses. There might be
: leading and trailing white space, and the ip's are separated by white
: space. So I wrote this to select the ones I wanted:
:
: /^\s*\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s+\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}\s*$/
:
: Then I got cute and trimmed it to this:
:
: /^\s*(\d{1,3}.){3}\d{1,3}\s+(\d{1,3}.){3}\d{1,3}\s*$/
:
: Can anyone golf it down shorter? I like with mine, since it works, but
: I'd love to see what the real Tigers in this group can do.
Slow and steady wins the race:
#! /usr/bin/perl -w
use strict;
# based on material from from pg. 124 of
# jfriedl's _Mastering Regular Expressions_
my $oct = qr/(?:[01]?\d\d?|2[0-4]\d|25[0-5])/;
my $ip = qr/$oct\.$oct\.$oct\.$oct/;
while (<>) {
if (/^\s*$ip\s+$ip\s*$/) {
chomp;
print "Match:\n '$_'\n";
}
}
Greg
--
Beware of the above code; I have only proved it correct, not tried it.
-- Knuth
------------------------------
Date: 25 Jul 2000 17:42:49 +0100
From: nobull@mail.com
Subject: Re: Safe.pm question
Message-Id: <u9k8eacgae.fsf@wcl-l.bham.ac.uk>
Jeff Davis <jdavis@genesiswd.com> writes:
> I would like to be able to run code in a container using Safe.pm which
> has access only to a certain set of builtin functions (like print) and a
> set of my own subroutines.
>
> Every time I try to use permit_only() it seems to work for builtins, but
> it does not accept my subroutine as an operator. If I use share after
> that to try to include my sub, than it doesn't work (I guess because the
> mask is already set).
No, it doesn't work because all you permited was 'print'. You didn't
include ':base_core' which the basic safe opcodes need to to just
about anything - like call subroutines or use symbols for example!
> If I use share and no permit_only then I can't
> restrict the use of builtins that are allowed by default in Safe.pm. My
> question is, how can I execute a piece of code where only print() and
> public_subroutine() (which is a sub I made) are allowed, and no others?
Do you really want to be that restrictive?
What things that :base_core permits do you really feel the need to deny?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 25 Jul 2000 15:22:28 GMT
From: Sergey Aleshin <asg@natlib.udm.ru>
Subject: Re: Sending email with attachment
Message-Id: <8lkbbk$4b0$1@dfree.natlib.udm.ru>
Eelke Kleijn <six4eight@nospamhotmail.com> wrote:
> Hi all,
> I know how to send an email with both plain text and html. I also know how
> to make clear what the attachment is using
> Boundary="_NextPart_putsomestuffhere_";
> But what I don't know is how the specify a path to the attachment, if this
> is possible. I can't seem to find out how to include an attachment that is
> present in the same directory. I don't want to use a module, by the way.
$ perldoc MIME::Lite
use MIME::Lite;
Or read rfc822 and make your version of this module ;-)
--
Sergey Aleshin
e-mail: asg@natlib.udm.ru
ICQ UIN: #73148842
------------------------------
Date: 25 Jul 2000 17:45:04 +0100
From: nobull@mail.com
Subject: Re: sort with use strict
Message-Id: <u9hf9ecg6n.fsf@wcl-l.bham.ac.uk>
Uri Guttman <uri@sysarch.com> writes:
> $a is always in package main...
Really?
$ perl -e 'package foo; print \$a, \$::a, $];'
SCALAR(0x80dc4bc)SCALAR(0x80dc4d4)5.00503
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 25 Jul 2000 10:50:05 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: Suggestion for syntax change
Message-Id: <397DB72D.79F142A9@mindspring.com>
Ilmari Karonen wrote:
>
> In article <qu1jnsshg2nofnt7u27v7o5vupnnvnjjuc@4ax.com>, Bart Lateur wrote:
> >That's just an example that model and implementation need not agree.
> >Perl not doing proper DWIM for @item[2 .. -2] because of how it's
> >implemented, seems too primitive an argument to me.
>
> The problem is that we'd end up with the sort of evilness already
> manifest in do/while loops, which behave in a most unexpected manner
> if the do{} isn't the only expression in the body of the statement.
>
> In your case, which of these should DWIM and which should not?
>
> @foo[2 .. -2]
> @foo[2 .. -2, ()]
> @foo[0 || 2 .. -2]
> @foo[@bar = 2 .. -2]
> @foo[grep 1x$_ !~ /^(11+)\1+$/ => 2 .. -2]
>
> In particular, if the third expression should be identical to the
> first, should replacing 0 with a known-to-be-false variable make a
> difference? (It does for do/while.)
>
I'm really having trouble understanding this. Could you give a real
code example? The obvious example I can come up with is:
#!/usr/bin/perl
do
{print "Loop 1\n"}
while (2..-2);
do
{print "Loop 2\n"}
while (0 || 2..-2);
But perhaps I mistake your point entirely.
------------------------------
Date: Tue, 25 Jul 2000 11:17:00 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: Suggestion for syntax change
Message-Id: <397DBD7C.1D3DF4FB@mindspring.com>
jason wrote:
>
> Bart Lateur wrote ..
> >jason wrote:
> >
> >>would there be many (any?)
> >>situations where you'd be interested in going from index (x) to index
> >>(Z-y) (where Z represents the length of the unknown LIST) ??
> >
> >Try skipping the first 2 items.
> >
> > @rest = @somelist[2 .. -1];
> >
> >If you're talking about dropping a few items at the end: indeed, that
> >would be rare.
>
> that's an array .. not an unknown list .. you could just do
>
> @rest = @somelist[2..$#somelist];
>
> but .. assuming you meant @somelist to represent an unknown LIST .. then
> that's not enough of an example
>
> I mean a real situation where you don't know the length of the list - or
> how many items will be in it .. when would you want everything relative
> to the end of an unknown list ??
>
> I can think of HEAPS of situations in named LISTs (arrays) where you'd
> want the last x elements .. or all but the first two elements .. but
> those situations are already handled with $# (as in the example above)
>
> I still contend that (LIST)[2..-1] should equate to (LIST)[2,1,0,-1] ..
> and 2..-1 should equate to (2,1,0,-1)
>
I have another argument against this interpretation, in addition to the
"lists of unknown length" one, though I think that one's valid as well.
If '[2..-1]' has the meaning '[2, 1, 0, -1]',
'foreach (2..-1) {something}'
becomes a bit of a problem. 'something' is not done now; but '2..-1' by
the "wraparound" interpretation would take on an obvious interpretation
in the 'foreach' case as well, causing 'something' to be executed 4
times, so there we'd have to make a choice between consistency and
backward compatibility. If we chose backwards compatibility, we'd have
to keep explaining the inconsistency.
Whereas by the "forwards" interpretation of '2..-1', it's pretty obvious
that the loop would not execute.
I'm actually starting to wonder whether we wouldn't be better served to
denote the descending case by an entirely new operator.
[2-..-1]
or
[2...-1]
or
(your suggestion here)
(It's hard to come up with examples for either of these arguments
against the "wraparound" interpretation, but the fact that it does
produce theoretical ambiguities (for..each) or things you can't do
(ascending slices of lists with unknown lengths) makes me think it's a
step in the wrong direction).
------------------------------
Date: 25 Jul 2000 11:23:31 -0400
From: Bobby de Vos <bobby@devos.org>
Subject: thread support
Message-Id: <t1qvgxui68c.fsf@kermit.wreck.org>
Greetings,
I wish to use perl threads for a production project, but then I saw
this warning in the perl 5.6.0 source, file perl-5.6.0/README.threads
The rest of this document only applies to the use5005threads
style of threads.
Support for threading is still in the highly experimental
stages. There are known race conditions that show up under
high contention on SMP machines. Internal implementation is
still subject to changes. It is not recommended for
production use at this time.
So, anyone have any experience with how well threads work in Perl,
either 5.6.0 or 5.005? Is one of these versions prefered over the
other, wrt thread support and stability? I rather not do this project
in C, using pthreads.
Thanks,
Bobby
--
Bobby "the fox" de Vos bobby@devos.org
ECE - Georgia Tech http://www.devos.org/bobby
------------------------------
Date: Tue, 25 Jul 2000 17:27:05 GMT
From: lou@visca.com (Lou Hevly)
Subject: Re: Why won't "use strict;" work?
Message-Id: <397de0c0.40525481@news.wanadoo.es>
abigail@foad.org (Abigail) wrote:
>The proper sequence is:
>
> - Open a file for read/write.
> - Lock the file.
> - Read the content.
> - Seek to beginning.
> - Write new content.
> - Truncate file.
Ummm, with utmost trepidation this beginner asks: Shouldn't that be
truncate, *then* write?
And to Mr NAKED1: Though I may be criticised for fish throwing, in the
spirit of 'Verba movent, exempla trahunt' I think this slightly
modified version, using strict, of perlfaq5's "I still don't get
locking..." is correct:
#!/usr/bin/perl -w
use strict;
use diagnostics; # useful for debugging; comment out later
use Fcntl qw/:flock :DEFAULT/;
my $counter = '/path/to/counter.txt';
sysopen(COUNT, $counter, O_RDWR|O_CREAT) or die "Couldn't
O_RDWR|O_CREAT $counter because $!";
flock (COUNT, LOCK_EX) or die "Couldn't flock: $!";
my $number = <COUNT> || 0;
$number++;
seek(COUNT,0,0) or die "Couldn't seek: $!";
truncate(COUNT,0) or die "Couldn't truncate: $!";
print COUNT "$number\n";
close COUNT or warn $!;
--
All the best,
Lou Hevly
lou@visca.com
http://www.visca.com
------------------------------
Date: Tue, 25 Jul 2000 17:55:26 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why won't "use strict;" work?
Message-Id: <1ukrnsgb15m2nml1e16ac7bjgh11nodl2o@4ax.com>
Lou Hevly wrote:
>> - Open a file for read/write.
>> - Lock the file.
>> - Read the content.
>> - Seek to beginning.
>> - Write new content.
>> - Truncate file.
>
>Ummm, with utmost trepidation this beginner asks: Shouldn't that be
>truncate, *then* write?
In hteory, both should work. However, I have had implementations that
refuse to truncate() a file right after having printed to it.
I would think that doing
seek FILE, 0, 1;
truncate FILE, tell FILE;
could fix that, but I haven't actually tried if it does.
--
Bart.
------------------------------
Date: Tue, 25 Jul 2000 17:46:38 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Yet another Regexp problem (sorry about the prev. post! my mistake I fwd it.)
Message-Id: <snrkjueo3j1123@corp.supernews.com>
In article <397DCAF1.AFB07BE0@ostas.lu.se>,
Jimmy Lantz <webmaster@ostas.lu.se> wrote:
: I'm matching with:
:
: $line =~ /\s.*([A-Z]+)\s.*(\d\d\d\d\d\d).*/s
:
: also tried:
:
: $line =~ /\s.*([A-Z]+)\s.*(\d\d\d\d\d\d).*\s/s
: and many more similar.
:
: the lines to be matched looks like this
: 2000-05-27 P 111111
: 2000-05-27 F 222222
: AAAAA BBB J88
:
: when matching this in a file it's no problem but when sent with a POST
: form and physical wrapping
: it doesn't work.
: It just matches the second and not the first line.
When you specify the /s regular expression switch, that tells the
regular expression matcher that . can match newline. Remember that the
regular expression quantifiers (*, +, ?, {m,n}) are greedy and will
attempt to match as much text as possible. When you know this, you can
see that the first part of your pattern (/\s.*/) matches the entire
first line.
If you want to match each line, say it explicitly:
while ($line =~ /^\s.*([A-Z]+)\s.*(\d\d\d\d\d\d).*$/mg) {
...;
}
The perlre manpage has this to say about the /m switch:
Treat string as multiple lines. That is, change "^" and "$" from
matching at only the very start or end of the string to the start or
end of any line anywhere within the string [...]
Hope this helps,
Greg
--
Feminists say 60 percent of the country's wealth is in the hands of
women. They're letting men hold the other 40 percent because their
handbags are full.
-- Earl Wilson
------------------------------
Date: Tue, 25 Jul 2000 19:14:25 +0200
From: Jimmy Lantz <jimmy.lantz@ostas.lu.se>
Subject: Yet another Regexp problem (sorry about the prev. post! my mistake I fwd it.)
Message-Id: <397DCAF1.AFB07BE0@ostas.lu.se>
Hi guys,
I'm pulling my last strands of hair out on this reg exp.
I have RTFM and searched for more , but the problem still eludes me.
The following problem
I'm matching with:
$line =~ /\s.*([A-Z]+)\s.*(\d\d\d\d\d\d).*/s
also tried:
$line =~ /\s.*([A-Z]+)\s.*(\d\d\d\d\d\d).*\s/s
and many more similar.
the lines to be matched looks like this
2000-05-27 P 111111
2000-05-27 F 222222
AAAAA BBB J88
when matching this in a file it's no problem but when sent with a POST
form and physical wrapping
it doesn't work.
It just matches the second and not the first line.
But at soon as I put a blank step after the 111111 or write something it
matches that line as well.
But I need it to match both lines with or without trailing text.
Pls. help me if you know the answer to this problem.
// Jimmy Lantz - Sweden
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3799
**************************************