[24529] in Perl-Users-Digest
Perl-Users Digest, Issue: 6709 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jun 20 00:05:44 2004
Date: Sat, 19 Jun 2004 21:05:06 -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 Sat, 19 Jun 2004 Volume: 10 Number: 6709
Today's topics:
Re: float storage <ebohlman@omsdev.com>
Re: float storage <postmaster@castleamber.com>
Formatting numbers to currency format <ducott@hotmail.com>
Re: Formatting numbers to currency format (Anno Siegel)
Re: Help with a "Post" procedure. <jimsimpson@cox.net>
Re: Help with a "Post" procedure. <usenet@morrow.me.uk>
How to update a txt file with another txtfile? (ricky)
Problems running perl without .pl extention (Kapil Khosla)
Re: Problems running perl without .pl extention <ceo@nospam.on.net>
Re: Problems running perl without .pl extention <postmaster@castleamber.com>
search /\/.*[^.].*$/ <ken_sington@nospam_abcdefg.com>
Re: search /\/.*[^.].*$/ <invalid-email@rochester.rr.com>
wanna do a good thing? <alena123@mail15.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 20 Jun 2004 01:57:44 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: float storage
Message-Id: <Xns950DD5E97C103ebohlmanomsdevcom@130.133.1.4>
ivo.welch@anderson.ucla.edu (ivo welch) wrote in
news:5159bba2.0406190945.45413bca@posting.google.com:
> (yes, 1GB is 4-byte float data size. yes, I could change the
> algorithm. what I should do is use an data base---but that would mean
> installing one and learning SQL for a 1-time application.)
There are a number of Perl modules that provide SQL-based access to
self-contained databases that don't require installing a full-blown
database server: DBD::SQLite would probably be a good choice (it stores
each database in a single file, and the module is self-contained; all you
need are it and DBI). The amount of SQL you'd need to know for such an
application can be learned in about an hour.
------------------------------
Date: Sat, 19 Jun 2004 22:34:54 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: float storage
Message-Id: <40d505de$0$200$58c7af7e@news.kabelfoon.nl>
Eric Bohlman wrote:
> ivo.welch@anderson.ucla.edu (ivo welch) wrote in
> news:5159bba2.0406190945.45413bca@posting.google.com:
>
>>(yes, 1GB is 4-byte float data size. yes, I could change the
>>algorithm. what I should do is use an data base---but that would mean
>>installing one and learning SQL for a 1-time application.)
>
> There are a number of Perl modules that provide SQL-based access to
> self-contained databases that don't require installing a full-blown
> database server: DBD::SQLite would probably be a good choice (it stores
> each database in a single file, and the module is self-contained; all you
> need are it and DBI). The amount of SQL you'd need to know for such an
> application can be learned in about an hour.
If you have SQL experience, yes. But learning it from scratch takes more
then one hour, especially if you want to run your queries fast.
Installing, configuring etc. will take more. My best (educated) guess
would be 2 days, at the least.
I consider learning SQL a good investment of time though. It's like
hashes, regexps, etc, once you understand them, you find new uses.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sat, 19 Jun 2004 19:57:10 GMT
From: "Robert TV" <ducott@hotmail.com>
Subject: Formatting numbers to currency format
Message-Id: <qU0Bc.811789$oR5.404683@pd7tw3no>
I would like to know if Perl has a function to correctly format a string of
numbers into currency format. I have a small subroutine that takes a number
and adds a tax amount. Below is the base:
$amount = 100;
$tax = 0.05 # 5% tax rate
$finaltotal = $amount * $tax;
$finaltotal = sprintf("%.02f",$finaltotal);
Sometimes when then $amount is a complex number such as 1423 I will get
several decimal places, and sprintf rounds to two decimal places. This is
good. But when the amount like simple as seen above, there are no cedimal
places, therefor sprintf doesnt have anything to round. I am trying to make
it so all $finaltotals have two decimal places, even if they are .00 or .90
etc. Can anyone help? TIA!
Robert
------------------------------
Date: 19 Jun 2004 20:34:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Formatting numbers to currency format
Message-Id: <cb2805$gq9$1@mamenchi.zrz.TU-Berlin.DE>
Robert TV <ducott@hotmail.com> wrote in comp.lang.perl.misc:
> I would like to know if Perl has a function to correctly format a string of
> numbers into currency format. I have a small subroutine that takes a number
> and adds a tax amount. Below is the base:
>
> $amount = 100;
> $tax = 0.05 # 5% tax rate
There's a semicolon missing after this statement. This is not the code
you ran.
Don't re-type code, copy and paste it.
> $finaltotal = $amount * $tax;
Shouldn't that be "$amount * ($tax + 1)"?
> $finaltotal = sprintf("%.02f",$finaltotal);
>
> Sometimes when then $amount is a complex number such as 1423 I will get
> several decimal places, and sprintf rounds to two decimal places. This is
> good. But when the amount like simple as seen above, there are no cedimal
> places, therefor sprintf doesnt have anything to round. I am trying to make
> it so all $finaltotals have two decimal places, even if they are .00 or .90
> etc. Can anyone help? TIA!
Are you saying, "sprintf '%.02f', ..." isn't showing trailing zeroes?
It should, and it does for me.
Show runnable code that demonstrates your problem.
Anno
------------------------------
Date: Sat, 19 Jun 2004 14:09:44 -0400
From: "Jim Simpson" <jimsimpson@cox.net>
Subject: Re: Help with a "Post" procedure.
Message-Id: <5k%Ac.3426$wD3.1766@lakeread03>
In my first post I should have explained that I tried to determine the
correct variables to use. I found the following in the source code for the
login sheet that I thought applied to "username" and that is why I used
"text" in my code.
<input type=text name="username" size="15" maxlength="35"
AUTOCOMPLETE="off">
And the following that is why I used "password"
<input type="password" name="password" size="15" ONKEYDOWN="return
handleEnterSubmission( this.form , event)" maxlength="35"
AUTOCOMPLETE="off">
And the following that I assume applies to the "button" confused me - but I
made a stab at it. I'm not sure how I show that the button has been pushed.
<input type="image" name="submit" value="Submit"
SRC="/images/login/log_on.gif" border="0">
Also i understand that some secure sites may encript the data going in. How
can I determine if that is required for this site?
I need more help please.
Jim
"Jim Simpson" <jimsimpson@cox.net> wrote in message
news:wgFAc.791$HN5.60@lakeread06...
> I am trying to automate logging in to an HTTPS site which requires a
"user
> name" and "password". It appears to me that the following code should do
the
> job - but it does not do it. Can someone help me out on this.
>
> I'm especially concerned about the "post" line. I do not understand what
> should be in the places where I have used 'text', 'password' and 'submit'.
>
> All help will be greatly appreciated.
>
> Jim
>
> #########################
> #A program to login to a secure site which requires a "user name" and
> password".
> #Load the source code of the site into a Microsoft Word document.
> #Using Windows 98 and ActivePerl v5.8
> #########################
>
> use strict;
> use Data::Dumper;
> use LWP::UserAgent;
> use HTTP::Cookies;
> use Win32::OLE::Const 'Microsoft Word';
>
> my $https_login = 'url of login sheet sought';
> my $https_user = 'my user name';
> my $https_pass = 'my password';
>
> #get already active Word application or open new
> my $Word = Win32::OLE->GetActiveObject('Word.Application')
> ||Win32::OLE->new('Word.Application', 'Quit');
>
> my $book = $Word->Documents("PrintOut.doc");
>
> # secure login
> my $ua = LWP::UserAgent->new();
> $ua->protocols_allowed( [ 'https'] );
> $ua->cookie_jar(HTTP::Cookies->new(file => ".cookies.txt", autosave =>
> 1));
> my $response = $ua->post($https_login, [ 'text' => "$https_user",
> 'password' => "$https_pass", 'submit' => "Log On" ] );
>
> $book->words(1)->{'text'} = Dumper($response);
>
>
------------------------------
Date: Sat, 19 Jun 2004 23:50:26 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Help with a "Post" procedure.
Message-Id: <cb2jg2$hga$1@wisteria.csv.warwick.ac.uk>
[don't top-post]
Quoth "Jim Simpson" <jimsimpson@cox.net>:
> "Jim Simpson" <jimsimpson@cox.net> wrote in message
> news:wgFAc.791$HN5.60@lakeread06...
> > I am trying to automate logging in to an HTTPS site which requires a
> "user
> > name" and "password". It appears to me that the following code should do
> the
> > job - but it does not do it. Can someone help me out on this.
> >
<snip>
> > my $response = $ua->post($https_login, [ 'text' => "$https_user",
> > 'password' => "$https_pass", 'submit' => "Log On" ] );
>
> In my first post I should have explained that I tried to determine the
> correct variables to use. I found the following in the source code for the
> login sheet that I thought applied to "username" and that is why I used
> "text" in my code.
> <input type=text name="username" size="15" maxlength="35"
> AUTOCOMPLETE="off">
>
> And the following that is why I used "password"
> <input type="password" name="password" size="15" ONKEYDOWN="return
> handleEnterSubmission( this.form , event)" maxlength="35"
> AUTOCOMPLETE="off">
>
> And the following that I assume applies to the "button" confused me - but I
> made a stab at it. I'm not sure how I show that the button has been pushed.
> <input type="image" name="submit" value="Submit"
> SRC="/images/login/log_on.gif" border="0">
The relevant parameter of <input> is 'name'; so you want
my $response = $ua->post(https_login, [
username => $https_user,
password => $https_pass,
submit => 'Submit',
]);
> Also i understand that some secure sites may encript the data going in. How
> can I determine if that is required for this site?
That is what https does for you.
Ben
--
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
ben@morrow.me.uk
------------------------------
Date: 19 Jun 2004 15:14:01 -0700
From: richardkreidl@northwesternmutual.com (ricky)
Subject: How to update a txt file with another txtfile?
Message-Id: <20375d4a.0406191414.4fa6166c@posting.google.com>
I have the following tab delimited master.txt file which has about
1000 records and looks like this:
NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom"
NTADPH0892M00 Standard; Prime Shift Monitoring WST None "JOHNSON, DON"
ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
ntadph0961m00 Standard; Prime Shift Monitoring WST None "Wayne, John"
NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam"
Then I have a tab delimited update.txt file which has about 1000
records also and looks like this:
NTAPTH0236M01 19687 307 1 1
NTADPH0853M00 31612 508 9 24
NTAPTH0271M00 21735 307 4 4
ntadph0919m00 19072 301 2 3
NTADPH0964L01 18000 307 4 4
I want to create a Perl script that will check for matches with the
update.txt file against the first field in the master.txt file. If a
match is found the master.txt file would be appended with the last
four fields from the update.txt file.
There are 3 records from the update.txt file that are found in the
master.txt file in the above example.
The result would look like this:
NTADPH0853M00 Premier WST None "Lee, Tom" 4607 "Lee, Tom" 31612 508 9
24
ntadph0919m00 Standard; Prime Shift Monitoring wst None "Lee, Tom"
19072 301 2 3
NTADPH0964L01 Premier WST None "Smith, Adam" 3786 "Smith, Adam" 18000
307 4 4
I also want to produce an error listing of all the records in the
update.txt file that don't match up with the master.txt file.
thanks
------------------------------
Date: 19 Jun 2004 14:35:00 -0700
From: khoslakapil@yahoo.com (Kapil Khosla)
Subject: Problems running perl without .pl extention
Message-Id: <919aa2da.0406191335.1ab2aecf@posting.google.com>
Hi,
I have a small perl code
####
use strict;
print $#ARGV;
####
When I do perl 1.pl, it runs fine and gives the output 0.
But when I do 1.pl, it gives me the output -1.
I did the following already.
assoc .pl=Perl
ftype Perl=perl.exe "%1" %*
set PATHEXT=.pl;%PATHEXT%
This should have done the trick but it doesnt seem to work for me.
Anyone has any suggestions? I am testing this on Windows Server 2003.
Thanks a lot,
Kapil
------------------------------
Date: Sun, 20 Jun 2004 01:38:08 GMT
From: ChrisO <ceo@nospam.on.net>
Subject: Re: Problems running perl without .pl extention
Message-Id: <4U5Bc.446$mm1.99@newssvr31.news.prodigy.com>
Kapil Khosla wrote:
> Hi,
> I have a small perl code
> ####
> use strict;
> print $#ARGV;
> ####
>
> When I do perl 1.pl, it runs fine and gives the output 0.
>
> But when I do 1.pl, it gives me the output -1.
>
> I did the following already.
>
> assoc .pl=Perl
> ftype Perl=perl.exe "%1" %*
> set PATHEXT=.pl;%PATHEXT%
>
> This should have done the trick but it doesnt seem to work for me.
> Anyone has any suggestions? I am testing this on Windows Server 2003.
Your FTYPE command needs the full path to the command your are "F
typing"... Like:
c:\> ftype Perl=c:\perl\bin\perl.exe "%1" %*
That should do it, I would think.
-ceo
------------------------------
Date: Sat, 19 Jun 2004 22:32:40 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Problems running perl without .pl extention
Message-Id: <40d50558$0$200$58c7af7e@news.kabelfoon.nl>
ChrisO wrote:
> Your FTYPE command needs the full path to the command your are "F
> typing"... Like:
Not if the command is in the PATH.
> c:\> ftype Perl=c:\perl\bin\perl.exe "%1" %*
>
> That should do it, I would think.
The script was already running ok. Why perl 1.pl gave 0 is the problem :-D.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Sat, 19 Jun 2004 23:05:57 -0400
From: Ken Sington <ken_sington@nospam_abcdefg.com>
Subject: search /\/.*[^.].*$/
Message-Id: <FGydnecco-6SYkndRWPC-w@speakeasy.net>
Not what I had expected.
I was hoping
/\/.*[^.].*$/
would find a "/" and does not contain any number of dots between any
number of characters.
A shash followed by any number of word characters is valid.
A shash followed by any number of word characters then a trailling slash
is valid.
A shash followed by any number of word characters then a dot then some
more chars is not valid.
If it has a dot between the final shash and end of string, it's not valid.
Here I expected a slash, anychar, must not have '.', anychar, $anchor
my $str = "/tmp/helloworld";
$str =~ /\/.*[^.].*$/
unless perl sees it as slash, anychar all the way to the end, so ignores
the rest of the regex.
other examples:
$str = "/tmp/hello"; <--- yes
$str = "/var/http-docs/cgi-bin/"; <--- yes
$str = "/var/http-docs/cgi-bin"; <--- yes
$str = "/var/http-docs/cgi-bin/hello.pl"; <--- no
$str = "/var/http-docs/cgi-bin/.blah"; <--- no
------------------------------
Date: Sun, 20 Jun 2004 03:33:32 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: search /\/.*[^.].*$/
Message-Id: <40D50574.6030809@rochester.rr.com>
Ken Sington wrote:
> Not what I had expected.
> I was hoping
> /\/.*[^.].*$/
> would find a "/" and does not contain any number of dots between any
> number of characters.
Well, your hopes aside, it will find a / followed by the largest number
of any character possible, followed by one non-period character,
followed by the largest number of any character possible, followed by
the end of the string. So for example, the string:
/blah/blah/blah.blah
will match -- / will match the first /, .* will match
blah/blah/blah.bla, [^.] will match h, and .* will match the empty
string. It seems like that's not what you want. Maybe something like:
$str=~/\/[^.]*$/
would do what you want (it does your examples correctly, anyway).
But you should probably make life easy for yourself, and
use File::Basename;
or similar, because the above regexp will probably not do what you want on
something like:
/blah.dir/blah/blah
for which the match will succeed, but starting with the second /
character. Is that what you want? Maybe:
$str=~/^\/[^.]*$/
? You don't define the exact behavior you want.
...
> other examples:
> $str = "/tmp/hello"; <--- yes
> $str = "/var/http-docs/cgi-bin/"; <--- yes
> $str = "/var/http-docs/cgi-bin"; <--- yes
> $str = "/var/http-docs/cgi-bin/hello.pl"; <--- no
> $str = "/var/http-docs/cgi-bin/.blah"; <--- no
--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
------------------------------
Date: Sat, 19 Jun 2004 22:20:27 +0000 (UTC)
From: <alena123@mail15.com>
Subject: wanna do a good thing?
Message-Id: <1087683616.631351@smtp.tvcom.ru>
Hello, my name is Alena Simons.
I'm a girl of 19 and I live in Russia. Two years ago my parents divorced and now I live only with my mother
and little sister.
My mother works hard to make both ends meet, she has to take odd jobs at the moment since she is currently laid off
from the major one. Besides, she has no specialty, so the wages are always low and much eaten up by regular bills.
It was hard to get a loan for my college and I guess it'll be even harder to pay the debt.
We are thinking of moving to a cheaper appartments since it's impossible to pay for this anymore.
Our total debt reaches $17,058. All we need is that you send us a few dollars to keep us alive.
I'm afraid for the future of my sister. She's only 11, but understands what situation we are in.
Please, please, help us. Even if you have only some extra cents on your account, please, do not hesitate to help us.
We'll be glad to any your help. Thank you for your time.
Our accounts:
E-gold: 1127463 (www.e-gold.com)
EVOCASH: 142772 (www.evocash.com)
------------------------------
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 6709
***************************************