[23646] in Perl-Users-Digest
Perl-Users Digest, Issue: 5853 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 24 18:05:47 2003
Date: Mon, 24 Nov 2003 15:05:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 24 Nov 2003 Volume: 10 Number: 5853
Today's topics:
Re: Assigning split to a list: undefined values? <mitia.nospam@northwestern.edu.invalid>
Re: Avoiding running a process twice (Anno Siegel)
Re: Avoiding running a process twice (Sam Holden)
Re: Can this script be used to spam? <abigail@abigail.nl>
Re: Can this script be used to spam? <noreply@gunnar.cc>
Re: client/ server <james.welsby@virgin.net>
Convert ISO-8859-1 (quoted-printable) to 8 bit <dreamer@cox.net>
Re: Image::Magick memory leak question <mgjv@tradingpost.com.au>
newbie <STDIN> question (leegold)
Re: newbie <STDIN> question <syscjm@gwu.edu>
Re: newbie <STDIN> question <noreply@gunnar.cc>
Re: newbie <STDIN> question Default@IO_Error_1011101.xyz
Re: newbie <STDIN> question (Tad McClellan)
Re: Perl Editor <syscjm@gwu.edu>
Re: Perl Editor <abigail@abigail.nl>
Re: Perl Editor <me@privacy.net>
Re: Perl Editor <dmcbride@naboo.to.org.no.spam.for.me>
Re: Perl Editor <emschwar@pobox.com>
Re: Perl Editor <kkeller-usenet@wombat.san-francisco.ca.us>
Re: Perl Editor Default@IO_Error_1011101.xyz
Re: Perl Editor <abigail@abigail.nl>
Re: push @arr, slice-of-href <eddhig22@yahoo.com>
Re: push @arr, slice-of-href <noreply@gunnar.cc>
Re: push @arr, slice-of-href (Tad McClellan)
Re: reading and writing to text file via form newbie <bmb@ginger.libs.uga.edu>
Re: sending stdin to a shell command in perl <mb@uq.net.au.invalid>
Re: status of redirecting STDOUT/STDERR to file (Anno Siegel)
Re: status of redirecting STDOUT/STDERR to file (Sam Holden)
Re: status of redirecting STDOUT/STDERR to file (Tad McClellan)
Re: substring <bigus_34@yahoo.co.uk>
undif as if it is 0 <eddhig22@yahoo.com>
Re: undif as if it is 0 <eddhig22@yahoo.com>
Re: undif as if it is 0 <dmcbride@naboo.to.org.no.spam.for.me>
Re: undif as if it is 0 <trammell+usenet@hypersloth.invalid>
Re: unpack query (Jack Penarth)
unpack vs. split problem (really weird) <mhunter@uclink.berkeley.edu>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Nov 2003 20:10:25 GMT
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: Assigning split to a list: undefined values?
Message-Id: <Xns943D904CBA527mitianorthwesternedu@63.218.45.22>
ko <kuujinbo@hotmail.com> wrote in
news:bpme0m$25q$1@pin3.tky.plala.or.jp:
> Dmitry Epstein wrote:
>> Here is a code snippet:
>>
>> while ($line = <F>) {
>> my ($node1, $node2, $node3) = split ' ', $line;
>> last unless defined $node3;
>> ...
>> }
>>
>> The idea here was that the loop stops if the line was split
>> into fewer than 3 values. It doesn't work however: when the
>> line has only 2 values, the variable $node3 is initialized
>> with zero instead of remaining undefined. How come?
>>
>> (I have since changed the code to use an array instead of a
>> list.)
>>
>
> Since the pattern ' ' is split()ing on whitespace, the newline
> on each line results in an empty trailing field ('', which is
> a defined value). So you need to get rid of the newline on
> each line:
>
> use strict;
> use warnings;
>
> while (my $line = <DATA>) {
> chomp $line;
> my ($node1, $node2, $node3) = split ' ', $line;
> last unless defined $node3;
> print join(" ", $node1, $node2, $node3), "\n"
> }
>
> __DATA__
> a s d
> a s
>
> HTH- keith
I don't think so. Split on ' ' is supposed to "chomp" any trailing
whitespace. In fact, if I use an array to store the value of split
instead of a list of scalars, the array does not receive a null
value in the end.
--
Dmitry Epstein
Northwestern University, Evanston, IL. USA
mitia(at)northwestern(dot)edu
------------------------------
Date: 24 Nov 2003 20:55:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Avoiding running a process twice
Message-Id: <bptr78$e04$1@mamenchi.zrz.TU-Berlin.DE>
Ed W <dodgynewsgroups@ewildgoose.demon.co.uk> wrote in comp.lang.perl.misc:
> > If you can use file locking (not sure about the windows side), that would
> > be the way to go. Again you use a file, but it isn't created/deleted
> > with program runs, but only locked (exclusively). The advantage is that
> > it's easier to get correct (because it's what locking is about), and
> > you're not responsible for deleting the file. The system takes care
> > of the lock.
>
> Could you show me a perl example of this in action perhaps? A unix version
> would be fine
Uh, no. To write one would require me to look things up in the
documentation. I prefer you do that. But thanks for not requiring
a windows version.
Also, you might have left an attribution (vulgo, indicated who you're
talking to).
Anno
------------------------------
Date: 24 Nov 2003 21:20:19 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: Avoiding running a process twice
Message-Id: <slrnbs4tgj.gnt.sholden@flexal.cs.usyd.edu.au>
On Mon, 24 Nov 2003 18:12:22 GMT,
Ed W <dodgynewsgroups@ewildgoose.demon.co.uk> wrote:
>> If you can use file locking (not sure about the windows side), that would
>> be the way to go. Again you use a file, but it isn't created/deleted
>> with program runs, but only locked (exclusively). The advantage is that
>> it's easier to get correct (because it's what locking is about), and
>> you're not responsible for deleting the file. The system takes care
>> of the lock.
>
> Could you show me a perl example of this in action perhaps? A unix version
> would be fine
perldoc -f flock
--
Sam Holden
------------------------------
Date: 24 Nov 2003 19:41:32 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Can this script be used to spam?
Message-Id: <slrnbs4nnc.sal.abigail@alexandra.abigail.nl>
David Staschover (davezx1@yahoo.com) wrote on MMMDCCXXXVII September
MCMXCIII in <URL:news:Oiswb.38545$A%3.512977@ord-read.news.verio.net>:
}} We are getting numerous bounceback messages with the following script in the
}} bounced email. It appears that someone is using this script to send spam. Is
}} there any way for a visitor to break this script over the web, changing the
}} recipient, or added Bcc's to this message through a web browser? And if so,
}} any idea how to fix it?
}}
}} Thanks in advance!
}}
}} #!/usr/bin/perl
}}
}} read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
}} @pairs = split(/&/, $buffer);
}} foreach $pair (@pairs)
}} {
}} ($name, $value) = split(/=/, $pair);
}} $value =~ tr/+/ /;
}} $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
}} $FORM{$name} = $value;
}} }
}}
}} open (MAIL, "|/usr/lib/sendmail -oi -oem -odi -t ") || die "Can't open
}} $mailpro>
}} print MAIL "To: recipient\@domain.com\n";
}} print MAIL "From: $FORM{'username'} ($FORM{'realname'})\n";
Just image what happens if username equals:
sales@example.net
Cc: davezx1@yahoo.com, someone@example.com, abigail@abigail.nl
Subject: NEW! Buy green pickles! NEW!
Buy our green pickles, with 10% more green.
Solution: ditch the script and use something from NMS.
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
------------------------------
Date: Mon, 24 Nov 2003 21:36:27 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Can this script be used to spam?
Message-Id: <bptqjk$1rgo9v$1@ID-184292.news.uni-berlin.de>
David Staschover wrote:
> We are getting numerous bounceback messages with the following
> script in the bounced email. It appears that someone is using this
> script to send spam. Is there any way for a visitor to break this
> script over the web, changing the recipient, or added Bcc's to this
> message through a web browser?
It's not safe, as others have pointed out.
You might find the module CGI::ContactForm useful as a replacement:
http://search.cpan.org/~gunnar/
If you click the link in the sig below, you see the default form that
is generated by the module.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 24 Nov 2003 21:13:10 -0000
From: "spleen" <james.welsby@virgin.net>
Subject: Re: client/ server
Message-Id: <aruwb.2147$3P2.1306474@newsfep1-win.server.ntli.net>
Yea sorry my first post wasnt very clear, Ive sorted the perl - I have a
server that takes the text string and puts it into a text file.
all I was woundering how to do was to how to do this on a free hosting
service, I cant seem to get it working on www.spaceports.com
sorry for my misinformed post to start with, my code is posted below.
although I dont think itll help anyone answer me becuase its more the
application of it that im confused by
cheers
gre
#!/usr/local/bin/perl
use IO::Socket;
$file = "/home2/pp10aagg/public_html/sms.txt";
open (FILE, >>$file) or die "cannot open $file: $!";
my $listening_socket =
IO::Socket::INET->new(Proto => 'tcp',
LocalPort => 2323,
Listen => 1,
Reuse => 1) or die $!;
$socket = $listening_socket->accept;
$socket->recv($line, 80);
print FILE "$line";
$socket->close;
close (FILE);
"Brian McCauley" <nobull@mail.com> wrote in message
news:u9k75pfycr.fsf@wcl-l.bham.ac.uk...
> "spleen" <james.welsby@virgin.net> writes:
> >
> > Basically at the moment Im planning on using a python script to send a
> > string of text to a website, I was woundering in perl, using the cgi-bin
how
> > I can accept this connection and take the text string and add it to a
file
> > (.txt)
>
> Basically, you should either learn en enough Perl write a script yourself
or hire
> someone who knows enough Perl to write it for you.
>
> Examples and tutorials of writing trivial CGI scipts in Perl can be
> found all over the place.
>
> If you have problems feel free to come here for help.
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: Mon, 24 Nov 2003 12:21:17 -0800
From: Fred <dreamer@cox.net>
Subject: Convert ISO-8859-1 (quoted-printable) to 8 bit
Message-Id: <3FC2683D.AC21234F@cox.net>
I use the following code to remove ISO-8859-1 from mail message-headers:
...
use MIME::QuotedPrint ;
$message =~ s/(Subject: |From: |Sender: |To: )
(\w*?)=\?ISO-8859-1\?[A-Z]\?(.+?)\?=/$1 $2$3/ig ;
if ($message =~ m/=[A-Za-z0-9]{2}/g ) {
$message =~ s/(=[A-Za-z0-9]{2})/decode_qp $1/ge ;
$message =~ s/Content-Transfer-Encoding:
quoted-printable/Content-Transfer-Encoding: binary/g ;
}
...
This works fine most of the time. However I am wondering if there is a
module which can do the job better.
--
Fred
------------------------------
Date: 24 Nov 2003 22:35:44 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Image::Magick memory leak question
Message-Id: <slrnbs51u1.tru.mgjv@verbruggen.comdyn.com.au>
On Mon, 24 Nov 2003 14:15:54 +0000 (UTC),
Stan Brown <stanb@panix.com> wrote:
> In <bpjl3q$qps$2@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>
>
>>Stan Brown <stanb@panix.com> wrote:
>>> In <3fbc4f37.145998938@news2.news.adelphia.net>
>>> posting.account@lynxview.com (William Herrera) writes:
>>> Yes, it make perfect sense. I was naievly believing that since I had left
>>> the subroutine, and the $image object was "local" to it, that all traces of
>>> it would eb retruned to the free pool, as would be done, for non malloced
>>> memory in C.
>>>
>>> This seems to be a pretty basic weakness of perl. I wonder if perl6
>>> addresses this?
>
>>No, this is a basic weakness of ImageMagick, or of C. Perl will
>>correctly tell the Image::Magick object to free itself at the end of
>>the scope: if it fails to do so correctly, this is not Perl's fault.
>
> Well, OK. I guess I was thinking in a perfect world, perl would be in
> charge of freeing all out of scope objects. Isn't that one og Java's claims
> to fame? Or not, I know littel about Java.
Perl does reference counting, and will "free" all objects that have no
references to them anymore. Image::Magick objects are not pure Perl
objects, however, but an XS wrapper around a C library. The memory
leak can be anywhere inside that XS or C code.
The ImageMagick library has had some memory leaks internally in the
past (which is why I advised using the latest library to see whether
the problem persists), which generally get fixed quite quickly.
While Image::Magick objects look like regular references to Perl
arrays, they're not. Perl only controls the freeing of memory up to
the freeing of the Image::Magick blessed object reference itself.
Everything after that is dealt with in the Image::Magick XS code, and
the ImageMagick library internally, and is (largely) out of the
control of perl, unless the author uses Perl structures in that code
and correctly keeps track of references.
It is quite easy to plug in a C module to perl that leaks memory.
However, that doesn't make it the fault of Perl that there is a leak.
The following little program (which will only report memory correctly
on Linux, really) illustrates that. it uses Inline::C instead of XS,
but the effect is the same: The code that allocates memory and doesn't
hand control of it over to perl, leaks, the code that does allow perl
to clean up, doesn't:
#!/usr/local/bin/perl
use warnings;
use strict;
use Inline 'C';
for my $i (0 .. 9)
{
my $foo = gimmePerlmemory();
print reportmem(), ", ";
}
print "\n";
for my $i (0 .. 9)
{
my $foo = gimmememory();
print reportmem(), ", ";
}
print "\n";
sub reportmem
{
open my $ps, "/proc/self/stat" or die;
seek $ps, 0, 0;
(split ' ', scalar <$ps>)[22] / 1024;
}
__END__
__C__
#include <stdlib.h>
char * gimmememory()
{
return malloc(4096);
}
SV * gimmePerlmemory()
{
return newSVpv("", 4096);
}
And the output is:
5940, 5948, 5948, 5948, 5948, 5948, 5948, 5948, 5948, 5948, 5948,
5948, 5952, 5956, 5960, 5964, 5968, 5972, 5976, 5980, 5984, 5988,
As you can see, the 4 kB of malloc'ed memory is being leaked, while
the 4 kB of newSV memory is neatly being reclaimed. The same goes for
external modules. If they don't clean up their own memory, or they
don't allow Perl to do it, the memory will be leaked.
Martien
--
|
Martien Verbruggen | In the fight between you and the world, back
Trading Post Australia | the world - Franz Kafka
|
------------------------------
Date: 24 Nov 2003 12:42:35 -0800
From: goldtech@worldpost.com (leegold)
Subject: newbie <STDIN> question
Message-Id: <679db0fb.0311241242.7e2807ba@posting.google.com>
What if a user presses enter for the line number?
Please see below.
How will I test for that and make $linenum default to 1 ?
IE. what's the value of STDIN when someone just hits return?
So I can test for that and make default eq. to 1.
Or is there some automagic?
Thanks
my $linenum;
.....snip...
print "What's your line number? [1]\n"; $linenum = <STDIN>;
chomp(&linenum);
IF (not $linenum =~ m/^\d+$/) {
die "only positive integers accepted\n";
}
.....
------------------------------
Date: Mon, 24 Nov 2003 16:15:45 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: newbie <STDIN> question
Message-Id: <3FC27501.5090008@gwu.edu>
leegold wrote:
> What if a user presses enter for the line number?
> Please see below.
> How will I test for that and make $linenum default to 1 ?
> IE. what's the value of STDIN when someone just hits return?
It occurs to me that in the time it took you to write this
post, you could've written a test script that would tell
you the answer.
Chris Mattern
> So I can test for that and make default eq. to 1.
> Or is there some automagic?
> Thanks
>
> my $linenum;
> .....snip...
>
> print "What's your line number? [1]\n"; $linenum = <STDIN>;
> chomp(&linenum);
> IF (not $linenum =~ m/^\d+$/) {
> die "only positive integers accepted\n";
> }
> .....
------------------------------
Date: Mon, 24 Nov 2003 22:35:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: newbie <STDIN> question
Message-Id: <bptu3c$1rtf96$1@ID-184292.news.uni-berlin.de>
leegold wrote:
> What if a user presses enter for the line number?
> Please see below.
> How will I test for that and make $linenum default to 1 ?
After the line
chomp($linenum);
you can for instance add:
$linenum ||= 1;
> chomp(&linenum);
--------^
> IF (not $linenum =~ m/^\d+$/) {
--^^
Please paste, not type, code that you post.
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 24 Nov 2003 21:48:32 GMT
From: Default@IO_Error_1011101.xyz
Subject: Re: newbie <STDIN> question
Message-Id: <Q0vwb.567$nM6.498@nwrdny01.gnilink.net>
> What if a user presses enter for the line number?
> Please see below.
> How will I test for that and make $linenum default to 1 ?
> IE. what's the value of STDIN when someone just hits return?
> So I can test for that and make default eq. to 1.
> Or is there some automagic?
> Thanks
>
> my $linenum;
> ......snip...
>
> print "What's your line number? [1]\n"; $linenum = <STDIN>;
> chomp(&linenum);
> IF (not $linenum =~ m/^\d+$/) {
> die "only positive integers accepted\n";
> }
> ......
>
Ahh i'm also a newbie but this might just do the trick.
I'd suggest waiting for other more experienced users here to verify this.
use ExtUtils::MakeMaker qw(prompt);
$default = 'yes';
$ans = prompt("Do Something? (yes/no)?", ($default ? 'yes' : 'no'));
$ans = lc($ans);
print "\nans = $ans\n";
if ($ans eq 'yes')
{
print "\nDo something here.\n";
}
else
{
print "\nNot doing something here.\n";
}
print "\nans = $ans\n";
------------------------------
Date: Mon, 24 Nov 2003 16:14:51 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie <STDIN> question
Message-Id: <slrnbs50mr.28s.tadmc@magna.augustmail.com>
leegold <goldtech@worldpost.com> wrote:
> Please see below.
Please see the Posting Guidelines that are posted here frequently.
> print "What's your line number? [1]\n"; $linenum = <STDIN>;
> chomp(&linenum);
^
^
Where is the linenum() subroutine defined?
> IF (not $linenum =~ m/^\d+$/) {
^^
^^
Syntax error.
If you give us not-Perl code, can we give you a not-answer followup?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 24 Nov 2003 14:32:44 -0500
From: Chris Mattern <syscjm@gwu.edu>
Subject: Re: Perl Editor
Message-Id: <3FC25CDC.4050605@gwu.edu>
Xaonon wrote:
> Ned i bach <c659b5f9.0311240932.58c5a21@posting.google.com>, AnnMarie
> <carusoa@optonline.net> teithant i thiw hin:
>
>
>>What is the best editor for Perl CGI-Scripts?
>
>
> Emacs.
>
What, Esc-Meta-Alt-Ctrl-Shift? Naw, vi!
Chris Mattern
------------------------------
Date: 24 Nov 2003 19:42:09 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl Editor
Message-Id: <slrnbs4noh.sal.abigail@alexandra.abigail.nl>
AnnMarie (carusoa@optonline.net) wrote on MMMDCCXXXVII September MCMXCIII
in <URL:news:c659b5f9.0311240932.58c5a21@posting.google.com>:
^^ What is the best editor for Perl CGI-Scripts?
cat
Abigail
--
perl -Mstrict -we '$_ = "goto _.print chop;\n=rekcaH lreP rehtona tsuJ";_1:eval'
------------------------------
Date: 24 Nov 2003 19:46:00 GMT
From: James Keasley <me@privacy.net>
Subject: Re: Perl Editor
Message-Id: <slrnbs4nvm.9a5.me@localhost.localdomain>
In article <slrnbs4noh.sal.abigail@alexandra.abigail.nl>, Abigail wrote:
> AnnMarie (carusoa@optonline.net) wrote on MMMDCCXXXVII September MCMXCIII
> in <URL:news:c659b5f9.0311240932.58c5a21@posting.google.com>:
> ^^ What is the best editor for Perl CGI-Scripts?
>
>
> cat
What about ed?
--
James jamesk[at]homeric[dot]co[dot]uk
I just got skylights put in my place. The people who live above me are
furious. (Steven Wright)
------------------------------
Date: Mon, 24 Nov 2003 20:02:57 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: Perl Editor
Message-Id: <Rttwb.485841$pl3.323538@pd7tw3no>
AnnMarie wrote:
> What is the best editor for Perl CGI-Scripts?
As you may be able to tell by now, each individual has their own
preference. The "best" editor is one you feel comfortable with that
has the features you desire. For example, I like having syntax
hilighting. Of course, perl throws most hilighters for a loop with
all its DWIMery.
Asking for the "best" is a useless excersise. Asking for
"alternatives" may lead to a more sane discussion ;-)
------------------------------
Date: Mon, 24 Nov 2003 12:59:13 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Perl Editor
Message-Id: <etoznelpmge.fsf@fc.hp.com>
James Keasley <me@privacy.net> writes:
> In article <slrnbs4noh.sal.abigail@alexandra.abigail.nl>, Abigail wrote:
>> AnnMarie (carusoa@optonline.net) wrote on MMMDCCXXXVII September MCMXCIII
>> in <URL:news:c659b5f9.0311240932.58c5a21@posting.google.com>:
>> ^^ What is the best editor for Perl CGI-Scripts?
>>
>>
>> cat
>
> What about ed?
ED IS THE STANDARD EDITOR!!!!
Though I'm surprised no-one has mentioned 'dd' yet.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Mon, 24 Nov 2003 13:10:58 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Perl Editor
Message-Id: <25stpb.bjk.ln@goaway.wombat.san-francisco.ca.us>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
On 2003-11-24, Eric Schwartz <emschwar@pobox.com> wrote:
> Though I'm surprised no-one has mentioned 'dd' yet.
I was sorely tempted, but didn't want to risk being taken seriously.
- --keith
- --
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.3 (GNU/Linux)
iD8DBQE/wnPfhVcNCxZ5ID8RAkJwAJ9TGfWIyATB8Qqk6rilnEfnSjpbCwCfXsC3
4oQvp57M/OQD4V4+3kyHXss=
=Qi1f
-----END PGP SIGNATURE-----
------------------------------
Date: Mon, 24 Nov 2003 22:09:00 GMT
From: Default@IO_Error_1011101.xyz
Subject: Re: Perl Editor
Message-Id: <0kvwb.622$nM6.83@nwrdny01.gnilink.net>
> What is the best editor for Perl CGI-Scripts?
>
well if you belive the saying 'you get what you pay for'
then its got to be komodo
------------------------------
Date: 24 Nov 2003 22:46:24 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: Perl Editor
Message-Id: <slrnbs52i0.sal.abigail@alexandra.abigail.nl>
James Keasley (me@privacy.net) wrote on MMMDCCXXXVII September MCMXCIII
in <URL:news:slrnbs4nvm.9a5.me@localhost.localdomain>:
&& In article <slrnbs4noh.sal.abigail@alexandra.abigail.nl>, Abigail wrote:
&& > AnnMarie (carusoa@optonline.net) wrote on MMMDCCXXXVII September MCMXCIII
&& > in <URL:news:c659b5f9.0311240932.58c5a21@posting.google.com>:
&& > ^^ What is the best editor for Perl CGI-Scripts?
&& >
&& >
&& > cat
&&
&& What about ed?
ed is for wussies who have to correct lots of mistakes.
Real (wo)men program right the first time around.
Abigail
--
INIT {print "Perl " }
END {print "Hacker\n"}
BEGIN {print "Just " }
CHECK {print "another "}
------------------------------
Date: Tue, 25 Nov 2003 07:45:14 +1100
From: Edo <eddhig22@yahoo.com>
Subject: Re: push @arr, slice-of-href
Message-Id: <3FC26DDA.7030307@yahoo.com>
thanks, I worked it out with you help, another more diffecult one, man I
tried for long time but I just don't seem to get it yet.
sub scan (\%\%) {
my ($dbits, $sbits) = @_;
my @kd = keys %$dbits; my @ks = keys %$sbits;
my @vs = @$sbits{ @ks };
for( 0 .. (@kd - @ks) ) {
my @vd = @$dbits{ @kd[$_ .. $_+@ks-1 ] };
my $tmp = check( \@vd, \@vs );
my $max = (sort {$b <=> $a} @top3)[0] || 0;
if ( $tmp > $max ) {
tie my (%set), 'Tie::IxHash';
$set{@tmp} = @kd; <---????
push @top3, \%set;
}
}
return @top3;
}
in the if block, all what I want to do is
use the $tmp as a key for section of %dbits which the sub check
evaluated its \@vd.
thanks
------------------------------
Date: Mon, 24 Nov 2003 22:07:55 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: push @arr, slice-of-href
Message-Id: <bptsej$1rtfh9$1@ID-184292.news.uni-berlin.de>
Edo wrote:
> in the if block, all what I want to do is use the $tmp as a key for
> section of %dbits which the sub check evaluated its \@vd.
In that case, why are you using @tmp as the key?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 24 Nov 2003 16:05:48 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: push @arr, slice-of-href
Message-Id: <slrnbs505s.28s.tadmc@magna.augustmail.com>
Edo <eddhig22@yahoo.com> wrote:
> thanks, I worked it out with you help, another more diffecult one, man I
> tried for long time but I just don't seem to get it yet.
If you had turned on "use strict" it would have pointed out
the error in milliseconds.
It is demeaning to be asked to do the work of a machine, please
have a machine take a try at it before asking thousands of
people around the world to look at it.
> $set{@tmp} = @kd; <---????
> all what I want to do is
> use the $tmp as a key
Then use $tmp as a key (your code above doesn't...)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 24 Nov 2003 15:57:49 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: reading and writing to text file via form newbie
Message-Id: <Pine.A41.4.58.0311241556480.17914@ginger.libs.uga.edu>
On Sat, 22 Nov 2003, Gunnar Hjalmarsson wrote:
> Never use such code unless you
> don't understand what it does!!
Now THAT should be a T-shirt. :-)
Regards,
Brad
------------------------------
Date: Tue, 25 Nov 2003 09:04:39 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: sending stdin to a shell command in perl
Message-Id: <bpu2q7$4jk$1@bunyip.cc.uq.edu.au>
Darin McBride wrote:
> Andrew wrote:
>
>
>>tadmc@augustmail.com (Tad McClellan) wrote in message
>>news:<slrnbs316h.ooh.tadmc@magna.augustmail.com>...
>>
>>>Andrew <myfam@surfeu.fi> wrote:
>>>
>>>
>>>>in my simple perl script I have to send string to stdin of an
>>>>excutable binary which I run from perl.
>>>
>>>
>>> perldoc perlopentut
>>>
>>> perldoc -f open
>>
>>Hm, I need to execute command from perl pass something to its stdin
>>and read from stdout. Can you give an example?
>
>
> That becomes a bit more difficult than I think Tad thought.
> Admittedly, I missed it, too.
>
> You may want to look at:
>
> perldoc IPC::Open2
>
>
If IPC::Open2 doesn't work for you (or is a bit unstable - I've had
problems a couple of times if I don't control the code of the process
I'm calling) you can do something like this:
1) create a temp file (File::Temp is good - make sure the file is not
automatically removed on exit)
2) fork with open('|-') (look this one up in the docs given above - very
handy)
3) In the child section, reopen STDOUT (and STDERR if you want) to the
temp filehandle, then exec the program you want to run.
4) In the parent program, print to the child's file handle (that you got
with the open call) the input you want to give it, then close the handle.
5) In the parent, seek to the start of the temp file and read in the output
6) Don't forget to clean up the temp file!
There's a lot of error checking you need to do (eg success of the open,
success of the exec, handling SIGPIPE if the child dies while you're
writing to it etc etc) but it will work without blocking problems (well,
so far it has all the time for me :)
This method doesn't really allow for a system where the parent and child
need to chat back and forth, but if that's the case then usually the
program you're calling will be written to expect interaction and
IPC::Open2 should be OK.
MB
------------------------------
Date: 24 Nov 2003 21:07:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: status of redirecting STDOUT/STDERR to file
Message-Id: <bptru8$e04$2@mamenchi.zrz.TU-Berlin.DE>
jonathan <ttyp32000@yahoo.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message
> news:<bpklsj$da3$1@mamenchi.zrz.TU-Berlin.DE>...
> > jonathan <ttyp32000@yahoo.com> wrote in comp.lang.perl.misc:
> > > hey all,
> > >
> > > just curious, but if I do the following (after __cut__), does this
> > > have any repercussions for the 'regular' STDERR, STDOUT handles?
> >
> > It shouldn't.
> >
> > Why are you dealing with STDOUT in redirect()? You're not using it in
> > any way.
>
> its called a *typo*. read:
Well, typos in code aren't exactly trivial, whether in communicating with
the machine or with other programmers. It made the meaning of your
extensive question "any repercussions" even harder to grasp.
> print STDOUT "HERE!!!\n";
> print STDERR "HEREA!!!!\n";
>
> I appreciate the help, but the attitude could be a little less snide.
> The code snippet was designed to show whether or not any effects might
> happen outside of the subroutine.
Short and to the point, yes. Snide, no.
Anno
------------------------------
Date: 24 Nov 2003 21:24:46 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: status of redirecting STDOUT/STDERR to file
Message-Id: <slrnbs4tou.gnt.sholden@flexal.cs.usyd.edu.au>
On 24 Nov 2003 10:46:56 -0800, jonathan <ttyp32000@yahoo.com> wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bpklsj$da3$1@mamenchi.zrz.TU-Berlin.DE>...
>> jonathan <ttyp32000@yahoo.com> wrote in comp.lang.perl.misc:
>> > hey all,
>> >
>> > just curious, but if I do the following (after __cut__), does this
>> > have any repercussions for the 'regular' STDERR, STDOUT handles?
>>
>> It shouldn't.
>>
>> Why are you dealing with STDOUT in redirect()? You're not using it in
>> any way.
>
> its called a *typo*. read:
>
> print STDOUT "HERE!!!\n";
> print STDERR "HEREA!!!!\n";
>
> I appreciate the help, but the attitude could be a little less snide.
> The code snippet was designed to show whether or not any effects might
> happen outside of the subroutine.
Your failure to read the posting guidelines that are posted here a lot, or
even worse failure to follow them after reading them, combined with that
post will I suspect greatly reduce the useful answers you get in future.
--
Sam Holden
------------------------------
Date: Mon, 24 Nov 2003 16:01:45 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: status of redirecting STDOUT/STDERR to file
Message-Id: <slrnbs4vu9.28s.tadmc@magna.augustmail.com>
jonathan <ttyp32000@yahoo.com> wrote:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bpklsj$da3$1@mamenchi.zrz.TU-Berlin.DE>...
>> Why are you dealing with STDOUT in redirect()? You're not using it in
>> any way.
>
> its called a *typo*.
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
Somebody ought to write these things down somewhere...
> I appreciate the help, but the attitude could be a little less snide.
If you had been more considerate of other's time, there would have
been no reaping what you had sown.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 24 Nov 2003 20:01:58 -0000
From: "Bigus" <bigus_34@yahoo.co.uk>
Subject: Re: substring
Message-Id: <Wstwb.2907$qn4.23041@newsfep4-glfd.server.ntli.net>
"Alexandre Jaquet" <alexj@freesurf.ch> wrote in message
news:3fc24122$0$3220$5402220f@news.sunrise.ch...
> Hi,
>
> I'm new to perl and I want to extract a substring from a response :
>
> I wanna to extract the part between pseudoinscrite= and " I've try
> something like that but don't know how to do :
>
> if ($resp->content =~/pseudoinscrite=(.+)"/) {
> // affect to $user the value
Something like:
($extracted) = $resp->content =~ /pseudoinscrite=(.+?)\"/;
or
($extracted) = $resp->content =~ /pseudoinscrite=([^\"]+)/;
should do it.
Bigus
------------------------------
Date: Tue, 25 Nov 2003 06:24:38 +1100
From: Edo <eddhig22@yahoo.com>
Subject: undif as if it is 0
Message-Id: <3FC25AF6.7010004@yahoo.com>
Hello
I am getting $max = undif if nothing in @top3, but due to the way the
code below is written, I need it to show 0 instead.
do I have to change the code? or there is an operator to change undif to
0 in this case?
thanks
my @kd = keys %$dbits; my @ks = keys %$sbits;
my @vs = @$sbits{ @ks };
for( 0 .. 5 ) {
my $tmp = 4;
my $max = (sort {$b <=> $a} @top3)[0];
if ( $tmp > $max ) {
... code
push @top3, \%set;
}
}
------------------------------
Date: Tue, 25 Nov 2003 06:51:11 +1100
From: Edo <eddhig22@yahoo.com>
Subject: Re: undif as if it is 0
Message-Id: <3FC2612F.3090505@yahoo.com>
Edo wrote:
> Hello
> I am getting $max = undif if nothing in @top3, but due to the way the
> code below is written, I need it to show 0 instead.
> do I have to change the code? or there is an operator to change undif to
> 0 in this case?
>
> thanks
>
> my @kd = keys %$dbits; my @ks = keys %$sbits;
> my @vs = @$sbits{ @ks };
>
> for( 0 .. 5 ) {
> my $tmp = 4;
> my $max = (sort {$b <=> $a} @top3)[0];
> if ( $tmp > $max ) {
> ... code
> push @top3, \%set;
> }
> }
>
what about
if ($max && ( $tmp > $max )) {
instead of
if ( $tmp > $max )
?
is this a good way to do it?
------------------------------
Date: Mon, 24 Nov 2003 20:05:21 GMT
From: Darin McBride <dmcbride@naboo.to.org.no.spam.for.me>
Subject: Re: undif as if it is 0
Message-Id: <5wtwb.485849$pl3.350064@pd7tw3no>
Edo wrote:
> Edo wrote:
>> Hello
>> I am getting $max = undif if nothing in @top3, but due to the way the
>> code below is written, I need it to show 0 instead.
>> do I have to change the code? or there is an operator to change undif to
>> 0 in this case?
>>
>> thanks
>>
>> my @kd = keys %$dbits; my @ks = keys %$sbits;
>> my @vs = @$sbits{ @ks };
>>
>> for( 0 .. 5 ) {
>> my $tmp = 4;
>> my $max = (sort {$b <=> $a} @top3)[0];
my $max = (sort {$b <=> $a} @top3)[0] || 0;
Better to use // or err, but those won't be available until at least
perl 5.10...
>> if ( $tmp > $max ) {
>> ... code
>> push @top3, \%set;
>> }
>> }
>
> what about
> if ($max && ( $tmp > $max )) {
> instead of
> if ( $tmp > $max )
Doesn't work if $tmp is -1 and $max is 0 ;-)
> ?
>
> is this a good way to do it?
------------------------------
Date: Mon, 24 Nov 2003 20:37:09 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: undif as if it is 0
Message-Id: <slrnbs4qvl.8cg.trammell+usenet@hypersloth.el-swifto.com.invalid>
On Tue, 25 Nov 2003 06:24:38 +1100, Edo <eddhig22@yahoo.com> wrote:
> Hello
> I am getting $max = undif if nothing in @top3, but due to the way the
> code below is written, I need it to show 0 instead.
> do I have to change the code? or there is an operator to change undif to
> 0 in this case?
>
> thanks
>
> my @kd = keys %$dbits; my @ks = keys %$sbits;
> my @vs = @$sbits{ @ks };
>
> for( 0 .. 5 ) {
> my $tmp = 4;
> my $max = (sort {$b <=> $a} @top3)[0];
> if ( $tmp > $max ) {
> ... code
> push @top3, \%set;
> }
> }
>
>
How about (untested):
use List::Util 'max';
my $max = max(@top3) || 0;
or maybe (also untested):
push(@top3, 0) unless @top3;
------------------------------
Date: 24 Nov 2003 11:13:13 -0800
From: jackpenarth@aol.com (Jack Penarth)
Subject: Re: unpack query
Message-Id: <f27d1c90.0311241113.55659dbc@posting.google.com>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<bpt20n$rnv$1@mamenchi.zrz.TU-Berlin.DE>...
> Jack Penarth <jackpenarth@aol.com> wrote in comp.lang.perl.misc:
> > I use the following code snippet on a file extracted from a
> > database(fixed length fields)before formatting the output for
> > printing.
> >
> > Field3 is the prime record identifier and often contains duplicate
> > entries. How can I modify my code so that only the first instance
> > (record) is used and the remaining records ditched?
> >
> > Code snippet follows:
> >
> > while (<FILE>) {
> > ($field1, $field2, $field3, $field4, $field5, $field6, $field7,
> > $field7, $field8, $field9, $field10, $field11, $field12, $field13,
> > $field14, $field15, $field16) = unpack($format1, $_)
> > write(OUT_PUT);
>
> There should be a "my" in front of the parenthesis full of variables.
> You're not running under strict, are you? What about warnings?
>
> Instead of single scalars ($field1, ... $field16), it would
> be better to use an array "@field".
>
> Also, there is a semicolon missing after unpack(). Is this really your
> code? Don't re-type code, copy/paste it.
>
> To select unique keys, use a hash to keep track of which you have seen:
>
> my %seen;
> while ( <FILE> ) {
> my ($field1, $field2, $field3, $field4, $field5, $field6, $field7,
> $field7, $field8, $field9, $field10, $field11, $field12, $field13,
> $field14, $field15, $field16) = unpack($format1, $_);
> next if $seen{ $field3};
> write(OUT_PUT);
> $seen{ $field3} = 1;
> }
>
> Anno
Thank you for your help. My own PC went up in a puff of smoke so I
had to use a colleagues machine and the snippet was typed from memory
as the query is quite urgent for me.
I am very inexperienced with perl but I am learning more each day.
Once again thanks.
John
------------------------------
Date: Mon, 24 Nov 2003 22:53:25 +0000 (UTC)
From: Mike Hunter <mhunter@uclink.berkeley.edu>
Subject: unpack vs. split problem (really weird)
Message-Id: <slrnbs52rf.19c.mhunter@celeste.net.berkeley.edu>
Hey everybody,
I'm having a weird problem. Check this out:
sub mth_inet_ntoa
{
my $stuff = shift;
$debug and print "mth_inet_ntoa_debug length \$stuff: ".(length $stuff)."\n";
my @o = split //, $stuff;
$debug and print "mth_inet_ntoa debug lengths ".
(length $o[0])." ".(length $o[1])." ".(length $o[2])." ".(length $o[3])."\n";
$debug and print "mth_inet_ntoa debug ".(join "", (unpack "b*", $stuff))."\n";
$debug and print "mth_inet_ntoa debug #".(join "", unpack "b*", $o[0]).
"#".(join "", unpack "b*", $o[1])."#".
(join "", unpack "b*", $o[2])."#".(join "", unpack "b*", $o[3])."#\n";
return "$o[0].$o[1].$o[2].$o[3]";
}
mth_inet_ntoa_debug length $stuff: 4
mth_inet_ntoa debug lengths 1 1 1 1
mth_inet_ntoa debug 00000001000001001010110000000000
mth_inet_ntoa debug #00000001#00000100#10101100#00000000#
Now, if I change from
split //, $stuff
to
unpack "CCCC", $stuff
I get these totally weirded-out results:
mth_inet_ntoa_debug length $stuff: 4
mth_inet_ntoa debug lengths 3 2 2 1
mth_inet_ntoa debug 00000001000001001010110000000000
mth_inet_ntoa debug #100011000100110000011100#1100110001001100#1010110011001100#00001100#
perl -V:
Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
Platform:
osname=freebsd, osvers=4.8-release, archname=i386-freebsd
...
Shouldn't unpack "CCCC" work?
Mike
------------------------------
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 5853
***************************************