[22993] in Perl-Users-Digest
Perl-Users Digest, Issue: 5212 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 11 13:12:35 2003
Date: Fri, 11 Jul 2003 03:05:07 -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, 11 Jul 2003 Volume: 10 Number: 5212
Today's topics:
Accessing elements in array ref of array references (fatted)
Re: compiling Perl code <bart.lateur@pandora.be>
Re: Find string in web page <spam@thecouch.homeip.net>
Flavell's second law? Was: Automatic page forwarding <derek.moody@clara.net>
Re: Hanging pipes in CGI Perl <bwalton@rochester.rr.com>
Re: Has anybody successfully built HTML::Parser module <bart.lateur@pandora.be>
Re: Help, perlcc bug or wrong code? <kalinabears@hdc.com.au>
Re: Help, perlcc bug or wrong code? <gareth.glaccum@btopenworld.com>
How to add a sequential number to a form <gregatwork@NOSPAMPLEASEhotmail.com>
Re: How to add a sequential number to a form <mbudash@sonic.net>
making replacements in a file <cyberjeff@sprintmail.com>
Re: making replacements in a file <bwalton@rochester.rr.com>
Re: making replacements in a file <spam@thecouch.homeip.net>
Re: Perl 5.8.0 compilation fails in chrooted environmen vrihad@myway.com
Perl and telnet <moliverius@w-link.net>
Perl code question <moliverius@w-link.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 11 Jul 2003 02:11:50 -0700
From: fatted@yahoo.com (fatted)
Subject: Accessing elements in array ref of array references
Message-Id: <4eb7646d.0307110111.4a18dd1d@posting.google.com>
Currently I'm comparing the first value of each of the array
references (which are stored in an array reference $ref_ref) as
follows:
if(map($_->[0] =~ /$keyword/i,@$ref_ref))
{
# Do something cunningly clever...
}
What I was wondering about (for no particular reason) is doing
something like:
if(map(/$keyword/i,cool_function(@$ref_ref, 0)))
{
# Do something equally cunningly clever...
}
Any idea's? (or should I get back to work ;)
------------------------------
Date: Fri, 11 Jul 2003 03:26:32 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: compiling Perl code
Message-Id: <o9bsgvs37gk4995jrevsn456badns7252g@4ax.com>
-bill wrote:
>I know little about Perl, so I ask the following question. when you
>compile Perl code, can a PDB(symbols file) be created the way you can
>within MSVS IDE for VB, C/C++ ?
"Compile"? Eh...
Anyway, look at the module B::Xref. You invoke it as
perl -MO=Xref yourscript.pl
optionally with options separated with commas, like
perl -MO=Xref,-r,-oXref.out.txt yourscript.pl
See B::Xref for the docs.
--
Bart.
------------------------------
Date: Fri, 11 Jul 2003 01:15:11 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Find string in web page
Message-Id: <zJrPa.15371$Pe2.513530@wagner.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Kirk Larsen wrote:
> Sounds simple enough. I need to retrieve the source from a web page
use LWP::Simple;
> and then find a link in that web page that ends with a string which I
> have stored in a variable.
There are a few ways to do this. I prefer HTML::TokeParser;
> Can someone please post or direct me to a
> sample of how to do this? Thanks!
my $url = 'http://www.freebsd.org';
my $match = 'man.cgi';
use LWP::Simple;
use HTML::TokeParser;
my $document = get($url) || die "Failed to retrieve document\n";
my $parser = HTML::TokeParser->new(\$document);
while ($token = $parser->get_tag("a")) {
if ($token->[1]->{"href"} =~ /$match$/) {
print "I matched $token->[1]->{href}\n";
}
}
For more information, see http://search.cpan.org/dist/HTML-Parser/lib/HTML/TokeParser.pm and
http://search.cpan.org/dist/libwww-perl/lib/LWP/Simple.pm.
Note that links are often relative, which means you'll often get a link to "something.html" instead
of "http://domain.com/dir/something.html". It'll be up to you to extrapolate the domain and
directory structure of the original URL (and append to it the link data, as well as possibly take
into account any ../.././ calls) to determine the full URL to call next.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/DkfieS99pGMif6wRApEdAJwIJrCRTLNOgtsxCSUYCY7NyO6/AgCZATFH
cc0PEq+mFhTbBDrQ/79fah4=
=/K0i
-----END PGP SIGNATURE-----
------------------------------
Date: Fri, 11 Jul 2003 01:51:13 +0100
From: "Derek.Moody" <derek.moody@clara.net>
Subject: Flavell's second law? Was: Automatic page forwarding in cgi perl script
Message-Id: <ant110013e61BxcK@half-baked-idea.co.uk>
In article <Pine.LNX.4.53.0307101203140.31457@lxplus078.cern.ch>,
Alan J. Flavell <URL:mailto:flavell@mail.cern.ch> wrote:
> On Thu, Jul 10, Christian Accart yelled out atop a fullquote:
>
> > Try this:
>
> Aha, another triumph for top-posting...
<snip howler>
> It's a sure-fire bogosity indicator, isn't it, folks?
Does this have sufficient status to become Flavell's second law?
Opinions?
Cheerio,
--
>> derek.moody@clara.net
------------------------------
Date: Fri, 11 Jul 2003 03:30:26 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Hanging pipes in CGI Perl
Message-Id: <3F0E2F51.7080704@rochester.rr.com>
Christophe Baegert wrote:
> Does anybody knows a reason why this program hangs ?
As I mentioned previously, this set of programs does not hang when run
under a properly-configured web server with proper permissions on the
various files [for example, on my system]. The reasons, again, why it
might hang when everything is not configured properly are detailed in
the references given in:
perldoc -q 500
The fixing of web server configuration problems is off-topic for this
newsgroup, as it has nothing to do with Perl -- the same problems would
be encountered were the programs written in any other language. You
will need to go through those references step-by-step in minute detail
and verify that everything is exactly proper. Don't skip any steps, as
the slightest little thing wrong is disastrous. If you try all this (it
is quite extensive) and are still unable to resolve the problems, try a
web server oriented newsgroup, like perhaps:
comp.infosystems.www.authoring.cgi
HTH.
>
> Christophe Baegert a écrit :
...
>> Sorry, this is my prog A.
>> -----------------------------------------------------------------------------
>>
>> #!/usr/local/bin/perl
>> use warnings;
>> $|=1;
>> print "Content-type: text/html\n\ntest";
>> $text="To: xxxx\@yyyyy.zzz\nFrom: xxxx\@yyyyy.zzz\nSubject:
>> test\n\ntest";
>>
>> open(MAIL,'|/home/xxx/cgi-bin/B.pl') or die "error : $!";
>> print MAIL $text;
>> close MAIL;
>> -----------------------------------------------------------------------------
>>
>>
>> This is my prog B.
>> -----------------------------------------------------------------------------
>>
>> #!/usr/local/bin/perl
>>
>> open(FILE,'>/tmp/file') or die "$!";
>> while($line=<STDIN>){
>> print FILE $line;
>> }
>> close FILE;
>> -----------------------------------------------------------------------------
>>
>>
>> It runs well under bash, but it displays nothing, without error and
>> without
>> exiting under CGI.
>>
>> When I comment the last three lines of prog A, it runs well even under
>> CGI.
...
>> Christophe.
--
Bob Walton
------------------------------
Date: Fri, 11 Jul 2003 03:21:10 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Has anybody successfully built HTML::Parser module on Cygwin?
Message-Id: <m5bsgvstt4nm37gac6kiv35t03voendl7m@4ax.com>
[dead group snipped]
Jose Gilberto Torres wrote:
>I've tried both 3.26 and 3.26 version of the code as well as perl 5.6
>and 5.8 on cygwin and I get this error everytime.
>
>"Can't find /usr/lib/perl5/5.6.1/ExtUtils/typemap in /home/blah
>blah/HTML-Parser3.26."
I would think you would need ExtUtils/typemap for building any module
using XS, not just this one.
Can you build other XS modules?
--
Bart.
------------------------------
Date: Fri, 11 Jul 2003 15:14:42 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Help, perlcc bug or wrong code?
Message-Id: <3f0e48cb$0$23122$5a62ac22@freenews.iinet.net.au>
"Gareth Glaccum" <verycoldpenguin@hotmail.com> wrote in message
news:991491a9.0307100657.12b679e3@posting.google.com...
> Hi, I am using perlcc to compile up some perl programs but I think I
> have a bug report to make.
> The problem is that $0 or $PROGRAM_NAME seems to be being squashed by
> the perlcc.
>
Afaik perlcc is no longer being maintained - and it has always been buggy.
I suggest trying the 'pp' utility that comes with the PAR module (available
from cpan) instead.
I get slightly different output from your script:
---------------------------
D:\pscrpt>perl temp.pl
temp.pl is my name, as is
D:\pscrpt>pp -o temp.out temp.pl
D:\pscrpt>temp.out
temp.out is my name, as is
----------------------------
Cheers,
Rob
------------------------------
Date: Fri, 11 Jul 2003 06:43:28 +0000 (UTC)
From: "Gareth Glaccum" <gareth.glaccum@btopenworld.com>
Subject: Re: Help, perlcc bug or wrong code?
Message-Id: <belmag$j77$1@hercules.btinternet.com>
Great, thanks. Although as far as I understand, pp is much less use for
hiding the code, which is what my boss wants. I will do it anyway, I mean
would the difference be noticed?
Thanks for the reply.
$PROGRAM_NAME is meant to be usuable if you are using 5.8.0
Gareth
"Sisyphus" <kalinabears@hdc.com.au> wrote in message
news:3f0e48cb$0$23122$5a62ac22@freenews.iinet.net.au...
>
> "Gareth Glaccum" <verycoldpenguin@hotmail.com> wrote in message
> news:991491a9.0307100657.12b679e3@posting.google.com...
> > Hi, I am using perlcc to compile up some perl programs but I think I
> > have a bug report to make.
> > The problem is that $0 or $PROGRAM_NAME seems to be being squashed by
> > the perlcc.
> >
>
> Afaik perlcc is no longer being maintained - and it has always been buggy.
>
> I suggest trying the 'pp' utility that comes with the PAR module
(available
> from cpan) instead.
>
> I get slightly different output from your script:
>
> ---------------------------
> D:\pscrpt>perl temp.pl
> temp.pl is my name, as is
>
> D:\pscrpt>pp -o temp.out temp.pl
>
> D:\pscrpt>temp.out
> temp.out is my name, as is
> ----------------------------
>
>
> Cheers,
> Rob
>
>
------------------------------
Date: Fri, 11 Jul 2003 09:20:50 +0800
From: "gwmbox" <gregatwork@NOSPAMPLEASEhotmail.com>
Subject: How to add a sequential number to a form
Message-Id: <bel3dj$g6i$1@ftp.curtin.edu.au>
Hi
I have a basic form mailer script but I want to add a number that increments
on each use of the form - like an ID for each request sent - how do I do
this - anyone got any code I can use to add this to a form script?
Thanks
Greg
------------------------------
Date: Fri, 11 Jul 2003 05:48:29 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: How to add a sequential number to a form
Message-Id: <mbudash-84FD0F.22482910072003@typhoon.sonic.net>
In article <bel3dj$g6i$1@ftp.curtin.edu.au>,
"gwmbox" <gregatwork@NOSPAMPLEASEhotmail.com> wrote:
> Hi
>
> I have a basic form mailer script but I want to add a number that increments
> on each use of the form - like an ID for each request sent - how do I do
> this - anyone got any code I can use to add this to a form script?
guess noone else is gonna answer this, so here:
#-----------------------------------------------------------------------
sub getseqno {
#-----------------------------------------------------------------------
open (SEQNBR, "+>>/path/to/lastseqno") or die ("Can't open SEQNBR:
$!");
# it's ours exclusively!
flock (SEQNBR, 2);
# ...rewind...
seek (SEQNBR, 0, 0);
# get last number
my $seqnbr = <SEQNBR>;
# ...rewind...
seek (SEQNBR, 0, 0);
# ...clear the file...
truncate (SEQNBR, 0);
# ...and rewrite it, adding 1 to the sequence number
$seqnbr++;
print SEQNBR $seqnbr;
# we're outa here! (note that perl's close also unlocks the file,
# as does the ending of the program, so an explicit flock is n/n
close (SEQNBR);
return $seqnbr;
}
hope this helps...
--
Michael Budash
------------------------------
Date: Fri, 11 Jul 2003 01:12:35 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: making replacements in a file
Message-Id: <3F0E0F3C.3CD4B2DA@sprintmail.com>
I have a file that I need to make some substitutions in:
open FH, "my_file" or die "Can't open... $!";
@file=<FH>;
Can I read the file handle so it is a scalar and I can just do this?:
$file=~s/replace_me/with_this/gis; # small files
and then print back to a filehandle.
Or should I do something like this:
my @new_file=();
while(<FH>){
$_=~s/replace_me/with_this/gi;
push @new_file, $_;
}
and then print @new_file to a filehandle? Or would that be a reference
to @new_file?
Seems like there should be a better way than any of these.
Jeff
------------------------------
Date: Fri, 11 Jul 2003 03:53:22 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: making replacements in a file
Message-Id: <3F0E34B0.40201@rochester.rr.com>
Jeff Thies wrote:
> I have a file that I need to make some substitutions in:
>
> open FH, "my_file" or die "Can't open... $!";
>
> @file=<FH>;
>
> Can I read the file handle so it is a scalar and I can just do this?:
Sure. Slurp it. Set the value of $/ to undef, perhaps like:
{local $/; #make $/ undef only for the duration of this block,
#so it doesn't screw up possible subsequent reads.
$file=<FH>; #slurp entire file to scalar.
}
This sets the input record separator string to undef, which is a special
case that causes file "slurping". See:
perldoc perlvar
for more info.
>
> $file=~s/replace_me/with_this/gis; # small files
>
> and then print back to a filehandle.
>
> Or should I do something like this:
>
> my @new_file=();
> while(<FH>){
> $_=~s/replace_me/with_this/gi;
> push @new_file, $_;
> }
>
> and then print @new_file to a filehandle? Or would that be a reference
> to @new_file?
That, of course, would also work, unless the "replace_me" string
contains stuff which is supposed to match over a newline. The fact that
you included the "s" regexp modifier in your previous "slurp version"
regexp indicates that perhaps you intended for that to be the case
(otherwise, "s" would serve no purpose).
Of course, you don't really have to push all the lines out to an array
in the above -- just write out the modified lines as you read them.
That gives your program the distinct advantage of being able to process
a gigabyte file on your old 386 with 16 Mb of memory. Just replace the
push line with something like:
print OUT $_;
and place something like:
open OUT,">output.file" or die "Oops, $!";
before the while loop.
>
> Seems like there should be a better way than any of these.
There's always more than one way to do it. Which is "better" depends on
a lot of stuff you haven't defined for us, as well as your opinion of
what "better" means.
>
> Jeff
>
--
Bob Walton
------------------------------
Date: Fri, 11 Jul 2003 00:57:14 -0400
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: making replacements in a file
Message-Id: <KsrPa.15050$Pe2.507029@wagner.videotron.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Jeff Thies wrote:
> I have a file that I need to make some substitutions in:
>
> open FH, "my_file" or die "Can't open... $!";
>
> @file=<FH>;
>
> Can I read the file handle so it is a scalar and I can just do this?:
>
> $file=~s/replace_me/with_this/gis; # small files
>
> and then print back to a filehandle.
>
> Or should I do something like this:
>
> my @new_file=();
> while(<FH>){
> $_=~s/replace_me/with_this/gi;
> push @new_file, $_;
> }
>
> and then print @new_file to a filehandle? Or would that be a reference
> to @new_file?
You can let perl worry about opening the files, writing back to them, and even looping over the
lines, through command-line switches. This program does what you're doing above:
- -- cut here --
#!/usr/bin/perl -pi
s/replace_me/with_this/gi;
- -- cut here --
That's it ! For more info on the -p and the -i switches (and many other interesting ones), see
perldoc perlrun
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE/DkOteS99pGMif6wRAvrYAKD/oylKq/WL6pLBixWlA9VCng542QCfY/dt
BbWHBtt+1GK7PCGVriMaMuA=
=6jHE
-----END PGP SIGNATURE-----
------------------------------
Date: 11 Jul 2003 02:00:26 -0700
From: vrihad@myway.com
Subject: Re: Perl 5.8.0 compilation fails in chrooted environment
Message-Id: <2a024f54.0307110100.7cf2eac5@posting.google.com>
> > I replaced the file lib/Cwd.pm with the one having following content:
> > package Cwd;
> > sub cwd { my $p = `pwd`; chop $p; $p }
> > 1;
>
> > Now the new error while doing make is:
>
> > Undefined subroutine &File::Spec::Unix::cwd called at
> > ../../lib/File/Spec/Unix.pm line 457.
>
> I see: you need to make Cwd::cwd() exportable. Insert the Exporter
> boilerplate at start (e.g., see how the original Cwd did it).
I went through the file Cwd.pm. I found that it is checking for unix
command pwd in directories /bin and /usr/bin. Since I was using busybox
for pwd and it was installed in /usr/local/bin, it was not getting detected.
I made a symlink of /usr/local/bin/pwd to /usr/bin/pwd and tried make again.
Now it has successfully passed through the sections where it was failing
before.
Though I am not familiar with perl, just a little more digging helped a lot.
Now my compilation is going fine without any hack. Thanks Illya for all the
help.
> P.S. And, please, report the whole story as a bug via perlbug.
It seems to be not a bug in perl installation script. Just the position of
one binary in my system was not correct.
Thanks
vrihad
------------------------------
Date: Fri, 11 Jul 2003 00:07:59 -0400
From: Matt Oliverius <moliverius@w-link.net>
Subject: Perl and telnet
Message-Id: <vgsnmgi1v1sr77@corp.supernews.com>
Hello,
I am trying to get Perl to make the hard things possible, but I'm having my
doubts on this one...
We basically have a huge C program that runs at work and it takes about 24
hours to run. We want to run this C program using several input files, but
doing so in series would literally take 8 months. Therefore, we need to
run this code on several machines to complete in a reasonable amount of
time. We obviously don't want to piss off the users of these machines so
we needed a solution.
Using the Perl telnet and ping modules, I wrote a script that goes through
a complete listing of hostnames, pings each one to make sure it is alive,
then telnets to the alive machines, sends a w command to get the number of
users and the load average. If the average of the 3 load average numbers
is less than 0.05 and the number of users is 1, then the script opens an
Xterm window with that hostname as the title of the Xterm window, and
telnets to that machine.
Where I am stuck is how can you automate the login in each one of those
Xterms? The initial script that telnets and logs in is done in a single
terminal window. However, once the open machines are determined, we want to
run each instance of the C code in a separate Xterm telnet session.
If anyone has any ideas, I'd love to hear them.
Thanks,
Matt
------------------------------
Date: Thu, 10 Jul 2003 23:26:06 -0400
From: Matt Oliverius <moliverius@w-link.net>
Subject: Perl code question
Message-Id: <vgsl80mu09koae@corp.supernews.com>
Hi all,
I'm trying to do something which I believe is quite complex, and I'm hoping
someone here might not find it so complex. The problem involves
permutations. Here is the structure of my input file
A5 613 Full 2100.00 53.00 200.00
A5 613 Full 2110.00 56.00 200.50
A5 613 Full 2113.00 58.00 201.00
A5 613 Full 2114.00 60.00 202.00
A5 613F Half 2100.00 61.00 205.00
A5 613F Half 2110.00 63.00 201.00
A5 613F Half 2130.00 68.00 205.00
A5 613F Half 2140.00 62.00 201.00
A5 613A Half 2120.00 61.00 205.00
A5 613A Half 2130.00 63.00 201.00
A5 613A Half 2140.00 68.00 205.00
A5 613A Half 2150.00 62.00 201.00
A5 614 Full 2100.00 53.00 200.00
A5 614 Full 2110.00 56.00 200.50
A5 614 Full 2113.00 58.00 201.00
A5 614 Full 2114.00 60.00 202.00
A5 614F Half 2100.00 61.00 205.00
A5 614F Half 2110.00 63.00 201.00
A5 614F Half 2130.00 68.00 205.00
A5 614F Half 2140.00 62.00 201.00
A5 614A Half 2120.00 61.00 205.00
A5 614A Half 2130.00 63.00 201.00
A5 614A Half 2140.00 68.00 205.00
A5 614A Half 2150.00 62.00 201.00
A5 615 Full 2100.00 53.00 200.00
A5 615 Full 2110.00 56.00 200.50
A5 615 Full 2113.00 58.00 201.00
A5 615 Full 2114.00 60.00 202.00
A5 616 Full 2100.00 53.00 200.00
A5 616 Full 2110.00 56.00 200.50
A5 616 Full 2113.00 58.00 201.00
A5 616 Full 2114.00 60.00 202.00
A5 617 Full 2100.00 53.00 200.00
A5 617 Full 2110.00 56.00 200.50
A5 617 Full 2113.00 58.00 201.00
A5 617 Full 2114.00 60.00 202.00
Basically, you can think of the second column as a compartment. There are
5 compartments total. Sometimes one or more of these compartments can be
used to store a half size box, so I basically want to permutate every
possible combination. If all compartments used had a full box or alternate
half box configuration then there would be 2^5 permutations because each
compartment either stores one full size box or 2 half size boxes. In the
above example, there are four possibilities since 613 has either full, or
half and 614 has either full or half and 615-617 only have full. I need to
print each permutation along with all the data in columns 0-5 in an ascii
file. Does anyone have any easy way of doing this? I have beat my head on
this one for hours.
Thank you for your time,
Matt
------------------------------
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 5212
***************************************