[11438] in Perl-Users-Digest
Perl-Users Digest, Issue: 5038 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 2 19:17:23 1999
Date: Tue, 2 Mar 99 16:00:24 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 2 Mar 1999 Volume: 8 Number: 5038
Today's topics:
Re: A smiple question <jglascoe@giss.nasa.gov>
Re: browser detection in CGI script (Ethan H. Poole)
Re: Determine web directory size (Dimitri Ostapenko)
Re: Determine web directory size (Larry Rosler)
Re: Finding the word after a word (Larry Rosler)
Re: Finding the word after a word (Abigail)
Re: Finding the word after a word (Sam Holden)
Help with hash references <pdafnedd@adfasdge.com>
Re: How to interrupt a foreach loop (Ethan H. Poole)
IO::Socket and udp - exits immediately <ac256@ncf.ca>
IO::Socket and udp - exits immediately <ac256@ncf.ca>
Re: logically impaired <staffan@ngb.se>
Re: method overriden! <emschwar@mail.uccs.edu>
Re: method overriden! (Martien Verbruggen)
Q: multiline write anna@water.ca.gov
Re[2]: does perl discourage obfuscated code? (was Re: P christopher@tokpela.com
Re: The millennium cometh -- eventually (Larry Rosler)
Re: The millennium cometh -- eventually <staffan@ngb.se>
Re: Tk binding and callbacks, EOT <bwarnock@gtemail.net>
Re: Variables in regular expressions (Ilya Zakharevich)
Re: y2k and 4-digit dates (was Re: foreach and while) (Abigail)
Re: Yes, I'm a newbie. Any suggestions despite that? <jglascoe@giss.nasa.gov>
Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 02 Mar 1999 18:07:26 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Dong Tang <tangd@ctcdist.com>
Subject: Re: A smiple question
Message-Id: <36DC6F2E.869C302@giss.nasa.gov>
[posted and mailed]
Dong Tang wrote:
>
> How do I detect if a string has any non-numeric character in it by using
> regular expression, but code below doesn't work.
> $foo = "3w43242";
> if ($foo =~ /![0-9]/)
> {
> print print "$foo has non-numeric charater.\n"
> }
print "$foo has non-numeric charater.\n" if $foo =~ /[^0-9]/;
Jay Glascoe
--
ping.
------------------------------
Date: Tue, 02 Mar 1999 18:04:59 -0500
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: browser detection in CGI script
Message-Id: <HbvxYEQZ#GA.196@rejz.ij.net>
In article <83iuck44in.fsf@vcpc.univie.ac.at>,
Tony.Curtis+usenet@vcpc.univie.ac.at says...
>
>Taking a photon-challenged stab though, what you
>probably want is something like:
>
> use CGI;
>
> my $agent = user_agent();
>
> if ($agent =~ /mozilla/i) {
> print redirect(URL_IF_USING_NETSCAPE);
> }
> else if ($agent =~ /.../) {
> print redirect(...);
> }
>
> # blah blah
> # perhaps neater to use a hash as a lookup table
> # See `perldoc CGI` for more info on user_agent()
>
><imho>
>Of course one could argue (and I do :-) that this
>"different HTML for different browsers" is entirely
>the wrong thing to do as correct HTML will display
>in any browser, so you'd never need to do something
>like this. Write HTML once and let the browsers
>display it.
></imho>
>
>Also whether you believe what the browser/user-agent
>claims it is, is up to you.
It may also be worth pointing out that Internet Explorer, AOL, and Netscape
will all identify themselves as "Mozilla". So detection gets a bit more
complicated than the above. IOW, think long and hard about whether or not
the limited benefits available from attempting to detect the browser type are
actually worth the maintenance trouble you will be creating (you will need to
update the browser table each time a new release of a supported browser is
issued since the features, behavior, and, sometimes, the user agent
identifier can change significantly).
--
Ethan H. Poole | Website Design and Hosting,
| CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day, Inc.--
| http://www.interact2day.com/
------------------------------
Date: Tue, 02 Mar 1999 23:01:53 GMT
From: euclid@fantom.com (Dimitri Ostapenko)
Subject: Re: Determine web directory size
Message-Id: <B5_C2.67$xJ4.254@198.235.216.4>
In article <36D06B8F.9C45F948@ic.ru>,
Dmitry Diskin <dda@ic.ru> writes:
> Hi,
>
> Is there any simple solution for count the total size of files in
> particular directory of web server?
>
> Dmitry.
There is much more elegant solution (as usually is the case) by
Tom Christiansen. I hope he doesn't mind if I quote it here:
#!/usr/bin/perl
use File::Find;
@ARGV = ('.') unless @ARGV;
my $sum = 0;
find sub { $sum += -s }, @ARGV;
print "@ARGV contains $sum bytes\n";
Dimitri Ostapenko,
Not another perl hacker (yet)
___
Murphy was an optimist.
-- Callagen
------------------------------
Date: Tue, 2 Mar 1999 15:13:15 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Determine web directory size
Message-Id: <MPG.114610677ae594539896c7@nntp.hpl.hp.com>
[Posted and a courtesy copy mailed.]
In article <1FZC2.66$xJ4.254@198.235.216.4> on Tue, 02 Mar 1999 22:31:25
GMT, Dimitri Ostapenko <euclid@fantom.com> says...
> In article <MPG.1144ffab770f5c1e9896bd@nntp.hpl.hp.com>,
> lr@hpl.hp.com (Larry Rosler) writes:
> > In article <36DB4913.D7A4FAF@sympatico.ca>, on Mon, 01 Mar 1999 21:12:35
> > -0500 dimitrio@sympatico.ca says...
...
> Thanks. I did. It works. Not everywhere though. Big deal, chdir $d.
> I am trying to help my namesake here, ok?
'Dimitrio' ne 'Dimitri'. But 'Dimitrio' =~ /Dimitri/ so it's close
enough. See -- Perl content! :-)
> > $tsz += -s "$d/$_";
>
> Umm, I like this better, actually, more portable than chdir, that's for sure.
Not really. The Perl 'chdir' function is portable to any environment
that supports a hierarchical file-system model. But it certainly is
more robust and efficient to be explicit about the absolute path rather
than execute system calls to change the directory and use the relative
filename.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Tue, 2 Mar 1999 15:16:36 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Finding the word after a word
Message-Id: <MPG.1146113276908f3a9896c8@nntp.hpl.hp.com>
In article <slrn7dopi6.svu.sholden@pgrad.cs.usyd.edu.au> on 2 Mar 1999
22:29:26 GMT, Sam Holden <sholden@pgrad.cs.usyd.edu.au> says...
> On Tue, 02 Mar 1999 14:04:30 -0700, Arne Jamtgaard <arnej@fc.hp.com> wrote:
> >I tried this, and couldn't get it to work unless I moved the
> >"my" defining $i and @words to before the for-loop. I think
> >by putting them in the for-loop declaration, they're out of
> >scope by the time you get to the return statement.
> >
> >Or am I missing something?
>
> Your missing a newer version of perl...
Not at all. In the newest official version of perl (5.005_02), the
scope of variables declared in the for-loop declaration is restricted to
the loop body. As published, Abigail's code does not work unless the
above change is made.
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 2 Mar 1999 23:21:05 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Finding the word after a word
Message-Id: <7bhrp1$ee$1@client2.news.psi.net>
Arne Jamtgaard (arnej@fc.hp.com) wrote on MMIX September MCMXCIII in
<URL:news:36DC525E.726D@fc.hp.com>:
<> Abigail wrote:
<>
<> > kalikste@uiuc.edu (kalikste@uiuc.edu) wrote on MMVIII
<> > September MCMXCIII in <URL:news:7bf4j7$ap3$1@nnrp1.dejanews.com>:
<> > ## Quick question for a regular expression-
<> > ##
<> > ## What is the most elegant way to extract the word after a specific
<> > ## word in a string (words seperated by one space)? For example, if
<> > ## the string is "The quick brown fox jumps over the lazy dog", given
<> > ## "brown", I want to return "fox". In my situation, each word will
<> > ## only appear once in the string. I appreciate all your input.
<>
<> > sub find_next_word {
<> > my ($word, $string) = @_;
<> > for (my ($i, @words) = (0, split / / => $string); $i < @words; ) {
<> > last if $words [$i ++] eq $word;
<> > }
<> > return $words [$i];
<> > }
<>
<> > Abigail
<>
<> I tried this, and couldn't get it to work unless I moved the
<> "my" defining $i and @words to before the for-loop. I think
<> by putting them in the for-loop declaration, they're out of
<> scope by the time you get to the return statement.
<>
<> Or am I missing something?
No, you are correct.
Abigail
--
perl -wlpe '}$_=$.;{' file # Count the number of lines.
------------------------------
Date: 2 Mar 1999 23:25:56 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Finding the word after a word
Message-Id: <slrn7doss4.18e.sholden@pgrad.cs.usyd.edu.au>
On Tue, 2 Mar 1999 15:16:36 -0800, Larry Rosler <lr@hpl.hp.com> wrote:
>In article <slrn7dopi6.svu.sholden@pgrad.cs.usyd.edu.au> on 2 Mar 1999
>22:29:26 GMT, Sam Holden <sholden@pgrad.cs.usyd.edu.au> says...
>> On Tue, 02 Mar 1999 14:04:30 -0700, Arne Jamtgaard <arnej@fc.hp.com> wrote:
>> >I tried this, and couldn't get it to work unless I moved the
>> >"my" defining $i and @words to before the for-loop. I think
>> >by putting them in the for-loop declaration, they're out of
>> >scope by the time you get to the return statement.
>> >
>> >Or am I missing something?
>>
>> Your missing a newer version of perl...
>
>Not at all. In the newest official version of perl (5.005_02), the
>scope of variables declared in the for-loop declaration is restricted to
>the loop body. As published, Abigail's code does not work unless the
>above change is made.
I guess I'll read the code next time... maybe I'll just make sure I've slept
at least once in the 24 hour period previous to posting...
Oh well, must go get another coffee... (the sad thing is I haven't even
written any perl)
--
Sam
Remember that the P in Perl stands for Practical. The P in Python
doesn't seem to stand for anything.
--Randal Schwartz in <8cemsabtef.fsf@gadget.cscaper.com>
------------------------------
Date: Tue, 02 Mar 1999 16:38:14 -0700
From: "Paul M. Neth" <pdafnedd@adfasdge.com>
Subject: Help with hash references
Message-Id: <36DC7666.17C7A20D@adfasdge.com>
I am working on the following perl script.
******************** START mergerh.pl
: # use perl
# mergerh.pl perl program to read RAWS file (rochelle.raws), extract
data year desired,
# sort and then fill blanks with CIRA data file (badl_t.all)
# export date and rh to external file
# make it handle leap year also
use strict
# define year to extract
$yr = 96;
@daysinmonth = (31,28,31,30,31,30,31,31,30,31,30,31);
# compute leap yr flag also, with easy computation
if ((1996 % 4) == 0) {
$lyf = 1;
} else {
$lyf = 0;
}
# specify the output seperators
$, = ' '; # set output field separator
$\ = "\n"; # set output record separator
# open the CIRA visibility transmissiometer file
open(CIRA,'badl_t.all') || die 'Cannot open file "badl_t.all".';
# open the RAWS data file also
open(RAWS,'rochelle.raws') || die 'Cannot open file "rochelle.raws".';
print "reading RAWS data";
while (<RAWS>) { # read data file (RAWS) listed on the cmd line
if (!/^:/) { # if a colon does NOT start a line then do this
($Date,$prec,$wsmph,$wd,$tempf,$fuelf,$rh,$bp,$wsgust,$mxgust) =
split(' ', $_, 9999);
# extract yr,mm,day,hr from long date string
$yymmddhh = substr($Date,0,8);
# extract 2 digit year from long date format
$datyear = substr($Date,0,2);
if ($datyear == $yr) { # if data year is == to year specified then
# assign key/val into hash
%raws=($yymmddhh,$rh);
print "1996 is OK and date = $yymmddhh and rh = $raws{$yymmddhh}";
$olddate = $yymmddhh;
} # end if datyear is right
} # end regex filter
} # while reading all lines
# READING APPEARS TO WORK
# output available data, hash might be missing some data
print "writing raws data";
for ($mm=1;$mm<=12;$mm++) { # loop over months
$maxdays = $daysinmonth[$mm-1]; # get maxdays
# check for leap yr and increment max days if needed
if (($mm==2) && ($lyf == 1)) {
$maxdays++
}
for ($d=1;$d<=$maxdays;$d++) { # loop over days
for ($h=0;$h<=23;$h++) { # loop over hrs
# pad month with 0 if needed
$padmm = sprintf( "%02d", $mm );
# pad day with 0 if needed
$paddd = sprintf( "%02d", $d );
# pad hr with 0 if needed
$padhh = sprintf( "%02d", $h );
# recreate the hash date using for loop variables
$newdate = $yr.$padmm.$paddd.$padhh;
print "new date = $newdate and new hash data = $raws{$newdate}"; #
PROBLEM?
print "old date = $olddate and old data = $raws{$olddate}"; #
PROBLEM?
print "$newdate and $raws{$newdate}\n";
}
}
}
******************** END mergerh.pl
As far as I can the reading ( e.g. 1996 is OK and date = 96012613 and rh
= 82.0)
seems to be working into the hash. The printing is giving errors. Or am
I referencing the
hash wrong?
******** start output
Use of uninitialized value at mergerh.pl line 71, <RAWS> chunk 50386.
new date = 96010620 and new hash data =
old date = 96010116 and old data = 64.0
Use of uninitialized value at mergerh.pl line 74, <RAWS> chunk 50386.
96010620 and
********* end output
I have also checked for spaces on the end of my concatenated date.
Thanks in advance
Paul
------------------------------
Date: Tue, 02 Mar 1999 18:10:23 -0500
From: ehpoole@ingress.com (Ethan H. Poole)
Subject: Re: How to interrupt a foreach loop
Message-Id: <J#6$ZHQZ#GA.203@rejz.ij.net>
[Posted and Emailed] In article <7bhad3$d91$1@news-1.news.gte.net>,
webmaster@provence-shop.com says...
>
>Hi,
>
>I'm a PERL toddler, and I would like to know if there is a way to
>interupt
>a foreach loop.
Familiarize yourself with the "last" command.
>
>Or is there a way to use a for loop. I assume there is, but I dunno how
>to
>do that?
You can use while() loops to exit when a specific condition is met.
--
Ethan H. Poole | Website Design and Hosting,
| CGI Programming (Perl & C)..
========Personal=========== | ============================
* ehpoole @ ingress . com * | --Interact2Day, Inc.--
| http://www.interact2day.com/
------------------------------
Date: 2 Mar 1999 22:50:16 GMT
From: Douglas Dickinson <ac256@ncf.ca>
Subject: IO::Socket and udp - exits immediately
Message-Id: <36DC6AC4.1D518323@ncf.ca>
First off, let me admit that this is as much of a socket question
as a perl question (perhaps more). I appologize.
I have several working client/server pairs that communicate via
'tcp' sockets. I'm trying to convert one to work with 'udp'.
I have spend all day burried in the following documentation and
man pages and am still at a loss:
socket-faq, perl FAQ, IO::Socket, perlfunc, perlipc, socket, bind,
connect, setsockopt, listen, accept, ...
Most documentation (and news postings too) seem to amount to
"It's similar for udp". I cannot seem to find useful help
for how to work with udp for client server communication.
The following simplistic code is straight from a working tcp
example, but with 'udp' for the Proto. *But* when run, the
server exits immediately after being launched.
Any help on how to get this simple example running with udp
would be greatly appreciated.
Many thanks in advance,
DouglasDD
SERVER
use IO::Socket;
$sock = new IO::Socket::INET (LocalHost => 'thisbox',
LocalPort => 1200,
Proto => 'udp',
Listen => 5,
Reuse => 1);
die "could not connect: $!\n" unless $sock;
while ( $new_sock = $sock->accept() ) {
while ( defined( $buf = <$new_sock> ) ) {
print( $buf );
}
}
close ( $sock );
CLIENT
use IO::Socket;
$sock = new IO::Socket::INET (PeerAddr => 'thisbox',
PeerPort => 1200,
Proto => 'udp');
die "Socket could not be created: $!\n" unless $sock;
print $sock "Msg $_: here's some text!\n";
$sock->flush();
close( $sock );
------------------------------
Date: 2 Mar 1999 22:54:33 GMT
From: Douglas Dickinson <ac256@ncf.ca>
Subject: IO::Socket and udp - exits immediately
Message-Id: <36DC6BDF.D542B9C6@ncf.ca>
First off, let me admit that this is as much of a socket question
as a perl question (perhaps more). I appologize.
I have several working client/server pairs that communicate via
'tcp' sockets. I'm trying to convert one to work with 'udp'.
I have spend all day burried in the following documentation and
man pages and am still at a loss:
socket-faq, perl FAQ, IO::Socket, perlfunc, perlipc, socket, bind,
connect, setsockopt, listen, accept, ...
Most documentation (and news postings too) seem to amount to
"It's similar for udp". I cannot seem to find useful help
for how to work with udp for client server communication.
The following simplistic code is straight from a working tcp
example, but with 'udp' for the Proto. *But* when run, the
server exits immediately after being launched.
Any help on how to get this simple example running with udp
would be greatly appreciated.
Many thanks in advance,
DouglasDD
SERVER
use IO::Socket;
$sock = new IO::Socket::INET (LocalHost => 'thisbox',
LocalPort => 1200,
Proto => 'udp',
Listen => 5,
Reuse => 1);
die "could not connect: $!\n" unless $sock;
while ( $new_sock = $sock->accept() ) {
while ( defined( $buf = <$new_sock> ) ) {
print( $buf );
}
}
close ( $sock );
CLIENT
use IO::Socket;
$sock = new IO::Socket::INET (PeerAddr => 'thisbox',
PeerPort => 1200,
Proto => 'udp');
die "Socket could not be created: $!\n" unless $sock;
print $sock "Msg $_: here's some text!\n";
$sock->flush();
close( $sock );
------------------------------
Date: Wed, 03 Mar 1999 00:55:08 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: logically impaired
Message-Id: <36DC7A5C.774DC0BE@ngb.se>
Jonathan Stowe wrote:
> On Tue, 02 Mar 1999 20:09:46 +0100 Staffan Liljas wrote:
> > Because I'm stupid, and I'm currently working my way towards the
> > record for supplying the most incorrect information to clp.misc in
> > a day.
> Nah I think that I won that one Saturday about a year ago when I'd had
> too many bottles of Budvar ;-}
Dang. Can't I be best at anything?
Staffan
------------------------------
Date: 02 Mar 1999 16:25:55 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: method overriden!
Message-Id: <xkfr9r7lbi4.fsf@valdemar.col.hp.com>
"Ekkis" <ekkis@arix.com> writes:
> Somebody whose name Ekkis snipped wrote:
> >$self->init(@_) calls the init method for the object $self; since $self
> >is of class c2, this is the subroutine c2::init.
>
> but, doesn't $self resolve differently depending on the scope of usage?
No. That would defeat one of the main purposes of OO, after all. That's
what lets me define a derived class that changes the behaviour of
base-class functions.
> after all, why should references in the base class actually be obscured by
> derived classes?
Because you might want to have your base class call
$self->write($string);
And have the write function behave differently between a Pencil and Pen
class. Otherwise, what's the point of overloading write()?
> >You probably want to write
> >
> > $self->c1::init(@_);
> >
> >to ensure that the init method for class c1 is called.
>
> do you mean to say that I have to hard-code references to myself if there's
> ever the possibility that some derived class some day will use a name the
> same as mine?
Only if you don't want to use the derived class' functionality. And why
wouldn't you want to do that?
> or otherwise I lose access to my own methods? when I write
>
> $self->init()
>
> in the new() constructor for my class I mean to init stuff for my class, not
> for some derived class!
The derived class should take care of calling your init() function if it
needs to. If it does, you should tell anyone deriving from your classes
to do so. If they don't follow your rules, then you get to mock them
roundly and make fun of their clothing.
> The derived class shouldn't have to know to call the base class's
> init() or any other particular internal functionality of my class
> otherwise good God!
They should if they intend on overriding its behaviour.
> I'm not building it right, but I can't figure out quite how.
It sounds like you want the equivalent of C++'s 'private' scope. As far
as I can tell, my (admittedly out-of-date) perltoot page says you can't
get there from here:
>From perltoot:
Perl doesn't impose restrictions on who gets to use which methods.
The public-versus-private distinction is by convention, not syntax.
This seems to suggest that if your derived classes are going to override
init(), you must tell them to call your init() when they do so, or else
to name it something else, and avoid overriding it.
-=Eric
------------------------------
Date: Tue, 02 Mar 1999 23:49:27 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: method overriden!
Message-Id: <bO_C2.86$hc3.837@nswpull.telstra.net>
In article <KNZC2.6463$8N5.70114@typhoon-sf.pbi.net>,
"Ekkis" <ekkis@arix.com> writes:
>>That's the point of objects! The object is of class 'c2', so for
>>finding methods, it will first look in 'c2'. It finds init in the
>>class 'c2', so c2::init is called, *not* c1::init.
>
>
> when you say "the object" you really mean the thing returned by c2->new() so
> I can understand that if I say:
>
> $o = c2->new();
> $o->init();
>
> the call will resolve to c2::init(). But why should calls in a base class
> resolve to code defined in derived classes? that is callback behaviour, not
> virtual functions.
I think your main problem exists in not realising what $self means in
the c1::new sub. Let's look at the code:
package c1;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless($self, $class);
$self->init(@_);
return $self;
}
# rest of code omitted, see original article.
When you do
$o = c2->new();
It calls the new method against the c2 class. The $proto in that new
method is set to the class name, $class therefore is also set to the
class (c2). You then call $class->SUPER->new(); The proto (the first
argument passed to this method) will be 'c2', which is the value of
$class. This means that you bless $self there, into the class c2, and
the init method from c2 will be called.
Proper inheritance should probably be done in a different way. Both
classes should use the same constructor, and the inheriting classes
don't define it. Any method that needs to call its SUPER's method does
that explicitly. Something like:
package c1;
use strict;
use Carp;
sub new {
my $proto = shift;
print "c1: Proto $proto\n";
my $class = ref($proto) || $proto;
print "c1: Class $class\n";
my $self = {};
bless($self, $class);
print "c1: self " . ref($self), "\n";
$self->init(@_);
return $self;
}
sub init {
my $self = shift;
# init stuff
print "Class I: init()\n";
}
1;
package c2;
use strict;
@c2::ISA = ("c1");
sub init {
my $self = shift;
$self->SUPER::init();
# init stuff
print "Class II: init()\n";
}
1;
package main;
my $o = c2->new();
__END__
c1: Proto c2
c1: Class c2
c1: self c2
Class I: init()
Class II: init()
I believe that this is what you really want, and you just are trying
to achieve it in a way that cannot be used for this without hardcoding
class names. Proper inheritance shouldn't rely on that.
Martien
--
Martien Verbruggen |
Webmaster www.tradingpost.com.au | "In a world without fences,
Commercial Dynamics Pty. Ltd. | who needs Gates?"
NSW, Australia |
------------------------------
Date: Tue, 02 Mar 1999 22:46:06 GMT
From: anna@water.ca.gov
Subject: Q: multiline write
Message-Id: <7bhpnc$kvn$1@nnrp1.dejanews.com>
I'm still trying to find my way around using formats for report output. Any
help would be appreciated.
I have a format for each "paragraph" of the report, but I want to modify it so
there is a subtotal line for each paragraph. I'm not certain how to do that.
Here's what the format looks like now:
--------------------------------------
format FLOW = ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~ $area2print
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @< @<<<<<<<<<<<<<<<<<<<<<<@>> @>>>>>>>
@>>>>>>>> @>>>>>>> @>>> $past, $pstrm, $pnote, $pmonmflow,
$pmonfiftyave,$pmonurun,$pmonper
Excerpt from report:
-------------------
SAN FRANCISCO BAY AREA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NAPA NEAR ST
HELENA 38.0 18.9 38.0 201
CENTRAL COASTAL AREA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ARROYO SECO NEAR
SOLEDAD 12.0 24.0 12.0 50 NACIMIENTO BELOW NACIMIENTO DAM 1.6 47.5
41.9 88
What I want the report to look like:
-----------------------------------
SAN FRANCISCO BAY AREA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ NAPA NEAR ST
HELENA 38.0 18.9 38.0 201
===== ===== ===== ===
38.0 18.9 38.0 201
CENTRAL COASTAL AREA ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ARROYO SECO NEAR
SOLEDAD 12.0 24.0 12.0 50 NACIMIENTO BELOW NACIMIENTO DAM 1.6 47.5
41.9 88
===== ===== ===== ===
13.6 71.5 53.9 75
Thanks in advance for your reply,
Anna
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 02 Mar 1999 22:53:53 GMT
From: christopher@tokpela.com
Subject: Re[2]: does perl discourage obfuscated code? (was Re: Perl evangelism)
Message-Id: <7bhq5u$le4$1@nnrp1.dejanews.com>
> But in summary, let us please stop passing around the myth that Perl
> *is* write-only code, or *encourages* write-only code. I've found
> neither of those to be true in my commercial experience, and you are
> merely damaging the Perl community by passing along such lies. In
> most of the code I've been asked to maintain from others (even
> beginners), the question was never "what are they doing here" but "why
> are they doing this", which would have been true no matter what the
> language.
Definitely! The main problem, IMHO, is lack of a true grasp of the concepts
combined with the patience and clarity to manifest those concepts into an
elegant project. This is a programmer issue, not the language (tool) problem.
> beginners), the question was never "what are they doing here" but "why
> are they doing this", which would have been true no matter what the
Yeah, like building a bridge with a little experience but instead of
researching other bridges, you would just "wing it" :)
> neither of those to be true in my commercial experience, and you are
> merely damaging the Perl community by passing along such lies. In
Right on, Randall!!
In article <m1pv6tqmji.fsf@halfdome.holdit.com>,
merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Russell" == Russell Schulz <Russell_Schulz@locutus.ofB.ORG> writes:
>
> Russell> I believe it. Perl encourages hard-to-read code. that's
> Russell> just the way it is, and if you don't apply a strong
> Russell> discipline when writing Perl, you're going to be the proud
> Russell> owner of a ton of read-only code.
>
> I completely disagree here. Perl does nothing to encourage this. The
> only thing that *does* is TPJ's Obfuscated Perl contest.
>
> I may have become partially famous for my obscure one-liners here on
> Usenet, but when I write production code for hire, it's compact but
> readable and well-documented. (Most of it looks similar to my book
> and columns.)
>
> Russell> I would guess only APL has ever had a higher reliance on
> Russell> symbols and gave a stronger nod towards compactness.
>
> Are you automatically associating "compact" and "symbols" with
> "unreadable"? Maybe you need a new definition. :) If you knew only
> Hawaiian, and then had to learn English, you'd probably scream at
> having to learn *26* letters now. I think you'll need a more
> agreeable definition of "obfuscated" before we can argue this further.
>
> My definition of "obfuscated" is "code that even when someone *knows*
> the language appears to do one thing and actually does another".
>
> Russell> have you ever seen someone propose an `obfuscated
> Russell> Smalltalk' contest?
>
> Smalltalk is completely opaque to someone that doesn't grok true
> OO-rientation. And it'd be trivial to write code in Smalltalk that
> looks like it does one thing and actually does somethign else. And
> Smalltalk is fun enough to program in itself that we don't need
> programming contests to encourage fun. :)
>
> Defending Smalltalk in a Perl newsgroup. That's odd. Of course, I've
> talked about Perl on Smalltalk (squeak) mailing lists, so it's only
> fair.
>
> But in summary, let us please stop passing around the myth that Perl
> *is* write-only code, or *encourages* write-only code. I've found
> neither of those to be true in my commercial experience, and you are
> merely damaging the Perl community by passing along such lies. In
> most of the code I've been asked to maintain from others (even
> beginners), the question was never "what are they doing here" but "why
> are they doing this", which would have been true no matter what the
> language.
>
> print "Just another Perl hacker,"
>
> --
> 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@teleport.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
>
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Tue, 2 Mar 1999 15:03:44 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: The millennium cometh -- eventually
Message-Id: <MPG.11460e2ca59d16769896c6@nntp.hpl.hp.com>
In article <slrn7donmh.jnf.fl_aggie@enso.coaps.fsu.edu> on 2 Mar 1999
21:55:05 GMT, I R A Aggie <fl_aggie@thepentagon.com> says...
> On Tue, 2 Mar 1999 10:55:10 -0500, Russell Schulz
> <Russell_Schulz@locutus.ofB.ORG> wrote:
...
> + stop saying `20th Century'.
>
> Tell that to the historians...
I wonder if this isn't a peculiarly English-language aberration. For
example, in Italian 'il Quattrocento' refers to the 1400's. What a
wonderful source of confusion.
> + stop whining about 2000 not being a change into a new millennium
> + (because it is,
>
> No. It isn't. You know it isn't.
I was surprised to discover that one hundred years ago folks were
smarter than we are now. The primary celebration for the end of the
Nineteenth Century was on December 31, 1900. My father -- born on
January 21, 1900 -- used to boast about being born in the Nineteenth
Century, and as time went on this became more startling to people he
said it to.
And I think this thread has run out of Perl content!
--
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 03 Mar 1999 00:50:12 +0100
From: Staffan Liljas <staffan@ngb.se>
Subject: Re: The millennium cometh -- eventually
Message-Id: <36DC7934.5C43A323@ngb.se>
I R A Aggie wrote:
> On Tue, 2 Mar 1999 10:55:10 -0500, Russell Schulz
> <Russell_Schulz@locutus.ofB.ORG> wrote:
> + stop writing functions that return year-1900.
> Why? the number for a given year is an arbritrary definition. If I
> choose to come up with a different numbering scheme, but one I can map
> into the currently accepted (the legal calendar), or any other
> calendar I choose, and as long as I document such behaviour, why
> should it matter to you?
The point here being to document it. No matter how you treat years -
tell everyone about it. Maybe not in this newsgroup, but in a comment in
the program.
> 1. The concept of "zero" hadn't been discovered, and wouldn't be until
> the 1100 or 1200's by _Islamic_ scholars. Ergo, when the calendar
> was laid out, it started with 1 AD. There was no 0th year.
Actually, the zero was discovered in India, if I'm not mistaken. But it
came to Europe through Persia.
> 3. The Roman legions where subdivided into smaller units. One of those
> units was called a 'century', was made up of 100 men, and was
> commanded by a centurion.
Is this really of interest? This just seems like another exampel of the
fact that 'cent-' refers to the number 100 (I'm not sure of the actual
term in latin, but italians call 100 'cento'). I fail to see your point.
Nobody's disputing that a century is a hundred years.
> 4. Ergo, a 'century' of years consists of 100 years, and that the
> 'first century AD' consists of the years 1-100, inclusive.
Well, neither of these follow from the above. But it is true that
century refers to a time-period of a hundred years. But what 100 years
it refers to, isn't so obvious.
If you say 'the N-th century', however, it seems apparent that you would
start at the beginning of the enumeration of years and take it to mean
the hundred years that start (N-1)*100 from the origin. Since the
origin, as you state, is 1, it means the years (N-1)*100+1 to N*100.
However, a century isn't limited to such a period -- at least you cannot
derive from the words latin origin, nor from history what year a century
should start with. A century is a hundred [consecutive] years. A person
is a century old when he/she turns 100, even if he/she was born in 1850,
and this is not an abuse of the term.
> 5. Since a millenium is 1000 years (10 centuries), it stands to reason
> that the first millenium was the years 1-1000, the second will be
> the years 1001-2000, yadda, yadda, yadda.
A millenium is 1000 [consecutive] years (period). The N-th millenium is
however, [usually] defined in the way you state.
There is no clear logical reason for all of this, exept the common
useage of the terms, and since the terms the N-th century or the N-th
millenium is often misunderstood, maybe we shouldn't use them so much.
In Sweden, we use (almost without exception) the notions "the 19
hundreds" and "the 2 thousands", meaning respectively, 1900 - 1999 and
2000 - 2999. This isn't without problems either, since it seems strange
to say "the 0 hundreds", but usually this isn't a big problem.
> Yeah. You disagree with the definition of what a century/millenium is.
> And there's nothing wrong with that.
No he doesn't (if I'm understanding him correctly). He's arguing that
you shouldn't use a term that, by common useage if not by definition, is
ambiguous.
> + have you _ever_ seen anyone think 2000 is part of the 1900s?
>
> Yes. People who have a clue. Alternatively, you can always use the
> Hewbrew calendar, where this year is 5759.
Well that's not correct. The 20th century is 1901 - 2000, but the 1900s
are the years that start with 19, ie 1900-1999.
Staffan
------------------------------
Date: Tue, 02 Mar 1999 23:15:43 GMT
From: "Bryan C. Warnock" <bwarnock@gtemail.net>
Subject: Re: Tk binding and callbacks, EOT
Message-Id: <zi_C2.2457$_J5.1174@news.rdc1.md.home.com>
Bryan C. Warnock wrote in message ...
>Cross-posted for wider distribution, reposted with additional information.
>Hopefully there are
>some gurus here who don't regularly follow the Tk group.
>
>I'm looking for an explanation of an (un?)documented (un?)feature related
to
>Tk bindings and callbacks.
>
{The rest snipped}
O'Tay, I'm probably going to write this up for the mailing list. It appears
to be a legit bug.
Moving back to CLPT for continued non-discussion.
On a side-note, (not that I expect anyone to see this, because it's in a
thread that most people will have already blown off - I mean, the same
author three posts in a row?), and because the
subject doesn't matter the question at all, but does anywhere care about
compiler warnings when building Perl? (Warnings like trying to test
equality between a negative value and an unsigned int, for example.)
------------------------------
Date: 2 Mar 1999 23:17:50 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Variables in regular expressions
Message-Id: <7bhriu$lq5$1@mathserv.mps.ohio-state.edu>
[A complimentary Cc of this posting was sent to Allan M. Due
<Allan@Due.net>],
who wrote in article <EKZC2.206$EU1.4436@nntp1.nac.net>:
> Of course, $ in a regex (smaking head with hand). Thank you, that was what I
> was missing. So obvious now that I see it.
This is what
perl -Mre=debugcolor
is for.
Ilya
------------------------------
Date: 2 Mar 1999 23:40:07 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: y2k and 4-digit dates (was Re: foreach and while)
Message-Id: <7bhssn$ee$2@client2.news.psi.net>
Staffan Liljas (staffan@ngb.se) wrote on MMIX September MCMXCIII in
<URL:news:36DC283A.4E261E27@ngb.se>:
.. Russell Schulz wrote:
.. > > It's all about context. 4 digits doesn't magically fix everything.
.. >
.. > actually, for the overwhelming majority of cases (AD1-AD9999), they
.. > do. if used consistently, if there hadn't been `year-1900' silliness,
.. > if data storage would have allowed them, if output fields were wide
.. > enough, there wouldn't have been a y2k concern.
..
.. Actually, AD1-AD9999 isn't really the overwhelming majority of all
.. cases. The Universe has existed for about 2E10 years, and is likely to
.. exist for at least that many more, so 1E4 years is only a 2.5E-7 part of
.. all years, not really a majority. However, it might be the overwhelming
.. majority of cases YOU need to consider. 4-digit years are appropriate
.. where you have programs that you expect to deal with timespans around
.. 1E3 years, and 2-digit years are fine when you're dealing with timespans
.. of 1E1 years. The rest is implementation.
I would say 1E4 and 1E2 (10000 and 100) years.
.. The problem arises when you assume that the context is obvious or
.. uninteresting. What if the front page doesn't contain that information?
.. What if you don't write documentation to show WHAT you're assuming about
.. your 2-digit (or four digit)? You get problems.
..
.. We get the same problem whenever the context isn't obvious but someone
.. considered it to be so. And four-digit years is an example of this, if
.. we're dealing with dates out of the ordinary.
And a third and important case is when data is moved from an environment
where the context is available, to one where it's not. A credit card
with an expiration date on it of "01" will not confuse anyone using the
card; it's a credit card, and there where no credit cards early this
century. And credit cards only have at most a few years before they
expire, so "01" has to be 2001.
But when it gets processed, the context might get lost....
Abigail
--
perl -wle 'print "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/'
------------------------------
Date: Tue, 02 Mar 1999 18:44:49 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: jim <wyma69@nidlink.com>
Subject: Re: Yes, I'm a newbie. Any suggestions despite that?
Message-Id: <36DC77F1.F2EB071A@giss.nasa.gov>
[posted and mailed]
jim wrote:
>
> Hi All,
>
> I'm attempting to monitor a very large, constantly growing, log file
> (RADIUS logs). My Idea is to read the new info each night from the log
> file, and write a file with the file size as of last reading, for reference
> at the next reading. Sounds simple enough, but I'm having trouble. What
> happens is that it gives me a file of the right length, but without the
> proper offset. the size calculates properly, but the reading starts at the
> beginning of the file rather than starting with the new stuff. the output
> file is padded at the start with null characters equal to what the offset
> should be. I'ts obviously ugly, but I can't for the life of me figure out
> where the problems are.
I can't say I agree with your overall program logic,
but <shrug>. Here's something in a similar spirit:
local (*LOG, *LAST, *OUT);
open LOG, "< detail" or die "foo: $!";
seek LOG, 0, 2;
my $size = tell LOG;
open LAST, "< last";
my $lastsize = <LAST> || 0;
seek LOG, 0 - $lastsize, 1;
open OUT, "> output" or die "beep: $!";
print OUT (<LOG>);
Jay Glascoe
--
"Narf."
--Pinky
------------------------------
Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>
Administrivia:
Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing.
]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body. Majordomo will then send you instructions on how to confirm your
]subscription. This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.
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 5038
**************************************