(no subject)
I have managed to get the sprintf statement to show the 00 on the right side, but still having trouble with the zero's dropping out on the left side of the decimal place, i.e. you have 250.00 it comes out 25.00, 500.00 comes out as 5.00. I'm at a loss what to do. I've been reading and there's something to do with local pc's and scalar and awk and what their set too, but I have no idea where to look. Can someone look at this sprintf script and give me an idea as to how to type it to have the 00 show up on the left side. Any suggestions would be appreciated. # Output the records to the file. $RECNUM = 0; $RECCOUNT = 0; while(! $RS->EOF) { I'm thinking now that it may be not the sprintf statement below,but where the string is $tmp=~s/\s+$//; #trim trailing white space I'm know sql, but not perl, so I'm not sure what that is saying tmp is equal to for ( $i = 0; $i < $Count; $i++ ) { $tmp = $RS->Fields($i)->value; $tmp =~ s/\s+$//; # trim trailing white space $amt = $tmp; # No datachecking here! To turn this off, set the next line to "OFF"; # This formats the SECOND field in the array (gotten from the database) to a # currency format. $DO_THIS_THING = "ON"; if( $i == 1 && $DO_THIS_THING eq 'ON' ) { $amt = sprintf( "%.2f", $tmp ); } # End Sir stuff ### print OUT $amt; #$RS->Fields($i)->value; print OUT "$FDELIM"; } print OUT "$date\t$cid\t$caccount\t$ctype\tSJC AR Batch\t$IDENT\t\t\t"; print OUT "$RDELIM"; $RECNUM++; $RECCOUNT++; if ( $RECNUM == 10) { print "."; $RECNUM = 0; } $RS->MoveNext; ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Having Problem with zero's dropping on left side of decimal placeHELP!
> $RECNUM = 0; > $RECCOUNT = 0; > while(! $RS->EOF) { > > for ( $i = 0; $i < $Count; $i++ ) > { > $tmp = $RS->Fields($i)->value; > $tmp =~ s/\s+$//; # trim trailing white space > $amt = $tmp; > > # No datachecking here! To turn this off, set the next line > to "OFF"; > # This formats the SECOND field in the array (gotten from > the database) to a > # currency format. > I think this is where my problem is: > $DO_THIS_THING = "ON"; > if( $i == 1 && $DO_THIS_THING eq 'ON' ) > { > $amt = sprintf( "%.2f", $tmp ); > } for my $i ( 0 .. $Count ) { $amt = sprintf("%.2f", $RS->Fields($i)->Value ) if $i == 1; print OUT $amt, $FDELIM; } I wasn't able to reproduce any of the problems you were having. printf("%.2f","250.00"); Came out as expected: '250.00' Could we have some reproducable sample code? ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: bad file
I ran into a similar problem with a script developed for Word97 that started recieving input from Word2000 users. It is the unicode problem. My inelegant work-around was to slurp each file in binmode, blow off all the nulls, write it back upon itself, then open it again with the old code. This should work, IF you can be sure that there is no binary data in the material. One other caveat: it will probably fail as soon as some user figures out that he can include some really neat foreign (unicode) character in a text field... Will - Original Message - From: Mike Nolen <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, April 12, 2001 1:25 PM Subject: bad file > All, > > Developers are sending me .sql files of code they extract from SQL Server > 7.0 > Enterprise Manager and it comes through with a \x00 (null) character in > between > every character in the file. When you open the attachment in a text editor > like > PFE, you'll see what I mean. If you open it in notepad it seems to be fine. > The first two characters at the top of the file appear to be \xff and \xfe. > I've tried to open as binmode, but it doesn't work. > > I use perl to open the file and parse it, but it sees the file as empty. > Any suggestions? > > Thanks, > Mike Nolen > Database Administrator IV > Dealer Solutions - ADP > [EMAIL PROTECTED] > (713)430-2075 > > ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Having Problem with zero's dropping on left side of decimal placeHELP!
Kathy Wilson wrote: > > When last I wrote, I was having trouble with all the zero's dropping out > when going from Service Pack 3 to Service Pack 6 on an Windows NT pc. > > I have managed to get the sprintf statement to show the 00 on the right > side, but still having trouble with the zero's dropping out on the left side > of the decimal place, i.e. you have 250.00 it comes out 25.00, 500.00 comes > out as 5.00. I'm at a loss what to do. I've been reading and there's > something to do with local pc's and scalar and awk and what their set too, > but I have no idea where to look. > I doubt this has anything to do with sprintf(). You can try the following: my $d = 500.00; my $s = sprintf("%.2f", $d); print "s=$s\n"; I expect you will see s=500.00 See the code below. > Can someone look at this sprintf script and give me an idea as to how to > type it to have the 00 show up on the left side. Any suggestions would be > appreciated. > > # Output the records to the file. > $RECNUM = 0; > $RECCOUNT = 0; > while(! $RS->EOF) { > > for ( $i = 0; $i < $Count; $i++ ) > { > $tmp = $RS->Fields($i)->value; > $tmp =~ s/\s+$//; # trim trailing white space > $amt = $tmp; > > # No datachecking here! To turn this off, set the next line > to "OFF"; > # This formats the SECOND field in the array (gotten from > the database) to a > # currency format. > I think this is where my problem is: > $DO_THIS_THING = "ON"; > if( $i == 1 && $DO_THIS_THING eq 'ON' ) > { > $amt = sprintf( "%.2f", $tmp ); > } Change the above code to this { $amt = sprintf( "%.2f", $tmp ); print "input=<$tmp> output=<$amt>\n"; print "input len=", length($tmp), " output len=", length($amt), "\n"; } It is important that the <> be around each value. Repost with the results with this print added. I would suspect the most likely causes is that $tmp is actually 5 rather than 500 or that you have a bug in the perl version you are using. If the first case then you might want to adjust the data appropriately. If the second then either get a newer version of perl or adjust the script to account for the bug. > > # End Sir stuff > ### > > print OUT $amt; #$RS->Fields($i)->value; > print OUT "$FDELIM"; > } > > print OUT "$date\t$cid\t$caccount\t$ctype\tSJC AR > Batch\t$IDENT\t\t\t"; > print OUT "$RDELIM"; > $RECNUM++; > $RECCOUNT++; > if ( $RECNUM == 10) { > print "."; > $RECNUM = 0; > } > $RS->MoveNext ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Hash problem
On Wed, 11 Apr 2001, $Bill Luebkert wrote: > Fabio Quintão (Perl++) wrote: > > > > Hi all, > > > > i'm doing a perl script and i have problems with that.its easy for > > almost all of you to answer that.i have 2 lists like > > @a= (1,2,3,4,5); > > @b = (1,2,6,7,89); > > > > and i put all of than in just one list like > > @c=(1,2,3,4,5,1,2,6,7,89); > > > > and i just want it to be a hash where the first element of the > > first list has the the first element of the second list as a pair... like > > %d = (1,1,2,2,3,6,4,7,5,89); > > > > i know it sounds strange but i really need to know that. > > Is there a way to do that? > > > > i hope someone can help me > > Thanks in advance > > One way is to just brute force it like in C: > > my @a = (1, 2, 3, 4, 5); > my @b = (1, 2, 6, 7, 89); > my %h = (); > > for (my $ii = 0; $ii < @a; $ii++) { > $h{$a[$ii]} = $b[$ii]; > } > > foreach (sort keys %h) { > print "$_ = $h{$_}\n"; > } > Have you tried using hash slice syntax?, e.g. @d{@a}=@b; [EMAIL PROTECTED] All opinions are my own and not necessarily those of my employer ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Inline.pm from CPAN
Inline.pm from CPAN Hi, Using PPM, I didn't locate this module at AS or Jenda, so I took a stab at installing it from CPAN using nmake, etc. Using Perl build 517 on Win95 Osr2 with no problems I extracted the archive to c:\temp and then went through the usual steps: perl makefile.pl nmake nmake test nmake install The makefile was built fine, but the nmake kept using blib as the root and nothing got installed under the Perl root. This didn't work. I welcome any suggestions to correctly do this. Thanks, Mark Pryor ICQ 64329574 Pgp KeyID: 0x1A966EC5 ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Inline.pm from CPAN
Success, my bad. nmake install<--- worked Thanks anyway, Mark -Original Message- From: Mark Pryor <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]> Date: Thursday, April 12, 2001 7:34 PM Subject: Inline.pm from CPAN >Inline.pm from CPAN > >Hi, > >Using PPM, I didn't locate this module at AS or Jenda, so I >took a stab at installing it from CPAN using nmake, etc. > >Using Perl build 517 on Win95 Osr2 with no problems >I extracted the archive to c:\temp and then went through >the usual steps: >perl makefile.pl >nmake >nmake test >nmake install > >The makefile was built fine, but the nmake kept using >blib as the root and nothing got installed under the Perl root. >This didn't work. I welcome any suggestions to correctly do this. > >Thanks, >Mark Pryor >ICQ 64329574 >Pgp KeyID: 0x1A966EC5 > > >___ >Perl-Win32-Users mailing list >[EMAIL PROTECTED] >http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
Re: Inline.pm from CPAN
> >Using PPM, I didn't locate this module at AS or Jenda, so I > >took a stab at installing it from CPAN using nmake, etc. Locating at, www.ActiveState.com - /PPMPackages/5.6plus/ http://www.ActiveState.com/PPMPackages/5.6plus/ -- [EMAIL PROTECTED] In message <00c801c0c3c4$c760f380$25d3b3d1@sprintmail> "Re: Inline.pm from CPAN" ""Mark Pryor" <[EMAIL PROTECTED]>" wrote: > Success, my bad. > > nmake install<--- worked > > Thanks anyway, > Mark > -Original Message- > From: Mark Pryor <[EMAIL PROTECTED]> > To: [EMAIL PROTECTED] > <[EMAIL PROTECTED]> > Date: Thursday, April 12, 2001 7:34 PM > Subject: Inline.pm from CPAN > > > >Inline.pm from CPAN > > > >Hi, > > .. > >Using Perl build 517 on Win95 Osr2 with no problems > >I extracted the archive to c:\temp and then went through > >the usual steps: > >perl makefile.pl > >nmake > >nmake test > >nmake install > > ___ Perl-Win32-Users mailing list [EMAIL PROTECTED] http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users