[16271] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3683 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 16 11:10:22 2000

Date: Sun, 16 Jul 2000 08: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: <963760212-v9-i3683@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 16 Jul 2000     Volume: 9 Number: 3683

Today's topics:
    Re: Perl can't add ! <bart.lateur@skynet.be>
    Re: Perl can't add ! <hermann@holzerath.de>
    Re: Please criticise this text extraction script <stephenk@cc.gatech.edu>
    Re: programming tools and techniques (Tad McClellan)
    Re: programming tools and techniques spike1@freenet.co.uk
    Re: programming tools and techniques (Keith Calvert Ivey)
        Sending data to a web server. <guymal@hotmail.com>
    Re: Sending data to a web server. <bwalton@rochester.rr.com>
    Re: Time in mili-seconds (Tad McClellan)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 16 Jul 2000 12:22:25 +0200
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl can't add !
Message-Id: <p133ns4b0f3vgoc0i8mh9st5jguj4e4526@4ax.com>

Cal Henderson wrote:

>: $result = int(($result + .005) * 100) / 100;   # round to 2 places
>
>easier to do:
>
>$result = sprintf("%.2f",$result);

If you want the same result, don't forget to loose unnecessary trailing
zeroes (and the dp, if not needed any more):

	$result = sprintf("%.2f",$result)+0;

You could see the original problem pop up all over again, due to the
fact that 0.01 does not have an exact representation in FP. I've never
seen this actually happen, though.

-- 
	Bart.


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

Date: Sun, 16 Jul 2000 15:22:54 +0200
From: Hermann Fass <hermann@holzerath.de>
To: "Kevin M. Sproule" <kmsproule@worldnet.att.net>
Subject: Re: Perl can't add !
Message-Id: <3971B72E.D6514788@holzerath.de>

With the use of printf rather than just print
your output could be formatted as well.

Herm.

