[18784] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 952 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 21 18:10:52 2001

Date: Mon, 21 May 2001 15:10:20 -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: <990483020-v10-i952@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 21 May 2001     Volume: 10 Number: 952

Today's topics:
    Re: Need help on formatting output <ren@tivoli.com>
        Question:  WWW::Search::Generic and Config::IniFiles <michael_of_neb@MailAndNews.com>
        scientific notation <todd@ti.com>
    Re: scientific notation (Greg Bacon)
        Slight problems with rounding. <nick@NOSPAM3db.co.uk>
    Re: Slight problems with rounding. (Randal L. Schwartz)
    Re: splitting string into an array (Craig Berry)
        this is rude. <cj@mt.net>
    Re: Urgent: CGI program wanted (dave)
    Re: XMLout() produces non-well-formed XML <dn131@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 21 May 2001 12:50:55 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Need help on formatting output
Message-Id: <m3d792eglc.fsf@dhcp9-172.support.tivoli.com>

On Mon, 21 May 2001, admin@the-piper.net wrote:

> The output looks like this:
> 
> Directoryname: 20010520
> 
> Programname                         Version  System
> ---------------------------------------------------
> Alibaba                             1.0      Linux
> Startrek                            40.1     Mac
> Zent                                4.04     Linux
> AlphaCentauri                       8.2      Win
> ....
> 
> Looks nice at the first look. My problem at this is that
> i.e. AlphaCentauri is already located in the next directory
> 20010521. But written in the content output of 20010520.
> 
> How can I handle this that after the directory is finished a new
> page with header is started?

It's been a while since I had to do this, but IIRC, you can set $- to
0 before calling write to force a new page.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 21 May 2001 14:27:07 -0400
From: Michael <michael_of_neb@MailAndNews.com>
Subject: Question:  WWW::Search::Generic and Config::IniFiles
Message-Id: <3B23A6FC@MailAndNews.com>

I'm trying to use the Generic Search engine under WWW.
It uses Config::IniFiles .

Nothing comes back from Generic.pm when it reads the config file.

What am I doing wrong ?

Will this method work to get Generic to work ?

Here's the code.

# perl -v -w
# test for 'generic' search using google_pop as the config ini file
##########################################################################
# DATA
##########################################################################
# here is a copy of the config ini file used below

=head1 THE CONFIG FILE google_pop
[options]
search_base_url=http://www.google.com/search
search_next_base_url=http://www.google.com/search
search_url=http://www.google.com/search
search_prefix=keyword=?hl=en&lr=&safe=off&q=
search_debug=1

[search]
search1=approximate_result_count
search1_pat=([0-9]+) of about <b>

[hit]
=cut
##########################################################################
use WWW::Search;
# call the subroutine in question
&SPOP;

# end of main
###################### Subroutines ######################

sub SPOP {
	print STDERR ("POP Generic Method\n"); # debug
	print STDERR "RESULTS: Generic:";

	my $search = new WWW::Search('Generic');
	$search->{'search_configfile'} = 'c:/Perl/lib/WWW/Search/google_pop';
	print STDERR "$search->{'search_configfile'}\n";

	#what is the returned hash from this config file???
	#options
	$value11=$search->{options}{search_base_url};
	$value12=$search->{options}{search_next_base_url};
	$value13=$search->{options}{search_url};
	$value14=$search->{options}{search_prefix};
	$value15=$search->{options}{search_debug};

	print STDERR 
"value11=$value11,value12=$value12,value13=$value13,value14=$value14,value15
=$
value15:\n";

	# search
	$value1=$search->{search}{search1};
	$value2=$search->{search}{search1_pat};
	$value3=$search->{search}{approximate_result_count};
	$value4=$search->{$native_options_ref};
	$value5=$search->{$options_ref};

	print STDERR 
"value1=$value1,value2=$value2,value3=$value3,value4=$value4,value5=$value5:
\n
";
	$query="%22traffic-power.%2Bcom%22&btnG=Google+Search";
	$result=$search->native_query(WWW::Search::escape_query($query));

	print STDERR "result=$result";

	#display the contents of the hash currently resulting from this search
	while (($key,$value)=each(%result)) {
		print STDERR "key:$key,value:$value";
		print LOG_IT "key:$key,value:$value";
	}
} # end sub SPOP

Thanks for any help.
Mike

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------



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

Date: Mon, 21 May 2001 16:12:20 -0500
From: Todd Bair <todd@ti.com>
Subject: scientific notation
Message-Id: <3B0984B4.6A03458F@ti.com>

