[16535] in Perl-Users-Digest
Perl-Users Digest, Issue: 3947 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 8 09:05:26 2000
Date: Tue, 8 Aug 2000 06:05:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965739912-v9-i3947@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 8 Aug 2000 Volume: 9 Number: 3947
Today's topics:
about "syntax error" of perl program(HELP!!!) najura@citiz.net
Re: about "syntax error" of perl program(HELP!!!) <panderse@us.ibm.com>
Re: CGI.PM How to get all Form's value in a HashTable? <flavell@mail.cern.ch>
Re: combinations - a better way to do this? <abe@ztreet.demon.nl>
Re: date manipulation <bart.lateur@skynet.be>
Re: date manipulation <flavell@mail.cern.ch>
Expert advise needed <kdl@softhome.net>
Re: function like grep <steve_button@my-deja.com>
Re: function like grep <All@n.due.net>
Re: Have split question <bart.lateur@skynet.be>
Re: Help!! Need to find user name jennlee_2@my-deja.com
Re: HTML Table To Text --How? <gellyfish@gellyfish.com>
Re: HTML Table To Text --How? <kent@darwin.eeb.uconn.edu>
Re: Novice question: How to kill a process <no@email.for.me>
one liner? (Anno Siegel)
Re: Perl and opening tcp socket <Peter.Dintelmann@dresdner-bank.com>
Re: printing backspace in WinNT <Peter.Dintelmann@dresdner-bank.com>
Re: Programming Ethics jthornton@my-deja.com
regexp - extract substrings gregosse2409@my-deja.com
Re: regexp - extract substrings (Rafael Garcia-Suarez)
Re: Sendmail delivery failures <andre@UltraShell.Net>
Re: Simple regular Expression Question <depesz@depesz.pl>
Re: what does foreach (0...10) do ??? <steve_button@my-deja.com>
WinNT binary compiled with -DMULTIPLICITY <frank.winkler@infineon.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 08 Aug 2000 10:43:15 GMT
From: najura@citiz.net
Subject: about "syntax error" of perl program(HELP!!!)
Message-Id: <8moo83$o4h$1@nnrp1.deja.com>
Hi:
Excuse me ,could you tell me how can I solve the problem of perl
program !I wrote the perl program to get the information from the FORM
and put the data send the client by E-Mail.But the system said "syntax
error at d:\test.pl line 46, near "if" ,Execution of d:\test.pl aborted
due to compilation errors. " ,when I testing the program. It's the
first time I write the perl program,so I don't know what I can do.if
you know something about it or you can solve the problem ,please send
me quickly!my E-mail is:ly054288@online.sh.cn
Thank you very much !!!
following is the code for test.pl:
-----------------------------------------------------
#!/usr/local/bin/perl
%postInputs=readpostInput();
$dateCommand="date";
$time='$dateCommand';
open(MAIL,"/usr/sbin/sendmail -t") || return 0;
select (MAIL);
print <<"EOF";
To:najura\@citiz.net
From:$postInputs{'email'}
Subject:ÐÅÏ¢µÇ¼±í
#Subject:$postInputs{'email'} Information Requested
$time
×ÓÅ®ÐÕÃû:$postInputs{'childname'}
ÐÔ±ð:$postInputs{'childsex'}
³öÉúÄêÔÂ:$postInputs{'childyear'}.$postInputs{'childmonth'}.$postInputs
{'childday'}
Ëù¶ÁÖÐѧ:$postInputs{'childschool'}
Ëù±¨×¨Òµ1(ѧԺ/ϵ):$postInputs{'d1'}.$postInputs{'z1'}
Ëù±¨×¨Òµ2(ѧԺ/ϵ):$postInputs{'d2'}.$postInputs{'z2'}
Ëù±¨×¨Òµ3(ѧԺ/ϵ):$postInputs{'d3'}.$postInputs{'z3'}
Ëù±¨×¨Òµ4(ѧԺ/ϵ):$postInputs{'d4'}.$postInputs{'z4'}
ÁªÏµµØÖ·:$postInputs{'address'}
ÓÊÕþ±àÂë:$postInputs{'zip'}
ÁªÏµµç»°:$postInputs{'telephone'}
E-Mail:$postInputs{'email'}
УÓÑÐÕÃû:$postInputs{'xyname'}
ÐÔ±ð:$postInputs{'xysex'}
³öÉúÄêÔÂ:$postInputs{'xyyear'}.$postInputs{'xymonth'}.$postInputs
{'xyday'}
¾Í¶Áʱ¼ä:$postInputs{'learnyear1'}.$postInputs
{'learnmonth1'}.$postInputs{'learnday1'}µ½³öÉúÄêÔÂ:$postInputs
{'learnyear2'}.$postInputs{'learnmonth2'}.$postInputs{'learnday3'}
¾Í¶ÁÔº/ϵ/רҵ:$postInputs{'xyd'}.$postInputs{'xyx'}.$postInputs{'xyz'}
Ŀǰµ¥Î»:$postInputs{'factory'}
Ö°Îñ:$postInputs{'zw'}
EOF
close(MAIL);
select(STDOUT);
printThankyou();
Sub readpostInput()
{My(%searchField,$buffer,$pair,@pairs);
if($ENV{'REQUEST_METHOD'} eq 'POST')
{
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
@pairs=split(/&/,$buffer);
foreach $pair(@pairs)
{($name,$value)=split(/=/,$pair);
$value=~tr/+/ /;
$value=~$/%([a-fA-F0-9][a-fA-F0-9]/pack
("c",hex($1)))/eg;
$name=~tr/+/ /;
$name=~$/%([a-fA-F0-9][a-fA-F0-9]/pack("c",hex
($1)))/eg;
$searchField($name)=$value;
}
}
return (%searchField);
Sub printThankyou()
{print<<"EOF";
Content-type:text/html
<html>
<head>
<title>ллÄãÌîдÁË2000ÄêУÓÑ×ÓÅ®±¨¿¼Ä¸Ð£ÐÅÏ¢µÇ¼±í!</title>
</head>
</html>
EOF
}
------------------------------------------------------------------------
-----------
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 08 Aug 2000 07:37:01 -0500
From: "Paul R. Andersen" <panderse@us.ibm.com>
Subject: Re: about "syntax error" of perl program(HELP!!!)
Message-Id: <398FFEED.5311F47A@us.ibm.com>
najura@citiz.net wrote:
>
> Hi:
> Excuse me ,could you tell me how can I solve the problem of perl
> program !I wrote the perl program to get the information from the FORM
> and put the data send the client by E-Mail.But the system said "syntax
> error at d:\test.pl line 46, near "if" ,Execution of d:\test.pl aborted
> due to compilation errors. " ,when I testing the program. It's the
> first time I write the perl program,so I don't know what I can do.if
> you know something about it or you can solve the problem ,please send
> me quickly!my E-mail is:ly054288@online.sh.cn
> Thank you very much !!!
>
> following is the code for test.pl:
> -----------------------------------------------------
>
> #!/usr/local/bin/perl
> ....
> Sub readpostInput()
> {My(%searchField,$buffer,$pair,@pairs);
> if($ENV{'REQUEST_METHOD'} eq 'POST')
> {
Try:
sub readpostInput
{
my(%searchField,$buffer,$pair,@pairs);
if($ENV......
Case is important in Perl.
--
Paul Andersen
+++++++++++++
The difference between theory and practice is that in theory there is no
difference between theory and practice; but in practice there is.
------------------------------
Date: Tue, 8 Aug 2000 12:43:31 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: CGI.PM How to get all Form's value in a HashTable?
Message-Id: <Pine.GHP.4.21.0008081221010.20544-100000@hpplus03.cern.ch>
On Tue, 8 Aug 2000, brian d foy wrote:
> > Unfortunately, the POD that comes with CGI.pm is not as good as
> > the documentation at http://stein.cshl.org/WWW/CGI/.
>
> it's the same stuff, adjusted for version differences.
You are mistaken, I'm afraid. I fell into that trap too, until
Lincoln Stein pointed out the problem to me. He maintains the HTML
version carefully, whereas the POD documentation, even in the newer
releases which I was discussing with him, contained quite a number of
pieces of obsolete and by-now misleading stuff.
On top of that, I'm sure I've spotted the occasional conversion error
introduced by the POD to HTML conversion process, though I can't now
point to one specifically. So if one stumbles into an apparently HTML
version which is in fact an HTML-ified POD (as happens for example in
the online documentation provided with ActivePerl) then there's a
problem, unfortunately.
------------------------------
Date: Tue, 08 Aug 2000 14:29:53 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: combinations - a better way to do this?
Message-Id: <ctrvosgs3ubqbugr1eqkjfmh6trog20th6@4ax.com>
On Mon, 07 Aug 2000 08:33:39 GMT, Chris W. <crasssh@my-deja.com> wrote:
> This is the first time I've used Perl for anything where I care about
> speed and efficiency. I have a working piece of code, but would
> appreciate pointers to any performance improvements.
>
> The problem: I have a set of data on individuals and want to compare
> the result of performing an analysis with various members of the set
> missing. I want to use Perl to generate replicates of the data with
> different individuals' data missing. The analysis *will* be slow and so
> I want to run it as few times as possible. Within the set of
> individuals, some are 'equivalent' - ie running the analysis with one
> missing would be the same as running with the other missing, so I want
> to run only once. In the example below, individuals '0' and '1' are
> equivalent since $classes[0] = $classes[1], as are individuals '2', '3'
> and '4'.
>
> The code:
<explanation snipped>
>
> #!/usr/bin/perl -w
> use strict;
>
> my @classes = ('1','1','2','2','2','3');
> my @data = ('--','--','--','--','--','--');
> my $missing_value = '**';
> my $max_missing = 2;
...
> Chris.
Hi Chris,
It took me some time to understand what your code did, mainly because
the data in @combinations was 'un intuitive'. IMO your code would
benefit if that data structure was a 'list of lists of lists'.
That looks like:
my @combinations = (
[ [0], [1], [2], [3], [4], [5] ],
[ [0, 1], [0, 2], [0, 3], [0, 4], [0, 5],
[1, 2], [1, 3], [1, 4], [1, 5],
[2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5] ]
);
With this data structure there is no need to get the combinations from a
linear list, which saves a lot of trouble and makes coding easier.
the output routine can look something like:
sub my_output {
my @list = @_;
my %seen;
for my $a_ref (@list) {
my @real_class = map $classes[$_]=>@$a_ref;
my $class_set = join ' ', sort @real_class;
next if exists $seen{$class_set};
$seen{$class_set}++;
my @new_data = @data;
$new_data[$_] = $missing_value for @$a_ref;
print "@new_data\n";
}
print "\n";
}
This can be called like:
my_output(@$_) for @combinations;
Now the problem is: 'How to get the list of lists of lists?'
The simple fix is to push [ @start ] (reference to an anon. array
containing the elements of @start) in your routine.
>
> ## This from Sitaram Chamarty - see
> ##http://faqchest.dynhost.com/prgm/perlu-l/perl-99/perl-9912/perl-991202
> /perl99122713_04014.html
>
> sub proc
> {
> my($startref, @more) = @_;
> my @start = @$startref;
>
> for (1..$max_missing) {
> push @{ $combinations[($_-1)] }, @start if @start and @start == $_
push @{ $combinations[($_-1)] }, [ @start ]
if @start and @start == $_
> }
> return if @start == $max_missing;
>
> # Now move each element of more over to start one at a time and
> recurse...
> foreach my $index (0 .. $#more) {
> proc([@start, $more[$index]], @more[$index+1 .. $#more]) }
> }
>
I looked at the link you supplied and searched back on Deja for the
actual thread and found an other way by Abigail. I slightly changed that
to fit the proposed data structure:
sub make_combi {
my($limit, @list) = @_;
my @q = ( [] );
for my $e (@list) {
@q = map { @$_ == $limit? $_: ([@$_, $e], $_) } @q;
}
my @combi;
for (@q) { push @{ $combi[@$_ - 1] }, $_ if @$_; }
return @combi;
}
This should be called like:
my @combinations = make_combi($max_missing, (0..$#data));
--
Good luck,
Abe
------------------------------
Date: Tue, 08 Aug 2000 11:30:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: date manipulation
Message-Id: <parvos01hij9rl7ktnk34ac28jii40d3uk@4ax.com>
Keith Calvert Ivey wrote:
>I don't understand why you think it's a nonproblem. Those two
>hours a year when the nonpedantic solution doesn't work are
>real, not merely theoretical, and the answers you get when you
>run your program then will be *wrong* unless you take summer
>time into account.
It's not just during those two years that it doesn't work. It will
happen whenever the two dates are on different sides of the date/time
when the hour shifts. The simple solutions simply add a whole multiple
of 24 hours to the time.
Now, what Larry Rosler proposed, is to make sure you get to the right
day, because you've started out from midday. Once you've got there, get
to the right local time by fixing the hour/minutes/seconds. Using
Time::Local (inverse of localtime; it's a joke) you can easily do that.
Or, if all you want is a string containing date and time, simply replace
the time string.
Final note: gmtime is in no way influenced by summer time. localtime is.
I don't see any unsolvable difficulties. Writing this code is the
easiest way to make sure it does precisely what you want it to do.
--
Bart.
------------------------------
Date: Tue, 8 Aug 2000 13:50:44 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: date manipulation
Message-Id: <Pine.GHP.4.21.0008081342000.20544-100000@hpplus03.cern.ch>
On Tue, 8 Aug 2000, Bart Lateur wrote:
> Now, what Larry Rosler proposed, is to make sure you get to the right
> day, because you've started out from midday.
Looked good to me..
> Final note: gmtime is in no way influenced by summer time.
So you could convert localtime to gmtime, add 24 hours, and convert
the result back again to localtime. No?
> I don't see any unsolvable difficulties. Writing this code is the
> easiest way to make sure it does precisely what you want it to do.
The problem seems to be that most people asking this question don't
actually know what they precisely want it to do. Once one has
clearly defined the problem in one's own mind, a solution becomes
pretty-much obvious, so the group doesn't get questions from people
who've already precisely defined their requirement.
------------------------------
Date: Tue, 8 Aug 2000 14:27:24 +0300
From: "Denys Kotseba" <kdl@softhome.net>
Subject: Expert advise needed
Message-Id: <8moqt3$rpp$1@app0.visti.net>
Hello,
My boss got the idea to develop an application (potentially for sale) which
would allow people with no technical knowledge create a web-shop. It would
be running on server and accessed though a regular browser. I feel Perl is a
good tool for this kind of task. He doesn't like the idea of writing it in
Perl because we would have to give out the source code. My question is: what
is the best solution to make the whole system somehow protected? (I know
it's the age of open source and the concept of hiding source code is strange
to Perl, but still ;) I thought combining a core in C and the rest in Perl
would solve the question, but I would like to hear other opinions.
Thanks.
Denys Kotseba
------------------------------
Date: Tue, 08 Aug 2000 10:08:40 GMT
From: Steve Button <steve_button@my-deja.com>
Subject: Re: function like grep
Message-Id: <8mom77$mlm$1@nnrp1.deja.com>
In article <398FD2F3.FAC921B1@poboxes.com>,
unplug <unplug@poboxes.com> wrote:
> Does perl has any function like grep??
>
> Rgds
> unplug
>
Yes, Perl has a "grep" function. Perl can also function like grep. what
do you want to do?
Steve
--
HuntAHome http://www.huntahome.com
Properties throughout the UK and Europe
Subscribe to receive a free daily email of all
matching properties. Free to advertise your property
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 08 Aug 2000 10:21:06 GMT
From: "Allan M. Due" <All@n.due.net>
Subject: Re: function like grep
Message-Id: <maRj5.13632$f_5.69000@news1.rdc1.ct.home.com>
@poboxes.com> wrote in message news:398FD2F3.FAC921B1@poboxes.com...
: Does perl has any function like grep??
Um, yes. It is called grep. It really does pay to at least take a peak at
the documentation.
perldoc -f grep
HTH
AmD
(Hope I am not troll feeding here)
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--Random Quote--
People get annoyed when you try to debug them.
Larry Wall
------------------------------
Date: Tue, 08 Aug 2000 11:19:50 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Have split question
Message-Id: <piqvos0r062s4o5n735dcr3k8c739acb75@4ax.com>
Johnny Shaieb wrote:
>If I have the following line to parse,,, how do I get what's in the
>middle.
>
>$line = "(945)";
>
>#I now I can do this
>($tmp1,$num,$tmp2) = split(/\(,\)/,$line);
>
>#but how do I rip out whats in the middle, without using the above
>#line.
How you ever found Perl is a mystery to me, because you're not using
what is the powerful feature that Perl is most famous for: regexes. See
the local docs, perlre.
There are many way's to do it. It all depends on what cases you want to
be able to handle.
Get digits:
($num) = $line =~ /(\d+)/;
Remove leading and trailing parentheses:
$num = $line;
$num =~ s/^\(//;
$num =~ s/\)$//;
Or, using tr///, you can delete ALL parantheses:
($num = $line) =~ tr/\(\)//d;
(Note: despite the similar syntax, tr/// does not use regular
expressions)
Same using s///:
($num = $line) =~ s/[\(\)]//g;
--
Bart.
------------------------------
Date: Tue, 08 Aug 2000 12:29:40 GMT
From: jennlee_2@my-deja.com
Subject: Re: Help!! Need to find user name
Message-Id: <8mouff$sb4$1@nnrp1.deja.com>
In article <878zu9gqcv.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
> >> On Mon, 07 Aug 2000 12:54:23 GMT,
> >> jennlee_2@my-deja.com said:
>
> > Hi, We just switched our Netscape web server to Novell
> > and use the NDS for authentication. I have a Perl
> > script called by submitting an HTML form, where I need
> > to know the username of the person who envokes it.
>
> > No environmental variable contains this username (I
> > dumped them all out to check for sure) and I am not sure
> > how to find it.
>
> > Can anyone assist with how to find the username?
>
> Which username are you interested in? My local login
> session and a name I enter for the web are likely to be
> completely different.
Hi - sorry I wasn't clear - we are using Novell NDS to authenticate
users (its an Intranet not a public web site) so I want their Novell
network username. When they hit the site the server makes them
authenticate.
I thought Since the web server (Netscape Enterprise) knows whether or
not they can visit particular directories, the username information must
be obtainable somehow. Although the fact that it is not an
environmental variable stumps me a bit. Perhaps the web server doesn't
know and only the OS knows and when a file is requested it either
returns it or an error. I'm not sure - anyone?
> If it's a Basic realm then you can do
>
> use CGI ':standard';
> my $name = remote_name();
>
> but it looks like it is something else because you said
> the name wasn't set in the environment.
>
> Can you be more specific? If this is about CGI you might
> try posting to comp.infosystems.www.authoring.cgi instead,
> where it would be more on topic.
Thanks for the suggestion - I'll try there as well. I just thought some
Perl guru out there would have experience with Novell authentication and
Perl.
Jennifer
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 08 Aug 2000 11:24:00 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: HTML Table To Text --How?
Message-Id: <k5Sj5.233$Ei6.41583@news.dircon.co.uk>
In comp.lang.perl.misc Dennis@nospam.com wrote:
> Many Web sites present their data in HTML Table format..you know <table>...
> bunch of stuff...</table>.
>
> While both Netscape and Explorer can easily save the HTML table to a text file,
> this seems to be an almost impossible feat for a perl script. Please, please
> correct me if I'm wrong. The Netscape route is ok if you want to display the
> results in a web browser but not ok if you just want the information on 100+
> different web tables so that you can plug the raw numbers into another program.
>
> Yes I've read the perldocs. Here are the methods that I tried and the failure
> of each.
>
> The HTML file is 68K and the resulting Netscape "save as" text file is 8k.
>
> I tried the below parsing routines without success: Also these failed under
> Perl 5.005 and 5.6
> ----------------------------------------------------------------------------------
> my $plain_text;
> $plain_text = HTML::FormatText->new->format(parse_html($content));
>
> This gave me "Can't find parse_html routine" . I searched CPAN but could not
> find the routine.
>
> -----------------------------------------------------------------------------
> my $p = HTML::Parser->new; # should really a be subclass
> $p->parse($content);
> print $p;
>
> This gave me the following error...don't know what it's asking for but no
> output:
> ---------- Perl Execute ----------
> HTML::Parser=HASH(0x813b18)
> Normal Termination
> Output completed (2 sec consumed).
>
That is was you asked it to print.
In the first instance I would suggest that you do a search on Deja News
for "HTML::Parser" in this newsgroup - you will find plenty of examples.
I have a page at <http://www.gellyfish.com/htexamples/> which has some
examples. Randal also has some examples in his articles at
<http://www.stonehenge.com/merlyn/> . THere is also some example code
in the lastest distribution of HTML::Parser which you should get from
CPAN if you havent already.
/J\
/J\
------------------------------
Date: 08 Aug 2000 08:09:01 -0400
From: Kent Holsinger <kent@darwin.eeb.uconn.edu>
Subject: Re: HTML Table To Text --How?
Message-Id: <m0k8dsrm3m.fsf@darwin.eeb.uconn.edu>
I don't do tables, but this will extract text from a local HTML file:
#!/usr/bin/perl -w
use HTML::FormatText;
use HTML::TreeBuilder;
use strict;
my $html = HTML::TreeBuilder->new->parse_file($htmlfile);
my $formatter = new HTML::FormatText;
print $formatter->format($html);
perldoc HTML::FormatText for more details
Kent
--
Kent E. Holsinger kent@darwin.eeb.uconn.edu
http://darwin.eeb.uconn.edu
-- Department of Ecology & Evolutionary Biology
-- University of Connecticut, U-3043
-- Storrs, CT 06269-3043
------------------------------
Date: Tue, 08 Aug 2000 10:43:44 GMT
From: "Dave @ kexis" <no@email.for.me>
Subject: Re: Novice question: How to kill a process
Message-Id: <AvRj5.134515$8u4.1225830@news1.rdc1.bc.home.com>
Doesn't just using `` execute the command to the shell? But then you might
as well use sh script for your problem...
#!/usr/bin/perl -w
&restart_named;
sub restart_named {
`kill -HUP \`ps -eaf | grep named | cut -c 11-15\``
sleep (howeverlongtowaittodoitagain?)
}
"Tim Conrow" <tim@ipac.caltech.edu> wrote in message
news:398F9664.B0699F88@ipac.caltech.edu...
> satyapal_deja@my-deja.com wrote:
> >
> > Perl is new to me.
> >
> > I want the following shell statement to be executed from Perl.
> >
> > kill -HUP `ps -eaf | grep named | cut -c 11-15`
> > (Baiscally I need to restart a named process)
>
> perldoc -f kill
>
> As for accessing the process table, I think there's a module that tries
> to do it in a platform independant way, but I'm not sure. If portability
> isn't a concern, start with
>
> ($ps) = grep(/named/,`ps -eaf`); # Only gets the first one
> $pid = (split(" ",$ps))[1];
>
> ... or as one line ...
>
> $pid = (split(" ",(grep(/named/,`ps -eaf`))[0]))[1];
>
> ... and season to taste. Me, I'd do more error checking along the way.
>
> --
>
> -- Tim Conrow tim@ipac.caltech.edu 626-395-8435
------------------------------
Date: 8 Aug 2000 11:45:59 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: one liner?
Message-Id: <8mortn$vd$1@lublin.zrz.tu-berlin.de>
Uri Guttman <uri@sysarch.com> wrote in comp.lang.perl.misc:
>>>>>> "RLS" == Randal L Schwartz <merlyn@stonehenge.com> writes:
>
>>>>>> "Chris" == Chris W <crasssh@my-deja.com> writes:
> Chris> I have lines of (variable length) data containing space-separated
> Chris> integers. I want to change all but the first five integers in each line
> Chris> to 0. I can do this by splitting it into an array, as below, but I am
> Chris> sure there must be some 'neater'/'shorter' way. Any suggestions?
>
> RLS> One line if you futz:
>
> RLS> { my $cnt = 0; s/(\d+)/++$cnt > 5 ? 0 : $1/ge; }
>
>another way:
>
> s{((?:\d+\s+){5})(.*)}{my $s = $2; $s =~ s/\d+/0/g ; "$1$s"}e ;
Yet another:
substr( $_, pos) =~ s/\d+/0/g if m/(?:\d+\s+){5}/g;
Anno
------------------------------
Date: Tue, 8 Aug 2000 13:20:53 +0200
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: Perl and opening tcp socket
Message-Id: <8moqcu$t0s1@intranews.dresdnerbank.de>
Hi,
rhlinuxguru@my-deja.com schrieb in Nachricht
<8moech$hdq$1@nnrp1.deja.com>...
>I want a perl script that will open a tcp connection on a specified
>port to an ip for like 30 seconds, and then close it....
so have a look at the FAQ and simply do it...
use Socket; # use the socket module
socket( SH, PF_INET, SOCK_STREAM, getprotobyname 'tcp' ) || die $!;
# create a tcp socket
connect( SH, sockaddr_in <port>, inet_aton <host> ) || die $!;
# connect your socket to
host/port
sleep 30; # wait 30 secs
close SH || warn $!; # close the socket
Be careful - this code is not tested. I simply typed it in (supply your
own
values for port/host).
>I dont need to capture data or send any data, i just need to open the
>socket, and keep it open for a specified amount of time...
>
>Is there an easy way to do this?
Almost everything can be done with perl ;-)
Best regards,
Peter Dintelmann
------------------------------
Date: Tue, 8 Aug 2000 13:37:06 +0200
From: "Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com>
Subject: Re: printing backspace in WinNT
Message-Id: <8morba$sun3@intranews.dresdnerbank.de>
Hi,
Murlimanohar Ravi schrieb in Nachricht
<22E71DAEC504D111B78100805FFE9DC73D13A9BF@pfs21.ex.nus.edu.sg>...
>
>I've been trying without success to print the backspace character (\b)
>using a perl CGI script.
>
>print "Hello";
>print "\b";
>
>should ideally output
>
>Hell
No. It should send the character sequence "Hello\b" to your client.
>When I ran the CGI script my output was
>
>Hello*
Since your browser cannot interpret the \b.
>I tried running it from the command line and I got just Hello.
Since \b is non-printable and thus "invisible". If you
print "Hello\bX"; on the command line you should get
HellX as output. But this is done by your console.
>I'm using WinNT/IIS. Does the \b character only work for UNIX?
This has nothing to do with NT/*ix differences.
Have a look at the string manipulation methods in the
perlfunc page to achieve what you want.
Best regards,
Peter Dintelmann
------------------------------
Date: Tue, 08 Aug 2000 10:38:16 GMT
From: jthornton@my-deja.com
Subject: Re: Programming Ethics
Message-Id: <8monuo$nqq$1@nnrp1.deja.com>
As you can see, there are mixed opinions about this thread. Some
say "write the code" while others say "don't" -- some don't even want
this OT thread cluttering the newsgroup (maybe if I said I wrote it in
Perl...I dunno).
If you take the position of "write it or someone will," you should
realize (as I did) that is how spam came to be. For the most part,
programmers always create the engines that drive spam to our homes and
offices (mass e-mail databases don't populate themselves and mass
mailings usually don't just happen).
Some of the pro-code supporters may have reached their conclusion
because they have resigned to the fact that stopping spammers is
probably a lost cause (and instead have focused their attention on
perfecting their home-grown, squish-it-dead spam super-filter.
Regardless, for me, it probably will come down to bitching rights. Spam
isn't a legal issue (yet), but if I want to reserve my right to bitch
the next time spam gets past my filter, I can't let myself become a
contributor.
4 a.m. ramblings,
-James
In article <8mfici$hgq$1@nnrp1.deja.com>,
jthornton@my-deja.com wrote:
> Many of you have experienced this situation -- your employer (or
> contractor) asks you to write a program that, from your point-of-view,
> can lead to no good.
>
> Recently, I was asked to compile a database of names and e-mail
> addresses of users that share a common interest. It was thought that
> these e-mail addresses would be extracted from various mailing lists
> and newsgroups.
>
> The corporation I am working with is a young, public company that
> trades on the stock market. I work directly with the Chairman/CEO, and
> he made the request to compile this database.
>
> Immediately I told him that I did not think this would go over well. I
> told him that people will not want to receive unsolicited e-mail, and
> that the corporation could get itself blacklisted. He then
said, "Don't
> make the mistake of assuming what we are going to do with them. Let
> this be a lesson...we'll do it right. If you see us about to do
> something wrong, scream and yell, but so don't assume."
>
> It's beyond me how you can appropriately use a list like this, but my
> time is under contract by this corporation. I wrote the code and
> populated the beginnings of the requested database, but I have not
> given it to them.
>
> What good can come from this? Is the proper use of this database my
> responsibility? Should the code never be written?
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 08 Aug 2000 12:07:22 GMT
From: gregosse2409@my-deja.com
Subject: regexp - extract substrings
Message-Id: <8mot5n$rd9$1@nnrp1.deja.com>
I've a problem and can't find the solution...
I've a string - on multiple lines (there are \n in the string).
Each substring has this structure : first|second|third| (pipe is the
separator)
example : blabla|bleble|blibli|
But the \n can be in a substring
example : blabla|ble\n
ble|blibli|
It is still one substring (3 records, separated by |)
I want to extract, one by one, all the substrings in my string...
How to do that ?
Thanks
Greg
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 08 Aug 2000 12:44:18 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: regexp - extract substrings
Message-Id: <slrn8p00eu.ipn.rgarciasuarez@rafael.kazibao.net>
gregosse2409@my-deja.com wrote in comp.lang.perl.misc:
>I've a string - on multiple lines (there are \n in the string).
>
>Each substring has this structure : first|second|third| (pipe is the
>separator)
>
>I want to extract, one by one, all the substrings in my string...
>How to do that ?
Use the split function.
@fields = split /\|/ => $yourstring;
Read the docs, read the faqs, read the answers to newbies in this
newsgroup... split is a very common and very useful function in perl
programs.
--
Rafael Garcia-Suarez
------------------------------
Date: Tue, 08 Aug 2000 10:11:09 GMT
From: Andre van Straaten <andre@UltraShell.Net>
Subject: Re: Sendmail delivery failures
Message-Id: <11Rj5.17895$ov2.456454@news-west.usenetserver.com>
Robert <robertNOroSPAM@kronos.custard.org.invalid> wrote:
> Hello,
> I am using a Perl "Mailing List" script for sending emails to a
> list of addresses. The script uses sendmail to send out to all
> the addresses, but is there a way of logging which emails in the
> list are invalid? In other words, can Perl, or sendmail, capture
> mail delivery failure notifications in any way?
> If a mailing list becomes particularly large, I want to find out
> which addresses in the list are invalid without mailing each
> person individually.
AFAIK if you try the telnet protocol on port 25 (talking to the SMTP
daemon of the addressee's host) with "HELO" and like that, you'll get an
immidiate reply for invalid addresses (on that host).
That's the only synchronous way (I think) I'm aware of.
-- avs
Andre van Straaten
http://www.vanstraatensoft.com
______________________________________________
flames please to /dev/null@vanstraatensoft.com
------------------------------
Date: 8 Aug 2000 11:05:24 GMT
From: "hubert depesz lubaczewski" <depesz@depesz.pl>
Subject: Re: Simple regular Expression Question
Message-Id: <8mophk$ejp$1@cyber.cs.net.pl>
Na grupie comp.lang.perl.modules Kenny Lim <kennylim@techie.com> wyrze¼bi³(a):
[KL] > I would like to know if it's possible that to increment
[KL] > on a "specific number" on a given project name.
[KL] > ETThread226
[KL] > Major Version = 2 (ie. increment to 3)
[KL] > Minor Version = 26 (ie. increment to 27)
$ perl -e '$a="ETThread226"; $a=~s/^(.*?)(\d)(\d*?)$/sprintf("%s%u%u",$1,$2+1,$3)/e; print $a'
ETThread326
$ perl -e '$a="ETThread226"; $a=~s/^(.*?)(\d)(\d*?)$/sprintf("%s%u%u",$1,$2,$3+1)/e; print $a'
ETThread227
the only important aprt is s/^(.*?)(\d)(\d*?)$/sprintf("%s%u%u",$1,$2,$3+1)/e;
(or ...$2+1,$3)
depesz
------------------------------
Date: Tue, 08 Aug 2000 10:02:33 GMT
From: Steve Button <steve_button@my-deja.com>
Subject: Re: what does foreach (0...10) do ???
Message-Id: <8molrn$min$1@nnrp1.deja.com>
In article <slrn8ovk6t.i7u.rgarciasuarez@rafael.kazibao.net>,
rgarciasuarez@free.fr (Rafael Garcia-Suarez) wrote:
> Steve Button wrote in comp.lang.perl.misc:
> >Notice the three dots instead of two. It seems to work, but why??
>
> Read the section on range operators in perlop.
>
> --
> Rafael Garcia-Suarez
>
Right. Read that. Phew! Bit confusing about what it does in a scalar
context, but I can see it makes no difference in a list context. (Well,
it's undocumented what it does in a list context).
The Camel makes no mention of it either.
Anyway, I've taken it out of all the code that I've inherited (all
using foreach) as it will only confuse some other poor sole in the
future.
Cheers,
Steve
--
HuntAHome http://www.huntahome.com
Properties throughout the UK and Europe
Subscribe to receive a free daily email of all
matching properties. Free to advertise your property
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 08 Aug 2000 14:52:12 +0200
From: Frank Winkler <frank.winkler@infineon.com>
Subject: WinNT binary compiled with -DMULTIPLICITY
Message-Id: <3990027C.BE6C72F8@infineon.com>
Hallo,
does somebody know, there can I get a Perl-binary for
WinNT, which is compiled with -DMULTIPLICITY ?
I tried to compile it with this switch,
but even the example-programm from perlembed.html
did not work.
TNX,
Frank.
frank.winkler@infineon.com
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3947
**************************************