[18623] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 791 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Apr 28 18:10:31 2001

Date: Sat, 28 Apr 2001 15:10:10 -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: <988495810-v10-i791@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 28 Apr 2001     Volume: 10 Number: 791

Today's topics:
        How to convert integer to string? (Perl newbie) <dblair99@home.com>
    Re: How to convert integer to string? (Perl newbie) <tony_curtis32@yahoo.com>
    Re: How to convert integer to string? (Perl newbie) <godzilla@stomp.stomp.tokyo>
    Re: operators: != vs. ne, strange behaviour (Rudolf Polzer)
    Re: Perl compete: Java is dead on server side!! PHP is  <xcyber@yahoo.com>
        POST vs QUERY STRING and parsing... Help? (nicktaken)
    Re: POST vs QUERY STRING and parsing... Help? (Eric Bohlman)
    Re: POST vs QUERY STRING and parsing... Help? (nicktaken)
        Redirecting STDERR more than once in a program. (Ted Wart)
    Re: Separate syslog file? (Pat Traynor)
    Re: Separate syslog file? (Anno Siegel)
        Should Perl be first? (BUCK NAKED1)
    Re: Should Perl be first? <comdog@panix.com>
    Re: Single character reads on sockets <djmarcus@ex-pressnet.com>
        UDP Packets with zero checksum <mheimer@gmx.at>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 28 Apr 2001 18:49:46 GMT
From: David Blair <dblair99@home.com>
Subject: How to convert integer to string? (Perl newbie)
Message-Id: <3AEB10C9.63BA566E@home.com>

Hi,
    I am trying to write a simple number guessing game in Perl. I need
to get the random number to between 1 and 10 to use it. I type $randnum
= int(rand * 10); but that is not satisfactory because it truncates the
the decimal rather than rounding it. I know about sprintf() but don't
know how to convert it back to a int to use in an if test against the
guess. There is no sscanf function like in C, so how would one do this?
Thanks.

Dave Blair



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

Date: 28 Apr 2001 13:58:06 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: How to convert integer to string? (Perl newbie)
Message-Id: <87bspg6edd.fsf@limey.hpcc.uh.edu>

>> On Sat, 28 Apr 2001 18:49:46 GMT,
>> David Blair <dblair99@home.com> said:

> Hi, I am trying to write a simple number guessing game
> in Perl. I need to get the random number to between 1
> and 10 to use it. I type $randnum = int(rand * 10); but

Actually you want int(rand 10);

> that is not satisfactory because it truncates the the
> decimal rather than rounding it.

+1 ?

hth
t
-- 
Just reach into these holes.  I use a carrot.


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

Date: Sat, 28 Apr 2001 13:13:12 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How to convert integer to string? (Perl newbie)
Message-Id: <3AEB2458.BDB67677@stomp.stomp.tokyo>

David Blair wrote:

(snipped) 

> I need to get the random number to between 1 and 10...

> $randnum = int(rand * 10);

> but that is not satisfactory because it truncates the
> the decimal rather than rounding it.


This is untrue.

Your code is attempting to find the product of
a word, "rand" and the number 10. This is not
possible; your code is not numeric in nature.
Your return is 0 (zero) not a truncated decimal.

A number between 1 and 10 would be an individual
number from 2 to 9, inclusive, if your intent is
non-decimal numbers. If your intent is decimal 
numbers, your game is not simple in nature.

By definition, there is an infinite amount of numbers
ranging between 1 to 2, alone, just as there is an
infinite amount of numbers between 1.1 and 1.2 per
accepted mathematical notions.

My test script presents a snippet for creating a
unique random whole number from 1 to 10, inclusive,
from 2 to 9 inclusive and an alternative method
using an array, albeit slower and less efficient.


Godzilla!
--

TEST SCRIPT:
____________


#!perl

print "Content-type: text/plain\n\n";

# Create A Whole Number, 1 to 10, inclusive:

$number = int (rand(10) + 1);

print "Rand 1 Method: $number\n\n";


# Create A Whole Number, 2 to 9, inclusive:

$number = int (rand(8) + 2);

print "Rand 2 Method: $number\n\n";


# Create A Whole Number With An Array, 2 to 9, inclusive:

@Array = (2 .. 9);

$number = $Array[rand(@Array)];

print "Array Method: $number";

exit;



PRINTED RESULTS:
________________

Rand 1 Method: 1

Rand 2 Method: 7

Array Method: 5


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

Date: Sat, 28 Apr 2001 20:50:16 +0200
From: eins@durchnull.de (Rudolf Polzer)
Subject: Re: operators: != vs. ne, strange behaviour
Message-Id: <slrn9em477.2to.eins@www42.t-offline.de>

