[30096] in Perl-Users-Digest
Perl-Users Digest, Issue: 1339 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 7 00:09:43 2008
Date: Thu, 6 Mar 2008 21:09:08 -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 Thu, 6 Mar 2008 Volume: 11 Number: 1339
Today's topics:
\@ and \& <rose@russ.org>
Re: \@ and \& <joost@zeekat.nl>
Re: \@ and \& <rose@russ.org>
Re: \@ and \& <ben@morrow.me.uk>
Re: \@ and \& <joost@zeekat.nl>
Re: \@ and \& <joost@zeekat.nl>
Re: \@ and \& <ben@morrow.me.uk>
Re: \@ and \& <rose@russ.org>
Re: FAQ 5.3 How do I count the number of lines in a fil <jm@nospam.fr>
How to pass a range (2 .. 42) by Getopt::Long to a scri <not@home.net>
Re: How to pass a range (2 .. 42) by Getopt::Long to a <joost@zeekat.nl>
Re: How to pass a range (2 .. 42) by Getopt::Long to a xhoster@gmail.com
Re: How to pass a range (2 .. 42) by Getopt::Long to a <abigail@abigail.be>
Re: minicpan, CPAN/CPANPLUS and autobundles on linux <doom@kzsu.stanford.edu>
Re: module needs to know its own path <No_4@dsl.pipex.com>
Re: regex for chars 192 to 255 <jm@nospam.fr>
Re: regexp for s/// <stoupa@practisoft.cz>
Re: regexp for s/// <stoupa@practisoft.cz>
Re: regexp for s/// <stoupa@practisoft.cz>
Re: Rename File Using Strring Found in File? <tadmc@seesig.invalid>
sample client server socket issue <jm@nospam.fr>
Re: sample client server socket issue <ben@morrow.me.uk>
Re: sample client server socket issue <jm@nospam.fr>
Re: sample client server socket issue xhoster@gmail.com
Re: sample client server socket issue <ben@morrow.me.uk>
Re: sample client server socket issue <abigail@abigail.be>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 7 Mar 2008 10:01:31 +0800
From: "Rose" <rose@russ.org>
Subject: \@ and \&
Message-Id: <fqq7lt$1pi$1@ijustice.itsc.cuhk.edu.hk>
Yesterday I was taught that I can use
\@array to refer an array and it does not make a copy of itself.
Indeed i don't quite understand what it means.
Today, I encounter another mysterious symbol \&, could anybody tell me what
\ and & are for?
my %sorted_features;
for my $f (@features) {
my $tag = $f->primary_tag;
push @{$sorted_features{$tag}},$f;
}
if ($sorted_features{obj}) {
$panel->add_track($sorted_features{obj},
$panel->add_track(-label => \&Label,);
}
sub Label
{
my $feature = shift;
my @notes;
foreach (qw(product result))
{
next unless $feature->has_tag($_);
@notes = $feature->each_tag_value($_);
last;
}
$notes[0];
}
------------------------------
Date: Fri, 07 Mar 2008 03:12:45 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: \@ and \&
Message-Id: <87ve3z1duq.fsf@zeekat.nl>
"Rose" <rose@russ.org> writes:
> Yesterday I was taught that I can use
>
> \@array to refer an array and it does not make a copy of itself.
>
> Indeed i don't quite understand what it means.
>
> Today, I encounter another mysterious symbol \&, could anybody tell me what
> \ and & are for?
\&something, \@something, \%something and \$something create references
to things.
References are "pointers" to data (or code). One of the ways that's
useful is that references can be much smaller than the data they point
at, so they are more efficient if you want to use the same data in
different parts of your program: instead of passing 10 Mb of data, you
just pass a reference that says: "look at that data over there".
Another way that they're useful is that all references that refer to the
same data really refer to the same data, while if you pass the data
around you generally create copies. Yet another useful feature of
references is that they allow you construct nested data structures.
You'll want to take a look at the perlreftut and perlref manpages.
To answer your particular question:
\ is the operator that takes a reference to whatever follows, and & is
the subroutine sygil. & isn't used much nowadays, but you still need it
in a few cases, and this is one of them:
sub some_subroutine {
print "My arguments are: @_\n";
}
my $ref = \&some_subroutine; # take a referent to some_subroutine
$ref->(1,2,3,4); # call the subroutine referred to by $ref.
HTH
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Fri, 7 Mar 2008 10:24:35 +0800
From: "Rose" <rose@russ.org>
Subject: Re: \@ and \&
Message-Id: <fqq914$2d2$1@ijustice.itsc.cuhk.edu.hk>
> To answer your particular question:
>
> \ is the operator that takes a reference to whatever follows, and & is
> the subroutine sygil. & isn't used much nowadays, but you still need it
> in a few cases, and this is one of them:
>
> sub some_subroutine {
> print "My arguments are: @_\n";
> }
>
> my $ref = \&some_subroutine; # take a referent to some_subroutine
>
> $ref->(1,2,3,4); # call the subroutine referred to by $ref.
>
> HTH
> --
> Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Oh, thanks! It's "pass by reference"... But in my specific case that the
subroutine "Label" is called in this way, is $sorted_features{obj} passed
and $notes[0] returned? The problem is that I'd like to call Label (the
codes of Label can't be modified) but don't know how to receive its outputs.
if ($sorted_features{obj}) {
$panel->add_track($sorted_features{obj},
$panel->add_track(-label => \&Label,);
}
sub Label
{
my $feature = shift;
my @notes;
foreach (qw(product result))
{
next unless $feature->has_tag($_);
@notes = $feature->each_tag_value($_);
last;
}
$notes[0];
}
------------------------------
Date: Fri, 7 Mar 2008 02:26:38 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: \@ and \&
Message-Id: <unl6a5-07h.ln1@osiris.mauzo.dyndns.org>
Quoth "Rose" <rose@russ.org>:
> Yesterday I was taught that I can use
>
> \@array to refer an array and it does not make a copy of itself.
>
> Indeed i don't quite understand what it means.
>
> Today, I encounter another mysterious symbol \&, could anybody tell me what
> \ and & are for?
\ takes a reference. &Label refers to the sub Label in the current
package. I believe I've already pointed you at perldoc perlreftut: it
explains things better than I could hope to here. Post again if you
still have trouble after reading that.
Ben
------------------------------
Date: Fri, 07 Mar 2008 03:36:35 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: \@ and \&
Message-Id: <87r6en1cr0.fsf@zeekat.nl>
"Rose" <rose@russ.org> writes:
> Oh, thanks! It's "pass by reference"... But in my specific case that the
> subroutine "Label" is called in this way, is $sorted_features{obj} passed
> and $notes[0] returned?
Yes. But you've got some syntax problems.
> The problem is that I'd like to call Label (the
> codes of Label can't be modified) but don't know how to receive its
> outputs.
Well, what do you want to do with it?
>
> if ($sorted_features{obj}) {
> $panel->add_track($sorted_features{obj},
This passes $sorted_features{obj} to the add_track method. You're also
missing a closing parenthesis here (or later): you probably want
$panel->add_track($sorted_features{obj}),
^-- close parenthesis
> $panel->add_track(-label => \&Label,);
this passes a reference to the Label subroutine to the add_track
method. I'm not sure if that's what you want. In any case, this
construct does *not* call the Label subroutine (though add_track may
call it later).
> sub Label
> {
> my $feature = shift;
>
> my @notes;
> foreach (qw(product result))
> {
> next unless $feature->has_tag($_);
> @notes = $feature->each_tag_value($_);
> last;
> }
> $notes[0];
> }
Whenever (if ever) Label is called, it will return $notes[0].
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Fri, 07 Mar 2008 03:42:23 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: \@ and \&
Message-Id: <87mypb1chc.fsf@zeekat.nl>
"Rose" <rose@russ.org> writes:
> Oh, thanks! It's "pass by reference"
I forgot to add this, but while this is more or less correct, perl
doesn't have the simple-minded view of references that most languages
that use the phrase "pass by reference" have. /Especially/ not when
dealing with references to subroutines.
Really, read perlreftut and perlref.
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: Fri, 7 Mar 2008 02:46:53 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: \@ and \&
Message-Id: <ttm6a5-07h.ln1@osiris.mauzo.dyndns.org>
Quoth "Rose" <rose@russ.org>:
>
> Oh, thanks! It's "pass by reference"...
Well, yes, literally speaking. However, 'pass by reference' is more
usually used to indicate that the called sub modifies its parameters,
and is able to do so because they were passed by reference; that is not
the case here. Passing a subref is simply the only way to pass a sub
value into another sub.
[code moved up here, for clarity]
> if ($sorted_features{obj}) {
> $panel->add_track($sorted_features{obj},
^^
I presume this is a typing error, and that line was supposed to end with
');'?
> $panel->add_track(-label => \&Label,);
> }
>
> sub Label
> {
> my $feature = shift;
>
> my @notes;
> foreach (qw(product result))
> {
> next unless $feature->has_tag($_);
> @notes = $feature->each_tag_value($_);
> last;
> }
> $notes[0];
> }
> But in my specific case that the subroutine "Label" is called in this
> way, is $sorted_features{obj} passed and $notes[0] returned?
Label returns $notes[0], yes. Whether, when, and with what arguments
Label is called, and what happens to that return value, are completely
under the control of the $panel object: that's the point of passing it
in, so the object can call it if it wants to. In this case I'd think
it's unlikely it would be called with $sorted_features{obj}, but I
couldn't tell without knowing what sort of object $panel is.
> The problem is that I'd like to call Label (the codes of Label can't
> be modified) but don't know how to receive its outputs.
I'm not sure exactly what you are trying to achieve, here. You can call
Label, yourself, with any arguments, and do what you like with the
return value; this is completely independant of the fact you have also
passed it into $panel->add_track. Can you post a *short* complete script
we can all run, and explain how it isn't doing what you want?
Ben
------------------------------
Date: Fri, 7 Mar 2008 13:00:41 +0800
From: "Rose" <rose@russ.org>
Subject: Re: \@ and \&
Message-Id: <fqqi5q$6bs$1@ijustice.itsc.cuhk.edu.hk>
> Label returns $notes[0], yes. Whether, when, and with what arguments
> Label is called, and what happens to that return value, are completely
> under the control of the $panel object: that's the point of passing it
> in, so the object can call it if it wants to. In this case I'd think
> it's unlikely it would be called with $sorted_features{obj}, but I
> couldn't tell without knowing what sort of object $panel is.
>
>> The problem is that I'd like to call Label (the codes of Label can't
>> be modified) but don't know how to receive its outputs.
>
> I'm not sure exactly what you are trying to achieve, here. You can call
> Label, yourself, with any arguments, and do what you like with the
> return value; this is completely independant of the fact you have also
> passed it into $panel->add_track. Can you post a *short* complete script
> we can all run, and explain how it isn't doing what you want?
>
> Ben
>
Although Label returns $notes[0], but it in turn depends on
$feature->each_tag_value($_); from where $feature is "shifted" in. I'm
unable to post a short complete script here because reproducing the
hierarchy of the data is impossible. Therefore my focus is try to understand
how to use the codes invented instead of reinventing the wheel.
That's the reason why I care about what is really passed into Label because
I have to ensure my object is in the correct structure to pass. In this
case, is $sorted_features{obj} shifted into Label? Or it depends on
add_track behaviour?
if ($sorted_features{obj}) {
$panel->add_track($sorted_features{obj}, -label => \&Label,);
}
sub Label
{
my $feature = shift;
my @notes;
foreach (qw(product result))
{
next unless $feature->has_tag($_);
@notes = $feature->each_tag_value($_);
last;
}
$notes[0];
}
------------------------------
Date: Thu, 06 Mar 2008 23:11:18 +0100
From: jm <jm@nospam.fr>
Subject: Re: FAQ 5.3 How do I count the number of lines in a file?
Message-Id: <47d06c07$0$21142$7a628cd7@news.club-internet.fr>
PerlFAQ Server a écrit :
> 5.3: How do I count the number of lines in a file?
>
>
> One fairly efficient way is to count newlines in the file. The following
> program uses a feature of tr///, as documented in perlop. If your text
> file doesn't end with a newline, then it's not really a proper text
> file, so this may report one fewer line than you expect.
>
> $lines = 0;
> open(FILE, $filename) or die "Can't open `$filename': $!";
> while (sysread FILE, $buffer, 4096) {
> $lines += ($buffer =~ tr/\n//);
> }
> close FILE;
>
> This assumes no funny games with newline translations.
How does this code handle other unicode new line codages, such as 0x85,
0x0d 0x0a?
------------------------------
Date: Fri, 7 Mar 2008 00:38:44 +0100
From: Tom Brown <not@home.net>
Subject: How to pass a range (2 .. 42) by Getopt::Long to a script?
Message-Id: <2008030700384416807-not@homenet>
Hello.
The following range is "hardcoded" in a script.
for my $range ( 13 .. 20 ) {
...
}
Now, I would like pass the range dynamically as option (Getopt::Long)
to the script in order to avoid the changes in the script itself. What
is the appropriate solution?
Thanks in advance.
Tom
------------------------------
Date: Fri, 07 Mar 2008 00:41:41 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: How to pass a range (2 .. 42) by Getopt::Long to a script?
Message-Id: <874pbj5sju.fsf@zeekat.nl>
Tom Brown <not@home.net> writes:
> Now, I would like pass the range dynamically as option (Getopt::Long)
> to the script in order to avoid the changes in the script itself. What
> is the appropriate solution?
What did you try? The answer's pretty obvious:
# get $start and $end from Getopt::Long
for my $range ($start .. $end) {
# do stuff
}
note that this expects $end >= $start
--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
------------------------------
Date: 07 Mar 2008 00:06:05 GMT
From: xhoster@gmail.com
Subject: Re: How to pass a range (2 .. 42) by Getopt::Long to a script?
Message-Id: <20080306190608.451$Rf@newsreader.com>
Tom Brown <not@home.net> wrote:
> Hello.
>
> The following range is "hardcoded" in a script.
>
> for my $range ( 13 .. 20 ) {
> ...
> }
>
> Now, I would like pass the range dynamically as option (Getopt::Long)
> to the script in order to avoid the changes in the script itself. What
> is the appropriate solution?
You just need use come up with a syntax to use on the command line, then
parse it and use it.
$ perl - 5..10
my $opt_range=shift; # doing this via Getopt is up to you
my ($min,$max) = ($opt_range =~ /^(\d+)\.\.(\d+)$/) or die;
foreach my $range ($min .. $max) {
print "$range\n";
};
__END__
5
6
7
8
9
10
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: 07 Mar 2008 03:55:51 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: How to pass a range (2 .. 42) by Getopt::Long to a script?
Message-Id: <slrnft1f66.q8.abigail@alexandra.abigail.be>
_
Tom Brown (not@home.net) wrote on VCCCI September MCMXCIII in
<URL:news:2008030700384416807-not@homenet>:
}} Hello.
}}
}} The following range is "hardcoded" in a script.
}}
}} for my $range ( 13 .. 20 ) {
}} ...
}} }
}}
}} Now, I would like pass the range dynamically as option (Getopt::Long)
}} to the script in order to avoid the changes in the script itself. What
}} is the appropriate solution?
Untested:
use Getopt::Long;
sub usage {
"usage: $0 --begin <begin> --end <end>\n";
}
GetOptions 'begin=i' => \my $begin,
'end=i' => \my $end
or die usage;
defined $begin or die usage;
defined $end or die usage;
for my $range ($begin .. $end) {
...
}
__END__
Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
.qq]98$^F76777$=56]);$^U=substr($]=>$|=>5)*(q.25..($^W=@^V))=>do{print+chr$^V
%$^U;$^V/=$^U}while$^V!=$^W'
------------------------------
Date: Thu, 06 Mar 2008 15:20:03 -0800
From: Joseph Brenner <doom@kzsu.stanford.edu>
Subject: Re: minicpan, CPAN/CPANPLUS and autobundles on linux
Message-Id: <87od9rh23g.fsf@kzsu.stanford.edu>
Michele Dondi <bik.mido@tiscalinet.it> writes:
> Joseph Brenner <doom@kzsu.stanford.edu> wrote:
>>> the node seems to have been relatively well received -judging
>>> from its XP-
>>Right. So you're a karma whore?
>
> No, an XP whore. Karma is on use.perl.org! ;)
>
> BTW: in this case XP showed up for what it really should be worth for
> - the value of a node.
>>Forgive me, but I think my problem was relatively obscure, and I
>>can't see why you would be so fascinated by it that you couldn't
>>let it rest.
>
> It's been one of the most interesting questions I read in clpmisc in
> months, period. (And incidentally a friend of mine, in real life heh,
> asked me something along those lines some time before that.) I'm
> fairly sick of "how do I get the sixth fielf" kinda questions...
Fair enough, but you see questions like this make you seem a lot
like someone who just doesn't Get It:
"Do I risk a report to the abuse, a lawyer's notification or
anything of comparable severity? If so, then I'll stop forever
because there's not point in undergoing a loss for the desire
to help an individual, and the community. "
What you risk is people thinking you're a jerk who doesn't care
about the standards of the community you claim you're trying to
help. The worst case is some people stop talking to you, and
roll their eyes whenever your name comes up.
------------------------------
Date: Fri, 07 Mar 2008 01:01:26 +0000
From: Big and Blue <No_4@dsl.pipex.com>
Subject: Re: module needs to know its own path
Message-Id: <3b-dnYN5T7t6Dk3anZ2dnUVZ8tqinZ2d@pipex.net>
Marten Lehmann wrote:
> Hello,
>
> within a perl module, I need to access content included with this
> module, but stored in separate files (WSDL definitions in my case).
>
> If my module lies in /usr/lib/perl5/xxx/MyModule.pm, the WDSL files
> could be stored in /usr/lib/perl5/xxx/MyModule/WSDLs/*.wsdl or similar.
>
> But how can the perl module find out where it has been loaded from?
You could use the __FILE__ macro
[mysys]: cat xyz/ABC.pm
package xyz::ABC;
print __PACKAGE__, " is in ", __FILE__, "\n";
1;
[mysys]: perl -I`pwd` -Mxyz::ABC -e ''
xyz::ABC is in /home/myhome/xyz/ABC.pm
--
Just because I've written it doesn't mean that
either you or I have to believe it.
------------------------------
Date: Thu, 06 Mar 2008 23:19:31 +0100
From: jm <jm@nospam.fr>
Subject: Re: regex for chars 192 to 255
Message-Id: <47d06df3$0$21142$7a628cd7@news.club-internet.fr>
RedGrittyBrick a écrit :
> John wrote:
>> "Tad J McClellan" <tadmc@seesig.invalid> wrote in message
>> news:slrnfsfsa7.6t2.tadmc@tadmc30.sbcglobal.net...
>>> John <john1949@yahoo.com> wrote:
>>>
>>>> Is there a character class like [a-zA-Z] for accented characters
>>>> that lie
>>>> between ASCII 192 and 255 (excluding 215 and 247)?
>>>
>>> ASCII defines characters from 0-127, so 192 and 255 are not in ASCII.
>>>
>>>
>>> --
>>> Tad McClellan
>>> email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
>>
>> Thanks. I should have said extended ASCII
>
> I'd rather you said "Code Page 1252", "Windows Latin-1", "ISO-8859-1" or
> the name of some other specific character set/encoding. :-)
I assume you can decode/encode it from your locale encoding to utf8, and
then use the \p IsAlpha IsAlnum property.
POSIX character classes and their Unicode and Perl equivalents:
alnum IsAlnum Alphanumeric
alpha IsAlpha Alphabetic
ascii IsASCII Any ASCII char
blank IsSpace [ \t] Horizontal whitespace (GNU extension)
cntrl IsCntrl Control characters
digit IsDigit \d Digits
graph IsGraph Alphanumeric and punctuation
lower IsLower Lowercase chars (locale and Unicode aware)
print IsPrint Alphanumeric, punct, and space
punct IsPunct Punctuation
space IsSpace [\s\ck] Whitespace
IsSpacePerl \s Perl's whitespace definition
upper IsUpper Uppercase chars (locale and Unicode aware)
word IsWord \w Alphanumeric plus _ (Perl extension)
xdigit IsXDigit [0-9A-Fa-f] Hexadecimal digit
http://perldoc.perl.org/perlreref.html
------------------------------
Date: Fri, 7 Mar 2008 01:32:18 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: regexp for s///
Message-Id: <fqq3ok$1ld4$1@ns.felk.cvut.cz>
Frank Seitz wrote:
> Petr Vileta wrote:
>>
>> Till now I use code bellow, but maybe can be writte as regexp.
>>
>> if($string =~ m/A:\s+([^B]+)\s+B:\s+(.+)/) { $myA = $1; $myB = $2;}
>> elsif($string =~ m/A:\s+(.+)/) { $myA = $1; $myB = '';}
>> elseif($string =~ m/B:\s+(.+)/) { $myA = ''; $myB = $1;}
>> else {$myA = $myB = '';}
>
> my ($myA) = $string =~ /A:\s+(\S+)/;
> $myA //= '';
> my ($myB) = $string =~ /B:\s+(\S+)/;
> $myB //= '';
>
> (//= Perl 5.10)
>
Thank you Frank for response, but your solution is unusable for now. On many
servers Perl 5.8 is installed and on some 5.6.1 too.
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: Fri, 7 Mar 2008 01:41:02 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: regexp for s///
Message-Id: <fqq3ok$1ld4$2@ns.felk.cvut.cz>
Abigail wrote:
> _
> The code below *USES* regexes. So, keep it if you want to have it
> using
> a regexp.
>
> ][ if($string =~ m/A:\s+([^B]+)\s+B:\s+(.+)/) { $myA = $1; $myB =
> $2;} ][ elsif($string =~ m/A:\s+(.+)/) { $myA = $1; $myB = '';}
> ][ elseif($string =~ m/B:\s+(.+)/) { $myA = ''; $myB = $1;}
> ][ else {$myA = $myB = '';}
>
Yes, this is example only, you are exact too much :-)
I forgot to mention that A: and B: are "constatnst", so if some of these *is*
in string then it is exactly "A:" or "B:", but parts after space are variable.
In other word string can contain one of
"A: " + some variable part
or
"B: " + some variable part
or both.
--
Petr
Skype: callto://fidokomik
Na mail uvedeny v headeru zpravy nema cenu nic posilat, konci to v PR*
:-)
Odpovidejte na petr na practisoft cz
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: Fri, 7 Mar 2008 01:52:57 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: regexp for s///
Message-Id: <fqq3ol$1ld4$3@ns.felk.cvut.cz>
John W. Krahn wrote:
> $ perl -le'
> for my $string ( "A: aaa B: bbb", "A: aaa", "B: bbb", "B: bbb A: aaa"
> ) { my ( $myA, $myB ) = $string =~
> /(?=.*A:\s*(\S+))?(?=.*B:\s*(\S+))?/; print qq[\$string =
> "$string" \$myA = "$myA" \$myB = "$myB"]; }
> '
> $string = "A: aaa B: bbb" $myA = "aaa" $myB = "bbb"
> $string = "A: aaa" $myA = "aaa" $myB = ""
> $string = "B: bbb" $myA = "" $myB = "bbb"
> $string = "B: bbb A: aaa" $myA = "aaa" $myB = "bbb"
>
>
>
What Perl version you use John? In my Perl 5.6.1 this not work and print
already $myA='' $myB=''
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your
mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>
------------------------------
Date: Thu, 6 Mar 2008 19:11:44 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Rename File Using Strring Found in File?
Message-Id: <slrnft15ig.7vi.tadmc@tadmc30.sbcglobal.net>
Tad J McClellan <tadmc@seesig.invalid> wrote:
> He Who Greets With Fire <Entwadumayla@HyenaKiller.com> wrote:
>> On Tue, 04 Mar 2008 12:10:16 GMT, Tad J McClellan
>><tadmc@seesig.invalid> wrote:
>>
>>>He Who Greets With Fire <Entwadumayla@HyenaKiller.com> wrote:
>>> foreach my $file ( glob 'E:/personalinjury/*.htm' ) { # untested
>>> rename $file, "$newfile.htm" or die "could not mv '$file' $!";
>> THere are however some problems
>> with the code you posted above here. For one, the rename() function
>> takes string values as arguments, not file handles.
>
>
> Right.
Oh. I think I see what happened there.
A filename glob (perldoc -f glob) is not the same as a "typeglob"
("Typeglobs and Filehandles" section in perldoc perldata).
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Thu, 06 Mar 2008 23:35:21 +0100
From: jm <jm@nospam.fr>
Subject: sample client server socket issue
Message-Id: <47d071a9$0$21144$7a628cd7@news.club-internet.fr>
I have written some perl client program and javascript server program.
Communication seams working in both direction, but the perl client
cannot read final data.
Perl use socket in blocking mode (default).
I open the connection with localhost, port number, and tcp.
When I read packets with a size of 512 or 4096, everything works fine
till the last packet. As the last packet is smaller than 4096, perl stay
blocked waiting for a complete packet.
I just want it to be blocked when no byte is available.
When I do not use a size of 512 or 4096, but a size of 1, everything
works fine, but I am wondering if it will not be too much slow.
my $buffer = '';
while ( not $buffer =~ /\n\n/ )
{
my $packet;
sysread $sock, $packet, 4096 ;
$buffer .= $packet ;
}
NB: I have tried different technics to read data:
$sock->read
$sock->recv
sysread $sock
and so on. This does not solve the problem.
------------------------------
Date: Thu, 6 Mar 2008 23:03:40 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: sample client server socket issue
Message-Id: <cr96a5-56g.ln1@osiris.mauzo.dyndns.org>
Quoth jm <jm@nospam.fr>:
> I have written some perl client program and javascript server program.
>
> Communication seams working in both direction, but the perl client
> cannot read final data.
>
> Perl use socket in blocking mode (default).
> I open the connection with localhost, port number, and tcp.
>
> When I read packets with a size of 512 or 4096, everything works fine
> till the last packet. As the last packet is smaller than 4096, perl stay
> blocked waiting for a complete packet.
When you say 'last packet', do you mean 'last packet before the
connection is closed' or 'last packet in this request'? If you mean the
former, then Perl will return an incomplete packet even in blocking
mode. If the latter, then you need to set the socket to non-blocking
mode, and be prepared to handle short reads all the way through. You
will also need to use IO::Select to wait for data after you get a short
read.
Ben
------------------------------
Date: Fri, 07 Mar 2008 00:57:59 +0100
From: jm <jm@nospam.fr>
Subject: Re: sample client server socket issue
Message-Id: <47d08508$0$21151$7a628cd7@news.club-internet.fr>
Ben Morrow a écrit :
> Quoth jm <jm@nospam.fr>:
>> I have written some perl client program and javascript server program.
>>
>> Communication seams working in both direction, but the perl client
>> cannot read final data.
>>
>> Perl use socket in blocking mode (default).
>> I open the connection with localhost, port number, and tcp.
>>
>> When I read packets with a size of 512 or 4096, everything works fine
>> till the last packet. As the last packet is smaller than 4096, perl stay
>> blocked waiting for a complete packet.
> When you say 'last packet', do you mean 'last packet before the
> connection is closed' or 'last packet in this request'?
I mean the server send several lines of text, then an empty line.
Then the server wait for the client.
All theses lines of text are assembled by network stacks in buffers of
4096 bytes, but last characters wont.
> If you mean the
> former, then Perl will return an incomplete packet even in blocking
> mode.
> If the latter, then you need to set the socket to non-blocking
> mode, and be prepared to handle short reads all the way through. You
> will also need to use IO::Select to wait for data after you get a short
> read.
>
> Ben
>
I was believing blocking mode better than non blocking!
------------------------------
Date: 06 Mar 2008 23:58:54 GMT
From: xhoster@gmail.com
Subject: Re: sample client server socket issue
Message-Id: <20080306185857.693$cv@newsreader.com>
Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth jm <jm@nospam.fr>:
...
> > When I read packets with a size of 512 or 4096, everything works fine
> > till the last packet. As the last packet is smaller than 4096, perl
> > stay blocked waiting for a complete packet.
>
> When you say 'last packet', do you mean 'last packet before the
> connection is closed' or 'last packet in this request'? If you mean the
> former, then Perl will return an incomplete packet even in blocking
> mode. If the latter, then you need to set the socket to non-blocking
> mode,
I have never seen this behavior with sysread. The only time I've seen
sysread block is when the alternative is to read 0 bytes (and of course
not even then when set to non-blocking). It happily does short non-zero
length reads when the alternative is blocking, even without setting it to
non-blocking mode.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Fri, 7 Mar 2008 02:22:41 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: sample client server socket issue
Message-Id: <hgl6a5-07h.ln1@osiris.mauzo.dyndns.org>
Quoth xhoster@gmail.com:
> Ben Morrow <ben@morrow.me.uk> wrote:
> > Quoth jm <jm@nospam.fr>:
> ...
> > > When I read packets with a size of 512 or 4096, everything works fine
> > > till the last packet. As the last packet is smaller than 4096, perl
> > > stay blocked waiting for a complete packet.
> >
> > When you say 'last packet', do you mean 'last packet before the
> > connection is closed' or 'last packet in this request'? If you mean the
> > former, then Perl will return an incomplete packet even in blocking
> > mode. If the latter, then you need to set the socket to non-blocking
> > mode,
>
> I have never seen this behavior with sysread. The only time I've seen
> sysread block is when the alternative is to read 0 bytes (and of course
> not even then when set to non-blocking). It happily does short non-zero
> length reads when the alternative is blocking, even without setting it to
> non-blocking mode.
Yes, you would seem to be correct, at least here (FreeBSD). I don't know
what's going on for the OP, then.
Ben
------------------------------
Date: 07 Mar 2008 03:58:27 GMT
From: Abigail <abigail@abigail.be>
Subject: Re: sample client server socket issue
Message-Id: <slrnft1fb3.q8.abigail@alexandra.abigail.be>
_
jm (jm@nospam.fr) wrote on VCCCI September MCMXCIII in
<URL:news:47d08508$0$21151$7a628cd7@news.club-internet.fr>:
!!
!! I was believing blocking mode better than non blocking!
If you think this is universal, why do you think there's non-blocking mode?
Abigail
--
A perl rose: perl -e '@}>-`-,-`-%-'
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1339
***************************************