[25616] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 7860 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 5 14:05:54 2005

Date: Sat, 5 Mar 2005 11:05:20 -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           Sat, 5 Mar 2005     Volume: 10 Number: 7860

Today's topics:
        Another use vs. require snafu <jkrugman345@yahbitoo.com>
    Re: Another use vs. require snafu <jkeen_via_google@yahoo.com>
    Re: Another use vs. require snafu <nobull@mail.com>
    Re: Another use vs. require snafu <jkrugman345@yahbitoo.com>
    Re: Another use vs. require snafu <jkrugman345@yahbitoo.com>
    Re: clpannounce problem <noreply@gunnar.cc>
    Re: clpannounce problem <1usa@llenroc.ude.invalid>
    Re: comparing two numbers (Anno Siegel)
    Re: comparing two numbers <postmaster@castleamber.com>
    Re: how to convert bit vectors to hex <newspost@kohombanDELETE.net>
    Re: LibXML UTF8 - Input is not proper UTF-8, indicate e <nobull@mail.com>
    Re: LibXML UTF8 - Input is not proper UTF-8, indicate e <groleau+news@freeshell.org>
    Re: negative backreference? <nospam-abuse@ilyaz.org>
    Re: negative backreference? (Anno Siegel)
        print isn't flashed using PERL by MSWin32 on Windows XP <e_rozenblat@hotmail.com>
    Re: print isn't flashed using PERL by MSWin32 on Window <newspost@kohombanDELETE.net>
    Re: print isn't flashed using PERL by MSWin32 on Window <e_rozenblat@hotmail.com>
    Re: print isn't flashed using PERL by MSWin32 on Window <e_rozenblat@hotmail.com>
    Re: print isn't flashed using PERL by MSWin32 on Window <1usa@llenroc.ude.invalid>
    Re: qx, Filter::Simple, and testing (Peter Scott)
        TCP/UDP Question <snail@localhost.com>
    Re: TCP/UDP Questions <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 5 Mar 2005 16:41:41 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Another use vs. require snafu
Message-Id: <d0cng4$hrr$1@reader1.panix.com>





I've spent more hours than I care to admit trying to understand
the difference between Perl's use and require, and I discovered
today that all this effort has been a miserable waste of time,
because use and require *still* confound my attempts at coding.
For example.

I have a method "a" in package A that must invoke a class method
"b" from a package B, and the identity of package B is not known
until runtime.

  package A;
  #...
  sub a {
    my ($self, $package) = @_;
    # use B;
    eval { "require $package; 1" } or die "Have a cow";

    $package->b;
  }

In the form above, perl dies with a message "Can't locate object
method "b" via package "B" (perhaps you forgot to load "B"?)".  If
I uncomment the "use B;" statement (and comment out the eval line),
the code runs fine, but of course this solution is not acceptable,
because I can't hard-code the package name.

I don't understand why perl will load B (via the eval'ed require
statement) without any errors, and still fail to find method b in
B.  What gives?

TIA!

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



------------------------------

Date: Sat, 05 Mar 2005 17:09:24 GMT
From: Jim Keenan <jkeen_via_google@yahoo.com>
Subject: Re: Another use vs. require snafu
Message-Id: <8JlWd.42600$ya6.993@trndny01>

J Krugman wrote:
> I've spent more hours than I care to admit trying to understand
> the difference between Perl's use and require, and I discovered
> today that all this effort has been a miserable waste of time,
> because use and require *still* confound my attempts at coding.
> For example.
> 
> I have a method "a" in package A that must invoke a class method
> "b" from a package B, and the identity of package B is not known
> until runtime.
> 
>   package A;
>   #...
>   sub a {
>     my ($self, $package) = @_;
>     # use B;
>     eval { "require $package; 1" } or die "Have a cow";
> 
>     $package->b;
>   }
> 
> In the form above, perl dies with a message "Can't locate object
> method "b" via package "B" (perhaps you forgot to load "B"?)".  If
> I uncomment the "use B;" statement (and comment out the eval line),
> the code runs fine, but of course this solution is not acceptable,
> because I can't hard-code the package name.
> 
> I don't understand why perl will load B (via the eval'ed require
> statement) without any errors, and still fail to find method b in
> B.  What gives?
> 

