[28467] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 9831 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 10 21:10:17 2006

Date: Tue, 10 Oct 2006 18:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 10 Oct 2006     Volume: 10 Number: 9831

Today's topics:
    Re: LWP and Unicode <jurgenex@hotmail.com>
    Re: LWP and Unicode <hjp-usenet2@hjp.at>
        No response from printer using Win32::SerialPort <woodycm@gmail.com>
    Re: return a series of matches from a hash lookup (reading news)
    Re: second substitution to work only on a found pattern <someone@example.com>
        Select <na@noaddress.com>
    Re: Select xhoster@gmail.com
    Re: Select <na@noaddress.com>
    Re: Select <na@noaddress.com>
    Re: Select <jgibson@mail.arc.nasa.gov>
    Re: Select xhoster@gmail.com
    Re: Select <na@noaddress.com>
    Re: Select <na@noaddress.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 10 Oct 2006 18:15:28 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: LWP and Unicode
Message-Id: <4rRWg.2308$HP.1701@trndny08>

Ted Zlatanov wrote:
> On  6 Oct 2006, benmorrow@tiscali.co.uk wrote:
>
>> It's not a question of this group's charter, it applies generally on
>> Usenet. There is no header in a Usenet article that specifies a
>> charset, so no way to use anything other than the default ASCII.
>>
>> I agree in principle: some form of charset header should be added, or
>> the charset should simply be specified to be UTF8. But until it is,
>> please refrain from using it.
>
> So there are really two questions:
>
> 1) are there any newsreaders that would cause problems when they found
>   UTF-8 encoded text?  Anything from a crash to an unusable session
>   would qualify (if Ctrl-L fixes it, I wouldn't consider it a
>   significant problem).

It is not only a question of newsreaders supporting UTF-8 but because Usenet 
was designed for ASCII (and that was never changed) there is no guarantee 
the all gateways and switches are 8-bit clean and won't corrupt messages 
that use 8 bits.

> 2) why not do a vote to change the charter to make UTF-8 the charset
>   for c.l.p.m?

Well, that's like a small town deciding that within its boundaries everyone 
should drive on the left side of the road.

jue 




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

Date: Tue, 10 Oct 2006 21:38:15 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: LWP and Unicode
Message-Id: <slrneintl7.g19.hjp-usenet2@yoyo.hjp.at>

On 2006-10-10 18:15, Jürgen Exner <jurgenex@hotmail.com> wrote:
> Ted Zlatanov wrote:
>> On  6 Oct 2006, benmorrow@tiscali.co.uk wrote:
>>
>>> It's not a question of this group's charter, it applies generally on
>>> Usenet. There is no header in a Usenet article that specifies a
>>> charset, so no way to use anything other than the default ASCII.

Content-Type: text/plain; charset=...

Introduced in RFC 1341 (June 1992). It is true that RFC 1036 was never
updated, but MIME is current practice on usenet.


>>> I agree in principle: some form of charset header should be added, or
>>> the charset should simply be specified to be UTF8. But until it is,
>>> please refrain from using it.
>>
>> So there are really two questions:
>>
>> 1) are there any newsreaders that would cause problems when they found
>>   UTF-8 encoded text?

There are some valid UTF-8 sequences which cause problems when they are
sent verbatim to a VT100-descended terminal. Of course there are also
ASCII sequences which will do that, so any newsreader which doesn't
filter unsafe characters is broken anyway.


> It is not only a question of newsreaders supporting UTF-8 but because Usenet 
> was designed for ASCII (and that was never changed) there is no guarantee 
> the all gateways and switches are 8-bit clean and won't corrupt messages 
> that use 8 bits.

There is no guarantee, but in practice 7-bit-ASCII based newsservers
stopped being a problem in early nineties - even before MIME was invented
(this may even have slowed down adoption of MIME in usenet - if you could
use any 8-bit-charset by convention (like ISO-8859-1 in de.* and fr.*),
why implement a baroque encoding scheme? In E-Mail MIME was necessary
because of sendmail's, er, interesting interpretation of the robustness
principle). EBCDIC hosts were a problem a bit longer, but they weren't
nice to pure ASCII postings, either.

