[19410] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1605 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 24 14:10:31 2001

Date: Fri, 24 Aug 2001 11:10:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <998676611-v10-i1605@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 24 Aug 2001     Volume: 10 Number: 1605

Today's topics:
        round off operator on Perl? <radiotito@yahoo.com>
    Re: sysread problem on socket <news@althepal#nospam#.com>
    Re: sysread problem on socket (Anno Siegel)
    Re: using $/  for input, that's not coming from a file. (Anno Siegel)
    Re: using $/  for input, that's not coming from a file. <mjcarman@home.com>
    Re: Using newlines in Parse::RecDescent <weymer@mediawise.de>
        UTF8 versus ISO-8859-2  <o.moser@mobilkom.at>
        Wait for single key press <florian@haftmann-online.de>
    Re: Wait for single key press (Anno Siegel)
    Re: Wait for single key press <cb@onsitetech.com>
    Re: Win32: how much disk space free? <bart.lateur@skynet.be>
    Re: zipping in perl <florian@haftmann-online.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 24 Aug 2001 19:57:36 +0200
From: Valentin 30IR976 <radiotito@yahoo.com>
Subject: round off operator on Perl?
Message-Id: <3B869590.F0B56210@yahoo.com>

Hello. I have results on my Perl program like 2.5, 87.9, and I want to
have only the "integer" part of this number. I know I can do something
like:

printf("%d",87.9);

and it prints 87 (what I want), but my question is if Perl has any
operator/function that make this thing automatic. I know in C exists,
but...in Perl?

--
73 de Valentin 30IR976 (161 DXCC) ICQ # 86220598 Firetalk # 1626864

web 30IR976:  http://www.geocities.com/titoradio
IR Members: Promote your IR-related-Website at:
http://www.topsitelists.com/bestsites/topir976list/topsites.html
web personal: http://get.to/zamora
SEMANA SANTA ZAMORA http://www.geocities.com/semanasantazamora




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

Date: Fri, 24 Aug 2001 16:00:26 GMT
From: Alex Hart <news@althepal#nospam#.com>
Subject: Re: sysread problem on socket
Message-Id: <uSuh7.800$qq2.386072@typhoon1.gnilink.net>

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

> > up. When I do a sysread on the filehandle, it doesn't read the whole
> > line. I need to do another sysread to pull in the rest of the line. I
> > wait plenty of time and I read in plenty of bytes. I have tried
> > changing both with no help. Unless I read the buffer again, I can't
> > get the whole line. I have tried using the select command in all sorts
> > of ways, with no effect.
>
> sysread is not ever garunteed to return any particular amount of data --
> it will return a nonzero amount of data as soon as some becomes
> available, but even if all the data is ready and waiting, it is entirely
> possible for sysread to only return a tiny bit of it, as little as one
> byte.
>

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.
This is the one point that I would love to understand after this whole
thing.
The erratic behavior is somehow tied to the server, but I don't understand
how.
What is the relation?

<<snippets of code removed>>

>
> I would suggest that you set $/ to $CRLF, and read using <>, and not use
> sysread.  Also, your $CRLF should be set to "\015\012" if you want it to
> be portable, not to "\r\n" which doesn't work on all platforms.

Good point, thanks.

> > my $protocol = (getprotobyname('tcp'))[2];
> > socket(POP, AF_INET, SOCK_STREAM, $protocol);
>
> Always, yes, always, check the return value of system calls.
>

This was just a quick, dirty piece of code that I used to check the
behavior.
In the real code I do a lot more checks. There's a lot of ugly stuff in
this code
for the same reason. In the future I'll clean it up a bit more.

>
> > my $server_socket = sockaddr_in (110, inet_aton($server));
> > connect(POP, $server_socket);
> > my $old_selected = select(POP);
> > $| = 1;
> > select($old_selected);
> > select(undef, undef, undef, .75);
>
> Is there a point to sleeping 3/4 of a second here?
>

I never fully understood the select command. Somehow, I thought that this
would
cause a .75 sec wait on all the data coming in.
I saw this somewhere(with .75), so I copied it. It always seemed like a lot
of this
hand made client stuff was black magic, and I never really questioned this.

I guess this line is sort of meaningless. I wonder how many other people
have
copied my crappy code.