This may or may not be the problem:

"B" is part of the name of several core modules as well as a top-level 
namespace on CPAN.  If the code above is the code you're actually having 
problems with, re-code with less problematic names.

jimk


------------------------------

Date: Sat, 05 Mar 2005 17:23:55 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Another use vs. require snafu
Message-Id: <d0cpl9$llo$1@sun3.bham.ac.uk>



J Krugman wrote:

> I've spent more hours than I care to admit trying to understand
> the difference between Perl's use and require,

And I just spent a long time looking at the code before I saw the mistake.

>     eval { "require $package; 1" } or die "Have a cow";

> I don't understand why perl will load B (via the eval'ed require
> statement) without any errors

It does not.  Look at the shape of those brackets - what perl does 
without error is simply construct the string 'require B; 1'.  Remove the {}.

Note: B is the name of a standard module and therefore not one you 
should use for your own modules.


, and still fail to find method b in
> B.  What gives?

Inspect $INC{'B.pm'} to see which B was loaded - perhaps it loaded the 
standard module of that name rather than your module.
> 
> TIA!
> 
> jill
> 



------------------------------

Date: Sat, 5 Mar 2005 17:29:27 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Another use vs. require snafu
Message-Id: <d0cq9n$n2s$1@reader1.panix.com>

In <8JlWd.42600$ya6.993@trndny01> Jim Keenan <jkeen_via_google@yahoo.com> writes:

>J Krugman wrote:
>> I've spent more hours than I care to admit trying to understand
>> the difference between Perl's use and require, and I discovered
>> today that all this effort has been a miserable waste of time,
>> because use and require *still* confound my attempts at coding.
>> For example.
>> 
>> I have a method "a" in package A that must invoke a class method
>> "b" from a package B, and the identity of package B is not known
>> until runtime.
>> 
>>   package A;
>>   #...
>>   sub a {
>>     my ($self, $package) = @_;
>>     # use B;
>>     eval { "require $package; 1" } or die "Have a cow";
>> 
>>     $package->b;
>>   }
>> 
>> In the form above, perl dies with a message "Can't locate object
>> method "b" via package "B" (perhaps you forgot to load "B"?)".  If
>> I uncomment the "use B;" statement (and comment out the eval line),
>> the code runs fine, but of course this solution is not acceptable,
>> because I can't hard-code the package name.
>> 
>> I don't understand why perl will load B (via the eval'ed require
>> statement) without any errors, and still fail to find method b in
>> B.  What gives?
>> 

>This may or may not be the problem:

>"B" is part of the name of several core modules as well as a top-level 
>namespace on CPAN.

I used the names A and B for the sake of the example.  The real
names of the modules are much longer.

If anyone wants to test what I described in my original post, I
give some code below.  Three files, Foo.pm, Bar.pm, frobozz.pl.
Run "perl frobozz.pl".  I get the same results with 5.6.1 and 5.8.4.

jill


# Foo.pm

package Foo;
use strict;

sub foo {
  my $package = $_[1];
  # use Bar;
  # For a good time, uncomment the previous line and (optionally)
  # comment out the next one.
  eval { "require $package; 1" } or die "Couldn't load $package\n";

  $package->bar;
}

1;

__END__

# Bar.pm

package Bar;
use strict;

sub bar {
  warn "Hello from Bar::bar\n";
}

1;

__END__

# frobozz.pl

use strict;
use Foo;

Foo->foo('Bar');

__END__

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



------------------------------

Date: Sat, 5 Mar 2005 17:49:03 +0000 (UTC)
From: J Krugman <jkrugman345@yahbitoo.com>
Subject: Re: Another use vs. require snafu
Message-Id: <d0cref$45r$1@reader1.panix.com>