>> 2) why not do a vote to change the charter to make UTF-8 the charset
>>   for c.l.p.m?
>
> Well, that's like a small town deciding that within its boundaries everyone 
> should drive on the left side of the road.

In the rest of the country everybody drives whereever they please :-).

Seriously: As much as I liked the USEFOR proposal to make UTF-8 the
default charset (instead of ASCII) on usenet, and as much as I dislike
MIME, I don't think declaring UTF-8 to be the default charset for a
single group would be a good idea. Charsets should be properly declared
in a MIME Content-Type header. As long as the charset is correctly
encoded, I think any reasonably widespread charset (and that includes
UTF-8) should be acceptable.

	hp

-- 
   _  | Peter J. Holzer    | > Wieso sollte man etwas erfinden was nicht
|_|_) | Sysadmin WSR       | > ist?
| |   | hjp@hjp.at         | Was sonst wäre der Sinn des Erfindens?
__/   | http://www.hjp.at/ |	-- P. Einstein u. V. Gringmuth in desd


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

Date: 10 Oct 2006 11:55:17 -0700
From: "woodycm" <woodycm@gmail.com>
Subject: No response from printer using Win32::SerialPort
Message-Id: <1160506517.896396.130800@i42g2000cwa.googlegroups.com>

I've posted this topic on Perlmonks.org as well...

I am using Win32::SerialPort to communicate (ie print) with a PAXAR
9855 printer. I can poll the printer status using Windows Terminal and
PAXAR's own gui tool, but cannot get a response from my perl program
(attached below). The print part works fine, it's the read that doesn't
work. Actually when SerialPort.pm runs, the got_p scalar, which is
where I believe the response from the device is populated, is blank (as
in null/nothing).

Any help in pointing me to where I have gone wrong, would be greatly
appreciated.
Thanks


Begin Code....

#!c:\perl\bin\perl
require 5.002;
use Win32;
use Win32::SerialPort;
use Win32::API;

$SerialPort = "COM1";
$ENQ = "^E";

$Port = Win32::SerialPort->new($SerialPort);
$Port->baudrate(9600)           || die "failed setting baudrate";
$Port->parity("none")           || die "failed setting parity";
$Port->databits(8)              || die "failed setting databits";
$Port->stopbits(1)              || die "failed setting databits";
$Port->handshake("xoff")        || die "failed setting handshake";
$flowcontrol = $Port->handshake || die "failed setting flowcontrol";

$Port->user_msg(1);
$Port->error_msg(1);
$Port->debug(1);

$Port->write_settings    || die "no settings";

#Write Immediate command to allow for Polling.
print "Send Immediate Command\n";
$Port->write('{I,E,"~123~044~034~124~125~126~094"|}');

#Print Label
$record_to_print = '';
$record_to_print = $record_to_print.'{F,26,A,R,E,600,400,"FMT26"|';
$record_to_print =
$record_to_print.'C,400,50,0,50,16,16,O,L,0,0,"CARTON",0|}';
$record_to_print = $record_to_print.'{B,26,N,1|}';
$Port->write($record_to_print);
sleep 2;

#Read from Printer
undef $msg;
($count, $msg) = $Port->read(4); # Read string 1
$code1 = substr($msg,1,1);
$code2 = substr($msg,2,1);
print "DATA = $msg | COUNT = $count\n";
print "CODE1 = $code1\n";
print "CODE2 = $code2\n";
sleep 2;

#Print ENQ to poll printer
$Port->write("^E");

#Read from Printer
undef $msg;
$msg = $Port->read(3); # Read string 1
$code1 = substr($msg,1,1);
$code2 = substr($msg,2,1);
print "DATA = $msg\n";
print "CODE1 = $code1\n";
print "CODE2 = $code2\n";

End Code....



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