Ren Maddox <ren@tivoli.com> wrote:
> On Fri, 27 Apr 2001, eins@durchnull.de wrote:
> 
> > perl -e "print 1e300 * 1e300";
> 
> That gives "1.#INF".
> 
> > The same -1.#IND or something else? Maybe they are really NaN and 
> > INF but ActivePerl does not support them (the FPU does, and AP does 
> > not check).
> 
> I'd say that's a pretty good theory.
> 
> Looks like:
> 
> -1.#IND <==> NaN <==> nan <==> NaNQ
> 1.#INF <==> INF <==> inf

Weird is: -1.#IND == -1.#IND, while NaN != NaN.

Interestingly this C program:

#include <stdio.h>
#include <math.h>

double x;

int main ()
{
 x = 1e300 * 1e300;
 printf ("%f - %d\n", x, x == x);
 x = sqrt (-1);
 printf ("%f - %d\n", x, x == x);
}

shows

inf - 1
nan - 0

so NaN is not equal to itself according to the C library (and isnan is 
superflous because this would work:

__INLINE__ int isnan(double x) { return x!=x; }

So one could conclude that the FPU says: NaN != NaN. Unfortunately I 
do not know if the FPU does equality tests on x86 - I do not know a 
FEQ opcode. If the C library has to decide, maybe the Windows API / 
MSVC++ says NaN == NaN.

Could anyone test this C program on different Windows C compilers? I 
tried the equivalent in Turbo Pascal 1.5/Windows example but it gives 
a runtime error because of error checking which cannot be disabled 
(Floating Point Overflow).

-- 
#!/usr/bin/perl -W -- WARNING: This copies a random file from
use strict;my$s;my$n=0;for # the  current  directory  to your 
(<*>){++$n;int rand$n or$s # signature  file.   Use  at  your
=$_};`cp $s ~/.signature`; # own risk! (c) 2001 Rudolf Polzer


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

Date: Sun, 29 Apr 2001 03:00:24 +0800
From: "xcyber" <xcyber@yahoo.com>
Subject: Re: Perl compete: Java is dead on server side!! PHP is 4 times faster than  JSP,CF,ASP!!
Message-Id: <9cf40t$jol8@rain.i-cable.com>

seems that you are very stupid and have no cure.

| PHP is born from "Perl + Java"
hey,what the hell r u talking about?

do u know python?
it is also OO
does it come from java?

PHP is the fastest growing language inthe world!!

sigh....
what kind of languages?
chinese or english or computer?

php is strictly a scripting lang.but not a programming lang.

or do u know what php is made from ?
do u know the concept of "wrapper"?
do u know the differences bewteen scripting lang and programming lang.?

PHP is the fastest web-scripting language and is 4 times faster than....

on which aspects?
development cycle?
compilation time or what?


What is the purpose of java on server side programming if PHP is
java-like
and is 4 times faster???


seems that u dunno the concept of separating application logic from data
representation..
so  u dunno the adv. of servlets..

no cure...

get a cure..



----- Original Message -----
From: "Al Dev" <alavoor@yahoo.com>
Newsgroups:
comp.lang.perl.misc,comp.lang.perl,comp.lang.perl.modules,alt.comp.perlcgi.f
reelance,alt.perl,alt.perl.flame,alt.perl.sockets,comp.lang.perl.tk,cz.comp.
lang.perl,de.comp.lang.perl.cgi
Sent: Friday, April 27, 2001 10:59 PM
Subject: Perl compete: Java is dead on server side!! PHP is 4 times faster
than JSP,CF,ASP!!


| Perl competetion: Java is dead on server side!! PHP is 4 times faster
| than JSP,CF,ASP!!
|
| PHP is born from "Perl + Java" and is the fastest growing language in
| the world!!
| PHP is object oriented. Analogy is perl is "C" and PHP is "C++" !!
|
| PHP is the fastest web-scripting language and is 4 times faster than
| JSP(Java
| Server Pages). PHP is becoming new "Java language", it is getting all
| the Java
| keywords like class, extends, implements, interface, inner classes etc..
|
| What is the purpose of java on server side programming if PHP is
| java-like
| and is 4 times faster???
|
| The benchmark says PHP is faster than ASP and ASP faster than
| ColdFusion..
| The order is : PHP > ASP > CF > JSP
| The JSP is the worst!! It is the slowest of all technology!!
|





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

Date: Sat, 28 Apr 2001 07:54:31 GMT
From: dirtfarmer@heehaw.com (nicktaken)
Subject: POST vs QUERY STRING and parsing... Help?
Message-Id: <3aea70c8$1_1@news3.nntpserver.com>

I have a pre-existing .asp that I need to submit form data to with a
perl script, then let that same script parse the results generated by
the .asp and generate a page based on the results.

I know how to do this by submitting via QUERY STRING in the url,
but the problem is that this .asp (not mine) requires the data to be
submitted via POST.

Is there any way I can POST data to the .asp?
Here is a simplified version of what I am doing with the query string so 
far...
<><><><><><><><><>

#!/usr/local/bin/perl
use CGI;
use LWP::Simple;

$url="http://www.somedomain.net/an.asp?somevar=somedata";

# load the web page into a string
$pagecontent=get($url);

print "Content-type: text/html\n\n";

print $pagecontent;
# actually here is where $pagecontent is parsed and results printed.

<><><><><><><><><>

Any help is GREATLY appreciated.


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

Date: 28 Apr 2001 17:08:30 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: POST vs QUERY STRING and parsing... Help?
Message-Id: <9cetee$edv$2@bob.news.rcn.net>

nicktaken <dirtfarmer@heehaw.com> wrote:
> I have a pre-existing .asp that I need to submit form data to with a
> perl script, then let that same script parse the results generated by
> the .asp and generate a page based on the results.

> I know how to do this by submitting via QUERY STRING in the url,
> but the problem is that this .asp (not mine) requires the data to be
> submitted via POST.

> Is there any way I can POST data to the .asp?
> Here is a simplified version of what I am doing with the query string so 
> far...
> <><><><><><><><><>

> #!/usr/local/bin/perl
> use CGI;
> use LWP::Simple;

[snip]

To handle POST requests, you'll need to use LWP::UserAgent and its 
cohorts.  You've obviously got the modules there already; read their 
documentation and look in the LWP Cookbook.



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

Date: Sat, 28 Apr 2001 19:47:24 GMT
From: dirtfarmer@heehaw.com (nicktaken)
Subject: Re: POST vs QUERY STRING and parsing... Help?
Message-Id: <3aeb17c7$1_1@news3.nntpserver.com>

In article <9cetee$edv$2@bob.news.rcn.net>, ebohlman@omsdev.com (Eric Bohlman) wrote:
>nicktaken <dirtfarmer@heehaw.com> wrote:
>> I have a pre-existing .asp that I need to submit form data to with a
>> perl script, then let that same script parse the results generated by
>> the .asp and generate a page based on the results.
>
>> I know how to do this by submitting via QUERY STRING in the url,
>> but the problem is that this .asp (not mine) requires the data to be
>> submitted via POST.
>
>> Is there any way I can POST data to the .asp?
>> Here is a simplified version of what I am doing with the query string so 
>> far...
>> <><><><><><><><><>
>
>> #!/usr/local/bin/perl
>> use CGI;
>> use LWP::Simple;
>
>[snip]
>
>To handle POST requests, you'll need to use LWP::UserAgent and its 
>cohorts.  You've obviously got the modules there already; read their 
>documentation and look in the LWP Cookbook.
>
Thank you very much.
I just didn't know what to look for.


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

Date: Sat, 28 Apr 2001 21:55:00 GMT
From: t_wart@hotmail.com (Ted Wart)
Subject: Redirecting STDERR more than once in a program.
Message-Id: <3aeb3928.204423790@netnews.worldnet.att.net>

		

 Hi,

I've a program that uses system to execute other programs. I can
grab the output from my system calls by redirecting standard error. The 
first time redirection works as planned. Subsequent redirects fail.
Since my script is pretty much a large loop I have worked around
the problem by exec'ing the program where I'd like to loop. Is 
there a more elegant solution? TIA, TW.

---------------------------------------------------------
Ted Wart                               t_wart@hotmail.com
Government Tech. Support/AUAAC - Austin-818 extention 121
---------------------------------------------------------


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

Date: Sat, 28 Apr 2001 13:02:00 GMT
From: pat@ssih.com (Pat Traynor)
Subject: Re: Separate syslog file?
Message-Id: <3aeabee5.354967@news.giganews.com>

On 28 Apr 2001 10:46:01 GMT, Jonathan Stowe <gellyfish@gellyfish.com>
wrote:

>Pat Traynor <pat@ssih.com> wrote:
>> I'm successfully logging output to my syslog file like this:
>> 
>> use Sys::Syslog qw(:DEFAULT setlogsock);
>> setlogsock('unix');
>> syslog('info', "Test message to syslog filel\n");
>> 
>> I understand how to send different levels of priority messages to
>> different log files via syslog.conf, but is there a way to have a
>> program log output to a custom log level?  e.g.:
>> 
>> syslog('mytest', "Test message to syslog filel\n");
>
>Surely that is an issue of the capability of your syslog daemon ?

Yes, I'm sure my syslog daemon will be a part of the process, but I
need to know how to do the programming in perl.


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

Date: 28 Apr 2001 17:45:01 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Separate syslog file?
Message-Id: <9cevit$3g5$3@mamenchi.zrz.TU-Berlin.DE>

According to Pat Traynor <pat@ssih.com>:
> On 28 Apr 2001 10:46:01 GMT, Jonathan Stowe <gellyfish@gellyfish.com>
> wrote:
> 
> >Pat Traynor <pat@ssih.com> wrote:
> >> I'm successfully logging output to my syslog file like this:
> >> 
> >> use Sys::Syslog qw(:DEFAULT setlogsock);
> >> setlogsock('unix');
> >> syslog('info', "Test message to syslog filel\n");
> >> 
> >> I understand how to send different levels of priority messages to
> >> different log files via syslog.conf, but is there a way to have a
> >> program log output to a custom log level?  e.g.:
> >> 
> >> syslog('mytest', "Test message to syslog filel\n");
> >
> >Surely that is an issue of the capability of your syslog daemon ?
> 
> Yes, I'm sure my syslog daemon will be a part of the process, but I
> need to know how to do the programming in perl.

Form the Sys::Syslog documentation:

       Sys::Syslog is an interface to the UNIX `syslog(3)'
       program.  Call `syslog()' with a string priority and a
       list of `printf()' args just like `syslog(3)'.

Where is the Perl specific problem?  Everything is in the syslog
man pages.

Anno


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

Date: Sat, 28 Apr 2001 15:14:13 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Should Perl be first?
Message-Id: <11863-3AEB2495-139@storefull-248.iap.bryant.webtv.net>

I'm wanting to learn a programming language to use mainly for web
applications, but that could also be used for business applications
off-line, and hopefully make me some money. I am much older than most of
you, and probably not as swift (as perhaps evidenced by some of my
questions in this forum).

I started learning Perl a few months ago, but still have much to learn.
Friends tell me that VB is THE language to learn. I know a little
VBScript, but no VB... and of course VBScript is not a programming
language. I'm confused. Should Perl be the first programming language
that I should learn? or would you recommend another programming
language? C++? Java? what?
 
Your input would be much appreciated.

--Dennis



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

Date: Sat, 28 Apr 2001 17:22:40 -0400
From: brian d foy <comdog@panix.com>
Subject: Re: Should Perl be first?
Message-Id: <comdog-1C86FB.17224028042001@news.panix.com>

In article <11863-3AEB2495-139@storefull-248.iap.bryant.webtv.net>, 
dennis100@webtv.net (BUCK NAKED1) wrote:

> Should Perl be the first programming language
> that I should learn?

learn whatever language you need to solve whatever problems
you want to solve.  if Perl is a good langauge for the task
at hand - learn Perl.  if it's not learn something else. :)

-- 
brian d foy <comdog@panix.com>
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html



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

Date: Sat, 28 Apr 2001 16:31:43 -0400
From: "David J. Marcus" <djmarcus@ex-pressnet.com>
Subject: Re: Single character reads on sockets
Message-Id: <tema55h0ecpt00@corp.supernews.com>

> I am trying to write a client and a server that communicate using the
>
>
> On the reader side I do:
>
>     read ( $sock, $lenlen, 1 );
>     read ( $sock, $len,      $lenlen );
>     read ( $sock, $msg,    $len );
>
> It seems that the first read hangs.
>
> Am I doing things correctly?
> Any suggestions? hints? advice? etc?

Some further information. After repeated experimentation I've determined
that the problem is actually a result of 'fork()'.
I'm runin AS 5.6.

On the server side I do:

    my $child = fork();

    if ($child == 0) {
       . . .
       read ( $sock, $lenlen, 1 );
       read ( $sock, $len,      $lenlen );
       read ( $sock, $msg,    $len );
       . . .
    }

This hangs.

When I do the 'read' sequence in the parent child, it works. I've sent a
message to AS but have not received a reply yet.

Is there a way to accomplish the 'fork()' properly (in this case I mean:
start a totally new process, Perl Interpreter and all and be able to pass
the socket to it).

-Thanks
David








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

Date: Sat, 28 Apr 2001 15:54:16 +0200
From: "Max Heimer" <mheimer@gmx.at>
Subject: UDP Packets with zero checksum
Message-Id: <9cei7b$1k2$1@news.tuwien.ac.at>

hi!

is there anybody who can give me a hint how to
create udp-packets, and send it to a host,
where the _checksum field_ is set to zero.
if i use socket, i've no control on the
checksum field.

thanx, max




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

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


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