How do format number like 22534238432.3955 to 2.2534e+10.  I
have tried Convert-SciEng-0.90, but it gives me 22.5342G.  Any
suggestions??

--
Todd




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

Date: Mon, 21 May 2001 21:35:29 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: scientific notation
Message-Id: <tgj2h1miqr2s3a@corp.supernews.com>

In article <3B0984B4.6A03458F@ti.com>,
    Todd Bair  <todd@ti.com> wrote:

: How do format number like 22534238432.3955 to 2.2534e+10.  I
: have tried Convert-SciEng-0.90, but it gives me 22.5342G.  Any
: suggestions??

% man perlfunc
[...]
        Perl's `sprintf' permits the following universally-known
        conversions:

[...]
            %e   a floating-point number, in scientific notation
[...]

Hope this helps,
Greg
-- 
The war . . . has tended, more than any other event in the history of the
country to militate against the Jeffersonian idea, that "the best government
is that which governs least."
    -- Illinois Governor Richard Yates, 1865


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

Date: Mon, 21 May 2001 22:37:51 +0100
From: "Nick" <nick@NOSPAM3db.co.uk>
Subject: Slight problems with rounding.
Message-Id: <tgj2jhskmmsc05@corp.supernews.co.uk>

This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C0E246.AB1A0090
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hello.

