[23894] in Perl-Users-Digest
Perl-Users Digest, Issue: 6096 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 9 03:05:50 2004
Date: Mon, 9 Feb 2004 00:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 9 Feb 2004 Volume: 10 Number: 6096
Today's topics:
Re: A Grep and a couple Awks <and a lot of Tassilo help (Agrapha)
Re: A Grep and a couple Awks <and a lot of Tassilo help <uri@stemsystems.com>
Re: A Grep and a couple Awks <and a lot of Tassilo help <usenet@morrow.me.uk>
Re: A Grep and a couple Awks <and a lot of Tassilo help (Agrapha)
Re: A Grep and a couple Awks <and a lot of Tassilo help <uri@stemsystems.com>
Re: A Grep and a couple Awks <and a lot of Tassilo help <Joe.Smith@inwap.com>
Array size <dd-b@dd-b.net>
Re: Array size <mpapec@yahoo.com>
Re: converting scalar to an array of elements <dha@panix.com>
Re: Copy Constructor Craziness (Unknown Poster)
Re: Copy Constructor Craziness (Jay Tilton)
Re: Getting CGI to read from a different STDIN source (Bill Gerba)
HTTP Get <tom@nosleep.net>
Re: HTTP Get <Joe.Smith@inwap.com>
moving structures <duff@hotmail.com>
Re: moving structures <duff@hotmail.com>
Re: moving structures <pinyaj@rpi.edu>
Re: moving structures (Walter Roberson)
Re: moving structures <duff@hotmail.com>
Re: moving structures <duff@hotmail.com>
need help with this little perl script <dannywork5@hotmail.com>
Performance patch to Parse-Yapp 1.05 <clint@0lsen.net>
Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail <clint@0lsen.net>
Re: Perl project update <tadmc@augustmail.com>
Tools needed to preserve the public domain <updinfo@public-domain.org>
use IO::Socket; <tom@nosleep.net>
Re: use IO::Socket; <usenet@morrow.me.uk>
Re: use IO::Socket; <uri@stemsystems.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 8 Feb 2004 21:13:57 -0800
From: brian@box201.com (Agrapha)
Subject: Re: A Grep and a couple Awks <and a lot of Tassilo help>
Message-Id: <11aabb15.0402082113.62a52880@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<bvkubd$7ko$1@nets3.rz.RWTH-Aachen.DE>...
> > # info about it. We begin by making sure they enter one
> > # on the command line or give them an example if they
> > # fail to do so.
> > ###
> >
> >
> > if (!$ARGV[0] or !$ARGV[1] or !$ARGV[2]) {
> > print "Syntax is \"./triag.pl accessnumber yyyymmdd mkt\"\n";
> > print "example: ./triag.pl 2015551212 20040101 lon1
> > die "Include an access number, date and market when starting
> > Triag\n";
> > }
>
> This is mostly a question of good style: usage-messages should go to
> stderr really:
>
> if (@ARGV != 3) {
> warn <<EOWARN;
> Syntax is $0 accessnumber yyyymmdd mkt
> example: $0 2015551212 20040101 lon1
> Include an access number, date and market when starting Triag
> EOWARN
> exit(1);
> }
>
> I use $0 because it is shorter and because it contains the exact path
> which you used to call your script.
$0 !? Very cool. I did not know what that variable was for even after
I looked it up. I had to run it once. Ok so the @ARGV is the global
array for the command line. Feed it 10 bits of info separated by ' '
and I can test for the number of elements by (@ARGV <operand> 10).
EOWARN is your Handle and << means to append into something called
"warn". The exit(1) must print out the "warn" we just prepopulated.
The terminator EOWARN seems to work only when I take all the
whitespace from in front and place it on the hard left. Othewise Perl
doesn't seem to find it. Would you describe "warn" ? What is that
variable to stderr? How does perl know what is what here? no "", no
echos (except an exit(1)) no ";" I'm missing a concept with "<<"
somewhere.
>
> Some of these variables shouldn't have file-scope. As far as I can see,
> $code and $users is only used in a for-loop later on. Better restrict
> their scope to this loop.
Agreed. This is bad form. I've corrected the issue (legacy bad code
style from the start of this script)
>
> Maybe a pipe-open is more appropriate here:
>
> open ZGREP, "|", "zgrep $ARGV[0] ./radiuslog/..."
> or die "Could not spawn zgrep: $!";
> my (@badcalls, $total);
> while (<ZGREP>) {
> $total++;
> push @badcalls, $_ if /,0 /;
> }
> close ZGREP;
>
> This needs less memory and gets rid of @selected altogether.
Confession here. The files this script opens are quite large. and
there are 30 files. The nifty shell script this came from was banned
due to memory issues. Thats why we created a perl script. Just that
helped dramatically. Still heavy on the machine but it takes 5 minutes
and not 15-20 minutes to run. If I can save memory cpu cycles then I'm
all for it.
> There is quite some redundancy in the above two loops. You can squeeze
> that into one:
>
> my %errorsz;
> foreach (@badcalls) {
> my ($code, $users) = (split)[3,7];
> $error_codes{ $code }++;
> $error_users{ $users }++;
> $errorsz{ $code }->{ $users }++;
> }
The redundancy is simply due to my lack of understanding. The complex
structure that is built here was quite beyond my skill level for the
moment. The issue is a hash of hashes. Up to this point I simply count
how many error codes or how many users. This is different. I have a
structure like this:
my %errors = (
2005551212 => {
101,4 => 10,
33,185 => 33,
},
2005551213 => {
63,43 => 15,
65,42 => 26,
},
...
);
the 10 digit numbers are phone numbers. The 101,4 is an example of an
error code. The 10 is the count. I need to sort this by phone number.
I.E.:
print "\nNumber / Error / Totals\n";
for my $n (sort { $a <=> $b } keys %errorsz) {
# $errorsz{ $n } is now itself a reference to a hash
my %codesz = %{ $errorsz{ $n } };
# compute the total numbers of errors for this phone-number
my $qty;
for ( keys %codesz ) {
$qty += $codesz{ $_ };
}
# display the stats for a given phone-number $n
print "$n - ", join ("/", keys %codesz), " - $qty\n";
}
I separated these out for 3 different prints just so I could keep it
straight in my mind.
> For the rest, Uri has already given good advise and there#s nothing to
> add.
Uri made a good point that all prints should come from the same
statement. just load up a variable and then print once. I'll look over
that section in a minute.
P.S. Could someone help me find the perldocs? Tassilo has mentioned
them multiple times and I have failed to ask him how do I access those
docs. Is it a web based application or something I can download?
------------------------------
Date: Mon, 09 Feb 2004 05:21:29 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: A Grep and a couple Awks <and a lot of Tassilo help>
Message-Id: <x7d68okeue.fsf@mail.sysarch.com>
perldoc perl
perldoc perlXXXX
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 9 Feb 2004 05:37:48 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: A Grep and a couple Awks <and a lot of Tassilo help>
Message-Id: <c076bc$rmh$1@wisteria.csv.warwick.ac.uk>
brian@box201.com (Agrapha) wrote:
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in message news:<bvkubd$7ko$1@nets3.rz.RWTH-Aachen.DE>...
> > This is mostly a question of good style: usage-messages should go to
> > stderr really:
> >
> > if (@ARGV != 3) {
> > warn <<EOWARN;
> > Syntax is $0 accessnumber yyyymmdd mkt
> > example: $0 2015551212 20040101 lon1
> > Include an access number, date and market when starting Triag
> > EOWARN
> > exit(1);
> > }
> >
> > I use $0 because it is shorter and because it contains the exact path
> > which you used to call your script.
>
> $0 !? Very cool. I did not know what that variable was for even after
> I looked it up. I had to run it once. Ok so the @ARGV is the global
> array for the command line. Feed it 10 bits of info separated by ' '
> and I can test for the number of elements by (@ARGV <operand> 10).
> EOWARN is your Handle and << means to append into something called
> "warn". The exit(1) must print out the "warn" we just prepopulated.
> The terminator EOWARN seems to work only when I take all the
> whitespace from in front and place it on the hard left. Othewise Perl
> doesn't seem to find it. Would you describe "warn" ? What is that
> variable to stderr? How does perl know what is what here? no "", no
> echos (except an exit(1)) no ";" I'm missing a concept with "<<"
> somewhere.
Very much so :).
<<HERE
...
HERE
is a here-doc, exactly as in shell. The statement
warn <<EOWARN;
blah
EOWARN
is equivalent to
warn "blah\n";
. See perldoc perlop. warn is simply a function being called with one
argument: see perldoc -f warn.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: 8 Feb 2004 23:12:20 -0800
From: brian@box201.com (Agrapha)
Subject: Re: A Grep and a couple Awks <and a lot of Tassilo help>
Message-Id: <11aabb15.0402082312.3b85f0fc@posting.google.com>
Uri Guttman <uri@stemsystems.com> wrote in message news:<x7r7xeja81.fsf@mail.sysarch.com>...
> >>>>> "A" == Agrapha <brian@box201.com> writes:
>
> A> #!/usr/bin/perl -w
> A> use strict;
>
> good!
>
Good! :)
>
> A> if (!$ARGV[0] or !$ARGV[1] or !$ARGV[2]) {
>
> eww!
> if ( @ARGV != 3 ) {
>
dern it :( I admit, the OR statements look a lot less appealing then
your neat 7 syllable command. I really need to tighten up my
statements.
>
>
> A> print "Syntax is \"./triag.pl accessnumber yyyymmdd mkt\"\n";
> A> print "example: ./triag.pl 2015551212 20040101 lon1
> A> die "Include an access number, date and market when starting
> A> Triag\n";
>
> why not a single die? and lose the \" stuff. here docs to the rescue!!
>
> die <<DIE ;
> Syntax is "./triag.pl accessnumber yyyymmdd mkt"
> example: ./triag.pl 2015551212 20040101 lon1
> Include an access number, date and market when starting Triag
> DIE
>
> what i like to do is make a usage sub like this:
>
> sub usage {
>
> my ( $err_text ) = @_ ;
>
> $err_text ||= '' ; # stop undef warnings
>
> die <<DIE ;
> $err_text
>
> Syntax is "./triag.pl accessnumber yyyymmdd mkt"
> example: ./triag.pl 2015551212 20040101 lon1
> Include an access number, date and market when starting Triag
> DIE
>
> }
>
> then you can call that in different places in the arg parsing stuff like
> this:
>
> usage( "missing arguments ) if @ARGV < 3 ;
> usage( "too many arguments ) if @ARGV > 3 ;
>
very slick..... Thats a very tight style. I don't fully understand the
die <<DIE
...
DIE
idea yet. Where can I find some online docs about the
initiator/terminator statements? The code above is so much easier to
read.
>
> declare your variables in the tightest scope possible. these are file
> scoped globals and are possibly too visible.
agreed. The scope was set too wide at first simply because I honestly
didn't know any better. I think it's fixed now keep the variables used
in the for- loops isolated to the for-loops.
> A> my @selected=`zgrep $ARGV[0]
> A> ./radiuslog/$ARGV[1]/server.$ARGV[2].Detail.$ARGV[1].gz`;
>
> CPAN has modules to read .gz files so you can save on a fork.
I'll search CPAN tonight. This is a serious bottleneck in the program.
The files I'm gleening through here are 1-5meg big and there are 30
files. Anything at all that will either let me slurp the files up or
zgrep them or what. Thanks for the tip on where to find the info on
zgreps.
> here docs again! precalculate the rate value:
> my $rate = 100 - (($fail / $total) * 100)
>
> print <<TOTALS ;
> total_calls $total total_failures $fail access number $ARGV[0]
> success rate for dates selected: $rate
> TOTALS
This must have been one of those gaps in my perl education. I think
after the third of fourth time I'm getting the idea. The TOTALS acts
like a " thats why there needs to be a terminator TOTALS as well. the
semicolon after the first TOTALS has me confused though whay doesn't
perl just end that statement after the ";" and error out the next 3
lines?
>
> again, i would build it all up in a single string and then print it. it
> is cleaner, faster and lets you control where you print it all. and
> statement modifiers will make it look even better:
>
> my $text = '' ;
>
> $text .= <<TXT ;
>
> ErrorCodes / Totals
> -------------------
> TXT
>
> $text .= <<TXT foreach keys %error_codes ;
> $_ / $error_codes{$_}
> TXT
>
> $text .= <<TXT ;
>
> PhoneNumber / TotalFail
> -----------------------
> TXT
>
> $text .= <<TXT foreach keys %error_users ;
> $_ / $error_users{$_}
> TXT
>
> etc.
>
> notice how much easier it is to read what will be printed and also to
> line it up? no extra " or \n or \t chars to provide visual noise. of
> course some don't like here docs as much as i do but they are infidels! :)
I really like the clarity there. I need to study the strings a bit
better. The semicolon in the statement
$text .= <<TXT foreach keys %error_users ;
has me confused. the .= means to add to the variable I think. but the
; seems to me to end the statement.
> A> for my $n (sort { $a <=> $b } keys %errorsz) {
> A> # $errorsz{ $n } is now itself a reference to a hash
> A> my %codesz = %{ $errorsz{ $n } };
>
> no need to copy that hash. see below
>
> A> # compute the total numbers of errors for this phone-number
> A> my $qty;
> A> for ( keys %codesz ) {
>
> for ( keys %{ $errorsz{ $n } } ) {
>
> A> $qty += $codesz{ $_ };
> A> }
>
> and that can be shrunk with a statement modifier (i like those too!).
>
> $qty += %{ $errorsz{ $_ } } for keys %{ $errorsz{ $n } } ;
>
> but you are only accessing and summing the values of the subhash and you
> don't need the keys for that. use the values function:
>
> $qty += $_ for values %{ $errorsz{ $n } } ;
>
> that is all you need there AFIACT from your code.
>
whew, ok Uri you just went over my head. This whole section is very
difficult for me to understand. Where can I find some good information
on how to understand a hash of hashes. ?
------------------------------
Date: Mon, 09 Feb 2004 07:20:39 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: A Grep and a couple Awks <and a lot of Tassilo help>
Message-Id: <x7wu6wiurd.fsf@mail.sysarch.com>
>>>>> "A" == Agrapha <brian@box201.com> writes:
A> Uri Guttman <uri@stemsystems.com> wrote in message news:<x7r7xeja81.fsf@mail.sysarch.com>...
A> if (!$ARGV[0] or !$ARGV[1] or !$ARGV[2]) {
>>
>> eww!
>> if ( @ARGV != 3 ) {
>>
A> dern it :( I admit, the OR statements look a lot less appealing then
A> your neat 7 syllable command. I really need to tighten up my
A> statements.
just don't tighten too much. good style is a balance between tight code
and clarity.
>> what i like to do is make a usage sub like this:
>>
>> sub usage {
>>
>> my ( $err_text ) = @_ ;
>>
>> $err_text ||= '' ; # stop undef warnings
>>
>> die <<DIE ;
>> $err_text
>>
>> Syntax is "./triag.pl accessnumber yyyymmdd mkt"
>> example: ./triag.pl 2015551212 20040101 lon1
>> Include an access number, date and market when starting Triag
>> DIE
>>
>> }
A> very slick..... Thats a very tight style. I don't fully understand the
A> die <<DIE
A> ...
A> DIE
A> idea yet. Where can I find some online docs about the
A> initiator/terminator statements? The code above is so much easier to
A> read.
that is called a here document. covered in perldata in the literals
section. it is a very clean way to do multiline strings.
>> here docs again! precalculate the rate value:
>> my $rate = 100 - (($fail / $total) * 100)
>>
>> print <<TOTALS ;
>> total_calls $total total_failures $fail access number $ARGV[0]
>> success rate for dates selected: $rate
>> TOTALS
A> This must have been one of those gaps in my perl education. I think
A> after the third of fourth time I'm getting the idea. The TOTALS acts
A> like a " thats why there needs to be a terminator TOTALS as well. the
A> semicolon after the first TOTALS has me confused though whay doesn't
A> perl just end that statement after the ";" and error out the next 3
A> lines?
the print statement is what needs the ;. the here doc literal has 2
parts. the <<TOKEN is where the string ends up in the expression. its
content is all the following lines up to the matching close TOKEN.
A> I really like the clarity there. I need to study the strings a bit
A> better. The semicolon in the statement
A> $text .= <<TXT foreach keys %error_users ;
A> has me confused. the .= means to add to the variable I think. but the
A> ; seems to me to end the statement.
same as above. you always need a ; to end (actually separate) a
statement. there are minor exceptions (last one in a block) but don't
fall into that trap as it will bite you when you need to add more code
later
>>
>> and that can be shrunk with a statement modifier (i like those too!).
>>
>> $qty += %{ $errorsz{ $_ } } for keys %{ $errorsz{ $n } } ;
>>
>> but you are only accessing and summing the values of the subhash and you
>> don't need the keys for that. use the values function:
>>
>> $qty += $_ for values %{ $errorsz{ $n } } ;
>>
>> that is all you need there AFIACT from your code.
>>
A> whew, ok Uri you just went over my head. This whole section is very
A> difficult for me to understand. Where can I find some good information
A> on how to understand a hash of hashes. ?
perldoc perlreftut
perldoc perllol
perldoc perldsc
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 09 Feb 2004 07:38:00 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: A Grep and a couple Awks <and a lot of Tassilo help>
Message-Id: <rNGVb.209351$nt4.987931@attbi_s51>
Agrapha wrote:
> P.S. Could someone help me find the perldocs? Tassilo has mentioned
> them multiple times and I have failed to ask him how do I access those
> docs. Is it a web based application or something I can download?
Yes to both.
-Joe
unix% perldoc perl # Unix (Linux) command line
C:\>perldoc perl # MS-DOS command window
Start -> Programs -> ActiveState ActivePerl 5.8 -> Documentation
http://www.perldoc.com/perl5.8.0/bin/perldoc.html
--
I love my TiVo - http://www.inwap.com/u/joe/tivo/
------------------------------
Date: Mon, 09 Feb 2004 01:32:15 -0600
From: David Dyer-Bennet <dd-b@dd-b.net>
Subject: Array size
Message-Id: <m2vfmgd7y8.fsf@gw.dd-b.net>
I know $#foo is the max subscript of @foo.
What's the max subscript of $f = [5, 4, 5, 4, 9]? (Yeah, I know, it's
4).
That is, if I have an array ref, how do I get the max subscript of
that array, without copying the whole thing to a temporary array?
--
David Dyer-Bennet, <mailto:dd-b@dd-b.net>, <http://www.dd-b.net/dd-b/>
RKBA: <http://noguns-nomoney.com> <http://www.dd-b.net/carry/>
Photos: <dd-b.lighthunters.net> Snapshots: <www.dd-b.net/dd-b/SnapshotAlbum/>
Dragaera/Steven Brust: <http://dragaera.info/>
------------------------------
Date: Mon, 09 Feb 2004 08:59:04 +0100
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: Array size
Message-Id: <23fe2097n6tue1gkedrqqdm50bas4ivu01@4ax.com>
On Mon, 09 Feb 2004 01:32:15 -0600, David Dyer-Bennet <dd-b@dd-b.net>
wrote:
>I know $#foo is the max subscript of @foo.
>
>What's the max subscript of $f = [5, 4, 5, 4, 9]? (Yeah, I know, it's
>4).
>
>That is, if I have an array ref, how do I get the max subscript of
>that array, without copying the whole thing to a temporary array?
$#{ $f } or just $#$f
------------------------------
Date: Mon, 9 Feb 2004 00:40:20 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: converting scalar to an array of elements
Message-Id: <slrnc2dlnk.hcp.dha@panix2.panix.com>
In article <40257AAB.4FBEC5FA@acm.org>, John W. Krahn wrote:
> Chuckb wrote:
>>
>> I should know this but, what is the quickest way to convert a scalar value
>> into an array?
>> Ex: $name="Fred";
>> so that
>> $arrayname[0]="F";
>> $arrayname[1]="r";
>> $arrayname[2]="e";
>> $arrayname[3]="d";
>
> I don't know which is the quickest, you'll have to use Benchmark for that.
[snip various methods]
While we're having fun, how about...
unshift @arrayname, chop $string_containing_Fred while $string_containing_Fred;
...although I have a feeling that may not scale well.
dha
--
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
Your pluck is admirable. However, arguing for a 'pure computer
science' approach in the perl5-porters mailing list is somewhat like
inquiring about mileage in a Maserati dealership. People are given to
drop their champagne glasses and stare. - Felix Gallo, p5p
------------------------------
Date: 8 Feb 2004 17:21:33 -0800
From: use63net@yahoo.com (Unknown Poster)
Subject: Re: Copy Constructor Craziness
Message-Id: <c62e93ec.0402081721.4d9c81d2@posting.google.com>
tiltonj@erols.com (Jay Tilton) wrote in message news:<4024a8f9.9404503@news.erols.com>...
>
> Back up a couple pages to see:
>
> The ++$a operation can be autogenerated using $a+=1 or $a=$a+1, ....
> ^^^^^^^
> That second part is a tricky read. Is the '=' in there supposed to be a
> copy constructor, or does it represent an ordinary, non-overloaded
> assignment?
>
The next sentence is also verrrry interesting:
"However, this does not trigger the copying behavior that a real
++ operator would."
Horsefeathers! That is exactly what is happening in this case.
A copy constructor is being autogenerated.
> There's a conspicuous change in the 5.8 docs:
>
> The ++$a operation can be expressed in terms of $a+=1 or $a+1, ....
>
> As I read it, that means that the class will use an available copy
> constructor to do ++$a, but it can finesse its way around a copy
> constructor's absence without having to autogenerate one.
In the example earlier in the thread, "++" is not EXPLICITLY
overloaded, but "+" is (and += is not). The copy constructor
is being autogenerated in this case - it is self-evident in
that $g and $f end up referencing different objects, while
there was no overloading of "=". The text of Programming Perl 3E
seems to be wrong, or at least very misleading, because I don't see
any justification for this autogeneration.
Now, for another intersesting result. When I do explicitly overload
"++" in the class, Perl bombs out at "++g" with an error message stating:
"... Operation '=', no method found, argument in overloaded
package Rational ..."
This seems more in line with what was stated in the book - that
autogeneration of a copy constructor (only?) takes place if the
class is "a plain scalar".
As Ricky Ricarco would say, "Somebody has some splainin to do!".
------------------------------
Date: Mon, 09 Feb 2004 06:02:16 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Copy Constructor Craziness
Message-Id: <402706db.164534398@news.erols.com>
use63net@yahoo.com (Unknown Poster) wrote:
: The next sentence is also verrrry interesting:
: "However, this does not trigger the copying behavior that a real
: ++ operator would."
:
: Horsefeathers! That is exactly what is happening in this case.
: A copy constructor is being autogenerated.
You are mistaken. There is no copy constructor involved at all.
: In the example earlier in the thread, "++" is not EXPLICITLY
: overloaded, but "+" is (and += is not). The copy constructor
: is being autogenerated in this case - it is self-evident in
: that $g and $f end up referencing different objects, while
: there was no overloading of "=".
If the overloaded '+' returns a new object, as it does in the pared-down
demonstration class I wrote in the previous article, how could you
sensibly expect an autogenerated '++' not to? This is not any kind of
evidence that a copy constructor is being used.
If your own overloaded '+' does not return a new object, it's time for
you to show the code for your overloaded operators.
: The text of Programming Perl 3E
: seems to be wrong, or at least very misleading,
The book is at least 3.5 years behind the Perl docs' revision state.
Save accusations of incorrectness for the current version.
Obsolescence issues aside, the fourth paragraph in the "The Copy
Constructor (=)" section of chapter 13 plainly says:
The need for copying is recognized only by mutators such as ++ or
+= . . . . If the operation is autogenerated via +, . . . then no
copying occurs, . . . .
What do you find wrong or misleading about that?
: because I don't see any justification for this autogeneration.
You're chasing phantoms here. There is no autogenerated copy
constructor.
: Now, for another intersesting result. When I do explicitly overload
: "++" in the class, Perl bombs out at "++g" with an error message stating:
: "... Operation '=', no method found, argument in overloaded
: package Rational ..."
Yes. If you're overloading a mutator, there needs to be a copy
constructor. If you're letting the mutator be autogenerated, a copy
constructor is irrelevant.
------------------------------
Date: 8 Feb 2004 21:35:31 -0800
From: junkmail@wirespring.com (Bill Gerba)
Subject: Re: Getting CGI to read from a different STDIN source
Message-Id: <7f2e88c6.0402082135.1ac6736f@posting.google.com>
Brilliant, both of you. Thanks!
------------------------------
Date: Fri, 6 Feb 2004 01:11:50 -0800
From: "Tom" <tom@nosleep.net>
Subject: HTTP Get
Message-Id: <402363a5$1@nntp0.pdx.net>
Does anyone know of issues where newlines are sometimes present in
downloaded web pages and sometimes not?
The source isn't changing, nor are the web pages, but it appears randon as
to whether or not the newlines show up.
Using NTTP, they always showed up, but can't use that anymore, getting bad
requests.
Thanks,
Tom
------------------------------
Date: Mon, 09 Feb 2004 07:58:18 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: HTTP Get
Message-Id: <q4HVb.7700$032.28554@attbi_s53>
Tom wrote:
> Does anyone know of issues where newlines are sometimes present in
> downloaded web pages and sometimes not?
> The source isn't changing, nor are the web pages, but it appears randon as
> to whether or not the newlines show up.
> Using NTTP, they always showed up, but can't use that anymore, getting bad
> requests.
Rip out all the IO code in your program and replace it with
use LWP::Simple;
It will take care of all the "bad request" problems.
-Joe
------------------------------
Date: Mon, 9 Feb 2004 00:34:08 +0000 (UTC)
From: "erehwon" <duff@hotmail.com>
Subject: moving structures
Message-Id: <c06ki0$ad4$1@titan.btinternet.com>
hi,
I'm trying to rearrange some lists, but am having problems(!) I'm quite
new to perl...
#some vectors
$a = [( 1,2,3)];
$b = [( 3,2,3)];
$c = [( 4,5,6)];
# lists of vectors - each list starting out containing one vector
$data{$i++} = [($a)];
$data{$i++} = [($b)];
$data{$i++} = [($c)];
now I want to merge $data{0} and $data{1} so I do:
$data{0} = [(@$data{0},@$data{1})];
$data{1} = undef;
but this doesn't work. It should effectively make the lists appear as
though I'd set them up like this in the first place:
$data{$i++} = [($a,$b)];
$data{$i++} = [($c)];
(my print routine looks like this:)
sub printdata
{
my $t = shift;
my $c;
foreach $c (@$t) {
print "( $$c[0], $$c[1],$$c[2] )";
}
print "\n";
}
and will print with:
foreach $i (sort keys $data )
{
printdata $data{$i};
}
can anyone tell me what I'm doing wrong when trying to merge the lists?
thanks,
JJ
------------------------------
Date: Mon, 9 Feb 2004 00:39:57 +0000 (UTC)
From: "erehwon" <duff@hotmail.com>
Subject: Re: moving structures
Message-Id: <c06kst$b0k$1@titan.btinternet.com>
ahh.. it's a problem with precedence I believe, seeing as the following
works:
$l = $data{0};
$r = $data{1};
$data{0} = [( @$l, @$r )];
But this is daft!... how do I do this in one line? :o)
thanks,
JJ
"erehwon" <duff@hotmail.com> wrote in message
news:c06ki0$ad4$1@titan.btinternet.com...
> hi,
> I'm trying to rearrange some lists, but am having problems(!) I'm quite
> new to perl...
>
> #some vectors
> $a = [( 1,2,3)];
> $b = [( 3,2,3)];
> $c = [( 4,5,6)];
>
> # lists of vectors - each list starting out containing one vector
> $data{$i++} = [($a)];
> $data{$i++} = [($b)];
> $data{$i++} = [($c)];
>
> now I want to merge $data{0} and $data{1} so I do:
>
> $data{0} = [(@$data{0},@$data{1})];
> $data{1} = undef;
>
> but this doesn't work. It should effectively make the lists appear as
> though I'd set them up like this in the first place:
> $data{$i++} = [($a,$b)];
> $data{$i++} = [($c)];
>
> (my print routine looks like this:)
>
> sub printdata
> {
> my $t = shift;
> my $c;
> foreach $c (@$t) {
> print "( $$c[0], $$c[1],$$c[2] )";
> }
> print "\n";
> }
>
> and will print with:
> foreach $i (sort keys $data )
> {
> printdata $data{$i};
> }
>
> can anyone tell me what I'm doing wrong when trying to merge the lists?
> thanks,
> JJ
>
>
>
------------------------------
Date: Sun, 8 Feb 2004 20:00:28 -0500
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: erehwon <duff@hotmail.com>
Subject: Re: moving structures
Message-Id: <Pine.SOL.3.96.1040208195840.29629C-100000@vcmr-86.server.rpi.edu>
[posted & mailed]
On Mon, 9 Feb 2004, erehwon wrote:
>$a = [( 1,2,3)];
>$b = [( 3,2,3)];
>$c = [( 4,5,6)];
>
># lists of vectors - each list starting out containing one vector
>$data{$i++} = [($a)];
>$data{$i++} = [($b)];
>$data{$i++} = [($c)];
>
>now I want to merge $data{0} and $data{1} so I do:
>
>$data{0} = [(@$data{0},@$data{1})];
>$data{1} = undef;
The @ in @$data{0} is binding to $data, not to $data{0}.
$data{0} = [ @{ $data{0} }, @{ $data{1} } ];
delete $data{$1};
Or, more succintly:
push @{ $data{0} }, @{ delete $data{1} };
I think.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: 9 Feb 2004 01:08:37 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: moving structures
Message-Id: <c06mil$ogd$1@canopus.cc.umanitoba.ca>
In article <c06ki0$ad4$1@titan.btinternet.com>,
erehwon <duff@hotmail.com> wrote:
: I'm trying to rearrange some lists, but am having problems(!) I'm quite
:new to perl...
:#some vectors
:$a = [( 1,2,3)];
:$b = [( 3,2,3)];
:$c = [( 4,5,6)];
:# lists of vectors - each list starting out containing one vector
:$data{$i++} = [($a)];
:$data{$i++} = [($b)];
:$data{$i++} = [($c)];
That isn't a list of vectors -- that is a hash of vectors.
:now I want to merge $data{0} and $data{1} so I do:
:$data{0} = [(@$data{0},@$data{1})];
:$data{1} = undef;
$data{0} = [@{$data{0}},@{$data{1}}];
--
Will you ask your master if he wants to join my court at Camelot?!
------------------------------
Date: Mon, 9 Feb 2004 01:20:30 +0000 (UTC)
From: "erehwon" <duff@hotmail.com>
Subject: Re: moving structures
Message-Id: <c06n8t$fm2$1@titan.btinternet.com>
> erehwon <duff@hotmail.com> wrote:
> : I'm trying to rearrange some lists, but am having problems(!) I'm quite
> :new to perl...
>
> :#some vectors
> :$a = [( 1,2,3)];
> :$b = [( 3,2,3)];
> :$c = [( 4,5,6)];
>
> :# lists of vectors - each list starting out containing one vector
> :$data{$i++} = [($a)];
> :$data{$i++} = [($b)];
> :$data{$i++} = [($c)];
>
> That isn't a list of vectors -- that is a hash of vectors.
Hmm.. I thought it was a hash of references to lists of references of lists
of scalars.
> :now I want to merge $data{0} and $data{1} so I do:
>
> :$data{0} = [(@$data{0},@$data{1})];
> :$data{1} = undef;
>
> $data{0} = [@{$data{0}},@{$data{1}}];
many thanks,
JJ
------------------------------
Date: Mon, 9 Feb 2004 01:20:53 +0000 (UTC)
From: "erehwon" <duff@hotmail.com>
Subject: Re: moving structures
Message-Id: <c06n9l$fn8$1@titan.btinternet.com>
thanks Jeff!
"Jeff 'japhy' Pinyan" <pinyaj@rpi.edu> wrote in message
news:Pine.SOL.3.96.1040208195840.29629C-100000@vcmr-86.server.rpi.edu...
> [posted & mailed]
>
> On Mon, 9 Feb 2004, erehwon wrote:
>
> >$a = [( 1,2,3)];
> >$b = [( 3,2,3)];
> >$c = [( 4,5,6)];
> >
> ># lists of vectors - each list starting out containing one vector
> >$data{$i++} = [($a)];
> >$data{$i++} = [($b)];
> >$data{$i++} = [($c)];
> >
> >now I want to merge $data{0} and $data{1} so I do:
> >
> >$data{0} = [(@$data{0},@$data{1})];
> >$data{1} = undef;
>
> The @ in @$data{0} is binding to $data, not to $data{0}.
>
> $data{0} = [ @{ $data{0} }, @{ $data{1} } ];
> delete $data{$1};
>
> Or, more succintly:
>
> push @{ $data{0} }, @{ delete $data{1} };
>
> I think.
>
> --
> Jeff Pinyan RPI Acacia Brother #734 2003 Rush
Chairman
> "And I vos head of Gestapo for ten | Michael Palin (as Heinrich
Bimmler)
> years. Ah! Five years! Nein! No! | in: The North Minehead
Bye-Election
> Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
>
------------------------------
Date: Mon, 09 Feb 2004 07:37:37 GMT
From: "Danny" <dannywork5@hotmail.com>
Subject: need help with this little perl script
Message-Id: <5NGVb.51406$WY4.13092252@news4.srv.hcvlny.cv.net>
this originally used the FLY executable to generate a graphical counter
which used to be ok but my server disabled the executiuon of binaries, so
now I just want the script to do what it does (update the counter.txt) and
not do any FLY stuff. I just need something returned to the calling .html,
I guess a blank graphic would do. But how do you do the below, so the html
will call the counter script and have something returned.
This part of the script doesnt work
# $output = `$flyprog -i $fly_temp`;
#$output = `blank.gif`';
print "Content-type: image/gif\n\n";
print "<img src=\"images\/blank.jpg\">";
original code was:
$output = `$flyprog -i $fly_temp`;
print "Content-type: image/gif\n\n";
print "$output";
------------------------------
Date: Mon, 09 Feb 2004 07:40:45 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Performance patch to Parse-Yapp 1.05
Message-Id: <slrnc2eebt.6nq.clint@poly.0lsen.net>
Hi:
In the generated code, Yapp places in the entire yystate and yyrules array
references directly in the call. For my application, which calls the
Parser thousands of times on a grammar that is almost 1000 lines, the
overhead to recreate this data structure each time dominates the run time.
Intuition says that moving this to a file-scoped lexical or global in the
package should mean that overhead is only paid once, and it does. For me,
this change results in almost a 4x speed improvement.
-Clint
--- lib/Parse/Yapp/Output.pm Sun Feb 11 07:29:25 2001
+++ Output.pm Sun Feb 8 00:30:59 2004
@@ -53,16 +53,18 @@
<<$head>>
+my $yystates = <<$states>>;
+
+my $yyrules = <<$rules>>;
+
sub new {
my($class)=shift;
ref($class)
and $class=ref($class);
my($self)=$class->SUPER::new( yyversion => '<<$version>>',
- yystates =>
-<<$states>>,
- yyrules =>
-<<$rules>>,
+ yystates => $yystates,
+ yyrules => $yyrules,
@_);
bless($self,$class);
}
------------------------------
Date: Mon, 09 Feb 2004 07:28:20 GMT
From: Clint Olsen <clint@0lsen.net>
Subject: Re: Perl pattern 5.6+ bug causing Parse::Yapp to fail
Message-Id: <slrnc2edkk.6nq.clint@poly.0lsen.net>
On 2004-01-24, pkent <pkent77tea@yahoo.com.tea> wrote:
>
> Try peppering your code/tokenizer/whatever with some debugging print()
> statements, and printing out the location and any relevant variable
> values. That might help, as does the debugging mode. Also are you using
> the latest versions of perl, Parse::Yapp, etc?
The problem has something to do with my code, but since the sub is just
trying to parse its own file (the generated .pm file), it's not as simple
as embedding print statements.
I am using Perl 5.8.X and the latest Yapp.
> Try putting all this so-sensitive data at the top of the module rather
> than scattered throughout the code, if it is. That way you can easily
> change the values to something inoffensive if you do need to show other
> people the code if you still need help.
Yeah, I need to tear out my stuff and put them in separate package files.
Thanks,
-Clint
------------------------------
Date: Sun, 8 Feb 2004 17:24:49 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl project update
Message-Id: <slrnc2dha1.1ir.tadmc@magna.augustmail.com>
Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote:
> That's amazingly silly.
For those of you who are pressed for time, thank Keith for letting
you know everything worth knowing about this (these?) thread, now
you won't need to bother reading it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 08 Feb 2004 23:39:48 +0000
From: David Tannenbaum <updinfo@public-domain.org>
Subject: Tools needed to preserve the public domain
Message-Id: <c06hc3$dal$1@news.ox.ac.uk>
Hi all,
I've just started working with an organization called the Union for the
Public Domain that is organizing to preserve the public domain in a
broad range of sectors. We are creating tools tools for online
organizing, and I was wondering if anyone on this list might be
interested in helping?
The Union for the Public Domain (UPD) is a non-profit membership
organization whose mission is to protect and enhance the public domain
in matters concerning intellectual property. UPD has a very broad
mission and we plan to work on a whole swathe of issues, from software,
to access to textbooks, to webcasting, to essential medicines. There are
a lot of groups working on these issues now, but they rarely leverage
each other's power in numbers. We are hoping to build some coordination.
The other goal is to broaden the circle of activists working on IP, to
include the more general public, which is affected by IP law and threats
to the public domain, but doesn't really understand either enough to
care (yet). We want to make the issues palatable so people understand
them, and create a "politics of IP," much like there is now a politics
of environmentalism.
The board of directors as it stands now includes Richard Stallman, Jamie
Love, who runs a group called the Consumer Project on Technology, Robin
Gross of IP Justice and Robert Weissman. The group was first started
approximately 8 years ago, but has been dormant for nearly as long, and
I've been hired part-time to restart it. We need all the help we can get.
We have a website (http://www.public-domain.org) and a listserve, but
not much else at this point. We want to be as creative as possible in
using online tools to mobilize the grassroots. The most pressing
projects are:
- Setting up a database of members, volunteers, media outlets, allies,
that would be accessible via a web interface, and could do things like
generate action alerts to members based on their geographical location
and other relevant characteristics. We are likely to use Perl and MySQL
to do this.
- Setting up tools that let people send an e-mail to the relevant
"target" (their EU representative; WIPO country delegate, etc).
- Setting up a mechanism for accepting donations, whether that means
going through a third party or processing them ourself.
All of the resulting software, scripts, etc, will be free.
If anyone is interested in collaborating on these projects, you can
e-mail me off list at updinfo@public-domain.org. I'm based in the UK and
would love to meet people in person as well, though e-mail is of course
good too.
Yours,
David
--
David Tannenbaum
Coordinator
Union for the Public Domain
davidt@public-domain.org
http://www.public-domain.org
------------------------------
Date: Thu, 5 Feb 2004 00:49:30 -0800
From: "Tom" <tom@nosleep.net>
Subject: use IO::Socket;
Message-Id: <40220d02$1@nntp0.pdx.net>
Hi
I've been using use IO::Socket;
and this to get web pages for a long time now, without problems:
$lrem = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "$lhost",
PeerPort => "http(80)",
);
Nothing has changed on my side, but now all I get 90% of the time is this:
Bad request
Your browser sent a request that this server could not understand.<P>
client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23):
/q<P>
Any solution to this would be greatly appreciated, thanks.
------------------------------
Date: Mon, 9 Feb 2004 04:41:49 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: use IO::Socket;
Message-Id: <c0732d$pss$1@wisteria.csv.warwick.ac.uk>
"Tom" <tom@nosleep.net> wrote:
> Hi
>
> I've been using use IO::Socket;
>
> and this to get web pages for a long time now, without problems:
>
> $lrem = IO::Socket::INET->new(
> Proto => "tcp",
> PeerAddr => "$lhost",
> PeerPort => "http(80)",
> );
>
> Nothing has changed on my side, but now all I get 90% of the time is this:
>
> Bad request
> Your browser sent a request that this server could not understand.<P>
>
> client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23):
> /q<P>
The problem is further down your program, where (presumably) you send
an HTTP/1.1 request without supplying a Host: header.
I would strongly suggest you use LWP, which will track changes to
protocols like this.
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces mollit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Mon, 09 Feb 2004 04:48:25 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: use IO::Socket;
Message-Id: <x7n07skgdi.fsf@mail.sysarch.com>
use LWP;
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 6096
***************************************