[24274] in Perl-Users-Digest
Perl-Users Digest, Issue: 6465 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 26 03:19:29 2004
Date: Mon, 26 Apr 2004 00:10:11 -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 Mon, 26 Apr 2004 Volume: 10 Number: 6465
Today's topics:
other perl groups <pfancy@bscn.com>
Re: other perl groups <uri@stemsystems.com>
Re: other perl groups <tadmc@augustmail.com>
Re: Pipe outputs response to browser <e01@removethis.toao.net>
Re: slurp not working? ideas please! <geoffacox@dontspamblueyonder.co.uk>
Re: slurp not working? ideas please! <geoffacox@dontspamblueyonder.co.uk>
Re: slurp not working? ideas please! <tassilo.parseval@rwth-aachen.de>
Re: slurp not working? ideas please! <tassilo.parseval@rwth-aachen.de>
Re: sort numeric lists <robin @ infusedlight.net>
Re: sort numeric lists <tassilo.parseval@rwth-aachen.de>
Re: sort numeric lists <King@ask.for.email.invalid>
Re: sort numeric lists <spamtrap@dot-app.org>
Re: variable interpolation failed :-( <tadmc@augustmail.com>
Web page - > Perl script invocation error ( using IBM (Faisal)
Re: Web page - > Perl script invocation error ( using <spamtrap@dot-app.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Apr 2004 21:30:54 -0500
From: "pfancy" <pfancy@bscn.com>
Subject: other perl groups
Message-Id: <408c8f7a$1@news.greennet.net>
Are the any other perl groups who will actually help out people who are NEW
to perl.
------------------------------
Date: Mon, 26 Apr 2004 03:09:58 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: other perl groups
Message-Id: <x7vfjncu49.fsf@mail.sysarch.com>
>>>>> "p" == pfancy <pfancy@bscn.com> writes:
p> Are the any other perl groups who will actually help out people who
p> are NEW to perl.
why don't you ask those groups if there are any?
kind of odd to ask this group for help while you insult them.
and there are plenty of resources to help you learn perl. hmm, perl
comes with plenty of docs and many of them are actually tutorials. there
are at least 2 or more books published about perl. maybe that number is
a trifle low.
what about all those great free scripts you can steal^Wborrow^Wlearn
from? millions of script kiddies who claim to know perl learned that
way!
ever heard of something called school or training?
i just heard of this neat thing called the interweb. maybe it could help
you?
is that helpful enough?
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, 26 Apr 2004 00:37:19 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: other perl groups
Message-Id: <slrnc8p80f.nlq.tadmc@magna.augustmail.com>
pfancy <pfancy@bscn.com> wrote:
> Are the any other perl groups who will actually help out people who are NEW
> to perl.
We do that here in this very newsgroup.
What made you think that we don't?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 26 Apr 2004 02:11:06 GMT
From: "Experienced but Undocumented" <e01@removethis.toao.net>
Subject: Re: Pipe outputs response to browser
Message-Id: <_c_ic.12908$i61.4066@clgrps13>
"Experienced but Undocumented" <e01@removethis.toao.net> wrote in message
news:fQKic.8316$en3.4090@edtnps89...
> I'm using the following script which outputs the response from the SMTP
> server to the browser. What should I do to make it work silently? Using
> PERL 5.6.1 on Redhat Linux 7.3.
> Thanks
>
> open(MAIL, "|/usr/sbin/sendmail -bs") or die "Could not launch Mailer";
Ah!
Since on this server, sendmail is Exim, the -bS commend will work.
------------------------------
Date: Mon, 26 Apr 2004 06:01:40 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: slurp not working? ideas please!
Message-Id: <q29p80t7tv72jnb29ombfm5ush63s3r1ar@4ax.com>
On Sun, 25 Apr 2004 00:03:12 +0900, ko <kuujinbo@hotmail.com> wrote:
Keith,
I am trying to implement your ideas but part is OK and part not ...
I am able to use
: main::choice( $attr->{value});
to pass the option data to the sub choice, but not clear how to get
the $text printed to OUT etc (ie into the results.htm file).
Also, not clear how to stop the data being printed to the screen? This
will tell you that I am not at all clear re how your code works!! eg
have I structured the code correctly? Would really appreciate it if
you could give brief explanation.
Cheers
Geoff
use strict;
use warnings;
use HTML::Parser;
my $data;
open (IN, "test.htm");
{ local $/; $data = <IN> }
my @to_print = qw[h2 p];
my @get_attr = qw[option];
my $current_tag = '';
sub start_tag {
my ($tag, $attr, $text) = @_;
$current_tag = $tag;
( grep { $current_tag eq $_ } @to_print )
? print $text
# ? main::printtext($text)
# : print $attr->{value};
: main::choice( $attr->{value});
}
sub default {
print shift if grep { $current_tag eq $_ } @to_print;
}
package main;
open( OUT, ">>results.htm" )
|| die "results.htm: $!"; #
print OUT ("<table width='100%' border='1'><tr> \n");
my $parser = HTML::Parser->new
(
report_tags => [ @to_print, @get_attr ],
default_h => [ \&default, 'text' ],
start_h => [ \&start_tag, 'tagname, attr, text' ],
)->parse( $data ) or die $!;
sub printtext {
my $text = @_ ;
print OUT ("<p> $text </p> \n");
}
sub choice {
my ($path) = @_;
if ( $path =~ /docs\/gcse\/student-activities\/finance/ ) {
intro($path);
gcsestudentactivitiesfinance($path);
} elsif ( $path =~ /docs\/gcse\/student-activities\/marketing/ ) {
intro($path);
gcsestudentactivitiesmarketing($path);
}
}
------------------------------
Date: Mon, 26 Apr 2004 06:04:51 GMT
From: Geoff Cox <geoffacox@dontspamblueyonder.co.uk>
Subject: Re: slurp not working? ideas please!
Message-Id: <pe9p80ptmdmfiju2oh9utngv88iu6c8ebh@4ax.com>
On Sun, 25 Apr 2004 22:12:50 +0200, "Tassilo v. Parseval"
<tassilo.parseval@rwth-aachen.de> wrote:
>That is somewhat unfortunate as the problem in question does not occur
>when I run your code. It's a bit tricky to address a bug that is not
>reproducible.
Tassilo,
Have you seen the post from Keith? He also got the same wrong order as
me! I have got part of his code working. You can see from my reply to
him that I cannot see yet how the $text is sent to the results.htm
file.
Cheers
Geoff
>
>Tassilo
------------------------------
Date: Mon, 26 Apr 2004 08:23:25 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: slurp not working? ideas please!
Message-Id: <c6iasf$avftf$1@ID-231055.news.uni-berlin.de>
Also sprach Geoff Cox:
> On Sun, 25 Apr 2004 22:12:50 +0200, "Tassilo v. Parseval"
><tassilo.parseval@rwth-aachen.de> wrote:
>
>>That is somewhat unfortunate as the problem in question does not occur
>>when I run your code. It's a bit tricky to address a bug that is not
>>reproducible.
> Have you seen the post from Keith? He also got the same wrong order as
> me! I have got part of his code working.
No, he hasn't. He wrote:
> I say that because I ran the code you supplied and the output file
> *was* in the same order as your test.htm. Maybe the problem is
> elsewhere?
So I didn't make that up. The code you supplied was ok and should work.
The fact that it doesn't means that the problem is indeed somewhere
else. I suspected it could be buffering, but apparently it's not.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 26 Apr 2004 08:40:13 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: slurp not working? ideas please!
Message-Id: <c6iasg$avftf$2@ID-231055.news.uni-berlin.de>
Also sprach Geoff Cox:
> On Sun, 25 Apr 2004 00:03:12 +0900, ko <kuujinbo@hotmail.com> wrote:
>
> Keith,
>
> I am trying to implement your ideas but part is OK and part not ...
>
> I am able to use
>
>: main::choice( $attr->{value});
>
> to pass the option data to the sub choice, but not clear how to get
> the $text printed to OUT etc (ie into the results.htm file).
>
> Also, not clear how to stop the data being printed to the screen? This
> will tell you that I am not at all clear re how your code works!! eg
> have I structured the code correctly? Would really appreciate it if
> you could give brief explanation.
The main difference to your previous subclassing approach is that you no
longer need two namespaces (main and MyParser). It all runs in main.
Furthermore, no file-handle needs to be passed around any longer. OUT is
implicitly global.
> use strict;
> use warnings;
> use HTML::Parser;
>
> my $data;
> open (IN, "test.htm");
> { local $/; $data = <IN> }
>
> my @to_print = qw[h2 p];
> my @get_attr = qw[option];
> my $current_tag = '';
>
> sub start_tag {
> my ($tag, $attr, $text) = @_;
> $current_tag = $tag;
> ( grep { $current_tag eq $_ } @to_print )
> ? print $text
> # ? main::printtext($text)
> # : print $attr->{value};
> : main::choice( $attr->{value});
Bah. That's a weird use of the ?: operator. Use a proper if:
if (grep { $current_tag eq $_ } @to_print) {
print OUT $text;
} else {
choice($attr->{value});
}
Note that you no longer need to package qualify choice(). It's all
defined in package main already.
> }
>
> sub default {
> print shift if grep { $current_tag eq $_ } @to_print;
print OUT shift if grep { $current_tag eq $_ } @to_print;
> }
>
>
> package main;
This is no longer needed either.
> open( OUT, ">>results.htm" )
> || die "results.htm: $!"; #
> print OUT ("<table width='100%' border='1'><tr> \n");
>
> my $parser = HTML::Parser->new
> (
> report_tags => [ @to_print, @get_attr ],
> default_h => [ \&default, 'text' ],
> start_h => [ \&start_tag, 'tagname, attr, text' ],
> )->parse( $data ) or die $!;
>
>
> sub printtext {
> my $text = @_ ;
> print OUT ("<p> $text </p> \n");
> }
>
> sub choice {
> my ($path) = @_;
>
> if ( $path =~ /docs\/gcse\/student-activities\/finance/ ) {
> intro($path);
> gcsestudentactivitiesfinance($path);
All those functions (intro() etc.) may also use OUT as output
file-handle. I can't say it often enough: It's all in the main package
now.
> } elsif ( $path =~ /docs\/gcse\/student-activities\/marketing/ ) {
> intro($path);
> gcsestudentactivitiesmarketing($path);
> }
>
> }
As you see, just printing to OUT is fine. All you have to ensure is that
open OUT, ...
happens before you use the file-handle. As far as I see, this is the
case in your program.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Sun, 25 Apr 2004 19:35:06 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: sort numeric lists
Message-Id: <c6hq7i$jt4$1@reader2.nmix.net>
"Uri Guttman" <uri.guttman@fmr.com> wrote in message
news:siscsmev4vec.fsf@tripoli.fmr.com...
> >>>>> "c" == christie <kenvin007@yahoo.com> writes:
>
> c> Guys.... Have you heard simplicity is beauty. Don't make your life
> c> more complited than it is.
>
> my life is very complite. :)
>
> c> Here is a hint
>
> oh boy! i need one of those!
>
> c> 9 2 6
> c> 5 1 6
>
> c> using split to differenciate first and second row.
>
> hmm, the OP already had those in an list of lists. why is split needed?
>
> c> push 9 2 &6 into arr_tmp1
> c> push 5 1 &6 into arr_tmp2
>
> and what language is that written in?
>
> c> push arr_tmp1[0] & arr_tmp2[0] into array1
> c> push arr_tmp1[1] & arr_tmp2[1] into array2
> c> push arr_tmp1[2] & arr_tmp2[2] into array3
>
> and what language is that written in?
>
> that isn't even legal pseudo-code! :)
>
> c> Just sort the array{1-3} . Sort array{1-3} == sort column{1-3}
>
> and how does that sort multiple columns?
>
> and your working code is where?
>
> and how do you extend that beyond 2 rows of 3 numbers each?
>
> what are you talking about?
>
> try a little more complication in your life. being correct is better
> than being simple.
>
> uri
uri, does my code...(below)...do what he needs?
Thanks,
-Robin
------------------------------
Date: Mon, 26 Apr 2004 06:55:35 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: sort numeric lists
Message-Id: <c6i4od$c88eb$1@ID-231055.news.uni-berlin.de>
Also sprach Robin:
> "The King of Pots and Pans" <King@ask.for.email.invalid> wrote in message
> news:fdjhc.65339$U83.9813@fed1read03...
>> On disk I have a 2d table of numbers. Something like this:
>>
>> 9 8 6
>> 4 5 6
>>
>> I read it in so that I have a list of references to lists. In other
>> words, a list of the rows.
>>
>> I want to first sort by column 2, then column 3. When I sort by column
>> 2 I get:
>>
>> 4 5 6
>> 9 8 6
>>
>> As expected because 5 < 8. When I sort by column 3 I get:
>>
>> 9 8 6
>> 4 5 6
>>
>> This is unexpected. Since 6 = 6, I don't want it to perform the
>> sort. See how it was already sorted by column 2 when column 3 elements
>> were equal, but now column 2 is unsorted again.
> haven't learned too much about pointers and references (my books suck), but
> I'd like to show you how to sort them if their truly seperated by spaces,
> you don't need a fancy sort routine. I saw your other code, and it was too
> fancy for such a simple operation. You should always post your code first.
>
> #!/usr/bin/perl
>
> $file = 'nums.txt';
>
> open (FILE, $file) or die "Error: $!";
> #flock it
> my (@array3, @array2, @array1, $tmp);
> @array1 = <FILE>;
> close (FILE);
> chomp (@array1);
> foreach (@array1)
> {
> @array2 = split (/ /);
> @array2 = sort (@array2);
> push (@array3, @array2);
> }
>
> print @array3;
I'm afraid that the specifications of the OP are slightly more
complicated. Given a file with these lines
6 5 4
3 2 1
your program turns this into the list
(4, 5, 6, 1, 2, 3)
The OP however wants to preserve the two dimensions of the table and
sort by the second and then by the third column. References are needed
for that.
To create the source array, the file can easily be read line-wise. No
slurping needed:
my @table;
while (<FILE>) {
push @table, [ split ];
}
After that we have:
@table = ( [6, 5, 4],
[3, 2, 1], );
The square brackets denote an array reference. @array has two elements,
both being references to arrays of length 3.
And finally the sort:
my @sorted = sort { $a->[1] <=> $b->[1]
or
$a->[2] <=> $b->[2] } @table;
$a and $b will hold the array references as they are found in @table.
'$a->[1]' is the second element in the array referenced by $a.
The sort condition
$a->[1] <=> $b->[1]
or
$a->[2] <=> $b->[2]
first compares the two second elements of the two lines in $a and $b. If
those are equal, then (and only then) '<=>' will return 0 and the second
comparison (which compares the third element of the two lines) is
carried out.
> on a side note- what does this do??
> push (@array3, [@array2]);
This will populate a new (anonymous) array with the values in @array2
and push a reference to this array onto @array3. It's the same as
writing:
push @array3, [ split ];
As for references in Perl (note that Perl doesn't know about pointers),
see the corresponding parts of the perldocs. Maybe in this order:
perlreftut (tutorial on references)
perllol (list of lists)
perldsc (data structure cookbook)
perlref (all there is about references)
References in Perl are more essential and vital than in many other
languages, as there is no generic support for multi-dimensional data
structures. Instead this is all done through references. Hence they
should be tackled rather early.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 26 Apr 2004 06:41:50 GMT
From: The King of Pots and Pans <King@ask.for.email.invalid>
Subject: Re: sort numeric lists
Message-Id: <Oa2jc.103171$U83.59394@fed1read03>
On Sun, 25 Apr 2004 at 22:42 GMT, Robin spoke:
> "The King of Pots and Pans" <King@ask.for.email.invalid> wrote in message
> news:fdjhc.65339$U83.9813@fed1read03...
>> On disk I have a 2d table of numbers. Something like this:
> haven't learned too much about pointers and references (my books suck), but
> I'd like to show you how to sort them if their truly seperated by spaces,
> you don't need a fancy sort routine. I saw your other code, and it
> was too fancy for such a simple operation. You should always post
> your code first.
Thanks for the insight. Those numbers in my original post were just an
example. The number of columns and rows are dynamic depending on which
file is loaded. They are not known values.
--
The King of Pots and Pans
------------------------------
Date: Mon, 26 Apr 2004 02:57:28 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: sort numeric lists
Message-Id: <p4SdnbuArKZFLxHdRVn-tA@adelphia.com>
Robin wrote:
> haven't learned too much about pointers and references (my books suck),
If you have a book that tells you Perl has pointers, then it does indeed
suck beyond measure.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
------------------------------
Date: Sun, 25 Apr 2004 20:34:54 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: variable interpolation failed :-(
Message-Id: <slrnc8oppu.n5u.tadmc@magna.augustmail.com>
Robin <robin@infusedlight.net> wrote:
>
>>
>> Better check the return value from system() if you care about
>> whether the copy worked or not...
Who said that?
Please provide an attribution when you quote someone.
> perl really should have a copy function.
It does, File::Copy.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 25 Apr 2004 22:44:29 -0700
From: fazfar2001@yahoo.com (Faisal)
Subject: Web page - > Perl script invocation error ( using IBM WebSphere )
Message-Id: <105c3a2a.0404252144.c9a3a90@posting.google.com>
Folks
We get the following error ( in the webserver error log s) when
trying to invoke a perl script from the webpage ( using IBM HTTP
server ):
'http://system.mt.att.com:5000/cgi-bin/login.pl'
Can't load '/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris/auto/DBD/Oracle/Oracle.so'
for module DBD::Oracle: ld.so.1: /usr/local/bin/perl: fatal:
libwtc9.so: open failed: No such file or directory at
/usr/local/lib/perl5/5.6.0/sun4-solaris/DynaLoader.pm line 200.
at PM/Query.pm line 6
Compilation failed in require at PM/Query.pm line 6.
BEGIN failed--compilation aborted at PM/Query.pm line 6.
Compilation failed in require at /opt/IBMHTTPD/cgi-bin/login.pl line
10.
BEGIN failed--compilation aborted at /opt/IBMHTTPD/cgi-bin/login.pl
line 10.
Note: a perl -c from the command line ( for login.pl) gives an 'o.k
for the syntax.
Now as far as the files go, the 'libwtc9.so' amd 'Oracle.so' lib
files are present in the LIBRARY PATH - Also, I tried reinstalling
the DBI and DBD oracle modules as was suggested in some of the web
postings - however that didnt' work either. Any specific ideas ?
am wondeirng if it has to do with some IBM HTTP server specific
setting ?
The server the script resides on runs Solaris 8 appreciate any help
:)
c
------------------------------
Date: Mon, 26 Apr 2004 02:55:39 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Web page - > Perl script invocation error ( using IBM WebSphere )
Message-Id: <p4SdnbiArKbwLxHdRVn-tA@adelphia.com>
Faisal wrote:
> Now as far as the files go, the 'libwtc9.so' amd 'Oracle.so' lib
> files are present in the LIBRARY PATH
Assuming scripts that use this module work at a shell prompt but not when
called via CGI - did you add to the library path with an environment
variable like LD_LIBRARY_PATH or similar? If so, does the server have the
same path in its environment as you do in your login environment?
Try running a simple test CGI that just prints all the key/value pairs in
%ENV, to verify the server's environment.
sherm--
--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.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 6465
***************************************