I'm currently using the following code to produce a percentage of =
various values. It basically loads an unknown quantity of numbers =
(separated by #'s), adds them up to form a total and then, as a separate =
process, attempts to work out what percentage of the total each =
individual number represents. I'm trying to create a poll system.  It =
mostly works okay, but I've noticed that certain results combinations =
produce percentages that do not add up to 100, and wondered if anyone =
could see the flaw in my "rounding" logic. The current rounding system =
I'm using was taken from www.perl.com but I'm not sure that I've got it =
in correctly.

Any help would be enormously appreciated.

Many thanks,

Nick.


sub load_results{
    open(POLLRESULTS, "<pollresults.dat");
    seek(POLLRESULTS,0,0);

    while(<POLLRESULTS>){
         @results =3D split(/#/,$_);
     }
    close(POLLRESULTS);

    @results_percentages =3D ();
    $percentages_count =3D 0;
    $results_total =3D 0;

# calculate total
    foreach (@results){
        $results_total +=3D $_;
    }

# calculate %ages and populate array.

    foreach (@results){
        $results_percentages[$percentages_count] =3D  int((($_ / =
$results_total)*100) + .5 * ((($_ / $results_total)*100) <=3D> 0));
        $percentages_count++;
    }
}

------=_NextPart_000_000A_01C0E246.AB1A0090
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4134.600" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DVerdana size=3D2>Hello.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>I'm currently using the following =
code to produce=20
a percentage of various values. It basically loads an unknown quantity =
of=20
numbers (separated by #'s), adds them up to form a total and then, as a =
separate=20
process, attempts to work out what percentage of the total each =
individual=20
number represents. I'm trying to create a poll system.&nbsp; It mostly =
works=20
okay, but I've noticed that certain results combinations produce =
percentages=20
that do not add up to 100, and wondered if anyone could see the flaw in =
my=20
"rounding" logic. The current rounding system I'm using was taken from =
</FONT><A=20
href=3D"http://www.perl.com"><FONT face=3DVerdana=20
size=3D2>www.perl.com</FONT></A><FONT face=3DVerdana size=3D2> but I'm =
not sure that=20
I've got it in correctly.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Any help would be enormously=20
appreciated.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Many thanks,</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Nick.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>sub load_results{</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>&nbsp;&nbsp;&nbsp; open(POLLRESULTS,=20
"&lt;pollresults.dat");<BR>&nbsp;&nbsp;&nbsp;=20
seek(POLLRESULTS,0,0);<BR></FONT></DIV>
<DIV><FONT face=3DVerdana=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;while(&lt;POLLRESULTS&gt;){<BR>&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
@results =3D split(/#/,$_);<BR>&nbsp;&nbsp;&nbsp;&nbsp; =
}<BR>&nbsp;&nbsp;&nbsp;=20
close(POLLRESULTS);</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>&nbsp;&nbsp;&nbsp; =
@results_percentages =3D=20
();<BR>&nbsp;&nbsp;&nbsp; $percentages_count =3D =
0;<BR>&nbsp;&nbsp;&nbsp;=20
$results_total =3D 0;</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2># calculate total</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>&nbsp;&nbsp;&nbsp; foreach=20
(@results){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $results_total =
+=3D=20
$_;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2># calculate %ages and populate=20
array.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>&nbsp;&nbsp;&nbsp; foreach=20
(@results){<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$results_percentages[$percentages_count] =3D&nbsp; int((($_ / =
$results_total)*100)=20
+ .5 * ((($_ / $results_total)*100) &lt;=3D&gt;=20
0));<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
$percentages_count++;</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>}</FONT></DIV></BODY></HTML>

------=_NextPart_000_000A_01C0E246.AB1A0090--



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

Date: 21 May 2001 14:44:29 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Slight problems with rounding.
Message-Id: <m1g0dyqsw2.fsf@halfdome.holdit.com>

>>>>> "Nick" == Nick  <nick@NOSPAM3db.co.uk> writes:

Nick> I'm currently using the following code to produce a percentage
Nick> of various values. It basically loads an unknown quantity of
Nick> numbers (separated by #'s), adds them up to form a total and
Nick> then, as a separate process, attempts to work out what
Nick> percentage of the total each individual number represents. I'm
Nick> trying to create a poll system.  It mostly works okay, but I've
Nick> noticed that certain results combinations produce percentages
Nick> that do not add up to 100, and wondered if anyone could see the
Nick> flaw in my "rounding" logic.

Rounding frequently messes up totals.  Haven't you ever seen "totals
do not add up to 100% because of rounding" on polls before?

As an example, take 1.2 10 times, and round that to the nearest
integer (12).  Now take the rounding first (1) and take it 10 times
(10).  See?  The sum of the roundeds is not the rounded of the sums.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Mon, 21 May 2001 20:34:21 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: splitting string into an array
Message-Id: <tgiuudo9gqlt02@corp.supernews.com>

Laszlo G. Szijarto (Laszlo.G.Szijarto@grc.nasa.gov) wrote:
: I apologize for my inexperience.  What is the most efficient way to split up
: a string of text which has numbers delimited by single spaces into an array
: of numbers?

Use the split function with its 'magic' argument, ' '.  If you're
splitting $_, you can just use split with no arguments to accomplish this.
For example:

  $_ = '-64 23 -15 42 3 8';
  @nums = split;
  print join ':', @nums;

Output:  -64:23:-15:42:3:8

See 'perldoc -f split' for details.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Mon, 21 May 2001 21:21:42 GMT
From: Carrie Jones <cj@mt.net>
Subject: this is rude.
Message-Id: <20010521152000.N58193-100000@www.mt.net>

I admit it. Kill file me if you must, but this is the only pre-subscribed
group that I have since my ISP switched mailservers and I'm trying to fix
a problem with posting. (I.e. this is a test. I know that alt.test is the
proper place, but I must use a pre-move group.) Abject appologies
included.

Carrie

-------------------------------------------------------
Carrie Jones
Assistant Systems Administrator
Montana Internet Corporation    cj@mt.net




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

Date: 21 May 2001 13:43:38 -0700
From: usted@cyberspace.org (dave)
Subject: Re: Urgent: CGI program wanted
Message-Id: <e2c00ae.0105211243.591febb2@posting.google.com>

How much do you want for it?

dave


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

Date: 21 May 2001 12:18:47 -0700
From: David Wake <dn131@yahoo.com>
Subject: Re: XMLout() produces non-well-formed XML
Message-Id: <9nvgmua4tk.fsf@Turing.Stanford.EDU>

clintp@geeksalad.org (Clinton A. Pierce) writes:

> [Posted and mailed]
> 
> In article <9nbsool8nl.fsf@turing.stanford.edu>,
> 	David Wake <dn131@yahoo.com> writes:
> > I am sure this is because the values in the database I am writing
> > using XMLout() are strings taken from webpages, and I assume that they
> > contain non-permissible characters.  Is there any way to get around
> > this problem?  Perhaps a method which wraps the offending text in
> > CDATA?
> 
> I just tried it...nope, works fine.
> 
> Wanna try paring your data down a bit and posting a sample piece of XML
> and code that doesn't covert correctly?
> 
For the record, I solved my problem.  There were two causes:

1. Some of the keys in my database contained whitespace.
2. Some of the values in my database contained illegal characters.

I replaced all whitespace with underscores and stripped out all
characters with codes < 32 or > 127.  Works fine now.

David


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

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


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