Date: Tue, 10 Oct 2006 20:53:30 GMT
From: "Mumia W. (reading news)" <paduille.4059.mumia.w@earthlink.net>
Subject: Re: return a series of matches from a hash lookup
Message-Id: <eLTWg.5497$Lv3.2029@newsread1.news.pas.earthlink.net>

On 10/10/2006 09:37 AM, Jack wrote:
> Hello,
> 
> I have been using the T/F exists with hashlookups successfully like
> this:
> if (exists $hash{$inputvalue}) {   }
> 
> But, can anyone provide a code example of doing a lookup that returns
> all the values which find a hash match in the event there is more than
> 1 match, allowing me to process those values ?
> 
> Thank you,
> 
> Jack
> 

Computer programming is a matter of precision--in both source code and 
terminology. I'm assuming that you were completely precise and accurate 
in requesting the hash values (however most people want the keys first):

my @matches = grep /mycriteria/, values %hash;

The above assumes that the hash values are strings.

Note, for keys, there will always be only one key with a particular 
value in a hash.

-- 
Mumia W.
paduille.4059.mumia.w@earthlink.net
This is a temporary e-mail to help me catch some s-p*á/m.


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

Date: Tue, 10 Oct 2006 21:33:21 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: second substitution to work only on a found pattern
Message-Id: <BkUWg.4701$P7.1485@edtnps90>

I.M. Postor wrote:
> 
> On Mon, 09 Oct 2006 18:36:20 GMT, John W. Krahn wrote:
> 
>> $slurped_text =~ s{(<(c0[1-9]|c1[012]) level="file">.*?</\2>)}{ ( my $x = $1 )
>>=~ s!\n *!!g; $x }seg;
>> print $slurped_text;
> 
> [snip]
> 
> Thanks a lot. It's the /e modifier, which does the trick I guess. I
> could not have written it, though.

That and making a copy of $1 because $1 is read-only.


John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


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

Date: Tue, 10 Oct 2006 16:40:01 -0400
From: lucas <na@noaddress.com>
Subject: Select
Message-Id: <4235c$452c051d$cef8bf09$29109@TEKSAVVY.COM>

I am writing a program where I need to be able to check for data on $socket
and STDIN.  I have been searching, and the only code I can come up with is:

