[16389] in Perl-Users-Digest
Perl-Users Digest, Issue: 3801 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 25 18:10:37 2000
Date: Tue, 25 Jul 2000 15:10:24 -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: <964563024-v9-i3801@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 25 Jul 2000 Volume: 9 Number: 3801
Today's topics:
or die not working <laf@gameonline.co.uk>
Re: or die not working (Mark-Jason Dominus)
Re: or die not working <tony_curtis32@yahoo.com>
Re: Perl Power Tools Project Asleep? <fortinj@attglobal.net>
Re: Perl Power Tools Project Asleep? (Tom Christiansen)
Re: perl reg. ex. problem <nospam@nospam.com>
Re: perl reg. ex. problem <nospam@nospam.com>
Re: perl v. tcl lvirden@cas.org
Re: perly.y (Mark-Jason Dominus)
Re: Proceedings of Perl Conference 4.0 <lr@hpl.hp.com>
question about Net::RawIP's generic ARGPROTO <cfollettNOcfSPAM@caspiannetworks.com.invalid>
Re: Question about redirecting output in perl on NT sbhide@my-deja.com
Re: question on lists of lists... of lists! (Abigail)
Re: question on lists of lists... of lists! <nospam@nospam.com>
Re: question on lists of lists... of lists! <nospam@nospam.com>
Reading and updating a file hayati@math.berkeley.edu
Re: Reading and updating a file <billy@arnis-bsl.com>
Re: Reading and updating a file hayati@math.berkeley.edu
Re: READING hashes eats memory!? <iltzu@sci.invalid>
Re: regexp to find two ip's in a line <lr@hpl.hp.com>
Regular expression question <prendj@europem01.nt.com>
Re: Regular expression question (Greg Bacon)
Re: Regular expression question (Abigail)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Jul 2000 19:24:49 +0100
From: "Neil Lathwood" <laf@gameonline.co.uk>
Subject: or die not working
Message-Id: <964549822.5577.0.nnrp-10.c246f13c@news.demon.co.uk>
Hi Folks, excuse the lame question but....
I can't seem to get the or die working. below is a quick test I tried but it
doesn't produce anything on the screen...any pointers?
#!/usr/bin/perl
print "content-type:text/html\n\n";
open(TEST, "./somat/somat.txt") or die "Error:- $!";
@test = <TEST>;
close(TEST);
--
Neil
------------------------------
Date: Tue, 25 Jul 2000 18:53:52 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: or die not working
Message-Id: <397de240.b9c$39@news.op.net>
Keywords: Swarthout, ale, continuous, filibuster
In article <964549822.5577.0.nnrp-10.c246f13c@news.demon.co.uk>,
Neil Lathwood <laf@gameonline.co.uk> wrote:
>Hi Folks, excuse the lame question but....
>
>I can't seem to get the or die working. below is a quick test I tried but it
>doesn't produce anything on the screen...any pointers?
The error message is going into your server's error log or somewhere
else that you don't want.
Look into using the CGI::Carp module. Try adding
use CGI::Carp 'fatalsToBrowser';
near the top of your program. If that doesn't work, try adding
BEGIN { open STDERR, ">&STDOUT" }
instead. This will redirect the error stream to go to the browser.
------------------------------
Date: 25 Jul 2000 14:00:32 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: or die not working
Message-Id: <874s5em3vz.fsf@limey.hpcc.uh.edu>
>> On Tue, 25 Jul 2000 19:24:49 +0100,
>> "Neil Lathwood" <laf@gameonline.co.uk> said:
> Hi Folks, excuse the lame question but.... I can't seem
> to get the or die working. below is a quick test I tried
> but it doesn't produce anything on the screen...any
... in the browser
you mean
> pointers?
> #!/usr/bin/perl
#!/usr/bin/perl -w
use strict;
use CGI ':standard';
use CGI::Carp 'fatalsToBrowser';
> print "content-type:text/html\n\n";
print header;
# print start_html(...);
> open(TEST, "./somat/somat.txt") or die "Error:- $!";
> @test = <TEST>; close(TEST);
print end_html;
Now die will output to the browser if possible.
perldoc CGI
perldoc CGI::Carp
hth
t
--
"With $10,000, we'd be millionaires!"
Homer Simpson
------------------------------
Date: Tue, 25 Jul 2000 17:23:23 -0400
From: John Fortin <fortinj@attglobal.net>
Subject: Re: Perl Power Tools Project Asleep?
Message-Id: <397E054B.A6B35B94@attglobal.net>
Tom Christiansen wrote:
>
> In article <1cb33308.018bfc9b@usw-ex0106-046.remarq.com>,
> quagga <nathan.thompsonNOnaSPAM@respironics.com.invalid> wrote:
> >So, is the Perl Power Tools project in low-power shutdown? Is
> >it resting? Neglected? Defunct? Waiting ... for Godot?
>
> The code is all intact and at http://doriath.perl.com/ppt/, and you
> may grab it from there. Nearly everything is done, save very hard
> things like nroff and vi. What happened is that I had an irrecoverable
> disk crash from which I was unable to restore the subscribers to
> the mailing list. Without the mailing list as a focal point, most
> participation dried up.
>
Are you planning a new mailing list? Are there archives?
I noticed that in some of the directories there are several versions.
Which (if any) are the
correct versions ( look in ls, for example ) ?
------------------------------
Date: 25 Jul 2000 15:58:43 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Perl Power Tools Project Asleep?
Message-Id: <397e0d93$1@cs.colorado.edu>
In article <397E054B.A6B35B94@attglobal.net>,
>Are you planning a new mailing list? Are there archives?
I have no plans right now. That's because it's summer, and
I like it that way. If someone wants to get a mailing list
on perl.org for that, this sounds fine.
>I noticed that in some of the directories there are several versions.
>Which (if any) are the
>correct versions ( look in ls, for example ) ?
I never decided which of several competing versions to promote.
That would have happened once the installing system for the whole
suite were more (well, any) developed.
--tom
------------------------------
Date: 25 Jul 2000 20:11:17 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: perl reg. ex. problem
Message-Id: <8lks95$gqm$0@216.155.32.41>
In article <8lk5cc$itt$1@nnrp1.deja.com>, joe_madden@my-deja.com wrote:
| What is wrong here. I am trying to remove the last line of an html file
| using perl. In this case, the line happens to be: </table><!---end--->
|
| I'm opening the file, reading in the lines and removing all occurences
| of this. Does anyone know why this is not working. It runs, but does
| not change the file at all. The permissions are correct.
|
| Here is the script:
|
| #!/usr/bin/perl -w
use strict;
| $outfile = "/home/user/user.html";
my $outfile..
| open(OUT, "$outfile") || die "cannot open";
| while(<OUT>){
| chomp;
| s/<\/table><!---end--->//;
| }
| close(OUT);
you aren't outputting any data.. all you are doing here is reading in a
file, and performing some edits on the read in data, but no were is that
data ever directed back OUT to the file.
#!/usr/bin/perl -w
use strict;
my $infile = "/home/user/user.html";
my $outfile = $infile . '.bak';
open IN, $infile or die "can't open input file : $!";
# always use $! to find out WHY ^^
my @file = <IN>
close IN;
my $removed = pop @file;
print
"I removed the following line from the end of the file:\n$removed\n";
open OUT, >$outfile or die "can't open output file : $!";
# ^ you need this to make sure the file is
# opened for output
print OUT @file;
close OUT;
__END__
of course something like this can be very memory intensive if the file
is large, as the entire file gets read into memory in @file, just so you
are aware.
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: 25 Jul 2000 20:13:12 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: perl reg. ex. problem
Message-Id: <8lksco$gqm$1@216.155.32.41>
In article <8lk5cc$itt$1@nnrp1.deja.com>, joe_madden@my-deja.com wrote:
| What is wrong here. I am trying to remove the last line of an html file
| using perl. In this case, the line happens to be: </table><!---end--->
bear in mind that I would have written a regex instead of simply using
pop if you had said "off the end of a file" instead of "remove the last
line of a file"... I of course assume that you know what you are saying
here..
:)
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: 25 Jul 2000 19:33:50 GMT
From: lvirden@cas.org
Subject: Re: perl v. tcl
Message-Id: <8lkq2u$dkj$8@srv38.cas.org>
According to <sjfromm@my-deja.com>:
:I'm looking for a scripting language to automate simple tasks, such as
:asking a user for a few parameters, then running some binary files on
:some data and logging what was done, etc.; or providing nice wrappers
:for some UNIX commands.
Frankly, and this is my personal bias, for the type of thing you are doing,
ksh/bash/etc. would probably be quite enough. I like the sh derivatives
because your script files look almost identical to what you would be
typing in at a command line. The other 3 languages mentioned all add
a variety of layers of syntax on top of the day to day command line
typing.
:I'm also interested in a reference about the different scripting
:languages (sh, tcl, perl, etc) that compares their syntax and merits.
I don't know of a _current_ reference of this type. Cameron Laird writes
about scripting quite frequently in a column done for SunWorld - others
write similar columns for competive publications. But I don't believe
that I've read anything in the past year comparing the various common
languages, comparing syntax and merits. Frankly, once you have moved off
from sh, the merits are in general, going to be a wash (each has their
own pluses and minuses that, IMO, cancel out the others' pluses and minuses).
--
<URL: https://secure.paypal.com/refer/pal=lvirden%40yahoo.com>
<URL: mailto:lvirden@cas.org> <URL: http://www.purl.org/NET/lvirden/>
Unless explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
------------------------------
Date: Tue, 25 Jul 2000 18:35:53 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: perly.y
Message-Id: <397dde06.ad6$2bf@news.op.net>
[Mailed and posted.]
In article <slrn8nrh95.vcg.abigail@alexandra.foad.org>,
Abigail <abigail@foad.org> wrote:
>Mark-Jason Dominus (mjd@plover.com) wrote on MMDXX September MCMXCIII in
><URL:news:397dbd35.5b6$1e5@news.op.net>:
>{} $x = new Carrot (color => 'orange');
>{} The answer, again, is 'it depends'. I forget just what it depends on.
>
>
>Whether there's a subroutine called 'new' in the current package.
Ha! You *wish* it were that simple.
If there is a subroutine called 'new' in the current package, then you
get the
new(Carrot(color => 'orange'))
parse, UNLESS Carrot::new *also* exists, in which case you get the
other parse:
'Carrot'->new(color => 'orange');
But EVEN IF Carrot::new exists, you get the first parse anyway, if
BOTH 'new' and 'Carrot' exist in the current package.
OK, so perhaps the rule is:
1. If main::new and main::Carrot both exist, take the first parse.
2. Otherwise, if Carrot::new exists, take the second parse.
3. Otherwise do something else.
No, that's not it either, because if main::Carrot and Carrot::new both
exist but main::new doesn't, then you get a compile-time error because
it tried to take the first parse and then got upset because there is
no 'new' function.
I sure hope Paul Prescod is listening. It would be a shame if he were
to miss this delight. Hi, Paul!
main::new and main::new main::Carrot neither
main::Carrot only only one
Carrot::new first parse second parse ERROR second parse
exists
Carrot::new first parse first parse ERROR second parse
doesn't
The 'ERROR' here indicates a compile-time error:
Bareword found where operator expected at /tmp/x.pl line 15, near "new Carrot"
(Do you need to predeclare new?)
I *think* that's the whole story, but I'm not sure.
------------------------------
Date: Tue, 25 Jul 2000 11:15:20 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Proceedings of Perl Conference 4.0
Message-Id: <MPG.13e779172d76fdec98abe6@nntp.hpl.hp.com>
In article <8lipg901pls@enews3.newsguy.com> on Mon, 24 Jul 2000 20:11:34
-0500, Asquith <asquith@macconnect.com> says...
> All,
> Is there a published (or will there be a published) proceedings (talks AND
> papers) from the Perl 4.0 conference or the larger Open-Source conference.
> Over the last couple of years, I have learned much about Perl, the
> community, and programming concepts in general from the few papers that I
> have seen reprinted on the web. If there are no proceedings, then I think
> O'Reilly is missing some sales or at least downloads.
Proceedings of the Perl Conference 4.0, O'Reilly. ISBN 0-596-00013-8,
US $19.95, CAN $29.95.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 25 Jul 2000 13:34:00 -0700
From: Charley Follett <cfollettNOcfSPAM@caspiannetworks.com.invalid>
Subject: question about Net::RawIP's generic ARGPROTO
Message-Id: <05a2c868.a5e58947@usw-ex0102-016.remarq.com>
I have a question regarding the subject. I am not sure whether
this is a problem with the module or if I am using it improperly.
I am attempting to send an RSVP (rfc2205) packet using the
generic ARGPROTO.
Here is the code I am using to send:
use Net::RawIP;
my $vers_and_flags = 1 & 0x00;
my $data = pack('C', $vers_and_flags) . pack('C', 1) . pack('n',
0) . pack('C', 64) . pack('n', 7);
$a = new Net::RawIP;
$a->set({ip => {tos => 0x00,
frag_off => 0x00,
protocol => 0x2e,
saddr => '192.168.9.28',
daddr => '192.168.9.70'},
generic => {data => $data}});
$a->send;
I then sniff the packet with tcpdump and get:
13:42:32.913171 < accord > grandprix: RSVP
4500 0028 c6ab 0000 402e 204a c0a8 091c
c0a8 0946 0000 0000 0000 0000 0000 0000
5000 ffff 1c0a 0000 0000 0000 0000
Now, it looks to me like that is the proper IP header, followed
by what looks like the default TCP header and maybe some spare
0x00's. I don't ever see my $data in the packet. Is this a bug in
the code or (more likely) am I using this incorrectly? If so, how
would something like this be done? Thanks in advance for any help
you can give.
Charley Follett
Caspian Networks
-----------------------------------------------------------
Got questions? Get answers over the phone at Keen.com.
Up to 100 minutes free!
http://www.keen.com
------------------------------
Date: Tue, 25 Jul 2000 20:30:53 GMT
From: sbhide@my-deja.com
Subject: Re: Question about redirecting output in perl on NT
Message-Id: <8lktdt$6m9$1@nnrp1.deja.com>
thanks for the information.
-- suraj
In article <8lifen$d7u$1@nnrp1.deja.com>,
The Glauber <theglauber@my-deja.com> wrote:
> In article <8lidun$bt3$1@nnrp1.deja.com>,
> sbhide@my-deja.com wrote:
> > Hi,
> >
> > I have this strange problem on NT 4.0.
> >
> > I have a simple script given below:
> > ----
> > print "Hello World!\n";
> > ---
> >
> > when I installed perl on my machine I allowed the installer to
> > associate .pl scripts with perl program so that i can just
> > say "test.pl" on a command window and it executes the script.
however
> > this has a side effect and that is when I redirect the output onto a
> > file, it is created without any contents now.
> >
> > i.e.
> >
> > C:\temp> test.pl > t
> > ->> here t is empty after the command
> >
> > however, if i run it explicitly as perl -w test.pl > t
> > ->> the t file has "Hello World!" in it.
> >
> > what is going on here?
>
> Ask Bill Gates... Redirection is ugly and broken in NT, even worse in
> 9x. There is a little note about this in the "quirks" document (in
case
> you're using Activestate's Perl), under the "ActivePerl FAQ section of
> the documentation. If you use pl2bat to convert your script to a batch
> file, the redirection should work.
>
> --
> Glauber Ribeiro
> theglauber@my-deja.com http://www.myvehiclehistoryreport.com
> "Opinions stated are my own and not representative of Experian"
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 25 Jul 2000 14:45:53 EDT
From: abigail@foad.org (Abigail)
Subject: Re: question on lists of lists... of lists!
Message-Id: <slrn8nro2r.vcg.abigail@alexandra.foad.org>
Rusty Williamson (rwilliamson@uno.gers.com) wrote on MMDXX September
MCMXCIII in <URL:news: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?
I don't respond to Jeopardists who quote an entire article in full and
have an obnoxious 10 line sig.
Abigail
--
:$:=~s:$":Just$&another$&:;$:=~s:
:Perl$"Hacker$&:;chop$:;print$:#:
------------------------------
Date: 25 Jul 2000 19:38:41 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: question on lists of lists... of lists!
Message-Id: <8lkqc1$n7s$2@216.155.32.41>
In article <Dbkf5.335$wn.12934@typhoon.san.rr.com>, "Rusty Williamson"
<rwilliamson@uno.gers.com> wrote:
post replies After questions, not before. .. it's not necessary to
include the entire previous article with your replies, only the relevant
parts, since usenet has article references which can be used to go back
to the previous text, like this ->
<Dbkf5.335$wn.12934@typhoon.san.rr.com>.
>Jeopardy quoting re-arranged<
| > $netTot{"$month"}{"$date"}={
| > "average" => $data1,
| > "med" => $data2,
| > "max" => $data3,
| > "min" => $data4
| > };
| 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?
first read
perldoc perllol
perldoc perldsc
quite thoroughly
all you need to is remember how your data is accessed and built
and build it in reverse.
I'd type it out for you, however the kind folks here made me read those
two documents first (when it was MY turn to ask your question) and
insisted I try and figure it out on my own, and you know, it worked! Now
I *know* the answer, and can re-create or manipulate these types of data
structures at will without having to ask more questions.
what you are basically looking for is how to 'de-reference' these hashes
of hashes (otherwise known as HoH).
HTH!
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: 25 Jul 2000 20:19:39 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: question on lists of lists... of lists!
Message-Id: <8lksor$gqm$2@216.155.32.41>
In article <slrn8nro2r.vcg.abigail@alexandra.foad.org>,
abigail@foad.org wrote:
| Rusty Williamson (rwilliamson@uno.gers.com) wrote on MMDXX September
| MCMXCIII in <URL:news:Dbkf5.335$wn.12934@typhoon.san.rr.com>:
| | 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?
|
| I don't respond to Jeopardists who quote an entire article in full and
| have an obnoxious 10 line sig.
Fine, then don't respond at all;
Far better than being snotty about it. :P
Seems to me that you DID respond after all ..
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Tue, 25 Jul 2000 18:29:52 GMT
From: hayati@math.berkeley.edu
Subject: Reading and updating a file
Message-Id: <8lkmaq$uk$1@nnrp1.deja.com>
Hello,
I have read the relevant manpages, I hope: open, opentut, write, print,
seek, truncate, perlrun, "How do I append a line at the beginning...."
FAQ. However, there are two areas I am not clear about.
1. Suppose I have a file not consisting of formatted records. I read
it into an array, manipulate the array, then want to write the contents
back to the file. I can't close the file in between reading and
writing, because I want to keep a lock on it. So I seek back to the
beginning of the file, write the contents of the array, then truncate
the file to the appropriate length. My question is: is there a way to
get this appropriate length without first writing the contents of the
array to a temp file?
2. In case there isn't, I want to make sure I understood what the -i
switch does. What I got out of the manpage is:
a backup copy of my input file is created, and my input file is just
erased and overwritten by any print statements, so that I don't have to
worry about truncating anything. I also don't have to worry about my
lock being released behind my back.
Is this correct?
Thank you in advance for any help.
Katia Hayati
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 25 Jul 2000 15:14:40 -0500
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: Reading and updating a file
Message-Id: <397DF530.25286258@arnis-bsl.com>
hayati@math.berkeley.edu wrote:
>
> Hello,
>
> I have read the relevant manpages, I hope: open, opentut, write, print,
> seek, truncate, perlrun, "How do I append a line at the beginning...."
> FAQ. However, there are two areas I am not clear about.
>
> 1. Suppose I have a file not consisting of formatted records. I read
> it into an array, manipulate the array, then want to write the contents
> back to the file. I can't close the file in between reading and
> writing, because I want to keep a lock on it. So I seek back to the
> beginning of the file, write the contents of the array, then truncate
> the file to the appropriate length. My question is: is there a way to
> get this appropriate length without first writing the contents of the
> array to a temp file?
>
IMHO, you may just truncate the file to zero-length and write to file
*after* truncating it.
Hope this helps.
Ilja.
------------------------------
Date: Tue, 25 Jul 2000 21:03:13 GMT
From: hayati@math.berkeley.edu
Subject: Re: Reading and updating a file
Message-Id: <8lkvac$85q$1@nnrp1.deja.com>
In article <397DF530.25286258@arnis-bsl.com>,
Ilja Tabachnik <billy@arnis-bsl.com> wrote:
> hayati@math.berkeley.edu wrote:
> >
> > 1. Suppose I have a file not consisting of formatted records. I
read
> > it into an array, manipulate the array, then want to write the
contents
> > back to the file. I can't close the file in between reading and
> > writing, because I want to keep a lock on it. So I seek back to the
> > beginning of the file, write the contents of the array, then
truncate
> > the file to the appropriate length. My question is: is there a way
to
> > get this appropriate length without first writing the contents of
the
> > array to a temp file?
> >
>
> IMHO, you may just truncate the file to zero-length and write to file
> *after* truncating it.
Right, of course. However, I am generally pretty nervous about deleting
before writing (the file in question is my incoming mail folder), and
what puzzled me was Abigail's "file updating sequence" in article
slrn8nnif0.vcg.abigail@alexandra.foad.org:
>> The proper sequence is:
>>
>> - Open a file for read/write.
>> - Lock the file.
>> - Read the content.
>> - Seek to beginning.
>> - Write new content.
>> - Truncate file.
>> - Close file (which releases the lock).
Katia Hayati
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 25 Jul 2000 21:42:07 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: READING hashes eats memory!?
Message-Id: <964559802.25515@itz.pp.sci.fi>
In article <8lkht3$l7o@news.or.intel.com>, Ken Barr wrote:
>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}
> }
> }
>}
There is probably a better solution; Instead of treating your data
structure as a sparse 2**32 times 2**32 matrix, checking each and
every possible combinations, it makes more sense to treat it as what
it is - a hash of hashes - and only look at the keys that do exist.
foreach my $src (keys %cell) {
foreach my $dst (keys %{ $cell{$src} }) {
my $i = $cell{$src}{$dst}{packets};
# ...
}
}
Or, alternatively, to minimize dereferencing and hash lookups:
while (my ($src, $src_v) = each %cell) {
while (my ($dst, $dst_v) = each %$src_v) {
my $i = $dst_v->{packets};
# ...
}
}
This of course assumes you don't have any keys in %cell that are not
in %src, or any keys in the second-level hashes that are not in %dst.
If there are any, you could always explicitly skip them.
You should definitely read the documentation for "my" and "each"
before using any of these solutions (yours included), though, as well
as that for the "strict" pragma and the Perl data structure tutorial.
--
Ilmari Karonen - http://www.sci.fi/~iltzu/
"The screwdriver *is* the portable method." -- Abigail
Please ignore Godzilla and its pseudonyms - do not feed the troll.
------------------------------
Date: Tue, 25 Jul 2000 12:24:59 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: regexp to find two ip's in a line
Message-Id: <MPG.13e7896443b1c9d998abe9@nntp.hpl.hp.com>
In article <snrlbgeq3j1121@corp.supernews.com> on Tue, 25 Jul 2000
17:59:12 GMT, Greg Bacon <gbacon@HiWAAY.net> says...
...
> 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";
> }
> }
The regex in the loop certainly warrants a /o modifier, as it isn't
likely to change for the duration of the program.
Also, as a stylistic matter, to save indenting and punctuation,
while (<>) {
next unless /^\s*$ip\s+$ip\s*$/o;
chomp;
print "Match:\n '$_'\n";
}
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 25 Jul 2000 19:20:22 +0100
From: "Prendergast, John [GAL:8041:EXCH]" <prendj@europem01.nt.com>
Subject: Regular expression question
Message-Id: <397DDA66.9DD7532@europem01.nt.com>
Hello,
Can anyone help me with the following regular expression:
I wish to match a pattern similar to the following
(Somepattern)(.*)(Not somesubpattern)(.*)(Somepattern)(.*)(Not
somesubpattern)...
where somesubpattern is a subset of somepattern and is a sequence of
identical characters.
e.g.
(aaaabbbbcccc)(.*)(not aaaaa)(.*)(aaaabbbbcccc)(.*)(not aaaaa)...
My problem is with the negation.
I can negative match on a single character with something like.
([^a]+)
But I'm unable to come with an express for (not aaaaa).
Thanks.
John
------------------------------
Date: Tue, 25 Jul 2000 18:33:44 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Regular expression question
Message-Id: <snrnc8m23j158@corp.supernews.com>
In article <397DDA66.9DD7532@europem01.nt.com>,
Prendergast, John [GAL:8041:EXCH] <prendj@europem01.nt.com> wrote:
: I wish to match a pattern similar to the following
: (Somepattern)(.*)(Not somesubpattern)(.*)(Somepattern)(.*)(Not
: somesubpattern)...
:
: where somesubpattern is a subset of somepattern and is a sequence of
: identical characters.
:
: e.g.
:
: (aaaabbbbcccc)(.*)(not aaaaa)(.*)(aaaabbbbcccc)(.*)(not aaaaa)...
It's usually easier for us to help you if you provide actual data.
: My problem is with the negation.
: I can negative match on a single character with something like.
: ([^a]+)
: But I'm unable to come with an express for (not aaaaa).
You're not very specific about your pattern. Would /[abc]+/ be
acceptable, or does it need to be /aaaabbbbcccc/? Why doesn't /[^a]+/
meet your needs?
Depending on your data, it may be more appropriate to use a real
parser. It's hard to make a useful suggestion, though, without a
clearer picture of your data.
Greg
--
Nothing inspires forgiveness quite like revenge.
-- Dogbert
------------------------------
Date: 25 Jul 2000 14:50:42 EDT
From: abigail@foad.org (Abigail)
Subject: Re: Regular expression question
Message-Id: <slrn8nrobt.vcg.abigail@alexandra.foad.org>
John [GAL:8041:EXCH] (prendj@europem01.nt.com) wrote on MMDXX September
MCMXCIII in <URL:news:397DDA66.9DD7532@europem01.nt.com>:
][
][ But I'm unable to come with an express for (not aaaaa).
/(?!aaaaa)./s
Abigail
--
perl -we '$@="\145\143\150\157\040\042\112\165\163\164\040\141\156\157\164".
"\150\145\162\040\120\145\162\154\040\110\141\143\153\145\162".
"\042\040\076\040\057\144\145\166\057\164\164\171";`$@`'
------------------------------
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 3801
**************************************