>
> >
> > my $first_response;
> > sysread(POP, $first_response, 1024);
>
> There's no garuntee that this will contain the entire first response,
> only that it will contain a nonzero amount of data [unless we've hit
> eof, in which case it will be zero bytes].

But this does work, at least 99.9% of the time

>
>
> $/ = "\015\012";
> my $first_response = <POP>;

Will this ever time out? What happens if \015\012 never appears?
Will the program freeze forever? I worry about this.

>
> --
> I'm not a programmer but I play one on TV...

I really appreciate your help in this. What a recourse.

- Alex Hart




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

Date: 24 Aug 2001 17:20:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sysread problem on socket
Message-Id: <9m62cj$1fq$1@mamenchi.zrz.TU-Berlin.DE>

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
> 
> > > up. When I do a sysread on the filehandle, it doesn't read the whole
> > > line. I need to do another sysread to pull in the rest of the line. I
> > > wait plenty of time and I read in plenty of bytes. I have tried
> > > changing both with no help. Unless I read the buffer again, I can't
> > > get the whole line. I have tried using the select command in all sorts
> > > of ways, with no effect.
> >
> > sysread is not ever garunteed to return any particular amount of data --
> > it will return a nonzero amount of data as soon as some becomes
> > available, but even if all the data is ready and waiting, it is entirely
> > possible for sysread to only return a tiny bit of it, as little as one
> > byte.
> >
> 
> 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.

> This is the one point that I would love to understand after this whole
> thing.
> The erratic behavior is somehow tied to the server, but I don't understand
> how.
> What is the relation?

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


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

Date: 24 Aug 2001 13:34:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: using $/  for input, that's not coming from a file.
Message-Id: <9m5l5m$euk$1@mamenchi.zrz.TU-Berlin.DE>

According to Klaus Foerster <klaus.foerster@motorola.com>:
> Hi everybody,
> 
> I have a perl program, that reads data from a file and changes
> dynamically
> (depending on the read in data) the input_record_separators ($/)
> 
> Now I want to use the same program to parse a file, that I read in
> already
> and is saved in an array.
> 
> the only idea to reuse the existing program is:
> 
> fork the process
> 1.) one process writes the array to it's stdout (connected to the 2nd
> forked
>     process) and exits afterwards.
> 
> 2.) the other process reads the first processes output via stdin and
> can now change $/ as required.
> 
> Does anyone have a more elegant solution, that avoids spaning
> processes or
> rewriting the code containing the changes to $/ massively.

Check out IO::Stringy (from CPAN).  It allows you to tie a filehandle
so that the data are taken from an array.

Anno


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

Date: Fri, 24 Aug 2001 07:53:13 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: using $/  for input, that's not coming from a file.
Message-Id: <3B864E39.568468EA@home.com>

Klaus Foerster wrote:
> 
> I have a perl program, that reads data from a file and changes
> dynamically (depending on the read in data) the > input_record_separators ($/)
> 
> Now I want to use the same program to parse a file, that I read in
> already and is saved in an array.
> 
> the only idea to reuse the existing program is:
> 
> fork the process
> 1.) one process writes the array to it's stdout (connected to the 2nd
> forked process) and exits afterwards.
> 
> 2.) the other process reads the first processes output via stdin and
> can now change $/ as required.
> 
> Does anyone have a more elegant solution, that avoids spaning
> processes or rewriting the code containing the changes to $/
> massively.

join() the array and split() (or maybe index() and substr() ) it using
the new criteria?

This sounds like an X/Y problem to me. Can you show us some sample code
and tell us what you're trying to accomplish?

-mjc


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

Date: Fri, 24 Aug 2001 15:27:56 +0200
From: Andreas Weymer <weymer@mediawise.de>
Subject: Re: Using newlines in Parse::RecDescent
Message-Id: <3B86565C.A36065F8@mediawise.de>




>          line:    <skip: qr/[ \t]*/> word(s) newline

Works fine.

Thanks,
Andreas



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

Date: Fri, 24 Aug 2001 18:54:16 +0200
From: Oliver Moser <o.moser@mobilkom.at>
Subject: UTF8 versus ISO-8859-2 
Message-Id: <ocucotc8pdbh0ubp5ns932deogm0rps7vv@4ax.com>