In <d0cpl9$llo$1@sun3.bham.ac.uk> Brian McCauley <nobull@mail.com> writes:

>J Krugman wrote:

>> I've spent more hours than I care to admit trying to understand
>> the difference between Perl's use and require,

>And I just spent a long time looking at the code before I saw the mistake.

>>     eval { "require $package; 1" } or die "Have a cow";

>> I don't understand why perl will load B (via the eval'ed require
>> statement) without any errors

>It does not.  Look at the shape of those brackets - what perl does 
>without error is simply construct the string 'require B; 1'.  Remove the {}.

Thanks!!!

>, and still fail to find method b in
>> B.  What gives?

>Inspect $INC{'B.pm'} to see which B was loaded - perhaps it loaded the 
>standard module of that name rather than your module.

Inspecting %INC is something I should have done after that bogus
eval statement and before the method call.

'nother burn, 'nother lurn.

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



------------------------------

Date: Sat, 05 Mar 2005 06:53:00 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: clpannounce problem
Message-Id: <38svopF5s02atU1@individual.net>

brian d foy wrote:
> It's not as if anyone actually pays attention to clpa anyway, and there
> are many other ways to announce modules. You're making a big stink and
> embarrassing yourself over something that has almost no value.

     http://faq.perl.org/perlfaq2.html#What_are_the_Perl_ne

CLPA is the first mentioned group in that FAQ entry. Seems like a 
revision highly advisable.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Sat, 05 Mar 2005 13:02:28 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: clpannounce problem
Message-Id: <Xns961051CD4EA1Basu1cornelledu@127.0.0.1>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in news:38svopF5s02atU1
@individual.net:

> brian d foy wrote:
>> It's not as if anyone actually pays attention to clpa anyway, and there
>> are many other ways to announce modules. You're making a big stink and
>> embarrassing yourself over something that has almost no value.
> 
>      http://faq.perl.org/perlfaq2.html#What_are_the_Perl_ne
> 
> CLPA is the first mentioned group in that FAQ entry. Seems like a 
> revision highly advisable.

FYI, the list is in alphabetical order.

Sinan


------------------------------

Date: 5 Mar 2005 07:04:12 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: comparing two numbers
Message-Id: <d0bllc$pdv$1@mamenchi.zrz.TU-Berlin.DE>