$rmask = '';
vec($rmask, fileno($socket), 1) = 1;
($sel,$rmask) = select($rmask,undef,undef,1);
if ($sel > 0) {

I have seen similar code at places like:
http://mmtsb.scripps.edu/cgi-bin/showsource?GenUtil.pm
http://www.galactic-guide.com/mothership/admin/lchat.pl

The received data is always terminated with a \n and so is the STDIN,
however I can't get that code to work for me.  If I could just get it to
check for data on $socket, if not, do another loop itteration, then that
would be fine.

Can someone point me in the right direction?

Regards,
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: 10 Oct 2006 21:07:49 GMT
From: xhoster@gmail.com
Subject: Re: Select
Message-Id: <20061010171043.522$g2@newsreader.com>

lucas <na@noaddress.com> wrote:
> I am writing a program where I need to be able to check for data on
> $socket and STDIN.  I have been searching, and the only code I can come
> up with is:
>
> $rmask = '';
> vec($rmask, fileno($socket), 1) = 1;
> ($sel,$rmask) = select($rmask,undef,undef,1);

You are overwriting $rmask with the "time remaining" from select,
and thus if you have more than one handle in the select you will not
be able to figure out which one became readable.

my $sel = select($rmask,undef,undef,1);

> if ($sel > 0) {
>
> I have seen similar code at places like:
> http://mmtsb.scripps.edu/cgi-bin/showsource?GenUtil.pm
> http://www.galactic-guide.com/mothership/admin/lchat.pl
>
> The received data is always terminated with a \n and so is the STDIN,

You probably have to use "sysread", then search the buffer for "\n"
yourself (as opposed to using <> or "readline" or "read".)

> however I can't get that code to work for me.

That is an awful description.  What did you expect?  What happened instead?

> If I could just get it to
> check for data on $socket, if not, do another loop itteration, then that
> would be fine.



Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 10 Oct 2006 17:26:07 -0400
From: lucas <na@noaddress.com>
Subject: Re: Select
Message-Id: <7cfcb$452c0feb$cef8bf09$4637@TEKSAVVY.COM>

xhoster@gmail.com wrote:

> lucas <na@noaddress.com> wrote:
>> I am writing a program where I need to be able to check for data on
>> $socket and STDIN.  I have been searching, and the only code I can come
>> up with is:
>>
>> $rmask = '';
>> vec($rmask, fileno($socket), 1) = 1;
>> ($sel,$rmask) = select($rmask,undef,undef,1);
> 
> You are overwriting $rmask with the "time remaining" from select,
> and thus if you have more than one handle in the select you will not
> be able to figure out which one became readable.
> 
> my $sel = select($rmask,undef,undef,1);
> 
>> if ($sel > 0) {
>>
>> I have seen similar code at places like:
>> http://mmtsb.scripps.edu/cgi-bin/showsource?GenUtil.pm
>> http://www.galactic-guide.com/mothership/admin/lchat.pl
>>
>> The received data is always terminated with a \n and so is the STDIN,
> 
> You probably have to use "sysread", then search the buffer for "\n"
> yourself (as opposed to using <> or "readline" or "read".)
> 
>> however I can't get that code to work for me.
> 
> That is an awful description.  What did you expect?  What happened
> instead?
> 
>> If I could just get it to
>> check for data on $socket, if not, do another loop itteration, then that
>> would be fine.

Okay, lets try this.  It still doesn't work.  The problem is $sel is always
zero.  

   my $rmask = '';
   vec($rmask, fileno($socket), 1) = 1;
   my $sel = select($rmask,undef,undef,1);
   if ($sel > 0) { 
      push(@array,sysread($socket,$_,1));
   }

I am expecting $sel to be greater than zero when there is data waiting on
$socket, otherwise, I'd like the infinate loop to keep looping.

-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Tue, 10 Oct 2006 18:42:36 -0400
From: lucas <na@noaddress.com>
Subject: Re: Select
Message-Id: <aed03$452c21d7$cef8bf09$12302@TEKSAVVY.COM>

lucas wrote:

> I am writing a program where I need to be able to check for data on
> $socket
> and STDIN.  I have been searching, and the only code I can come up with
> is:
> 
> $rmask = '';
> vec($rmask, fileno($socket), 1) = 1;
> ($sel,$rmask) = select($rmask,undef,undef,1);
> if ($sel > 0) {
> 
> I have seen similar code at places like:
> http://mmtsb.scripps.edu/cgi-bin/showsource?GenUtil.pm
> http://www.galactic-guide.com/mothership/admin/lchat.pl
> 
> The received data is always terminated with a \n and so is the STDIN,
> however I can't get that code to work for me.  If I could just get it to
> check for data on $socket, if not, do another loop itteration, then that
> would be fine.
> 
> Can someone point me in the right direction?

I have found IO::Select.  It does exactly what I want.  In case anybody is
interested, the three main things are:

Define use:
use IO::Select;

Create new object:
my $select = IO::Select->new($socket,STDIN); #use two handles

Check for data on either handle:
my @ready = $select->can_read;

More than one handle may be ready, so read from them all:
for $handle (@ready) {

I found this information here:
http://www.webmonkey.com/webmonkey/97/18/index2a_page3.html?tw=programming

Regards,
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Tue, 10 Oct 2006 15:46:00 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Select
Message-Id: <101020061546006086%jgibson@mail.arc.nasa.gov>

In article <7cfcb$452c0feb$cef8bf09$4637@TEKSAVVY.COM>, lucas
<na@noaddress.com> wrote:

[problem with checking for data on socket and stdin snipped]

> 
> Okay, lets try this.  It still doesn't work.  The problem is $sel is always
> zero.  
> 
>    my $rmask = '';
>    vec($rmask, fileno($socket), 1) = 1;
>    my $sel = select($rmask,undef,undef,1);
>    if ($sel > 0) { 
>       push(@array,sysread($socket,$_,1));
>    }
> 
> I am expecting $sel to be greater than zero when there is data waiting on
> $socket, otherwise, I'd like the infinate loop to keep looping.

If $sel is never zero, then there is no data on $socket and your
problem is likely elsewhere. Look at 'perldoc perlipc' for some example
TCP/IP clients and servers. Look at the UDP example for a use of
select.

You could also consider using IO::Socket and IO::Select,
object-oriented layers for the socket and select calls.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
    ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------        
                http://www.usenet.com


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

Date: 10 Oct 2006 23:03:59 GMT
From: xhoster@gmail.com
Subject: Re: Select
Message-Id: <20061010190654.946$gf@newsreader.com>

lucas <na@noaddress.com> wrote:
>
> Okay, lets try this.  It still doesn't work.  The problem is $sel is
> always zero.
>
>    my $rmask = '';
>    vec($rmask, fileno($socket), 1) = 1;
>    my $sel = select($rmask,undef,undef,1);
>    if ($sel > 0) {
>       push(@array,sysread($socket,$_,1));
>    }
>
> I am expecting $sel to be greater than zero when there is data waiting on
> $socket, otherwise, I'd like the infinate loop to keep looping.

You should show a *complete* script that demonstrates what you want to
demonstrate.  Are you sure the socket is open?  I can't replicate your
problem:

my $rmask="";
vec($rmask,fileno(STDIN),1)=1;
my $sel=select($rmask,undef,undef,5);
print $sel;

If I don't provide any keyboard input within 5 seconds, it prints "0".  If
I do provide some, I get "1".


I can also get the expected result with a socket:

$ perl -wle 'use IO::Socket; my $x=IO::Socket::INET->new(Listen=>1, \
  LocalPort=>9876) or die $@; my $rmask=""; vec($rmask,fileno($x),1)=1; \
  my $sel=select($rmask,undef,undef,5); print $sel;'

Then in another session within 5 seconds run:

$ telnet localhost 9876

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 10 Oct 2006 19:49:08 -0400
From: lucas <na@noaddress.com>
Subject: Re: Select
Message-Id: <ee94$452c316f$cef8bf09$11050@TEKSAVVY.COM>

xhoster@gmail.com wrote:
> You should show a *complete* script that demonstrates what you want to
> demonstrate.  Are you sure the socket is open?  I can't replicate your
> problem:
> 
> my $rmask="";
> vec($rmask,fileno(STDIN),1)=1;
> my $sel=select($rmask,undef,undef,5);
> print $sel;
> 
> If I don't provide any keyboard input within 5 seconds, it prints "0".  If
> I do provide some, I get "1".
> 
> 
> I can also get the expected result with a socket:
> 
> $ perl -wle 'use IO::Socket; my $x=IO::Socket::INET->new(Listen=>1, \
>   LocalPort=>9876) or die $@; my $rmask=""; vec($rmask,fileno($x),1)=1; \
>   my $sel=select($rmask,undef,undef,5); print $sel;'
> 
> Then in another session within 5 seconds run:
> 
> $ telnet localhost 9876

Thanks for your time with this. I have it worked out now.
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

Date: Tue, 10 Oct 2006 19:49:40 -0400
From: lucas <na@noaddress.com>
Subject: Re: Select
Message-Id: <155b7$452c318f$cef8bf09$11050@TEKSAVVY.COM>

Jim Gibson wrote:
> If $sel is never zero, then there is no data on $socket and your
> problem is likely elsewhere. Look at 'perldoc perlipc' for some example
> TCP/IP clients and servers. Look at the UDP example for a use of
> select.
> 
> You could also consider using IO::Socket and IO::Select,
> object-oriented layers for the socket and select calls.

I'll take a look, thanks.
-- 
lucas
-------------------------
Perl Coder since 2001
shift || die;
-------------------------


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

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 9831
***************************************


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