[19415] in Perl-Users-Digest
Perl-Users Digest, Issue: 1610 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 25 11:05:27 2001
Date: Sat, 25 Aug 2001 08:05:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998751907-v10-i1610@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 25 Aug 2001 Volume: 10 Number: 1610
Today's topics:
Re: Check subroutine data from other process <cave@pertus.com.pl>
Re: Check subroutine data from other process <ilya@martynov.org>
how to get named constants in Perl (Joachim Ziegler)
Re: how to get named constants in Perl <info@fruiture.de>
Re: how to get named constants in Perl (Martien Verbruggen)
Re: need help with regexp... (Larry A Barowski)
Re: Need Perl module or regexp to slurp specific XML re (Yves Orton)
Re: one character at a time (Yves Orton)
Re: perl comments (David Combs)
Re: perl comments <jonasbn@wanadoo.dk>
Re: perl comments (Tad McClellan)
Re: pl or not pl, that is the question <bart.lateur@skynet.be>
Re: pl or not pl, that is the question (Yves Orton)
Re: Statement modifiers?? <ilya@martynov.org>
String replacements using s/// <Jeff@aetherweb.co.uk>
Re: String replacements using s/// <bcaligari@fireforged.com>
Re: String replacements using s/// <skoehler@upb.de>
Re: String replacements using s/// (Yves Orton)
Re: String replacements using s/// <bart.lateur@skynet.be>
Re: sysread problem on socket (Anno Siegel)
Re: This has got to be a bug <skoehler@upb.de>
Re: Webmail (Tad McClellan)
Re: Why is $i so popular? <unglaeubiger@web.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 25 Aug 2001 15:22:30 +0200
From: Mirek Rewak <cave@pertus.com.pl>
Subject: Re: Check subroutine data from other process
Message-Id: <iv8fotk4gi7kop96n28jvl449po1ukv25k@4ax.com>
On 25 Aug 2001 12:24:46 +0400, Ilya Martynov <ilya@martynov.org>
wrote:
>If you want to use named pipes or sockets for communication and do not
>want processes to be blocked use select (see 'perldoc -tf select';
>note that Perl have two functions named select; you need select which
>accepts four arguments). There was an example of select usage in
>perlipc.
I modified the example and get skelet of main program processing, but=20
there occured other problem: process will be never idle, it take 97%
cpu time on my comp even it don't do long time operation. Is there a
compromise between blocking and polling?
Here is my example code:
#!/usr/local/bin/perl -w
use strict;
use IO::Socket;
use IO::Select;
$SIG{CHLD} =3D sub {wait ()};
my $main_sock =3D new IO::Socket::INET ( LocalHost =3D> 'localhost',
LocalPort =3D> 2345,
Proto =3D> 'tcp',
Listen =3D> 5,
Reuse =3D> 1,
);
die "Nie mog=EA utworzy=E6 gniazda: $!\n" unless ($main_sock);
my $sel =3D new IO::Select ($main_sock);
my @ready;
my $new_sock;
my $i=3D0;
while (1) {
@ready =3D $sel->can_read(0); # avoid blocking
foreach my $fh (@ready) {
if ($fh=3D=3D $main_sock) {
$new_sock =3D $main_sock->accept;
$sel->add($new_sock);
}
else {
my $buf;
while (defined ($buf =3D <$fh>)) {
print "Data from client: $buf";
}
$sel->remove($fh);
$fh->close;
}
}
if ($do_operation) {
print "Loop: $i\n"; # there will be long time
operation
$i++;
}
}
close ($main_sock);
Pozdrowienia
Mirek Rewak
cave@pertus.com.pl
------------------------------
Date: 25 Aug 2001 18:49:02 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Check subroutine data from other process
Message-Id: <87lmk8tctd.fsf@abra.ru>
>>>>> On Sat, 25 Aug 2001 15:22:30 +0200, Mirek Rewak <cave@pertus.com.pl> said:
MR> I modified the example and get skelet of main program processing, but
MR> there occured other problem: process will be never idle, it take 97%
MR> cpu time on my comp even it don't do long time operation. Is there a
MR> compromise between blocking and polling?
MR> [..skip..]
Look here:
while(1) {
my $state = check_state;
if($state) {
do_something
}
}
This is simplified representation of your skelet of main
program. Since most time $state is false this loop is just empty
loop. It will consume all available CPU time.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: 25 Aug 2001 04:52:44 -0700
From: ziegler@algorilla.de (Joachim Ziegler)
Subject: how to get named constants in Perl
Message-Id: <93aad7d0.0108250352.18b3c6ab@posting.google.com>
i've seen the following line of code for defining a contant scalar
equal to pi:
*PI=\3.141592;
can someone please explain what's going on here behind the scenes?
is this the preferred way in Perl to do something like "const double
PI=3.1415;" in C?
how do i create named constants in Perl?
btw, i see nothing about this subject in the FAQ:
ziegler[11]:~/Desktop/Perlkurs$ perldoc -q constant
No documentation for perl FAQ keyword `constant' found
are named constants nothing of interest in Perl?
greetings from saarland in the middle of western-europe
joachim
------------------------------
Date: Sat, 25 Aug 2001 14:08:43 +0200
From: "fruiture" <info@fruiture.de>
Subject: Re: how to get named constants in Perl
Message-Id: <9m84ts$dho$02$1@news.t-online.com>
"Joachim Ziegler" <ziegler@algorilla.de> wrote:
>..
> are named constants nothing of interest in Perl?
>
usally it's enough to write a subroutine like that:
sub PI () { 3.141592654 }
This will work like a constant.
But there is alos a perl-pragma named constant
use constant PI => 3.141592654;
% perldoc constant
and
*PI = \3.141592654
is imho not usefull, but see
% perldoc perldata
'typeglobs'
> greetings from saarland in the middle of western-europe
greetings from mac-pom in the east of western-europe
--
do something for your health
______fruiture.de___yeah!_
------------------------------
Date: Sat, 25 Aug 2001 22:13:30 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: how to get named constants in Perl
Message-Id: <slrn9of5ja.3ga.mgjv@martien.heliotrope.home>
On 25 Aug 2001 04:52:44 -0700,
Joachim Ziegler <ziegler@algorilla.de> wrote:
> i've seen the following line of code for defining a contant scalar
> equal to pi:
>
> *PI=\3.141592;
>
> can someone please explain what's going on here behind the scenes?
Uck. I haven't seen that for a while.
This makes the scalar slot of the typeglob PI an alias for the constant
3.141592. The perldata and perlref documentation have some things to say
about typeglobs and references.
I'd certainly not recommend this.
> is this the preferred way in Perl to do something like "const double
> PI=3.1415;" in C?
No. The preferred way, nowadays, would be to use the const pragma:
use const PI => 3.141592;
or rather, to get a bit more precision:
use const PI => 4 * atan2(1, 1);
> how do i create named constants in Perl?
perldoc constant
This will generate a subroutine that always returns the same value and
doesn't take any parameters. Looks more like a constant than a thing
with a $ in front of it.
> btw, i see nothing about this subject in the FAQ:
>
> ziegler[11]:~/Desktop/Perlkurs$ perldoc -q constant
> No documentation for perl FAQ keyword `constant' found
That's odd... Maybe the question doesn't come up often enough...
What I find more staggering is that perldata doesn't refer to it. It is
pretty badly documented.
> are named constants nothing of interest in Perl?
They are. A whole pragma is devoted to them :)
> greetings from saarland in the middle of western-europe
Greetings back.
Martien
--
Martien Verbruggen |
Interactive Media Division | System Administration is a dirty job,
Commercial Dynamics Pty. Ltd. | but someone said I had to do it.
NSW, Australia |
------------------------------
Date: 25 Aug 2001 06:12:58 -0700
From: larrybar@eng.auburn.edu (Larry A Barowski)
Subject: Re: need help with regexp...
Message-Id: <76e741cc.0108250512.6034ab84@posting.google.com>
wentzcovitch@hotmail.com (John Wentzcovitch) wrote in message news:<405f748b.0108241053.28163580@posting.google.com>...
> I'm trying to use JGrasp (a nice multi-language free IDE found at
> http://www.eng.auburn.edu/grasp/grasp_main.shtml ) with a compiler
> that reports errors as:
> *** ERROR 318 IN LINE 26 OF C:\TMP\TEST.C: can't open file 'graph.h'
>
You can use the expression:
.*IN LINE (\d+) OF (\S(?:\s*\S)*): .*
The full jGRASP syntax has a prefix that indicates you are
specifying the filename and line number in that order. The
full spec would be:
f1-.*IN LINE (\d+) OF (\S(?:\s*\S)*): .*
If there are other, different error formats (or if this one
is not quite correct), just send a list of them to the bug
reporting email address you'll find in the jGRASP help, and
we'll send you an expression that will cover all of them.
-Larry Barowski
> In order to have JGrasp jump to the error location in the source file,
> one has to specify an "error format" string that contains a perl5
> regular expression associated with target flags.
>
> I do not know Perl and was only able to discover that (F\ (.*?)\:)
> finds the filename and (\d+) finds the line number on my error
> message, but was not able to create an expression that would match
> both filename and line number.
>
> Any help is greatly appreciated.
>
> John
>
>
> JGrasp documentation about "error format":
> The target flags are:
> f= filename c= class 1= start line 2= start column 3= end line 4= end
> column
>
> For click-to-error to work, the numbers of target flags must be equal
> to the number of matching groups in the regular expression. If a
> filename or class is matched and the corresponding file exists, a
> click will open the file. If the start line is matched, that line will
> be highlighted. If the start and end lines and columns are matched,
> that piece of text will be matched. If a filename and class are
> matched, the filename will be tried first. If the same target type
> matches multiple times, the last match is used. Unmatched groups are
> ignored, so you can use or'ed expressions and repeated target flags to
> match multiple possible formats.
> As an example, "f1-(\S(?:\s*\S)*):(\d+):.*" will match the file
> and line number of a GNU-style error message, as:
> c:\tmp\test.c:22:error:stdio.h: No such file or directory
------------------------------
Date: 25 Aug 2001 07:16:48 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Need Perl module or regexp to slurp specific XML records
Message-Id: <74f348f7.0108250616.51f59ab8@posting.google.com>
"M.L." <mel2000@hotmaildot.com> wrote in message news:<9ljpom$9pi2q$1@ID-19545.news.dfncis.de>...
<SNIP>
> When I originally posed my question I took shortcuts in my explanation in
> order to get to the point. I left out a lot of code details that I thought
> weren't critical to the mission of slurping XML. In fact, my coding will
> allow for new elements to be added without changing the code since each
> element name will be in an array:
>
> for example, @recArr = qw(name address city state phone zip email);
While I can see the point of leaving stuff out that isnt important,
the problem is deciding what is and is not important. Maybe in the
future point out that you have left out logic that we might consider
important to know. As for your approach sounds ok on the face of
it... (But the more flexibility you need, the more likely that a roll
your own solution will break....)
SNIP
> Actually, the snippets I used were in pidgin Perl and not intended as
> production code. Nothing has actually been written yet. In context of a
> recap, did you really think I intended the "where:" to be included as part
> of an instruction? Everything I typed was hurriedly copied from scratch
> paper, Google, or a previous poster.
No I didnt think you meant 'where:' to be part of the code. :-) OTOH
when people post code on CLPM then most likely a lot of people will
cut and paste it and try to get it to run, then fix it then post it
back. To a certain degree people here expect the code in a format
that this can be done (with DATA blocks and the like) with the minimum
hassle. That way we can help without proofreading and reformating
first....
SNIP
> Actually, I won't be using such literals in my final code. The states will
> be assigned as loop variables; the the XML element names will be variables
> pointing to their array position. No hard-coding.
Itd be interesting to see how you implement this. May I suggest
reading up on the m//o modifier and qr// if you havent already done
so. Possibly they will improve performance.
>
> > > local ($/) = '</record>';
> > > local @ARGV = 'filename.xml';
> >
> > This line is just for testing purposes right? (local @argv)
> > Also I believe you have muddled the list concept up a bit:
> >
> > local $/='</record>'; #scalar assignment
> > local @ARGV=qw(filename.xml); #see perlop for qw() #list assignment
>
> I copied the lines above from a Google thread. The author might have been
> writing pidgin Perl too for all I know. Thanks for your correction though.
Ok. Well they are wrong cause they assign a scalar to a list. Now
perl will employ DWIM and process it ok, but its not _really_ correct.
(Pedantic mode was on when I replied I believe :-)
> > > foreach (grep(/<state>\s*$user_parameter\s*<\/state>/i, <>))
> >
> > Hmm, if your file is very large and there are many records that will
> > match then using a for might cause you problems. I would stick with
> > a while personally...
> >
> > while (<>) {
> > next unless /$match_cond/io; # see perlre for the o modifier
>
> I don't understand why one example is more problematic than the other. I'll
> use yours since you say so.
The foreach/grep method reads the file into a big list (because <> is
in list context as it is a parameter to grep) greps it (filters it by
the regex) into a second list after which the first list is thrown
away, then finally foreach iterates over that. (Im pretty sure it
doesnt get optimized into the equivelent while) If the file is huge
this could be problem, not to mention the extra overhead.
The while on the other hand reads an element checks it, and if its ok
processes it, otherwise just gets the next one from the file. The
statement while(<>) is about equiv. to while(defined($_=<>)), so the
<> is in scalar context, returning only one line (see IO operators in
perlop). No overheads of creating lists and iterating over them. As
its a file you dont really need an array to iterate, the file is
serial and just reading it essentially iterates over it.
SNIP
> Again, I was trying to save bandwidth and had no idea everything would be
> scrutinized so much.
Heh. :-)
SNIP
> > > $records{$id}{'address'} = m/<address>\s*(.*?)\s*<\/address>/i;
> >
> > And once again the list context is the problem...
> >
> > ($records{$id}{'name'}) = m/<name>\s*(.*?)\s*<\/name>/i;
SNIP
> I'll have to do some research on that list context problem.
Subs in perl are allwed to know the context in which they were called
via the wantarray function. Three contexts, void, scalar and list.
Many perl operators and functions understand their context and adjust
their output accordingly. the m// operator is an example, consider
its entry in perlop 'Searches a string for a pattern match, and in
scalar context returns true if it succeeds, false if it fails.' and
'If the /g option is not used, m// in list context returns a list
consisting of the subexpressions matched by the parentheses in the
pattern, i.e., ($1, $2, $3...).'. So what you were trying to do was
'pull' a value from some text using a regex, not to store whether or
not it was possible to do so. In order to get the list context all you
had to do was put parens around the value you wanted the list to be
stored to. Since a list assigned to a list 'fills up' the list from
element 0 on, the first thing captured gets moved over. An easier
example to understand is localtime()
#!perl
use strict;
use warnings;
my (undef,$min,$hour,
$mday,$mon,$year) = localtime(); #list assignment
my @tparts = localtime(); #list assignment (@tparts is a
list)
my $tstr = localtime(); #scalar assignment
print "$year-$mon-$mday $hour:$min\n";
print "@tparts\n";
print $tstr;
__END__
Ouputs Something like:
101-7-25 15:46
3 46 15 25 7 101 6 236 1
Sat Aug 25 15:46:03 2001
The first case illustrates assigning to a list of scalars, and
ignoring the ones you dont need at the end as well as any in between
(by using undef on the LHS). The second case shows 'filling up' an
array in list context. It recieves all of the elements that localtime
returns. The third shows that when localtime knows it is in scalar
context it converts the time to a nice formatted string and returns
it. Notice that its year shows 2001 but the scalar $year from earlier
has not been corrected. Cool eh? While perhaps confusing at first
once you get the hang of context it soon becomes as intuitive as using
plural and singular sense in spoken language, and as useful too (I
think, and I suppose so do many others :-)
<SNIP>
> Thanks for all your advice Yves; the time saved will be a big help..
Glad to be helpful.
Cheers,
Yves
------------------------------
Date: 25 Aug 2001 07:53:49 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: one character at a time
Message-Id: <74f348f7.0108250653.4e260d0@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3B8734BB.3DDA1D93@earthlink.net>...
> Ken wrote:
> my $string = "my little string";
> while( /(.)/gs ) {
> print $1, "\n";
> }
print $1."\n" while ($string=~/(.)/gs );
:-)
yves
------------------------------
Date: 25 Aug 2001 10:27:42 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: perl comments
Message-Id: <9m7uiu$mr6$1@news.panix.com>
In article <3b796b7f@news.victoria.tc.ca>,
Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
>
>
>One useful area is after an __END__ . Everything after this line is
>ignored.
>
>I often put programming notes there, such as examples of things to be
>parsed, or requirement notes I can read while programming, or bits of half
>finished code I think I might want to use, or examples, etc. etc. etc.
>like a scratch pad area.
>
OK. Now, suppose for test purposes you're also
using __DATA__.
What is the interaction between those two?
Actually, I cannot imagine that this would work:
perl-code
perl-code
perl-code
...
perl-code
__DATA__
1
one
2
two
3
__END__
Now is the time for all good men to come.
David
------------------------------
Date: Sat, 25 Aug 2001 12:54:44 +0200
From: jonasbn <jonasbn@wanadoo.dk>
Subject: Re: perl comments
Message-Id: <Pine.LNX.4.21.0108251252350.2199-100000@localhost.localdomain>
On 25 Aug 2001, David Combs wrote:
> In article <3b796b7f@news.victoria.tc.ca>,
> Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
> >
> >
> >One useful area is after an __END__ . Everything after this line is
> >ignored.
> >
> >I often put programming notes there, such as examples of things to be
> >parsed, or requirement notes I can read while programming, or bits of half
> >finished code I think I might want to use, or examples, etc. etc. etc.
> >like a scratch pad area.
> >
>
> OK. Now, suppose for test purposes you're also
> using __DATA__.
>
> What is the interaction between those two?
>
> Actually, I cannot imagine that this would work:
>
> perl-code
> perl-code
> perl-code
> ...
> perl-code
> __DATA__
> 1
> one
> 2
> two
> 3
> __END__
> Now is the time for all good men to come.
>
>
>
> David
>
>
>
>
Programming Perl 3rd. Ed. states:
If you are going to put your pod at the end of the file, and you're using an __END__ or __DATA__ token, make sure to put an empty line before the forst POD directive
__END__
=head1 NAME
...
jonasbn
------------------------------
Date: Sat, 25 Aug 2001 07:59:37 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: perl comments
Message-Id: <slrn9of4p9.djb.tadmc@tadmc26.august.net>
David Combs <dkcombs@panix.com> wrote:
>In article <3b796b7f@news.victoria.tc.ca>,
>Malcolm Dew-Jones <yf110@vtn1.victoria.tc.ca> wrote:
>>
>>
>>One useful area is after an __END__ . Everything after this line is
>>ignored.
>OK. Now, suppose for test purposes you're also
>using __DATA__.
>
>What is the interaction between those two?
>
>Actually, I cannot imagine that this would work:
>
>perl-code
>perl-code
>perl-code
>...
>perl-code
>__DATA__
>1
>one
>2
>two
>3
>__END__
>Now is the time for all good men to come.
To inline or not to inline, that is the question:
http://search.cpan.org/doc/DCONWAY/Inline-Files-0.60/lib/Inline/Files.pm
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 25 Aug 2001 14:23:33 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: pl or not pl, that is the question
Message-Id: <r4dfotk93h2rks5bp74ut1gqrks0hvs9eo@4ax.com>
Randal L. Schwartz wrote:
>Please stop with this nonsense about "Perl scripts are named .pl".
>Maybe they *must* be on stupid operating systems that need to use
>extensions, but *not* under Unix.
Are you saying that Unix does not have stupid quirks? Puh!
--
Bart.
------------------------------
Date: 25 Aug 2001 07:38:28 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: pl or not pl, that is the question
Message-Id: <74f348f7.0108250638.7a87978e@posting.google.com>
gnari <gnarinn@hotmail.com> wrote in message news:<998678623.426515280269086.gnarinn@hotmail.com>...
> In article <93aad7d0.0108240201.240f78b2@posting.google.com>,
> Joachim Ziegler <ziegler@algorilla.de> wrote:
> >hi perlers,
> >
> >is it ok to call an ordinary perl-script 'helloworld.pl',
> >or should it rather be call just 'helloworld'?
SNIP
> on Win, just make sure the extention you use is associated with the perl
> binary, and you should be ok.
I agree. Ive set up a few different extensions and set up various
icons for them. That way when I look at a directory full of different
types of scripts I can visually see which I want, some are associated
with my editor,and some with the executable. Frankly filesnames with
no extension get on my nerves just cause of the icon. I guess i have
been tainted by the desktop :-)
yves
------------------------------
Date: 25 Aug 2001 16:32:59 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: Statement modifiers??
Message-Id: <871ym0uxok.fsf@abra.ru>
>>>>> On 25 Aug 2001 09:49:21 GMT, dkcombs@panix.com (David Combs) said:
DC> Anyway, about assertions.
DC> You really need macros to do them "right".
DC> You define assert *as a macro*.
DC> So that Assert(i > j) generates:
DC> if not (i > j) {
DC> either-die-or-warn-or-goIntoDebugger("Assertion Failed: " . "i > j")
DC> }
DC> (not exact syntax, but at least readable)
You can implement same thing in Perl using source filters.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/) |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Sat, 25 Aug 2001 11:18:08 +0100
From: "Jeff Snoxell" <Jeff@aetherweb.co.uk>
Subject: String replacements using s///
Message-Id: <9m7u1c$l3o$1@neptunium.btinternet.com>
Hi,
Can anyone explain why this:
$start = "This is a string, which I want, hopefully, to turn into a keyword
list. Hopefully."
$commaspace = ', ';
$dotspace = '. ';
$dot = '.';
$space = ' ';
$start =~ s/$commaspace/$space/g;
$start =~ s/$dotspace/$space/g;
$start =~ s/$dot/$space/g;
$start =~ s/$space/$commaspace/g;
gives this:
$start = "Thi, i, , string, whic, , want, hopefully, t, tur, int, , keywor,
list, Hopefully, ";
instead of what I want which is:
$start = "This, is, a, string, which, I, want, hopefully, to, turn, into, a,
keyword, list, Hopefully, ";
Thanks,
Jeff
------------------------------
Date: Sat, 25 Aug 2001 10:46:28 -0000
From: "Brendon Caligari" <bcaligari@fireforged.com>
Subject: Re: String replacements using s///
Message-Id: <9m7vab01t4k@enews3.newsguy.com>
"Jeff Snoxell" <Jeff@aetherweb.co.uk> wrote in message
news:9m7u1c$l3o$1@neptunium.btinternet.com...
> Hi,
<snip snip>
> $commaspace = ', ';
> $dotspace = '. ';
> $dot = '.';
> $space = ' ';
>
> $start =~ s/$commaspace/$space/g;
> $start =~ s/$dotspace/$space/g;
> $start =~ s/$dot/$space/g;
> $start =~ s/$space/$commaspace/g;
>
<snip snip>
in regex, '.' (dot) matches ANY character and therefore hast to be escaped
It is also a good idea to 'use strict' and lexicals, and much shorter to
type ' ' than $space.
B
------------------------------
Date: Sat, 25 Aug 2001 14:59:58 +0200
From: "Sven Köhler" <skoehler@upb.de>
Subject: Re: String replacements using s///
Message-Id: <9m87fn$25s$06$1@news.t-online.com>
>
> $start =~ s/$commaspace/$space/g;
> $start =~ s/$dotspace/$space/g;
> $start =~ s/$dot/$space/g;
> $start =~ s/$space/$commaspace/g;
>
you must use
$start =~ s/\Q$commaspace\E/$space/g;
$start =~ s/\Q$dotspace\E/$space/g;
$start =~ s/\Q$dot\E/$space/g;
$start =~ s/\Q$space\E/$commaspace/g;
but instead all of this, i would use
@keywords = split /\W+/, $start;
------------------------------
Date: 25 Aug 2001 07:27:40 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: String replacements using s///
Message-Id: <74f348f7.0108250627.2ff8d79a@posting.google.com>
"Jeff Snoxell" <Jeff@aetherweb.co.uk> wrote in message news:<9m7u1c$l3o$1@neptunium.btinternet.com>...
SNIP
> $start = "This is a string, which I want, hopefully, to turn into a keyword
> list. Hopefully."
SNIP
> instead of what I want which is:
>
> $start = "This, is, a, string, which, I, want, hopefully, to, turn, into, a,
> keyword, list, Hopefully, ";
hmm. I have to say that I dont buy that that is what you really want.
(Should there really be a trailing ', ' I wonder)
@words = split /[\s,.]+/, $start;
$finish= join(', ',@words);
#Adding the trailing ', ' and the variable names is up to you
yves
------------------------------
Date: Sat, 25 Aug 2001 14:43:18 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: String replacements using s///
Message-Id: <l2efot055jdoje4jo8tcpjkuk0cpjrk8jn@4ax.com>
Jeff Snoxell wrote:
>$start = "This is a string, which I want, hopefully, to turn into a keyword
>list. Hopefully."
>
>$commaspace = ', ';
>$dotspace = '. ';
>$dot = '.';
>$space = ' ';
>
>$start =~ s/$commaspace/$space/g;
>$start =~ s/$dotspace/$space/g;
>$start =~ s/$dot/$space/g;
>$start =~ s/$space/$commaspace/g;
>
>gives this:
>
>$start = "Thi, i, , string, whic, , want, hopefully, t, tur, int, , keywor,
>list, Hopefully, ";
Actually, it returns a string like ", , , , , ..."
"." matches any character. You want "\Q" (quotemeta):
$start =~ s/\Q$commaspace/$space/g;
$start =~ s/\Q$dotspace/$space/g;
$start =~ s/\Q$dot/$space/g;
$start =~ s/\Q$space/$commaspace/g;
But why not replace the lot in one go?
$start =~
s/\Q$commaspace\E|\Q$dotspace\E|\Q$dot\E|\Q$space\E/$commaspace/g;
(BTW "\E" stands or "end").
--
Bart.
------------------------------
Date: 25 Aug 2001 14:33:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sysread problem on socket
Message-Id: <9m8cvq$feq$1@mamenchi.zrz.TU-Berlin.DE>
According to Alex Hart <news@althepal#nospam#.com>:
> Anno Siegel wrote:
>
> > According to Alex Hart <news@althepal#nospam#.com>:
> > > Benjamin Goldberg wrote:
> > >
> > > > Alex Hart wrote:
> > > > >
> > > > > I have a POP client that I wrote by hand (well, I use Socket.pm) and
> > > > > its has worked perfectly until recently. I found one server that it
> > >
> > > Is there really no rhyme or reason to the way sysread works? I have tested
> > > my program on tons of servers and it always worked. How come the behavior
> > > was so predictable before this one server?? This is totally confusing to
> > > me.
> >
> > sysread() doesn't screen you from the behavior of the data source as
> > much as read() and company do. In particular, reading from a socket,
> > it gives you whatever the far end makes available, when it becomes
> > available (on package level, I suppose). If the remote end decides
> > to send a certain message in two portions, it will take two sysread()s,
> > no matter what.
> >
> > I comes as no surprise that some servers behave differently in how
> > they package their material. You have just been lucky so far. You
> > can either continue using sysread() and, calling it in appropriate
> > loops, make it cope with the new behavior. Or you switch to
> > <POP> and let the system cope with it.
> >
> > [detailed discussion snipped]
> >
> > Anno
>
> <<a lot was cut out>>
>
> Will <POP> ever time out. What if the server does not respond legally, and
> never sends the end of line character? Will the client stick?
No, <POP> won't time out by itself. You can make it using select() or
the techniques described under perldoc -q "slow event". If the server
never sends end-of-line, the client will hang indefinitely without this.
> Why would the server spit out its confimation message in more than one
> portion? Not only that, but it's unpredictable. It breaks up the data at
> different points each time. The behavior of this server makes no sense. Or
> does it?
It doesn't have to make sense, it may split a message just because it
can. Buffered read screens you from this behavior, but sysread doesn't.
Anno
------------------------------
Date: Sat, 25 Aug 2001 15:06:22 +0200
From: "Sven Köhler" <skoehler@upb.de>
Subject: Re: This has got to be a bug
Message-Id: <9m87rn$2q4$06$1@news.t-online.com>
> They should not have matched in either case (right!?!) but in
> the first case they do.
>
i think you didn't realize, that if you do something like /$qq/ and $qq='.'
it is not treated like /\./ but only as /./
do can work around this by using /\Q$qq\E/ which means that $qq is quoted
( than we'll have /\./ )
------------------------------
Date: Fri, 24 Aug 2001 22:48:58 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Webmail
Message-Id: <slrn9oe4gq.ccp.tadmc@tadmc26.august.net>
fanzila@yahoo.com <fanzila@yahoo.com> wrote:
>I want to set up free webmail service for my site, where the user sign
>up automatly
>does anyone know free script ?
Yes.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 25 Aug 2001 14:37:09 +0200
From: "Thomas W." <unglaeubiger@web.de>
Subject: Re: Why is $i so popular?
Message-Id: <3b879bf4_1@news.arcor-ip.de>
well, just think about "iterator" and its first letter ...
------------------------------
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 1610
***************************************