Dear NG,

	I've got a big problem with UTF8, LDAP and slovenian
characters ( ISO-8859-2 ). 

It's about a portal regsitration for a slovenian company. The user
fills out a HTML form, where special charcters like ^s (small s with
carron ) are allowed. 

My perl script converts the CGI parameters and writes them into LDAP;
The problem is, that i have to covert that freak stuff characters into
UTF8, which is no problem when your source characters are encoded with
ISO-8859-1 (Latin1). But those special characters I get from the HTML
form are ISO-8859-2 (Latin2, as far as I know). 

Actually, I've two problems. First,  I want to convert those Latin2
chars in utf8, but the Unicode::String module does not support that (
does it??). Second, when i read out LDAP data, it's encoded in utf8
(which is correct [at least for IPlanet Directory Sever] ), and to
display the registration summary correctly, I have to reconvert the
userdata (in utf8) to ISO-8859-2. 

I 'm stuck and I'm really sick of those feaky chars, so I would really
appreciate if you could help me.

regards,

	Oliver
 ------------------------------
Oliver Moser
mobilkom austria AG & Co. KG
IT://mob.app
Mobil: +43-664-331-2544
mailto:o.moser@mobilkom.at


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

Date: Fri, 24 Aug 2001 17:13:52 +0100
From: Florian Haftmann <florian@haftmann-online.de>
Subject: Wait for single key press
Message-Id: <3B867D3F.EA270E8F@haftmann-online.de>

Hi!

I'm writing a perl script that from time to time outputs information on
the console to the user;
between to section, I want the script to halt and wait for one key press
(indicating the user has finished reading).
The whole should run under Win32.
Any ideas?

-f.h.


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

Date: 24 Aug 2001 17:22:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Wait for single key press
Message-Id: <9m62hf$1fq$2@mamenchi.zrz.TU-Berlin.DE>

According to Florian Haftmann  <florian.haftmann@stud.tum.de>:
> Hi!
> 
> I'm writing a perl script that from time to time outputs information on
> the console to the user;
> between to section, I want the script to halt and wait for one key press
> (indicating the user has finished reading).
> The whole should run under Win32.
> Any ideas?

perldoc -q 'single key' might give you some.

Anno


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

Date: 24 Aug 2001 17:24:01 GMT
From: "Christian Brink" <cb@onsitetech.com>
Subject: Re: Wait for single key press
Message-Id: <9m62jh$5qk@dispatch.concentric.net>

Perldoc is your friend -

'perldoc -q key' will get you your answer (It's the 5th FAQ)

"Florian Haftmann" <florian@haftmann-online.de> wrote in message
news:3B867D3F.EA270E8F@haftmann-online.de...
> Hi!
>
> I'm writing a perl script that from time to time outputs information on
> the console to the user;
> between to section, I want the script to halt and wait for one key press
> (indicating the user has finished reading).
> The whole should run under Win32.
> Any ideas?
>
> -f.h.






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

Date: Fri, 24 Aug 2001 14:13:34 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Win32: how much disk space free?
Message-Id: <b3ocotob8fhrd4d7us4ovoibgm25ee81ij@4ax.com>

Bart Lateur wrote:

>Win32::DriveInfo looks like it will work.

Note that this is a plain perl wrapper module around Win32::API. Get
that one from Activestate
(<http://www.activestate.com/PPMPackages/zips/6xx-builds-only/Win32-API.zip>

-- 
	Bart.


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

Date: Fri, 24 Aug 2001 17:07:10 +0100
From: Florian Haftmann <florian@haftmann-online.de>
Subject: Re: zipping in perl
Message-Id: <3B867BAE.B5525F67@haftmann-online.de>



Brendon Caligari schrieb:
> 
> "mk" <mkarasick@diggstown.com> wrote in message
> news:41c8ef03.0108231140.7cb5d72b@posting.google.com...
> > Anybody know a package out there that lets me zip files for NT?  Thanks.
> 
> I don't know of any (but there might be) though you might be using the
> WinZip Command Line Support Addon.

> http://www.winzip.com/wzcline.htm

If you won't to avoid WinZip, take a free zip implementation, e. g. the
zip-tools contained in the Cygwin environment for windows www.cygwin.com

-f.h.


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

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


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