"Kevin M. Sproule" wrote:
> 
> "Stuart Horner" <stuart@unidev.com> wrote in message
> news:NUVb5.16320$EQ3.572715@news-east.usenetserver.com...
> > I'm having a Perl adding error!
> >
> > Here is the code:
> >
> > foreach $key (@Sorted)
> > {
> >   print "\"$InitialAmount\" + \"$SearchResults{$key}{'Amount'}\" = ";
> >   $InitialAmount = $SearchResults{$key}{'Amount'} + $InitialAmount;
> >   print "\"$InitialAmount\"\n";
> > }
> >
> > Here is a snippit of the output:
> >
> > "823.35" + "24.95" = "848.3"
> > "848.3" + "24.95" = "873.25"
> > "873.25" + "24.95" = "898.200000000001"
> > "898.200000000001" + "24.95" = "923.150000000001"
> > "923.150000000001" + "24.95" = "948.100000000001"
> > SNIP
> > What is going on with this?? I'm just adding two numbers together, from a
> > hash of a hash!
> >
> > I've had this problem on two different machines running two different
> > operating systems, on two different versions of Perl.
> >
> > Sun OS 7 Perl 5.003 and RedHat 6.1 (I don't know the kernal version) Perl
> > 5.6
> >
> > All the printing is only to show the results at each step for debugging.
> > (i.e. finding out where the heck that .000000000001 is coming from).
> >
> > Any responses appreciated!!
> >
> > Regards,
> >
> > Stuart Horner
> > stuart@NOSPAMPLEASE.core-comm.com
> >
> > Please remove the nospamplease. to e-mail.
> >
> 
> Stuart,
> 
> What you are now learning about is called Floating Point Approximation.
> This occurs in all computer languages.  The following example is in C:
> 
> // fptest.c  -  Kevin Sproule  7/15/2000
> 
> #include <stdio.h>
> #include <dos.h>
> 
> int main()
> {
>    double init=823.35,
>           inc=24.95;
>    int i;
> 
>    for (i=0; i<3; i++)
>    {
>     printf("%.13f + %.13f = ",init,inc);
>     init += inc;
>     printf("%.13f\n",init);
>    }
>    return 0;
> }
> 
> Results:
> 
> 823.3500000000000 + 24.9500000000000 = 848.3000000000001
> 848.3000000000001 + 24.9500000000000 = 873.2500000000001
> 873.2500000000001 + 24.9500000000000 = 898.2000000000002
> 
> These results are similar to what you encountered.  The errors creep in
> because computers are only capable of approximating the floating point
> values.  It is necessary to use whole numbers or to round your results to
> keep things accurate.  Some folks like to do all integer math while other
> prefer to just round the results of calculations.
> 
> Simple Perl rounding:
> 
> $result = int(($result + .005) * 100) / 100;   # round to 2 places
> 
> Yours truly,
> 
> Kevin Sproule


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

Date: Sun, 16 Jul 2000 09:55:23 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: Please criticise this text extraction script
Message-Id: <3971BECA.FEF0810C@cc.gatech.edu>

rhys wrote:

> I would be grateful for suggestions on how I could have done this better
> (although I am pleased that I finally got it working at all).
>
> The objective is to extract email addresses from html pages - I have
> already used it to email British members of parliament!.
>
> I tried to use grep without spliting the HTML string but did not
> succeed. Is it necessary to split the HTML string into smaller discrete
> scalars?
>
> Also I am not pleased that there are so many embedded loops.
>
> Thanks for your suggestions.
>
> rhys
>
> #!/usr/bin/perl -w
>
> # Extracts email addresses embedded in (especially html) text
> # usage - $0 inputfilename outputfilename
>
> $infile = shift;
>

No error checking.  What happens if the wrong number of parameters are entered?


>
>         open(INFILE,"<$infile") or die "Unable to open \$infile $infile :
> $!\n";
>         @lines = <INFILE>;
>         close (INFILE);

>
>         foreach $line(@lines)
>

  Throwing the entire file into memory, then iterating over the array, line by line?  Bad idea for large files.  use while(<INFILE>) instead.



>                 {
>                 @split = split(/(\"|:|\<|\>)/,$line);
>

Although this could be more nicely written as split /[":<>]/, even that is unnecessary (and based on assumptions that aren't necessarily
true).  Why not use a global match?


>
>                 $prev_match = "";
>                 foreach(@split)
>                         {
>                         if (/(\w+\.)*\w+@\w+(\.\w+)*/)
>                         # if matches email address ~ need to not create duplicate                                                       #
> array elements
>                                 {
>                                 if ($_ ne $prev_match)
>                                         {
>                                         push @emails, $_;
>                                         $prev_match = $_;
>                                         }
>                                 }
>                         }
>                 }
>

This whole $prevmatch thing is also unnecessary and based on potentially false assumptions.  If you don't want duplicate addresses, use a
hash.  This also gives you the option of sorting addresses.
Just use /(\w+\.)*\w+@\w+(\.\w+)*/g and place all matching strings into a hash.  This will grab multiple addresses on the same line not
separated by those delimeters.


>
> $outfile = shift;
>         open(OUTFILE,">$outfile") or die "Unable to open \$outfile $outfile :
> $!\n";
>         foreach $email(@emails)
>                 {
>                 print OUTFILE "$email\n";       # use join?
>                 }
>         close OUTFILE;

Here you would use (keys %emails) instead of @emails, but you could also set $, to "\n" and print the entire array in one line.

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Sun, 16 Jul 2000 08:23:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: programming tools and techniques
Message-Id: <slrn8n3aa3.jab.tadmc@magna.metronet.com>


[ trimmed Newsgroups ]


On Sun, 16 Jul 2000 08:25:03 GMT, acunet3278@my-deja.com <acunet3278@my-deja.com> wrote:

>I am taking a beginner C language course.


That's nice.


>Could you kindly share your experience with me?


Sure.

Ask a Perl question, and someone will answer it.


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sun, 16 Jul 2000 14:20:31 +0100
From: spike1@freenet.co.uk
Subject: Re: programming tools and techniques
Message-Id: <vqcsk8.85n.ln@ridcully.freenet.co.uk>

In comp.os.linux.misc acunet3278@my-deja.com wrote:
> I am taking a beginner C language course.
> Could you kindly share your experience with me?
> Where can information be found about the following topics:

> When, why and how to use a debugger?

When you compile code, one of the options is to include a symbol table
within the code that links to the source code. When you run it through a
debugger, you can see which line is executing at any point in the program,
set watchpoints (points in the program where the debugger will do something
like report the values of specified veriables), breakpoints (this causes the
program to halt at a particular point).

The simplest and most obvious use ofa debugger is to just run a program that
is known to crash, as the last thing the debugger will do is report the line
in the source code that caused the failure (which REALLY helps in tracking
down fatal bugs).

> What is it used for?

D'uh! It's *USED* for debugging programs! What did you think? Insecticide? 

> When, why and how to use a Make?

When you have a medium to large program, using numerous source files, make
is used to speed up the compilation process. If you just used gcc, and
#included all the required source files each time, it's not very efficient
and can take AGES for a long program... Especially if you only altered one
line in the code to fix a bug.

With make, each source file is compiled separately and then linked together
to form the final executable. Make keeps tabs on when a file was last
updated, so if you have 4 source files say:

window.c
graphics.c
menus.c
paint.c

Where paint is the main() routine.

Now, using the gcc method, changing one line of window.c would mean you'd
have to compile all the files together to produce the final paint program.

Using make on the other hand, it would detect a change in only window.c, and
would only recompile that file, and then relink the other parts of the
program to form the new execuateble.

> What is it used for?

See above. + lots more. 
Make is also capable of generating documentation, installing software, and
many other things. You just have to know how to program it.

> Additionally:
> What is a target?

Another things with make is the ability to have different options included
in the make file. 

Commone examples are:
make all (Make all files and executable)
make world (something only deities tend to be able to do)
make docs (don't compile the code, just generate the documentation)
make coffee (This sends a signal to the coffee machine to make coffee)
make install (install the software you've made)
make gpl (strips out all proprietory code from a commercial program and
          makes it GPL compliant)
make config/menuconfig/xconfig (make a configuration program and run it)
make clean (remover all files previously generated by make)

All these are targets.

> What is build?

You "build" software. It's another word for the compilation process, and is
also used as a method of versioning by altering the number associated with
each time the program is built.

> What is a makefile?

See above. It's the program that tells make what to do, sets the targets,
etc. No makeifle, no targets, nothing apart from an error message will
happen.

> What is a project file?

Some Developement Environments produce a project file. This can be just a
dump of all the source into one file or a complicated hierarchy of different
versions of the code, depending on the IDE.)

> Your advise, tips, comments, suggestions are welcome. I look forward to
> hearing from you. Thank you.

Just hope I've not been duped into doing your homework for you. Get a book
on C programming. Reading books is still a requirement in education, isn't
it?

[If this is your homework, I included a few slight mistakes in there to lose
you points]

:)
-- 
|                          |What to do if you find yourself stuck in a crack|
|  spike1@freenet.co.uk    |in the ground beneath a giant boulder, which you|
|                          |can't move, with no hope of rescue.             |
|Andrew Halliwell BSc(hons)|Consider how lucky you are that life has been   |
|           in             |good to you so far...                           |
|    Computer Science      |   -The BOOK, Hitch-hiker's guide to the galaxy.|


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

Date: Sun, 16 Jul 2000 14:10:02 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: programming tools and techniques
Message-Id: <3977c201.137985961@news.newsguy.com>

tadmc@metronet.com (Tad McClellan) wrote:

>Ask a Perl question, and someone will answer it.

Except perhaps when it seems to be quoting directly from a
homework assignment, as in this case.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC
(Free at last from the forced spamsig of
Newsfeeds.com, cursed be their name)


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

Date: Sun, 16 Jul 2000 13:18:54 +0200
From: "Guy" <guymal@hotmail.com>
Subject: Sending data to a web server.
Message-Id: <8ks25l$lvn$1@news.netvision.net.il>

Does anybody know how I can send data to a web server using a perl script.
(like submitting a form but without using HTML forms on the client side)
For example: instead of logging in manually to my web-mail account (using
their HTML forms: name, password) I would like to run a perl script that
knows my login name and password, and submits this information to the
original form action URL. That way instead of going to let's say
www.hotmail.com and logging in there, I just run my perl script and it
automatically logs-in for me. (without using a browser during the procedure)
If this sounds complicated, tell me and I'll try to explain it better.

Thanks,
Guy






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

Date: Sun, 16 Jul 2000 12:41:24 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Sending data to a web server.
Message-Id: <3971ADB6.CE889BC2@rochester.rr.com>

Guy wrote:
> 
> Does anybody know how I can send data to a web server using a perl script.
> (like submitting a form but without using HTML forms on the client side)
> For example: instead of logging in manually to my web-mail account (using
> their HTML forms: name, password) I would like to run a perl script that
> knows my login name and password, and submits this information to the
> original form action URL. That way instead of going to let's say
> www.hotmail.com and logging in there, I just run my perl script and it
> automatically logs-in for me. (without using a browser during the procedure)
> If this sounds complicated, tell me and I'll try to explain it better.
 ...
> Guy
Take a look at the LWP module.  I think it might do what you want.
-- 
Bob Walton


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

Date: Sun, 16 Jul 2000 08:19:55 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Time in mili-seconds
Message-Id: <slrn8n3a3b.jab.tadmc@magna.metronet.com>

On Sun, 16 Jul 2000 08:54:07 GMT, martho@my-deja.com <martho@my-deja.com> wrote:
>
>> You can, however, get _time_ in a finer resolution, but that is
>> in the Perl FAQ, so you have doubtless already seen that
>> solution.
>Which Perl-FAQ do you mean ? I found about 12...


   "How can I measure time under a second?"


>> Why won't the answer given there work for you?
>>
>>    perldoc -q time
>
>... I didn't get the perldoc in my perl-installation. 


Then you did not get a successful installation.


>Where can I get
>the doc-files ?


They are included with the perl distribution.

Perl is free.

Download it, and you have the docs.


Or, click on "FAQs" at www.perl.com...


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3683
**************************************


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