[21827] in Perl-Users-Digest
Perl-Users Digest, Issue: 4031 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 26 00:06:22 2002
Date: Fri, 25 Oct 2002 21:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 25 Oct 2002 Volume: 10 Number: 4031
Today's topics:
AUTOLOAD and multiple inheritance <heather710101@yahoo.com>
Re: AUTOLOAD and multiple inheritance <heather710101@yahoo.com>
Re: AUTOLOAD and multiple inheritance <tassilo.parseval@post.rwth-aachen.de>
Building Net::RawIP <vladimir@NoSpamPLZ.net>
Capture Error Messages (jaya prakash)
Re: Capture Error Messages <nospam@nospam.com>
Re: Chart creation <ron@savage.net.au>
Re: Difference between @foo = <`some program`> and @foo (Tipu)
Re: Difference between @foo = <`some program`> and @foo (Tipu)
Re: GNU plot in perl <pa@panix.com>
Re: Perl Help <jurgenex@hotmail.com>
Re: Perl Help (PeteA)
Re: Regular Expression <depesz@depesz.pl>
Re: Replacing string in binary file develop@gistenson.com
Re: Replacing string in binary file <tassilo.parseval@post.rwth-aachen.de>
Re: Replacing string in binary file <jurgenex@hotmail.com>
Re: Replacing string in binary file <me@dwall.fastmail.fm>
Sendmail Bcc doesn't work (Serge)
Re: Sendmail Bcc doesn't work (Tad McClellan)
Simple Question on Hash ... <pasdespam_desmond@zeouane.org>
Re: Simple Question on Hash ... <me@dwall.fastmail.fm>
Re: Simple Question on Hash ... <pasdespam_desmond@zeouane.org>
Re: Simple Question on Hash ... ctcgag@hotmail.com
Re: Simple Question on Hash ... (Jay Tilton)
Re: Slow code, improvements requested (Jan Fure)
Re: Slow code, improvements requested (Jan Fure)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 25 Oct 2002 22:48:11 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: AUTOLOAD and multiple inheritance
Message-Id: <apchnb$1b9$1@reader1.panix.com>
Suppose that I have two base classes A and B, both of which implement
the AUTOLOAD method, and I want to have a subclass C that inherits
from both (@C::ISA = ('A', 'B')). How can I write the AUTOLOAD to
pass control along the chain (possibly to another AUTOLOAD method) in
case it doesn't know how to handle a particular method call?
Thanks!
hk
------------------------------
Date: Fri, 25 Oct 2002 23:13:18 +0000 (UTC)
From: Da Witch <heather710101@yahoo.com>
Subject: Re: AUTOLOAD and multiple inheritance
Message-Id: <apcj6e$1q3$1@reader1.panix.com>
In <apchnb$1b9$1@reader1.panix.com> Da Witch <heather710101@yahoo.com> writes:
>Suppose that I have two base classes A and B, both of which implement
>the AUTOLOAD method, and I want to have a subclass C that inherits
>from both (@C::ISA = ('A', 'B')). How can I write the AUTOLOAD to
>pass control along the chain (possibly to another AUTOLOAD method) in
>case it doesn't know how to handle a particular method call?
Found it! Sorry.
------------------------------
Date: 25 Oct 2002 23:31:00 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: AUTOLOAD and multiple inheritance
Message-Id: <apck7k$gpg$2@nets3.rz.RWTH-Aachen.DE>
Also sprach Da Witch:
> Suppose that I have two base classes A and B, both of which implement
> the AUTOLOAD method, and I want to have a subclass C that inherits
> from both (@C::ISA = ('A', 'B')). How can I write the AUTOLOAD to
> pass control along the chain (possibly to another AUTOLOAD method) in
> case it doesn't know how to handle a particular method call?
Not sure what you want. Your new class C will inherit both the AUTOLOAD
from A as well as the one from B. Since AUTOLOAD is basically a
catch-all mechanism, the usual left-to-right search through @INC will
not apply and C will always call B::AUTOLOAD().
If with 'chain' you mean going to the next AUTOLOAD if one wasn't able
to do its work, you should be able to say (in A::AUTOLOAD() for
instance):
B::AUTOLOAD($AUTOLOAD);
I never tested that though, but don't see any reason why it should fail.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Sat, 26 Oct 2002 00:44:37 GMT
From: "Vladimir P." <vladimir@NoSpamPLZ.net>
Subject: Building Net::RawIP
Message-Id: <Vzlu9.1480$Pu6.159778@wagner.videotron.net>
Since Net::RawIP has not moved ahead since .09d Tue Nov 21 11:47:43 2000,
I'd like to post the fix here so it will be archived and available
on Google and other engines....
Problem:
[root@goblin Net-RawIP-0.09d]# perl -v
This is perl, v5.8.0 built for i686-linux-thread-multi
On Linux RH7.3
make produces:
util.c: In function `host_to_ip':
util.c:122: `my_perl' undeclared (first use in this function)
util.c:122: (Each undeclared identifier is reported only once
util.c:122: for each function it appears in.)
make: *** [util.o] Error 1
Solution:
Add #include "XSUB.h" on top of util.c
--
.signature: No such file or directory
------------------------------
Date: 25 Oct 2002 19:49:48 -0700
From: prakashrj@hotmail.com (jaya prakash)
Subject: Capture Error Messages
Message-Id: <ee5d9.0210251849.38c32ac8@posting.google.com>
Hi,
The following code snippet is is not writing to the STDRR.
#!/usr/local/bin/perl -w
die "THIS IS AN ERROR MESSAGE";
I was trying to capture the error messages from the command prompt in
the follwoing way. I am suprised to know that it is not directing
STDERR to "err" file.
$./error 2>err
THIS IS AN ERROR MESSAGE
$
I also tried:
$./error 0>err
THIS IS AN ERROR MESSAGE
$
$./error 1>err
THIS IS AN ERROR MESSAGE
$
Where does the function "die" write it's output to? Can I capture
messages that are only outputted when a program dies through "die"?
Thanks,
Prakash.
------------------------------
Date: Fri, 25 Oct 2002 20:20:13 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Capture Error Messages
Message-Id: <3dba095d$1_6@nopics.sjc>
"jaya prakash" <prakashrj@hotmail.com> wrote in message
news:ee5d9.0210251849.38c32ac8@posting.google.com...
> Hi,
>
> The following code snippet is is not writing to the STDRR.
>
> #!/usr/local/bin/perl -w
> die "THIS IS AN ERROR MESSAGE";
>
> I was trying to capture the error messages from the command prompt in
> the follwoing way. I am suprised to know that it is not directing
> STDERR to "err" file.
>
> $./error 2>err
> THIS IS AN ERROR MESSAGE
> $
>
> I also tried:
>
> $./error 0>err
> THIS IS AN ERROR MESSAGE
> $
>
> $./error 1>err
> THIS IS AN ERROR MESSAGE
> $
>
> Where does the function "die" write it's output to? Can I capture
> messages that are only outputted when a program dies through "die"?
STDERR (stderr). It has nothing to do with Perl. It's your login shell. What
shell are you in?
------------------------------
Date: Sat, 26 Oct 2002 11:28:04 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Chart creation
Message-Id: <apcr4b$1duf$1@arachne.labyrinth.net.au>
"brian d foy" <comdog@panix.com> wrote in message news:251020021411050248%comdog@panix.com...
> In article <3DB996B5.B779EC7F@yahoo.com>, Michael Gauf <mgauf@yahoo.com> wrote:
>
> > I am looking a open-source, server-side chart (bar, pie, candlestick,
> > fever, etc.) creation program for UNIX environment. It should also be
> > able to connect to a MySQL database.
>
> GD::Graph can make nice charts, and DBI can connect to databases. it's
> up to you to glue them together. :)
>
> --
> brian d foy <comdog@panix.com> - Perl services for hire
> The Perl Review - a new magazine devoted to Perl
> <http://www.theperlreview.com>
Michael
Try the superb DBD::Chart and it's new cousin (untried by me) DBIx::Chart, which tie together the components you want.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
------------------------------
Date: 25 Oct 2002 20:19:46 -0700
From: jandirb@hotmail.com (Tipu)
Subject: Re: Difference between @foo = <`some program`> and @foo = `some program` ??
Message-Id: <ab341de3.0210251919.2eeebcc2@posting.google.com>
jandirb@hotmail.com (Tipu) wrote in message news:<ab341de3.0210240921.7d9e0e54@posting.google.com>...
> Anyone know how the two are different?? I used to use the former but
> for certain situations only the latter works.
>
> Thank you
Ok. Got it. Thank you Tad and Jay.
Actually my observation was that if the output of "some program" is a
bunch of words it would place each word (of each line) in separate
elements of the array while the latter would only place each line in a
separate element of the array.
I was expecting the behaviour of the latter. so if the output of "some
program" had only one word per line then the behaviour for both of
them is the same. I ran into trouble when the output had multiple
words per line.
However i do not yet under stand how it fits in with glob. I thought
glob would return the element only if it matches a file in the current
directory??
T.
------------------------------
Date: 25 Oct 2002 20:53:59 -0700
From: jandirb@hotmail.com (Tipu)
Subject: Re: Difference between @foo = <`some program`> and @foo = `some program` ??
Message-Id: <ab341de3.0210251953.6e50f80a@posting.google.com>
tiltonj@erols.com (Jay Tilton) wrote in message news:<3db897f6.549660643@news.erols.com>...
> tiltonj@erols.com (Jay Tilton) wrote:
>
> : One feeds the return of `some program` into glob(),
> :
> : H>perl -MO=Deparse -e "@foo = <`some program`>"
> : @foo = CORE::GLOBAL::glob('`some program`', 0);
> ^ ^
> ^ ^
> Er...rather, it globs the string '`some program`' without ever doing
> the backticks thing.
It does do the backtick thing. In both cases it returns the output of
"some program" in an array. See my other reply.
>
> : Big difference if the return from contains things meaningful to
> : glob(), no difference if it doesn't.
>
> Big difference, period.
>
> Sorry about that.
T.
------------------------------
Date: Fri, 25 Oct 2002 22:26:52 +0000 (UTC)
From: Pierre Asselin <pa@panix.com>
Subject: Re: GNU plot in perl
Message-Id: <apcgf8$vh$1@reader1.panix.com>
In <f33fa166.0210251149.601c8d27@posting.google.com> achakrab@nmsu.edu (Anirban Chakraborti) writes:
>@x=[1,2,4,5,6];
>@y=[1,2,4,5,6];
This code doesn't do what you think it does. You probably mean
@x=(1,2,4,5,6);
@y=(1.2.4.5.6);
with parentheses (), not brackets []. The code you wrote creates two
anonymous arrays and assigns a *reference* to @x and @y. For example
your @x array has a single element, $x[0], which is a reference to the
first anonymous array. $x[1] through $x[5] do not exist.
>gnuplot({"title" => "sapa",
> "output type"=>"png",
> "output file"=>"gnupsa1.png"},
> [{"title" => "data1",
> "style" => "lines",
> "type" => "columns"}, @x,
> @y]
>);
Should have been
...
"type" => "columns"}, \@x,
\@y]
);
with backslashes \ before the @, to pass *references* to the arrays @x
and @y. The code you wrote appends the contents of @x and @y to the
list you're building, and it only works because of your first error.
>for($i = 0;$i<6;$i++)
>{
> $x[$i]=6;
>}
so @x is a normal array. Good.
>@y=[1,2,3,4,5,6];
should have been:
@y=(1,2,3,4,5,6);
>use Chart::Graph::Gnuplot qw(gnuplot);
>gnuplot({"title" => "sapa",
> "output type"=>"png",
> "output file"=>"gnupsa1.png"},
> [{"title" => "data1",
> "style" => "lines",
> "type" => "columns"}, @x,@y],
>);
Should have been:
...
"type" => "columns"}, \@x,\@y],
Read the "perlref" man page for more information.
------------------------------
Date: Sat, 26 Oct 2002 00:20:33 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Perl Help
Message-Id: <ldlu9.13762$iV1.2842@nwrddc02.gnilink.net>
PeteA wrote:
To access the Perl help please see "perldoc perldoc".
It will you about all the features and options of the Perl online
documentation program.
jue
------------------------------
Date: 25 Oct 2002 19:22:03 -0700
From: pallia@hotmail.com (PeteA)
Subject: Re: Perl Help
Message-Id: <2965ae60.0210251822.313a54@posting.google.com>
Yea I meant for download or viewing on the web but if not looks like I
will have look into the Instructor's Resource CD-ROM that accompanies
Perl How to Program. Thanks anyway.
Brian McCauley <nobull@mail.com> wrote in message news:<u9smyu4h2g.fsf@wcl-l.bham.ac.uk>...
> pallia@hotmail.com (PeteA) writes:
>
> > Subject: Perl Help
>
> Please put the subject of your post in the Subject of your post. If
> in doubt try this simple test. Imagine you could have been bothered
> to have done a search before you posted. Next imagine you found a
> thread with your subject line. Would you have been able to recognise
> it as the same subject?
>
> > Anyone out there have any or all solutions to the problems in the PERL
> > How to Program book by Deitel?
>
> Hell, you could almost have fit the whole thing in the subject line!
>
> BTW: It's Perl not PERL.
>
> Anyhow, back to the question, the answer is "yes". According to the
> Prentice Hall web site the product in question[1] is in-stock. I've
> not looked on other book retailers' web sites but doubtless many other
> stockists have it too.
>
> Or did I miss-understand?
>
> [1] Instructor's Resource CD-ROM that accompanies Perl How to Program
------------------------------
Date: Fri, 25 Oct 2002 23:52:31 +0200
From: hubert depesz lubaczewski <depesz@depesz.pl>
Subject: Re: Regular Expression
Message-Id: <slrn.pl.arjf8v.ebv.depesz@depeszws.depesz.pl>
MR wyrzeĽbił(a):
> Why be so rude? No problem with telling him which doc to look in but it CAN
sorry, but it was just beacause one can use example that i gave for
previous question, just by modifying 2 chars. nothing more. and i really
belive that if someone wants to be a programmer in any language, he has
to know how to use help systems (man, perldoc, <f1>, faq, whatever).
depesz
--
hubert depesz lubaczewski http://www.depesz.pl/
------------------------------------------------------------------------
Mój Boże, spraw abym milczał, dopóki się nie upewnię, że naprawdę mam
co¶ do powiedzenia. (c) 1998 depesz
------------------------------
Date: Fri, 25 Oct 2002 22:41:59 +0000 (UTC)
From: develop@gistenson.com
Subject: Re: Replacing string in binary file
Message-Id: <apchbn$hek$1@flood.xnet.com>
Tassilo,
What is top-post. Let me know, and I'll stop doing it.
You said that I should get rid of the develop@gistenson.com. I'll look
into how to do this and take care of it, if it poses a problem.
You said I should look again, it through a fatal error. I'm trying my code
in debug and see no errors.
I don't know that inline replace will work against a file. I was asking if
there was a way similar to doing an inline replace within a scalar (e.g.
$s =~ s/old/new/;).
Since the file contains primarily binary data, has no line breaks and
could be a few meg in size, I am looking for an efficient way to replace a
known character string that will appear somewhere in the file.
I don't know how to do this other than doing a grep based onthe the known
character string. I would expect that the result of the grep would be a
one element array whose element would contain the entire content of the
file. Then I could do the s/// against this element and then write the
resulting scalar to a file.
Maybe this is the best solution. Do the facts that most of the file's
content is binary and the file could be a few meg in size rule out this
approach?
A general apology to the group if it appears that I am ignoring some of
the group's etiquette. It's not intentional. Being blind I sometimes
(often?) miss things.
Thanks,
Dan
------------------------------
Date: 25 Oct 2002 23:31:00 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Replacing string in binary file
Message-Id: <apck7k$gpg$1@nets3.rz.RWTH-Aachen.DE>
Also sprach develop@gistenson.com:
> What is top-post. Let me know, and I'll stop doing it.
It means that you put your reply on top of other people's postings.
Instead, you should put them below your quotations to make it easier for
the groupt to follow the discussion. Just like I am doing now.
> You said that I should get rid of the develop@gistenson.com. I'll look
> into how to do this and take care of it, if it poses a problem.
I never said that.
> You said I should look again, it through a fatal error. I'm trying my code
> in debug and see no errors.
I doubt it:
open F, ".bashrc";
<F> =~ s/asd/asc/;
__END__
Can't modify <HANDLE> in substitution (s///) at - line 2 , near
"s/asd/asc/;"
Execution of - aborted due to compilation errors.
> I don't know that inline replace will work against a file. I was asking if
> there was a way similar to doing an inline replace within a scalar (e.g.
> $s =~ s/old/new/;).
You can treat a file like an array of scalars, thusly:
use Tie::File;
tie my @file, "Tie::File", "filename" or die $!;
for (@file) {
s/old/new/;
}
untie @file;
tie() will do its magic behind the scene and anything you change within
the array is transparently changed in the file as well.
> Since the file contains primarily binary data, has no line breaks and
> could be a few meg in size, I am looking for an efficient way to replace a
> known character string that will appear somewhere in the file.
The above should also work with binary files, I think. It's not the most
efficient way though, rather the most conventient one.
> I don't know how to do this other than doing a grep based onthe the known
> character string. I would expect that the result of the grep would be a
> one element array whose element would contain the entire content of the
> file. Then I could do the s/// against this element and then write the
> resulting scalar to a file.
Yes, you could do that. But there is no need for a grep() here:
open FILE, $file or die ...;
binmode FILE; # might be needed on some platforms
my $content = do { local $/; <FILE> };
$content =~ s/old/new/g; # perhaps you want global replace
open NEW, ">newfile" or die ...;
binmode NEW; # likeweise here
print NEW $content;
> Maybe this is the best solution. Do the facts that most of the file's
> content is binary and the file could be a few meg in size rule out this
> approach?
No, not as long as you have enough memory. I would guess that reading
the file with one slurp should be the quickest way.
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Sat, 26 Oct 2002 00:33:20 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Replacing string in binary file
Message-Id: <kplu9.13802$iV1.2654@nwrddc02.gnilink.net>
[Do not post jeopardy style; rearranged into chronological order]
develop@gistenson.com wrote:
> <jurgenex@hotmail.com> wrote:
>> develop@gistenson.com wrote:
>>> I want to replace a string in a binary file. For example, I want to
>>> replace the string "abc" with the string "xyz". Is there a way to do
>>> this? Something similar to replacing a string in a scalar? (e.g.
>>> $variable =~ s/abc/xyz/;)
>
>> What happened when you tried it?
[...]
>
> I tried opening the file and then doing:
>
> <DAT> =~ s/abc/xyz/;
>
> Although the file contained the string: abc, nothing happened; it was
> not replaced with: xyz. In other words, the statement did nothing.
Beside the fact that <DAT> in scalar context will read only one(!) line
(unless you tweak some global variables): where do you write the modified
text back to the file?
Something tells me that you should read "perldoc -q middle":
How do I change one line in a file[...]?
jue
------------------------------
Date: Sat, 26 Oct 2002 01:34:27 GMT
From: "David K. Wall" <me@dwall.fastmail.fm>
Subject: Re: Replacing string in binary file
Message-Id: <Xns92B2DB77A693Edkwwashere@63.240.76.16>
develop@gistenson.com wrote:
> Tassilo,
[snip]
> You said that I should get rid of the develop@gistenson.com. I'll look
> into how to do this and take care of it, if it poses a problem.
What he said was "Also sprach develop@gistenson.com:". Note that Tassilo's
email address is in Germany. "also sprach" is roughly equivalent to "thus
spoke".
--
David Wall - me@dwall.fastmail.fm
"Oook."
------------------------------
Date: 25 Oct 2002 16:55:27 -0700
From: pulsar10@email.com (Serge)
Subject: Sendmail Bcc doesn't work
Message-Id: <2481ff4b.0210251555.599fd506@posting.google.com>
Hi,
My CGI Perl script is supposed to send some stuff to two places - the
program office and a confirmation email to the person that filled out
the form. The person submits his email without the "\" before the "@"
so I used the following code to solve to put a backslash there:
# insert backslash into email $email_address of form someone@email.com
($e_one,$e_two)=(split(/\@/,$email_address));
$e_full=$e_one."\\@".$e_two;
#end
I then put the following in the sendmail part:
#now, send the email
$path="/usr/lib/sendmail";
open(SENDMAIL, "|$path -t") || die "Unable to open sendmail\n";
print SENDMAIL "To: Program Office <some_email1\@email.com>\n";
print SENDMAIL "Bcc: Student < $e_full >\n";
print SENDMAIL "From: Website <some_email2\@email.com>\n";
print SENDMAIL "Subject: Class Change Request\n\n";
print SENDMAIL "Class change request number $request_number.\n\n";
etc.
However, the script doesn't send the email to the student. I can't
figure out what is wrong here. I would gladly appreciate some help.
Thank you in advance.
------------------------------
Date: Fri, 25 Oct 2002 22:45:51 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sendmail Bcc doesn't work
Message-Id: <slrnark3vf.1sf.tadmc@magna.augustmail.com>
Serge <pulsar10@email.com> wrote:
> The person submits his email without the "\" before the "@"
> so I used the following code to solve to put a backslash there:
Why do you think that you need to insert a backslash?
> # insert backslash into email $email_address of form someone@email.com
> ($e_one,$e_two)=(split(/\@/,$email_address));
> $e_full=$e_one."\\@".$e_two;
You could have done that with a substitution instead:
$email_address =~ s/\@/\\@/;
But don't.
> print SENDMAIL "Bcc: Student < $e_full >\n";
> However, the script doesn't send the email to the student.
Probably because there is a backslash in the address.
> I can't
> figure out what is wrong here.
Don't add a backslash :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 26 Oct 2002 00:40:35 +0000
From: Desmond Coughlan <pasdespam_desmond@zeouane.org>
Subject: Simple Question on Hash ...
Message-Id: <slrnarjp43.clb.pasdespam_desmond@lievre.voute.net>
Hi,
I'm trying out some simple perl commands that I've found on this page ...
url:http://www.perldoc.com/perl5.8.0/pod/perlintro.html
... and have got to the part about hashes. Rather than use the colour
of fruit, I changed it ...
#!/usr/bin/perl
{
my %family_colouring = {
sister1 => "brown",
father => "grey",
mother => "grey",
sister2 => "blonde",
moi => "brown",};
$test_member = $family_colouring{"sister1"};
print $test_member ;
}
Try as I might, I cannot get that script to print. It runs, no
problems, no error messages, but it will not print out 'brown',
irrespective of what I do. I tried moving the braces around, I tried
changing the name of the scalars ... :-(
This is a simple question, I know, and I apologise for taking up your time
with it. Rest assured that I did try to find the answer elsewhere. :-(
--
Desmond Coughlan |CUNT#1 YGL#4 YFC#1 YFB#1 UKRMMA#14 two#38
desmond @ zeouane.org |BONY#48 ANORAK#11
http: // www . zeouane . org
------------------------------
Date: Sat, 26 Oct 2002 00:59:25 GMT
From: "David K. Wall" <me@dwall.fastmail.fm>
Subject: Re: Simple Question on Hash ...
Message-Id: <Xns92B2D586C424Adkwwashere@216.148.227.77>
Desmond Coughlan <pasdespam_desmond@zeouane.org> wrote:
> I'm trying out some simple perl commands that I've found on this page
> ...
>
> url:http://www.perldoc.com/perl5.8.0/pod/perlintro.html
>
> ... and have got to the part about hashes. Rather than use the colour
> of fruit, I changed it ...
>
> #!/usr/bin/perl
> {
This brace and the one that matches it aren't necessary. Bare blocks can
be useful, but I don't think you need them just yet.
> my %family_colouring = {
That { at the end should be a (. As it is, you're creating a hash with a
key that is a stringified hash reference, and the associated value is
undefined.
> sister1 => "brown",
> father => "grey",
> mother => "grey",
> sister2 => "blonde",
> moi => "brown",};
Make this } a ), too.
> $test_member = $family_colouring{"sister1"};
> print $test_member ;
This is OK.
> }
>
> Try as I might, I cannot get that script to print. It runs, no
> problems, no error messages, but it will not print out 'brown',
> irrespective of what I do. I tried moving the braces around, I tried
> changing the name of the scalars ... :-(
Braces and parentheses do very different things....
--
David Wall - me@dwall.fastmail.fm
"Oook."
------------------------------
Date: Sat, 26 Oct 2002 01:06:27 +0000
From: Desmond Coughlan <pasdespam_desmond@zeouane.org>
Subject: Re: Simple Question on Hash ...
Message-Id: <slrnarjqkj.clb.pasdespam_desmond@lievre.voute.net>
Le Sat, 26 Oct 2002 00:59:25 GMT, David K. Wall <me@dwall.fastmail.fm> a écrit :
{ snip }
>> my %family_colouring = {
> That { at the end should be a (. As it is, you're creating a hash with a
> key that is a stringified hash reference, and the associated value is
> undefined.
Um ... I believe that a new pair of glasses is called for. Again, sorry
for the twattish question, and thank you for the response.
<fx: slinks away with tail between legs ...>
--
Desmond Coughlan |CUNT#1 YGL#4 YFC#1 YFB#1 UKRMMA#14 two#38
desmond @ zeouane.org |BONY#48 ANORAK#11
http: // www . zeouane . org
------------------------------
Date: 26 Oct 2002 01:44:02 GMT
From: ctcgag@hotmail.com
Subject: Re: Simple Question on Hash ...
Message-Id: <20021025214402.853$OX@newsreader.com>
Desmond Coughlan <pasdespam_desmond@zeouane.org> wrote:
>
> Try as I might, I cannot get that script to print. It runs, no
> problems, no error messages,
How do you know there are no error messages? You declined to ask
for them.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service
------------------------------
Date: Sat, 26 Oct 2002 01:45:41 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Simple Question on Hash ...
Message-Id: <3db9f2db.38872111@news.erols.com>
Desmond Coughlan <pasdespam_desmond@zeouane.org> wrote:
: Le Sat, 26 Oct 2002 00:59:25 GMT, David K. Wall <me@dwall.fastmail.fm> a écrit :
:
: { snip }
:
: >> my %family_colouring = {
:
: > That { at the end should be a (. As it is, you're creating a hash with a
: > key that is a stringified hash reference, and the associated value is
: > undefined.
:
: Um ... I believe that a new pair of glasses is called for.
Perl itself has a dandy set of spectacles for you to borrow:
use warnings;
It would have barked about "Reference found where even-sized list
expected at foo.pl line N."
------------------------------
Date: 25 Oct 2002 16:05:29 -0700
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Re: Slow code, improvements requested
Message-Id: <e47a84bf.0210251505.5c3dfd72@posting.google.com>
"John W. Krahn" <krahnj@acm.org> wrote in message news:<3DB9347C.AC8506F@acm.org>...
>
<--------------- Snip ------------------------------------>
> Perhaps this will speed it up:
>
> my $linelimit = 31999;
>
<--------------- Snip ------------------------------------>
Thank you John, it is very nice of you to provide some code to help me
out, and I also appreciate Uri's comments about good usage of the PERL
language. I will re-write the code following the suggestions.
I tried the code you provided, and unfortunately it also slows down to
a crawl as well :-(
In your version of the script, I added some comments lines, and
determined which operation stops:
open INPUT_FILE, $file or die "can't open $file: $!";
print "Done opening $file\n";
my ( $heading, @sorted ) = <INPUT_FILE>;
print "Done reading file: $file into array named at-sorted!\n";
From the terminal output, I can determine that the program gets stuck
on the line reading the INPUT_FILE filehandle into the $heading and
@sorted.
The first iteration of the outer loop takes about 15 seconds, the next
iteration takes about 15 minutes, from which 95-99% of the time is
spent (re)defining @sorted. For the rest of the time the program runs,
it takes 15-30 minutes per file.
The input files are tab delimited text-files of size 5-6MB, with
~100000 lines.
Is there a way to clear all variables except the loop index/string at
the beginning of the outer loop?
Jan
------------------------------
Date: 25 Oct 2002 19:24:01 -0700
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Re: Slow code, improvements requested
Message-Id: <e47a84bf.0210251824.63330db7@posting.google.com>
brian d foy <comdog@panix.com> wrote in message news:<251020021054000731%comdog@panix.com>...
> In article <e47a84bf.0210241733.2a3e81d3@posting.google.com>, Jan Fure <jan_may2002_fure@attbi.com> wrote:
>
> > I suspect my sort operation takes most of the computer resources.
>
> don't suspect - know!
>
> CPAN has a lot of good profilers, such as Devel::SmallProf or Devel::DProf.
>
> http://www.ddj.com/documents/s=1498/ddj0104pl/
Thanks, and my suspicion was wrong, it was the:
@array = <INPUT_FILE>;
line in the script that will hang the second loop iteration. I find it
by incerting print statements.
I re-wrote the script such that it calls another perl script
separately to process each file, and the slowdown does not occur, the
code is below:
use strict;
use warnings;
my $linelimit=31998;
opendir(DIR, ".") or die "Can't open directory $!";
my @tfiles = sort(grep(/.txt/, readdir(DIR))); #find files/dirs
containing ".txt"
closedir(DIR);
foreach (<@tfiles>) {
print "$_\n";
}
# Lines above determine which files to operate on, and list them
foreach my $file (@tfiles) {
my ( $name ) = $file =~ /^(.+)\.txt$/;
system("sub8.pl $file $linelimit $name");
}
------------------------------
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.
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 4031
***************************************