[23000] in Perl-Users-Digest
Perl-Users Digest, Issue: 5220 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 13 21:06:06 2003
Date: Sun, 13 Jul 2003 18:05:09 -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 Sun, 13 Jul 2003 Volume: 10 Number: 5220
Today's topics:
[Q] package "IO::Handle" <bill_knight2@yahoo.com>
Re: Big hash question <newsreadermail@charter.net>
Re: Big hash question (Tad McClellan)
Re: Big hash question (Tad McClellan)
Re: Carriage Return / Line Feed question (David Efflandt)
Re: Check fileage with -M when path contains a point? (Math55)
Re: Couple of array/reference type questions (One more! <apollock11@hotmail.com>
Re: Couple of array/reference type questions (One more! <bart.lateur@pandora.be>
Re: Couple of array/reference type questions (One more! <apollock11@hotmail.com>
Couple of array/reference type questions <apollock11@hotmail.com>
Re: Couple of array/reference type questions <REMOVEsdnCAPS@comcast.net>
Re: Couple of array/reference type questions <apollock11@hotmail.com>
detecting memory leaks in Perl (Jerome Sui)
Re: duplicate removal <jurgenex@hotmail.com>
Re: flock() and W95 <noreply@gunnar.cc>
Re: How do I apply the search and replace routine so th <shotoku.taishi@virgin.net>
multi-part forms in CGI.pm <zchababe@comcast.net>
Re: multi-part forms in CGI.pm (Sam Holden)
Need help with wwwboard perl cgi script <cryo-fan@mylinuxisp.com>
Re: Need help with wwwboard perl cgi script <asu1@c-o-r-n-e-l-l.edu>
Re: Perl and telnet <Wolfgang_.fischer@freenet.de>
Re: Perl and telnet <jaspax@u.washington.edu>
Re: Perl and telnet (Bryan Castillo)
Re: problem with DBI.pm and ORDER BY RAND() in mysql <me@verizon.invalid>
Re: regex and parsing <asu1@c-o-r-n-e-l-l.edu>
Six GUARANTEED Paid Sign Ups ARE Money (steve parkes)
Re: String concatenation with .= <FH> (Bryan Castillo)
Re: uninitialized value in pattern match (Gilgames)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 13 Jul 2003 23:16:06 +0000 (UTC)
From: bill <bill_knight2@yahoo.com>
Subject: [Q] package "IO::Handle"
Message-Id: <besp7m$32j$1@reader1.panix.com>
If I try STDOUT->foo("bar") in the debugger I get:
DB<1> STDOUT->foo("bar")
Can't locate object method "foo" via package "IO::Handle" (perhaps you forgot to load "IO::Handle"?) at (eval 25)[/usr/share/perl/5.6.1/perl5db.pl:1521] line 2.
...but
DB<2> p ref STDOUT
DB<3> p ref *STDOUT
DB<4>
How come Perl treats STDOUT as an IO::Handle object in <1>, but
ref does not report any class in <2> or <3>?
TIA,
-bill
------------------------------
Date: Sun, 13 Jul 2003 13:38:55 -0500
From: "S. Heiling" <newsreadermail@charter.net>
Subject: Re: Big hash question
Message-Id: <vh39pmtjcbph06@corp.supernews.com>
"Perhaps you could just put the data in a __DATA__ section."
Thanks. I'm working on using __DATA__, and it stops anything after that from
"compiling", but I'm having some trouble getting anything out of my hash.
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbh0ga9.anm.tadmc@magna.augustmail.com...
> S. Heiling <newsreadermail@charter.net> wrote:
>
> > And I'm trying to work it from a single script.
>
>
> Perhaps you could just put the data in a __DATA__ section.
>
>
> > "Don't load the whole hash at startup."
> >
> > How can I do that?
>
>
> The post you quoted had code that does that.
>
> I do not see that you even need a hash at all...
>
>
> > %hash = (
> >
> > key0 => "very long value.......",
> > key1 => "valy long value.......",
> >
> > );
>
>
> Remove that code that loads the hash, put the data in __DATA__ instead.
>
>
> > while ( ($key, $value) = each %hash) {
> >
> > # The keys are file names or directory paths.
> > # The values are the file data unpacked into hex.."H"
> >
> > }
>
>
> > I've tried putting the hash after the while statement but still, a long
> > wait.
>
>
> Perl compiles your entire program, so where it is located in the
> source code will not matter.
>
>
> > is there a way?
>
> --------------------------------------
> # untested
> while ( <DATA> ) {
> chomp;
> my($key, $value) = split / => /;
>
> # do stuff with only 1 pair at a time in memory
> }
>
> __DATA__
> key0 => very long value.......
> key1 => valy long value.......
> --------------------------------------
>
>
> See the "Scalar value constructors" section in perldata.pod
> for info on the DATA filehandle and the __DATA__ token.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Sun, 13 Jul 2003 17:14:40 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Big hash question
Message-Id: <slrnbh3meg.lus.tadmc@magna.augustmail.com>
S. Heiling <newsreadermail@charter.net> wrote:
> "Perhaps you could just put the data in a __DATA__ section."
Who said that?
Please provide an attribution when you quote someone.
Please mark quoted text following Usenet convention, so you don't
confuse people's newsreaders.
Have you seen the Posting Guidelines that are posted here frequently?
> Thanks.
If you mean that, then please learn to compose followups properly.
Soon.
[ snip 75 lines of TOFU ]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 13 Jul 2003 17:33:55 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Big hash question
Message-Id: <slrnbh3nij.lus.tadmc@magna.augustmail.com>
[ lines rearranged into context ]
S. Heiling <newsreadermail@charter.net> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbh0ga9.anm.tadmc@magna.augustmail.com...
>> S. Heiling <newsreadermail@charter.net> wrote:
>>
>> > And I'm trying to work it from a single script.
>>
>> Perhaps you could just put the data in a __DATA__ section.
> Thanks. I'm working on using __DATA__, and it stops anything after that from
> "compiling",
Well yes, "code" gets compiled, loading a hash is "code".
It will take a "long time" if the hash is large.
If we can get the job done _without_ this large hash, then
our problem will be solved!
The best way to get a performance improvement is nearly always
by doing a careful analysis of the _algorithm_ being used.
Your algorithm seems to require that you have access to _all_
of the pairs, we suggested an algorithm that has only a single
pair in memory.
What are you going to really be doing in the loop code?
_Must_ you have them all available, or is one-at-a-time workable?
>> I do not see that you even need a hash at all...
> but I'm having some trouble getting anything out of my hash.
Errr, what hash? !!
If you follow my suggestions in the post that you are following up to,
then *there is no hash*.
If you are still talking about a hash, then you didn't understand
what I described earlier.
My code had no hash. Show code with a hash if you want to
start talking about a hash again.
(and if you _do_ need them all, ie. you _must have_ the hash, then
the answer is to use a tied hash or a real DB, as suggested earlier.
)
[snip yet more TOFU...]
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 13 Jul 2003 04:05:14 +0000 (UTC)
From: efflandt@xnet.com (David Efflandt)
Subject: Re: Carriage Return / Line Feed question
Message-Id: <slrnbh1mjp.r7s.efflandt@typhoon.xnet.com>
On Sat, 12 Jul 2003, Chris Kolosiwsky
<phignuton@_nospamplease_hotmail.com> wrote:
><original post -- 'snip'>
>
> On Sat, 12 Jul 2003 00:06:58 +0000, David Efflandt wrote:
>
>> It depends what OS the script is running on. An OS that expects \x0d\0a
>> for line endings (DOS/Win) is not going to recognize just \x0d (old Mac)
>> as a line ending. An OS that uses \x0a for line endings would not
>> recognize \x0d as a line ending and may give unexpected results with
>> \x0d\x0a line endings.
>>
>> So you should either convert data line endings to proper type for the OS
>> the script is running on or, set $/ to whatever you expect actual line
>> endings to be (see: perldoc perlvar).
>>
>
> I should have included this in the initial post, but the text file is
> generated on a solaris machine and the script is being run from a linux
> box using perl 5.8. When the file was ftp'd to a DOS box, the ascii
> transfer converted the CR to CR/LF but that was to the DOS box. Another
> file with only a CR (still running on a linux box) transferred via FTP
> ascii (but not to a DOS machine) resulted in no output. A hex dump of the
> first (DOS FTP) file shows the CR/LF and a hex dump of the second file
> (unix -> linux FTP) shows only a CR.
What generated the data with CR's in it. Both Solaris and Linux use LF
for newlines in text files. If you transfer files directly between
Solaris and Linux, ascii or binary mode does not matter because no
conversion is necessary (I typically use scp). If it passes though
Windows use ascii mode both to and from Windows. I think only pre-OS X
Mac uses CR only for line endings.
> I will try setting $/ and update. Thanks!
Maybe you need to look at what generates the data in the first place and
see if it is malformed (if it is Perl it should be using "\n" for
newlines). But note that data from web form textareas may contain CR-LF
pairs regardless of browser OS.
--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://cgi-help.virtualave.net/ http://hammer.prohosting.com/~cgi-wiz/
------------------------------
Date: 13 Jul 2003 15:19:36 -0700
From: magelord@t-online.de (Math55)
Subject: Re: Check fileage with -M when path contains a point?
Message-Id: <a2b8188a.0307131259.25ddf7bc@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbh0et4.anm.tadmc@magna.augustmail.com>...
> Math55 <magelord@t-online.de> wrote:
>
> > why cant i check the age of a file with -M?
>
>
> Because the file is not where you think it is.
>
> It is someplace else.
>
>
> > ---
> > use File::Basename;
> > $path="/home/raid/golchert/.cxoffice/dotwine/filelist.dat";
> > #$path="/home/raid/golchert/Downloads/CD Control QE 1.0.1.12.exe";
> >
> > chdir (dirname($path));
>
>
> What if that fails?
>
> You should check to see if you actually got what you asked for:
>
> chdir(dirname $path) or die "could not chdir() $!";
>
>
> > $relFile= (fileparse($path));
> > $rf.="/".$relFile;
>
> /filelist.dat
> and
> /home/raid/golchert/.cxoffice/dotwine/filelist.dat
>
> are (probably) not the same file.
>
> The 1st one likely does not exist (and that is the one you are looking at).
>
>
> > print "\n age of $path = ".(-M $rf). "\n" if (-M $rf <=100 && !(-d
> > $rf));
> >
> > ---
> >
> > maybe you have to change to a pth that contains a point at your
> > system.
>
>
> Huh?
>
> You cannot "change to a path". What did you mean there?
>
> Did you mean "change to a directory" instead?
>
> You are not required to do anything to your cwd in order to do
> a filetest such as -M, so why are you (attempting to) change
> your cwd?
>
>
> > i tried with absolute and relative path,
>
>
> Show us what you have tried.
>
> The code you've shown does not attempt to use a relative path, and
> the absolute path that it tries is not the correct absolute path.
>
>
> > both did not
> > work:-(...
>
>
> Then fix them.
hi, i tried like that:
print "\n age of $path = ".(-M $path). "\n" if (-M $path <=100 && !(-d
$path));
that was my first try. when $path contains something like that:
$path="/tmp/hello.txt" it works fine, but as soon as there is a point
like the path i mentioned before -M fails....
:-(
------------------------------
Date: Sun, 13 Jul 2003 13:10:43 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Re: Couple of array/reference type questions (One more!)
Message-Id: <besec7$1aki$1@agate.berkeley.edu>
Now I remember the other one:
How do I find the last subscript of a reference to an
array without first dereferencing it? You know, with the
$# syntax.
Thank you again,
------------------------------
Date: Sun, 13 Jul 2003 20:13:50 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Couple of array/reference type questions (One more!)
Message-Id: <r9f3hvse35l7pggpb2gcsatg70ms31s01g@4ax.com>
Arvin Portlock wrote:
>How do I find the last subscript of a reference to an
>array without first dereferencing it? You know, with the
>$# syntax.
$#{$ref}
or
$#$ref
--
Bart.
------------------------------
Date: Sun, 13 Jul 2003 14:02:00 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Re: Couple of array/reference type questions (One more!)
Message-Id: <beshcc$1cli$1@agate.berkeley.edu>
Bart Lateur wrote:
> Arvin Portlock wrote:
>
>
> >How do I find the last subscript of a reference to an
> >array without first dereferencing it? You know, with the
> >$# syntax.
>
>
> $#{$ref}
> or
> $#$ref
Thanks! I won't even ATTEMPT to explain why I never thought
to try that.
------------------------------
Date: Sun, 13 Jul 2003 12:53:04 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Couple of array/reference type questions
Message-Id: <besdb4$1a02$1@agate.berkeley.edu>
There are several array type things I find myself doing all
the time and I'd like to know, once and for all, the best way
to do them. For the moment I'm most interested in core language
commands rather than specialized modules, but I'm interested to
hear about modules as well if they're really useful.
1. Grepping an array of references possible?
If I have an array of hash references, is there a way to use
grep() to find those elements whose values match a given value?
I.e., is there a grep() way to do this? I just like grep () and
I'm confortable with it and want to use it as much as I can.
my $ref = {};
$ref->{title} = 'Gone with the wind';
$ref->{date} = '1952';
push @books, $ref;
my @mybooks;
foreach my $book (@books) {
if ($book->{title} =~ /Gone/) {
push @mybooks, $book;
}
}
How would I use grep () in a scalar context if I just wanted
to know how many books contained "Gone" and didn't want to
create a new array? How about if I only wanted to know whether
the array contained ANY book whose title contained that word,
without the overhead of counting them all? For that last I'm
guessing a foreach loop is as good as it gets, but since I do
it all the time I just want to make sure I'm not missing any-
thing magical.
2. Replacing elements of an array of references.
Suppose I'm a book seller who just got in a new shipment of
"Gone with the wind." I want to replace the old edition in
my array with the new edition. This is the best I can come up
with (preserving order is important):
my $new_edition = {};
$new_edition->{title} = 'Gone with the wind';
$new_edition->{date} = '2003';
for (my $i = 0; $i++; $i <= $#books) {
$books->[$i] = $new_edition if $books->[$i]->{title}
eq 'Gone with the wind';
}
Any way to do this with grep ()?
Those are the only two I can think of at the moment. Thanks for
any advice!
------------------------------
Date: Sun, 13 Jul 2003 16:13:56 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Couple of array/reference type questions
Message-Id: <Xns93B7AF4C434B6sdn.comcast@206.127.4.25>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Arvin Portlock <apollock11@hotmail.com> wrote in news:besdb4$1a02$1
@agate.berkeley.edu:
> 1. Grepping an array of references possible?
...
>
> my $ref = {};
> $ref->{title} = 'Gone with the wind';
> $ref->{date} = '1952';
> push @books, $ref;
> my @mybooks;
> foreach my $book (@books) {
> if ($book->{title} =~ /Gone/) {
> push @mybooks, $book;
> }
> }
@mybooks = grep $_->{title} =~ /Gone/, @books;
>
> How would I use grep () in a scalar context if I just wanted
> to know how many books contained "Gone" and didn't want to
> create a new array?
$num = grep $_->{title} =~ /Gone/, @books;
> How about if I only wanted to know whether
> the array contained ANY book whose title contained that word,
if (grep $_->{title} =~ /Gone/, @books) { ...}
But you're right, a foreach loop is not a bad way to do that, especially
if the list is large, and you use 'last' once you have found a match.
> 2. Replacing elements of an array of references.
...
>
> my $new_edition = {};
> $new_edition->{title} = 'Gone with the wind';
> $new_edition->{date} = '2003';
> for (my $i = 0; $i++; $i <= $#books) {
> $books->[$i] = $new_edition if $books->[$i]->{title}
> eq 'Gone with the wind';
> }
>
> Any way to do this with grep ()?
No; a foreach loop is your best bet here:
foreach my $book (@$books)
{
$book = $new_edition if $book->{title} eq '....';
}
- --
Eric
$_ = reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print
-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBPxHLkmPeouIeTNHoEQIYRACeN8hFSv1+6HlLNrHju1jqd4lHO3AAoPn2
hYnPru0bZbhNYPFSlmAk8oBw
=+f9C
-----END PGP SIGNATURE-----
------------------------------
Date: Sun, 13 Jul 2003 14:31:34 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Re: Couple of array/reference type questions
Message-Id: <besj3q$1dti$1@agate.berkeley.edu>
I'm printing this out and pinning it to my computer! Thanks you so
much Eric.
BTW, yes, the foreach is cleaner than my for. I forgot they're
references after all and I needn't go through all that subscript
nonsense.
Arvin
Eric J. Roode wrote:
> -----BEGIN xxx SIGNED MESSAGE-----
> Hash: SHA1
>
> Arvin Portlock wrote in news:besdb4$1a02$1
> @agate.berkeley.edu:
>
>
>
>
> >1. Grepping an array of references possible?
>
> ...
>
> > my $ref = {};
> > $ref->{title} = 'Gone with the wind';
> > $ref->{date} = '1952';
> > push @books, $ref;
> > my @mybooks;
> > foreach my $book (@books) {
> > if ($book->{title} =~ /Gone/) {
> > push @mybooks, $book;
> > }
> > }
>
>
> @mybooks = grep $_->{title} =~ /Gone/, @books;
>
>
> > How would I use grep () in a scalar context if I just wanted
> > to know how many books contained "Gone" and didn't want to
> > create a new array?
>
>
> $num = grep $_->{title} =~ /Gone/, @books;
>
>
> >How about if I only wanted to know whether
> > the array contained ANY book whose title contained that word,
>
>
> if (grep $_->{title} =~ /Gone/, @books) { ...}
>
> But you're right, a foreach loop is not a bad way to do that, especially
> if the list is large, and you use 'last' once you have found a match.
>
>
> >2. Replacing elements of an array of references.
>
> ...
>
> > my $new_edition = {};
> > $new_edition->{title} = 'Gone with the wind';
> > $new_edition->{date} = '2003';
> > for (my $i = 0; $i++; $i <= $#books) {
> > $books->[$i] = $new_edition if $books->[$i]->{title}
> > eq 'Gone with the wind';
> > }
> >
> > Any way to do this with grep ()?
>
>
> No; a foreach loop is your best bet here:
>
> foreach my $book (@$books)
> {
> $book = $new_edition if $book->{title} eq '....';
> }
>
> - --
> Eric
> $_ = reverse sort qw p ekca lre Js reh ts
> p, $/.r, map $_.$", qw e p h tona e; print
>
> -----BEGIN xxx SIGNATURE-----
> Version: PGPfreeware 7.0.3 for non-commercial use
>
> iQA/AwUBPxHLkmPeouIeTNHoEQIYRACeN8hFSv1+6HlLNrHju1jqd4lHO3AAoPn2
> hYnPru0bZbhNYPFSlmAk8oBw
> =+f9C
> -----END PGP SIGNATURE-----
------------------------------
Date: 13 Jul 2003 07:37:19 -0700
From: jsui123@hotmail.com (Jerome Sui)
Subject: detecting memory leaks in Perl
Message-Id: <307493cc.0307122350.6be6db11@posting.google.com>
What's a good way of detecting memory leaks in Perl ?
Does the following pattern introduce a garbage collection problem ?
package Some::ObjectObserver;
use Some::Object;
sub new {
my $self = bless {}, shift;
$self->{objects} = [Some::Object->new(sub {$self->onEvent})];
return $self;
}
sub onEvent {
}
1;
__END__
package Some::Object;
sub new {
my $self = bless {}, shift;
$self->{onEvent} = shift;
return $self;
}
1;
__END__
------------------------------
Date: Sun, 13 Jul 2003 04:42:41 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: duplicate removal
Message-Id: <5r5Qa.7926$qn1.4710@nwrddc04.gnilink.net>
john62@electronmail.com wrote:
> ok, this is probably another easy question. does anyone
> know how to remove duplicates in a list of strings?
The Fine Manual knows.
Please check "perldoc -q duplicate":
How can I remove duplicate elements from a list or array?
jue
------------------------------
Date: Sun, 13 Jul 2003 12:47:36 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: flock() and W95
Message-Id: <berd9f$7n05r$1@ID-184292.news.uni-berlin.de>
Steve Grazzini wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
>>Steve Grazzini wrote:
>>>In order to mimic the builtin "*" prototype I think you'd need
>>>something like this:
>>
>>So it is possible. :) Thanks, I'll consider it. Or maybe that would
>>be to overdo it; needing to use the typeglobe in the filehandle
>>argument isn't that inconvenient.
>
> If you're not trying to imitate the built-in flock() maybe you should
> call your function safe_flock() or something unambiguous... and if you
> are trying to imitate it then you need to handle bareword-filehandles.
>
> Anyway, I noticed this cleaner alternative in perlsub (and I think you
> were reinventing 'use subs' as well :-) so -->
>
> use Symbol qw(qualify_to_ref);
> use subs qw(flock);
>
> sub flock (*$) {
> my $fh = qualify_to_ref(shift, caller);
> my $ret = eval { CORE::flock($fh, shift) };
> if ($@) {
> require Carp;
> Carp::carp($@);
> }
> return $ret;
> }
I'm not using 'subs' since, as I mentioned in a reply to Tassilo, I
want the solution to cover also occurrences of flock() in modules like
Tie::File that don't use or require anything from my program.
I guess you can say that I'm not just imitating flock(), I'm changing
its documented behaviour. But it's true that it's not my _intention_
to make it unable to handle bareword filehandes, and Symbol.pm allows
for seemingly clean code... Okay, I'm convinced. ;-) This is what I
have for now:
BEGIN {
# Disregard "unimplemented" flock() errors
use Symbol;
*CORE::GLOBAL::flock = sub(*$) {
my $fh = qualify_to_ref(shift, caller);
unless (eval { CORE::flock $fh, shift }) {
return 0 unless $@ =~ /unimplemented/;
}
return 1;
};
}
Is there really any reason to deal with other error messages but the
"unimplemented" ditto in this piece of code? Even if eval() is used,
possible error messages seem to end up in $! as usual, so this works
as usual:
flock FH, LOCK_EX or die $!;
(and it's a CGI program, and I'm already using CGI::Carp).
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 13 Jul 2003 12:59:15 +0100
From: "Shotoku Taishi" <shotoku.taishi@virgin.net>
Subject: Re: How do I apply the search and replace routine so that it works?
Message-Id: <berhj4$jll$1@newsg2.svr.pol.co.uk>
Hi there
Thank you so much for your response. I have got the search and replace
routine to work now. :-)
Michael
"J. Gleixner" <glex_nospam@qwest.net> wrote in message
news:Y51Pa.65$z21.64151@news.uswest.net...
> Shotoku Taishi wrote:
> [...]
> > foreach $a (@a) {
> > print OUTPUT <<EOT;
> > file=$a log=$a\.log
> > EOT
> > }
> [...]
> > I have tried
> > s/\.exp\./\./g;
> > but the output does not seem to change.
> >
> > How do I apply the search and replace routine so that it works?
>
> Need to apply your substitution on something, using =~, otherwise it
> only operates on $_.
>
> foreach my $a (@a)
> {
> my $log = $a;
> $log =~ s/\.exp\./\./;
>
> print OUTPUT "file=$a log=$log.log\n";
> }
>
> foreach (@a)
> {
> print OUTPUT "file=$_ ";
> s/\.exp\./\./; # $_ is operated on
> print OUTPUT "log=$_.log\n";
> }
>
------------------------------
Date: Sun, 13 Jul 2003 22:43:11 GMT
From: "Zak" <zchababe@comcast.net>
Subject: multi-part forms in CGI.pm
Message-Id: <3glQa.48793$GL4.12663@rwcrnsc53>
Hi,
I am a new comer to CGI.pm and find it extremely useful. I have created
multi-form pages and with little struggle have succesfully been able to save
states from one form to another (from one page to another). Two groups of
people will be using the mutli-form pages to fill out the fields.
GROUP A fills out pages 1, 2, 3.
GROUP B fills out pages 4, 5.
I have used save_parameters and restore_parameters to bring back the forms
partially filled out. My dilemma now is:
when I bring the forms back for the second group (GROUP B) to fill out their
sections (page 4, 5), I want to "gray" sections 1, 2, 3 (pages 1, 2, 3 in
view access only but not hide them) that Group A had already filled. Not
give GROUP B access to enter text in fields for pages 1, 2, 3 but be able to
display information. I don't want to use hidden() because it would hide the
fields entriely. I want to display fields in pages 1, 2, 3 in view mode only
for GROUP B but give them write access to pages 4,5.
restore_parameters bring all pages and all fields in write access.
Does anyone have an idea how manipulate this one? Any help is appreciated.
Thanks.
------------------------------
Date: 13 Jul 2003 22:57:21 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: multi-part forms in CGI.pm
Message-Id: <slrnbh3ouh.fej.sholden@flexal.cs.usyd.edu.au>
On Sun, 13 Jul 2003 22:43:11 GMT, Zak <zchababe@comcast.net> wrote:
> Hi,
> I am a new comer to CGI.pm and find it extremely useful. I have created
> multi-form pages and with little struggle have succesfully been able to save
> states from one form to another (from one page to another). Two groups of
> people will be using the mutli-form pages to fill out the fields.
> GROUP A fills out pages 1, 2, 3.
> GROUP B fills out pages 4, 5.
> I have used save_parameters and restore_parameters to bring back the forms
> partially filled out. My dilemma now is:
> when I bring the forms back for the second group (GROUP B) to fill out their
> sections (page 4, 5), I want to "gray" sections 1, 2, 3 (pages 1, 2, 3 in
> view access only but not hide them) that Group A had already filled. Not
> give GROUP B access to enter text in fields for pages 1, 2, 3 but be able to
> display information. I don't want to use hidden() because it would hide the
> fields entriely. I want to display fields in pages 1, 2, 3 in view mode only
> for GROUP B but give them write access to pages 4,5.
>
> restore_parameters bring all pages and all fields in write access.
>
> Does anyone have an idea how manipulate this one? Any help is appreciated.
> Thanks.
By outputting the appropriate HTML for those fields.
I doubt CGI.pm will do that for you (though I could be wrong, check the
CGI.pm. perldoc CGI, documentation to be sure). So you will probably
have to add the appropriate HTML to the field before outputting it,
CGI.pm allows you to set arbitrary attributes I believe (though you're
code would have to decide on which fields to do so).
What those attributes are (and whether there is such a standard
attribute or if you need to dive into browser specific extensions) is
something you can probably find out in one of the html newsgroups, such
as comp.infosystems.www.authoring.html.
--
Sam Holden
------------------------------
Date: Sun, 13 Jul 2003 19:01:50 -0500
From: randy <cryo-fan@mylinuxisp.com>
Subject: Need help with wwwboard perl cgi script
Message-Id: <vms3hvkqibiorcjtm8214kh02unionm9t8@4ax.com>
I have uploaded the nms perl cgi wwwboard bulletin board script to my
ftp url, and have set permissions, but it does not work. (Note that
this perl script is a cleaned up more secure version of Matt's
infamous script)
Here is the situation:
I have uploaded the wwwboard.html file to to my
/home/cryofan/public_html directory, and the wwwboard.pl file is in
the /home/cryofan/public_html/cgi-bin directory, and the wwwboard.html
file is chmod 777 and wwwboard.pl is 755.
When I go to http://www.mylinuxisp.com/~cryofan/wwwboard.html I do
get the message posting form, but when I try to post a message, the
browser goes to http://www.mylinuxisp.com/cgi-bin/wwwboard.pl which is
an HTTP 404 "This page cannot be found" page. What happened to the
"cryofan" part of the URL, anyway?
Here are my variables in the wwwboard.pl file (some parts are
deleted):
///////////////start wwwboard.plfile/////////////////////////
#!/usr/bin/perl -Tw
#
# $Id: wwwboard.pl,v 1.51 2003/04/16 17:01:09 nickjc Exp $
#
$DEBUGGING = 1;
$emulate_matts_code = 1;
$max_followups = 10;
$basedir = '/home/cryofan/public_html';
$baseurl = 'http://www.mylinuxisp.com/~cryofan';
$cgi_url ='http://www.mylinuxisp.com/~cryofan/cgi-bin/wwwboard.pl';
As for why I have the tilde before "cryofan" in the $baseurl and
$cgiurl above, I put that in because that is what I have to type into
the browser in order to access my webpages there.
Here is the form action path in the wwwboard.html file:
<form method="post" action="/cgi-bin/wwwboard.pl">
Anyone have any ideas?
Thanks
-------------
-Randy
------------------------------
Date: 14 Jul 2003 00:58:22 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Need help with wwwboard perl cgi script
Message-Id: <Xns93B7D55A1FFCasu1cornelledu@132.236.56.8>
randy <cryo-fan@mylinuxisp.com> wrote in
news:vms3hvkqibiorcjtm8214kh02unionm9t8@4ax.com:
<snip>
> When I go to http://www.mylinuxisp.com/~cryofan/wwwboard.html I do
> get the message posting form, but when I try to post a message, the
> browser goes to http://www.mylinuxisp.com/cgi-bin/wwwboard.pl which is
> an HTTP 404 "This page cannot be found" page. What happened to the
> "cryofan" part of the URL, anyway?
<snip>
> $cgi_url ='http://www.mylinuxisp.com/~cryofan/cgi-bin/wwwboard.pl';
<snip>
> Here is the form action path in the wwwboard.html file:
> <form method="post" action="/cgi-bin/wwwboard.pl">
Why do $cgi_url and the action part of the form not match?
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Sun, 13 Jul 2003 09:19:43 +0200
From: Wolfgang Fischer <Wolfgang_.fischer@freenet.de>
Subject: Re: Perl and telnet
Message-Id: <pan.2003.07.13.07.19.33.76983@freenet.de>
On Fri, 11 Jul 2003 00:07:59 -0400, Matt Oliverius wrote:
> 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.
You don't need to check for users and CPU usage. Instead, you should give
your program a low priority (nice -19 program).
For security reasons you should use ssh.
>
> 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.
Why do you need xterms? It would be better to interact to the telnet
session directly from the perl program.
>
> If anyone has any ideas, I'd love to hear them.
>
> Thanks,
>
> Matt
------------------------------
Date: Sun, 13 Jul 2003 10:29:11 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Perl and telnet
Message-Id: <Pine.A41.4.55.0307131026570.98154@dante18.u.washington.edu>
Wolfgang Fischer sikyal:
> You don't need to check for users and CPU usage. Instead, you should give
> your program a low priority (nice -19 program).
> For security reasons you should use ssh.
You mean `nice 19 program`. Using -19 gives your program an exceptionally
high priority and will probably cripple your system, if it's a
processor-intensive program.
Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog
------------------------------
Date: 13 Jul 2003 17:00:18 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: Perl and telnet
Message-Id: <1bff1830.0307131600.196025f0@posting.google.com>
Matt Oliverius <moliverius@w-link.net> wrote in message news:<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 you are already using xterm on the client (meaning you have X on the
client), why don't you just invoke xterm on the server with the display
of the client. You have already logged in via Net::Telnet.
Something like this:
use strict;
use warnings;
use Net::Telnet;
use Sys::Hostname;
my $host = 'psylocke';
my $user = 'bryanc';
my $pass = 'pass';
my $myhost = hostname;
my $rmt_script = './my_script';
eval {
my $telnet = Net::Telnet->new($host) || die;
$telnet->login($user, $pass) || die;
my $cmd = "xterm -T $host -display ${myhost}:0 -e '$rmt_script' &";
print "Running command: $cmd\n";
my @output = $telnet->cmd($cmd);
print "Result: ", @output, "\n";
$telnet->close;
};
warn $@ if ($@);
If you have the time and resources, I would suggest writing a client/server
program instead.
> If anyone has any ideas, I'd love to hear them.
>
> Thanks,
>
> Matt
------------------------------
Date: Sun, 13 Jul 2003 23:06:52 GMT
From: "dw" <me@verizon.invalid>
Subject: Re: problem with DBI.pm and ORDER BY RAND() in mysql
Message-Id: <gClQa.10971$D%1.8130@nwrddc01.gnilink.net>
"Joe Blower" <motiv8xREMOVETHIS@top25web.com> wrote in message
news:ammdnSGv5q0XC5KiXTWJgQ@comcast.com...
> When I execute the following SQL statement at the mysql> prompt, I get a
> random result:
>
> SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND() LIMIT 1;
>
> When I wrap it in my perl code, I always get the first row in the
database.
>
> my $dbh = DBI->connect("dbi:mysql:$db:host=$db_host", $db_user, $db_pass);
>
> my $sql = "SELECT proxy FROM proxies WHERE active = 1 ORDER BY RAND()
LIMIT
> 1";
How about removing the 'LIMIT 1"?
------------------------------
Date: 13 Jul 2003 21:08:09 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: regex and parsing
Message-Id: <Xns93B7AE50B928Fasu1cornelledu@132.236.56.8>
justin_rodino@yahoo.co.uk (Justin Rodino) wrote in
news:8f89781b.0307072312.66e5e327@posting.google.com:
<snip>
> Here is an example line that will be read in (it might get wrapped,
> but you can be assured its always one line):
>
> <ExecutionEnvironment ExecutionContext="Admin" LogonName=""
> LogonDomain="" LogonPassword="" Interactive="false"
> AllowUserExecution="true" UserNotifyTimeout="false" RunForUsers="First
> user who logs in" CanRunWhen="whether or not a user is logged on"
> StartWindow="Normal" ScheduleRetry="true" MinConnectionSpeed="0"/>
and if the file is in XML format as you indicate, why not use
XML::Parser?
C:\develop\src\misc>cat txml.pl
#! C:/Perl/bin/perl.exe -w
use diagnostics;
use strict;
use warnings;
use XML::Parser;
my $p = new XML::Parser(Handlers => {Start => \&handle_start});
while(<DATA>) {
$p->parse($_);
}
sub handle_start {
my $Expat = shift;
my $Element = shift;
my ($attr, $val);
while((defined ($attr = shift)) && (defined ($val = shift))) {
print $attr, " = ", '"', $val,'"', "\n";
}
}
__DATA__
<ExecutionEnvironment ExecutionContext="Admin" LogonName=""
LogonDomain="" LogonPassword="" Interactive="false"
AllowUserExecution="true" UserNotifyTimeout="false"
RunForUsers="First user who logs in"
CanRunWhen="whether or not a user is logged on" StartWindow="Normal"
ScheduleRetry="true" MinConnectionSpeed="0"/>
Note that the above is entered as a single line, but wrapped in the
newsreader.
Output:
C:\develop\src\misc>txml.pl
ExecutionContext = "Admin"
LogonName = ""
LogonDomain = ""
LogonPassword = ""
Interactive = "false"
AllowUserExecution = "true"
UserNotifyTimeout = "false"
RunForUsers = "First user who logs in"
CanRunWhen = "whether or not a user is logged on"
StartWindow = "Normal"
ScheduleRetry = "true"
MinConnectionSpeed = "0"
--
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov
------------------------------
Date: Sun, 13 Jul 03 22:42:00 GMT
From: morewealth@ultimateinbox.com(steve parkes)
Subject: Six GUARANTEED Paid Sign Ups ARE Money
Message-Id: <03071322420010600@news.blueyonder.co.uk>
Six GUARANTEED Paid Sign Ups ARE Money
Hello Fellow NetMarketer,
Get Your FREE**SIX GUARANTEED Paid Sign Ups**
**UNLIMITED Income**
**Paid DAILY**
**NO Sponsoring Required**
**Join with the Financial Peace TEAM**
http://www.globaldailypay.com/morewealth
If YOU really want to make money online,
***THIS WILL DO IT!***
Do you want to be guaranteed PAID signups in your downline
and not just signups that stay free and never upgrade? How
about NO SPONSORING REQUIRED! Get Your Six Guaranteed
Sign Ups NOW!! The Financial Peace TEAM is $uccesssful!
Creating Wealth With...
The Most POWERFUL International Program On The Net!
Experts say that we are presented with only TWO great
opportunities in our lifetime. We don't know if this is
your first or your second....but we do know that
****THIS IS ONE OF THEM!****
Best Regards,
Financial Peace TEAM
------------------------------
Date: 13 Jul 2003 06:53:35 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: String concatenation with .= <FH>
Message-Id: <1bff1830.0307122124.2bbdb86d@posting.google.com>
powell_luke@hotmail.com (Luke Powell) wrote in message news:<e7ccbaac.0307111514.1e0a8253@posting.google.com>...
> rook_5150@yahoo.com (Bryan Castillo) wrote in message news:<1bff1830.0307082117.49fd08a1@posting.google.com>...
> > powell_luke@hotmail.com (Luke Powell) wrote in message news:<e7ccbaac.0307081353.527d24e5@posting.google.com>...
> > > I was writing a program to parse some data and I found something odd.
> > > I'm using the ActiveState 5.8.0 for Windows (build 804) version of
> > > Perl, and I found that when I did this:
> > >
> > > $record .= <FH>; #replaces rather than appends to $record
> > >
> >
> > Could you post a very small script that shows this?
> > I couldn't reproduce what you describe above. (although Im using 5.6.1)
> > Here is what I tried:
> >
> > use strict;
> > use warnings;
> > open(F,"<$0") || die $!;
> > my $record = "first line\n";
> > $record .= <F>;
> > print "record = ",$record,"\n";
> >
> > Its output was:
> > record = first line
> > use strict;
> >
>
> Sure Brian... This actually made me investigate the problem a little
> more closely, so I can be a little more specific about the cause. It
> appears to only be a problem when I use $/ = \4 to make it a fixed
> record length mode. Here's the script:
>
> use strict;
> use warnings;
> open(FH,"temp.txt");
> $/=\5
$/=\5; # <- forgot semi-colon
> my $string="This ";
> $string.=<FH>;
> print $string;
>
> temp.txt contains:
> works
>
> This outputs:
> works
>
Im seeing the same problem for 5.8.0, on Windows98 and Free BSD 5.0. Using
5.6.1, Im getting the expected results.
I'm thinking this is a bug in 5.8.0.
> Thanks for your replying :).
>
> Luke
------------------------------
Date: 13 Jul 2003 19:26:49 GMT
From: gilgames@aol.coma (Gilgames)
Subject: Re: uninitialized value in pattern match
Message-Id: <20030713152649.20826.00000254@mb-m10.aol.com>
<<
$netscape = (defined $ENV{HTTP_USER_AGENT} && $ENV{HTTP_USER_AGENT} =~
/netscape/i ) ? 1 : 0;
hth-
--
Michael Budash
>>
Thanks
------------------------------
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 5220
***************************************