David Wall  <darkon.tda@gmail.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
> > David K. Wall <darkon.tdo@gmail.com> wrote in
> > comp.lang.perl.misc: 
> >> John Bokma <postmaster@castleamber.com> wrote:
> >> > David K. Wall wrote:
> >> > 
> >> >> if ( 1 == keys %hash ) {
> >> >>     print "All the same\n";
> >> > 
> >> > Aargh, keys %hash = 1 with warnings on gives:
> >> > Found = in conditional, should be == at ...
> >> > 
> >> > Never understood crippled^H^H^H^H^H^H^H^Hdefensive
> >> > programming :-( 
> >> 
> >> It wasn't intended to be defensive.  I typed it that way
> >> because I was too lazy to type an extra set of parentheses. 
> >> :-) 
> > 
> > But you don't have to.  "keys" binds tightly enough for "keys
> > %hash == 1" to work.  The warning about "=" instead of "==" is
> > unrelated. 
> 
> I trust you to be correct, but if I'm too lazy to type a set of 
> parentheses, what makes you think I remember or will check to see 
> how tightly keys() binds?  <smile>

Ah, but then John was right in seeing it as defensive programing.

Anno


------------------------------

Date: 5 Mar 2005 08:00:11 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: comparing two numbers
Message-Id: <Xns96101460A6DA0castleamber@130.133.1.4>

Anno Siegel wrote:

> David Wall  <darkon.tda@gmail.com> wrote in comp.lang.perl.misc:
>> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>> > David K. Wall <darkon.tdo@gmail.com> wrote in
>> > comp.lang.perl.misc: 
>> >> John Bokma <postmaster@castleamber.com> wrote:
>> >> > David K. Wall wrote:
>> >> > 
>> >> >> if ( 1 == keys %hash ) {
>> >> >>     print "All the same\n";
>> >> > 
>> >> > Aargh, keys %hash = 1 with warnings on gives:
>> >> > Found = in conditional, should be == at ...
>> >> > 
>> >> > Never understood crippled^H^H^H^H^H^H^H^Hdefensive
>> >> > programming :-( 
>> >> 
>> >> It wasn't intended to be defensive.  I typed it that way
>> >> because I was too lazy to type an extra set of parentheses. 
>> >> :-) 
>> > 
>> > But you don't have to.  "keys" binds tightly enough for "keys
>> > %hash == 1" to work.  The warning about "=" instead of "==" is
>> > unrelated. 
>> 
>> I trust you to be correct, but if I'm too lazy to type a set of 
>> parentheses, what makes you think I remember or will check to see 
>> how tightly keys() binds?  <smile>
> 
> Ah, but then John was right in seeing it as defensive programing.

:-D or maybe :-(.

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


------------------------------

Date: Sat, 05 Mar 2005 17:50:22 +0800
From: GreenLeaf <newspost@kohombanDELETE.net>
Subject: Re: how to convert bit vectors to hex
Message-Id: <38tdplF5qfn4eU1@individual.net>

Jeff Stampes wrote:

> As you can tell from my email address, the people I work around know 
> something about VHDL and processors :)

Now THAT was a funny coincidence :p


------------------------------

Date: Sat, 05 Mar 2005 14:24:15 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: LibXML UTF8 - Input is not proper UTF-8, indicate encoding !
Message-Id: <d0cf4e$gpd$1@sun3.bham.ac.uk>



Vlajko Knezic wrote:

> Not so sure what is going on here but is something to do with the way UTF8 
> is handled in Perl and/or LibXML

I've seen something similar - I fixed it by performing an explicit 
utf8::upgrade() on every string before passing it to any of the LibXML 
library methods.

If that doesn't help then it looks to me like this could be an issue 
with CGI.pm and/or your web browser.

> Everything works well until UTF8 character is entered in the text field (for 
> example é) .

I suspect this is not what is happening.  It appears that the browser is
sending the form sumbission data using some other encoding (e.g. Latin1(
and Perl's CGI.pm is assuming it's UTF8 thus generating an invalid utf8
string.

>       <input type="text" name="test" />

Since your text field does not specify an encoding the browser is free
to choose any it likes but the recommendation is that it should choose
the one used to encode the document containing the form.  I notice your
document contains:

>     <meta http-equiv="Content-Type" content="text/html;
>     charset=utf-8"/>

I would not expect Content-Type to be setable via <meta> but then again
I may be wrong.

For more informed discussion about this I suggest you
go to a group where discussion of how browsers handle HTML forms is
on-topic.



------------------------------

Date: Sat, 05 Mar 2005 12:19:55 -0500
From: Wes Groleau <groleau+news@freeshell.org>
Subject: Re: LibXML UTF8 - Input is not proper UTF-8, indicate encoding !
Message-Id: <38u81eF5ql4u7U1@individual.net>

Brian McCauley wrote:
> document contains:
> 
>>     <meta http-equiv="Content-Type" content="text/html;
>>     charset=utf-8"/>
> 
> I would not expect Content-Type to be setable via <meta> but then again
> I may be wrong.

That tag works on all my web pages, on numerous Mac and windoze browsers.

-- 
Wes Groleau

Truth often suffers more from the heat of its defenders
than from the arguments of its opposers.
                        -- William Penn


------------------------------

Date: Sat, 5 Mar 2005 10:43:05 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: negative backreference?
Message-Id: <d0c2fp$2ib2$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
Anno Siegel
<anno4000@lublin.zrz.tu-berlin.de>], who wrote in article <d0aq0m$a3t$1@mamenchi.zrz.TU-Berlin.DE>:
> That reports "AAA", the case where both are equal.  Now turn the sense
> of the test around, wrapping the backreference in a negative lookahead:
> 
>     for ( ( 'rdns=AAA helo=AAA', 'rdns=BBB helo=AAA') ) {
>         print "got <$1>\n" if /rdns=(.*) helo=(?!\1)/;
>     }   
> 
> Now it reports "BBB".  That's it.

Do not think so.  One needs some anchor at the end.  Something like

  /rdns=(\w+) helo=(?!\1\b)/;

(mutatis mutandis).  Having different match than \w+ will lead so more
complicated stuff than \b...  In perfect life, one would use something
like my (proposed) onion rings:

  /rdns=(\S*) helo=(?& \S* & (?!\1)/;

Hope this helps,
Ilya


------------------------------

Date: 5 Mar 2005 11:13:22 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: negative backreference?
Message-Id: <d0c48i$39r$1@mamenchi.zrz.TU-Berlin.DE>

Ilya Zakharevich  <nospam-abuse@ilyaz.org> wrote in comp.lang.perl.misc:
> [A complimentary Cc of this posting was sent to
> Anno Siegel
> <anno4000@lublin.zrz.tu-berlin.de>], who wrote in article
> <d0aq0m$a3t$1@mamenchi.zrz.TU-Berlin.DE>:
> > That reports "AAA", the case where both are equal.  Now turn the sense
> > of the test around, wrapping the backreference in a negative lookahead:
> > 
> >     for ( ( 'rdns=AAA helo=AAA', 'rdns=BBB helo=AAA') ) {
> >         print "got <$1>\n" if /rdns=(.*) helo=(?!\1)/;
> >     }   
> > 
> > Now it reports "BBB".  That's it.
> 
> Do not think so.  One needs some anchor at the end.  Something like
> 
>   /rdns=(\w+) helo=(?!\1\b)/;

That's right.

> (mutatis mutandis).  Having different match than \w+ will lead so more
> complicated stuff than \b...  In perfect life, one would use something
> like my (proposed) onion rings:
> 
>   /rdns=(\S*) helo=(?& \S* & (?!\1)/;

Is that proposal available somewhere?  I'm not sure how "(?&" is supposed
to work.  Should the parens balance?

Anno


------------------------------

Date: 5 Mar 2005 02:53:16 -0800
From: "reyal" <e_rozenblat@hotmail.com>
Subject: print isn't flashed using PERL by MSWin32 on Windows XP
Message-Id: <1110019996.527609.319500@z14g2000cwz.googlegroups.com>

Hi,
  I am using on WindowsXP home edition, PERL edition identified as
"v5.8.6 built for MSWin32-x86-multi-thread".

When using the print command, it doesn't flash the output string if
there is no "\n" at the end of the string.

Is this configurable or do I have to live with it?

Thanks,
Eyal



------------------------------

Date: Sat, 05 Mar 2005 19:28:56 +0800
From: GreenLeaf <newspost@kohombanDELETE.net>
Subject: Re: print isn't flashed using PERL by MSWin32 on Windows XP
Message-Id: <38tjidF5r5palU1@individual.net>

reyal wrote:
> When using the print command, it doesn't flash the output string if
> there is no "\n" at the end of the string.
> 
> Is this configurable or do I have to live with it?
> 

It is configurable. :)

Simple answer, set the variable $| = 1 before you print.
WHY is explained here:
http://www.perl.com/doc/manual/html/pod/perlvar.html

Look for "autoflush".

Cheers,
sat


------------------------------

Date: 5 Mar 2005 04:55:48 -0800
From: "reyal" <e_rozenblat@hotmail.com>
Subject: Re: print isn't flashed using PERL by MSWin32 on Windows XP
Message-Id: <1110027347.990871.236060@g14g2000cwa.googlegroups.com>

Thanks indeed.



------------------------------

Date: 5 Mar 2005 05:27:02 -0800
From: "reyal" <e_rozenblat@hotmail.com>
Subject: Re: print isn't flashed using PERL by MSWin32 on Windows XP
Message-Id: <1110029222.643082.61680@f14g2000cwb.googlegroups.com>

Sorry to bother again, but it doesn't work. And when looking again in
this group I found this problem already reported some 9 years ago:

************************************************************

 Tungning Cherng   Sep 9 1996, 12:00 am     show options

Newsgroups: comp.lang.perl.misc
From: che...@uumanbbn.com (Tungning Cherng ) - Find messages by this
author
Date: 1996/09/09
Subject: flush stdout with eof
Reply to Author | Forward | Print | Individual Message | Show original
| Report Abuse

The following script
- without 'if (eof)' statement, the output will show up when I type the
input
  right away (which as I expect.)
- with 'eof' (as the script), the output will delay.  The first line
input
  won't show up until the second line input is entered
  (which I don't understand.)

I thought I put "select(STDOUT); $|=1;" to flush out the output.  But
it
does not work.

#!/usr/local/bin/perl
select(STDOUT); $|=1;
while (<STDIN>)
{
  print "before \n";
  if (eof)
  {
    print "lastline-> $_";
    last;
  }
  print "output-> $_";
}


The output looks like:
first line
before
second line
output-> first line
before
lastline-> second line     (I typed ^D to eof)

Can someone explain?

Thanks,
Donnie


*******************************************************************************
I'm not sure that they originate from the same problem, but still I
don't have a solution. For now I simply add "\n"s.

Thanks anyway,
Eyal



------------------------------

Date: Sat, 05 Mar 2005 15:27:23 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: print isn't flashed using PERL by MSWin32 on Windows XP
Message-Id: <Xns96106A5EE926Basu1cornelledu@127.0.0.1>

"reyal" <e_rozenblat@hotmail.com> wrote in
news:1110029222.643082.61680@f14g2000cwb.googlegroups.com: 

> Subject: Re: print isn't flashed using PERL by MSWin32 on Windows XP

'flash' and 'flush' are two different things. ITYM 'flush'.

Not PERL, Perl.

> Sorry to bother again, but it doesn't work.

What doesn't work? Please quote an appropriate amount of context when 
you are responding. Please read the posting guidelines posted here 
regularly.

> And when looking again in this group I found this problem already 
> reported some 9 years ago:
> 
> ************************************************************
> 
>  Tungning Cherng   Sep 9 1996, 12:00 am     show options

There is no point in cutting and pasting from Google like this. What if 
I wanted to check other messages in that thread? It would have been far 
more useful to use the message ID to refer to the message.

> I'm not sure that they originate from the same problem, but
> still I don't have a solution. For now I simply add "\n"s.

Maybe I am very easily confused, but this got me curious so I decided to 
test is myself. Here is the code:

#! /usr/bin/perl

use strict;
use warnings;

$| = 1;

while(<STDIN>) {
    print "$. << ";
    if (eof) {
        print "lastline: $_";
    } else {
        print "entered: $_";
    }
}

__END__

Notice that I am not chomp'ing $_ after input. So, I would expect to see 
the following when I run this script:

D:\Home\asu1\UseNet\clpmisc> t
one
1 << entered : one
two
2 << entered : two
 ...

In fact, I would have expected this output even without setting 
autoflush on. Instead, what get is:

D:\Home\asu1\UseNet\clpmisc> t
one
1 << two
entered : one
2 << three
entered : two
3 << 
 ...

If I change the code to:

#! /usr/bin/perl

use strict;
use warnings;

my $t = time;

while(<STDIN>) {
    print "$. << ";
    if ($t > time) {
        print "lastline : $_";
    } else {
        print "entered : $_";
    }
}

__END__

I get:

D:\Home\asu1\UseNet\clpmisc> t
one
1 << entered : one
two
2 << entered : two
 ...

So, the culprit seems to be the call to eof.

Now, the documentation of eof does indeed state that it is not very 
useful in an interactive setting, and I do not think I have a line of 
code anywhere with a call to eof in it (be it C, Java or Perl). Granting 
that, I am still a little confused about this behavior.

Sinan.


------------------------------

Date: Sat, 05 Mar 2005 10:39:56 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: qx, Filter::Simple, and testing
Message-Id: <00gWd.577940$6l.368218@pd7tw2no>

In article <d0au0t$dkk$1@mamenchi.zrz.TU-Berlin.DE>,
 anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>Abigail  <abigail@abigail.nl> wrote in comp.lang.perl.misc:
>> 
>> I'm working on a module that uses source filtering, using Filter::Simple.
>> One of the things it does is replacing certain constructs inside double
>> quoted environments, like "", qq {}, etc. Testing "", s///, m//, qq{}
>> is fairly straightforward. 
>> 
>> I'm looking for ideas on how to test qx{} (and ``). It should work on
>> any platform Perl works on, and it should be safe.
>
>So you want something that can be safely executed on every system that
>runs Perl (whatever "execute" means on that system).  Is that what you're
>getting at?  If not, apologies.

The one executable you can count on being there is perl, so I
would think executing `$^X -v` would be pretty safe.  Although
according to perlvar there are platforms that don't support
command output capture to begin with.

-- 
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/


------------------------------

Date: Sat, 5 Mar 2005 07:07:27 -0800
From: "Snail" <snail@localhost.com>
Subject: TCP/UDP Question
Message-Id: <d0chtd$tam$1@news.astound.net>

I've been playing around with the following example code:

----------------------------------------------------------------------
#!/usr/bin/perl -w

use strict;
use IO::Socket;

$| = 1;

my $msgin;
my $listenport = 9999;
my $maxlen = 5000;
my $port = shift || $listenport;
$SIG{'INT'} = sub {exit 0};
my $sock = IO::Socket::INET->new(Proto=>'udp',LocalPort=>$port) or die
"Cannot open socket!";

while( $sock -> recv ( $msgin, $maxlen ) ) {
   next if fork;
   do_stuff_with( $msgin );
}
----------------------------------------------------------------------

And similar examples for tcp using accept().

My question is (mainly for TCP servers), if you fork the server, how can 
you then communicate between multiple connected clients?

Seems to that, say if one client conencts, then at soem point issues a 
command like "view all" there seems to be no way to itterate through the 
clients to send backa reponse. In other words, client A is forked, data 
is recieved from it, but since it is forked, it wont know of the other 
clients. Even if the server's process (the original/main process) 
maintains a list of all clients, when a client is forked, and then other 
clients connect, then the version of the list the forked client "sees" 
will be not be updated as new clients connect (or if old ones 
disconenct.)

What is a good solution for this?





------------------------------

Date: Sat, 05 Mar 2005 17:12:20 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: TCP/UDP Questions
Message-Id: <d0covk$ld0$1@sun3.bham.ac.uk>

Snail wrote:

 > Re: TCP/UDP Question

The word "question" can, and usually should, be omitted in subject lines.

I don't think your question is related to TCP/UDP.


> I've been playing around with the following example code:

> my $sock = IO::Socket::INET->new(Proto=>'udp',LocalPort=>$port) or die
> "Cannot open socket!";
> 
> while( $sock -> recv ( $msgin, $maxlen ) ) {
>    next if fork;
>    do_stuff_with( $msgin );
> }
> ----------------------------------------------------------------------
> 
> And similar examples for tcp using accept().

And fork()!  Very significantly fork().

> My question is (mainly for TCP servers),

So why did you show us the code for UDP server that has nothing to do 
with your problem?

 > if you fork the server, how can
> you then communicate between multiple connected clients?

Right, that is your question.  You want to know how can you communicate 
between forked processes.

The usual suspects are:
   Shared memory.
   Temporary files.
   Sockets.

If communication needs not be fast then temporary files are probably 
simplest.  There are also various modules on CPAN to allow you to tie 
variables to shared memory or files so that you can simpl set the value 
in on process and read it in another.



------------------------------

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 V10 Issue 7860
***************************************


home help back first fref pref prev next nref lref last post