Re: Perl-Win32-Users Digest, Vol 11, Issue 10
At 08:53 AM 6/20/2007 +0530, jagdish eashwar wrote: >I got an idea after your suggestion that I should explore the Text::Wrap >module. If I can get perl to split the string after every so many >characters, I'll have achieved what I want. Is that possible? That's exactly what Text::Wrap does. If u just want to brutally unconditionally wrap the text u can repeatedly do substr()'s on it and join each piece with new lines. -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Perl-Win32-Users Digest, Vol 11, Issue 10
Hi, I got an idea after your suggestion that I should explore the Text::Wrap module. If I can get perl to split the string after every so many characters, I'll have achieved what I want. Is that possible? jagdish eashwar On 6/20/07, [EMAIL PROTECTED] < [EMAIL PROTECTED]> wrote: Send Perl-Win32-Users mailing list submissions to perl-win32-users@listserv.ActiveState.com To subscribe or unsubscribe via the World Wide Web, visit http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users or, via email, send a message with subject or body 'help' to [EMAIL PROTECTED] You can reach the person managing the list at [EMAIL PROTECTED] When replying, please edit your Subject line so it is more specific than "Re: Contents of Perl-Win32-Users digest..." Today's Topics: 1. control characters in perl (jagdish eashwar) 2. RE: control characters in perl (Michael Higgins) 3. RE: control characters in perl (Chris Wagner) -- Message: 1 Date: Tue, 19 Jun 2007 21:08:21 +0530 From: "jagdish eashwar" <[EMAIL PROTECTED]> Subject: control characters in perl To: perl-win32-users@listserv.activestate.com Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="iso-8859-1" Hi, Do word processors insert any character for word wraps like they do for new lines(\n)? If yes, what is the corresponding perl control character? I need to split a multi line string from a word table cell at the word wraps. jagdish eashwar -- next part -- An HTML attachment was scrubbed... URL: http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/perl-win32-users/attachments/20070619/143b2071/attachment-0001.html -- Message: 2 Date: Tue, 19 Jun 2007 09:40:48 -0700 From: "Michael Higgins" <[EMAIL PROTECTED]> Subject: RE: control characters in perl To: Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii" > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of jagdish eashwar > Sent: Tuesday, June 19, 2007 8:38 AM > To: perl-win32-users@listserv.activestate.com > Subject: control characters in perl > > Hi, > > Do word processors insert any character for word wraps like > they do for new lines(\n)? If yes, what is the corresponding > perl control character? I need to split a multi line string > from a word table cell at the word wraps. > > jagdish eashwar > > Some of the more commonly used ASCII codes: Chr(9) = tab Chr(11) = manual line break (shift-enter) Chr(12) = manual page break Chr(13) = vbCrLf (return) Chr(14) = column break Chr(30) = non-breaking hyphen Chr(31) = optional hyphen Chr(32) = space Chr(34) = quotation mark Chr(160) = nonbreaking space For more see also "Chr$" under VBA Help. USAGE EXAMPLE: Selection.TypeText text:=Chr(12) see: www.jojo-zawawi.com/code-samples-pages/code-samples.htm HTH, -- . . . . . . . . .. ... . . .``. .`. .`. . . .` . . . . .` .` . .`. . `. . ` . . .`..`` .```. . . .. . .. . . `.`. . . . . `. . . .`..` `..` . . . `..` -- Message: 3 Date: Tue, 19 Jun 2007 13:43:36 -0400 From: [EMAIL PROTECTED] (Chris Wagner) Subject: RE: control characters in perl To: perl-win32-users@listserv.activestate.com Message-ID: <[EMAIL PROTECTED]> Content-Type: text/plain; charset="us-ascii" At 09:40 AM 6/19/2007 -0700, Michael Higgins wrote: >> Do word processors insert any character for word wraps like >> they do for new lines(\n)? If yes, what is the corresponding >> perl control character? I need to split a multi line string >> from a word table cell at the word wraps. Not that I know of. AFAIK they calculate the wrap everytime. Check out the Text::Wrap module. -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 -- ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs End of Perl-Win32-Users Digest, Vol 11, Issue 10 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Truncating decimal number
How about #!/usr/bin/perl -w use strict; my $number = 10.25233006477356 ; my $truncatedNumber = sprintf("%10.6f", $number) ; print $truncatedNumber ; Result: 10.252330 Keeping in mind that %10.6f is the format for a floating point number with 9 digits and the decimal point or a total of 10. If you number could contain more than three digits to the left of the decimal point you would have to increase 10 to some larger number. Bill From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Brian Rowlands (Greymouth High School) Sent: Tuesday, June 19, 2007 10:18 PM To: perl-win32-users@listserv.activestate.com Cc: John Townsend Subject: RE: Truncating decimal number From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Townsend Sent: Wednesday, 20 June 2007 10:50 a.m. To: perl-win32-users@listserv.activestate.com Cc: Chad Freeman Subject: Truncating decimal number I'm trying to truncate a number, 10.25233006477356, to 6 decimal points. E.g. 10.252330. I don't need to round the number, I just want it to drop everything after the 6th decimal point. This should be easy, but I'm drawing a blank. Thanks Working with strings is probably the most natural way. Convert to a string and peel off the string as far as the 6th DP as people are suggesting. However, mathematically speaking, subtracting 0.000 000 5 from the number and then rounding should work exactly the same. Hope that helps Brian Rowlands ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Truncating decimal number
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of John Townsend Sent: Wednesday, 20 June 2007 10:50 a.m. To: perl-win32-users@listserv.activestate.com Cc: Chad Freeman Subject: Truncating decimal number I'm trying to truncate a number, 10.25233006477356, to 6 decimal points. E.g. 10.252330. I don't need to round the number, I just want it to drop everything after the 6th decimal point. This should be easy, but I'm drawing a blank. Thanks Working with strings is probably the most natural way. Convert to a string and peel off the string as far as the 6th DP as people are suggesting. However, mathematically speaking, subtracting 0.000 000 5 from the number and then rounding should work exactly the same. Hope that helps Brian Rowlands ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Truncating decimal number
8<-- I'm trying to truncate a number, 10.25233006477356, to 6 decimal points. E.g. 10.252330. I don't need to round the number, I just want it to drop everything after the 6th decimal point. This should be easy, but I'm drawing a blank. 8<-- In the spirit of TMTOWTDI, and the with the subtle elegance of one liners try: use strict; use warnings; my $pi = 22 / 7; print "pi is about $pi\n"; $pi =~ s/^(\d+)\.(\d+)$/"$1." . substr($2, 0, 6)/e; print "now pi is about $pi\n"; __END__ Just in ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Truncating decimal number
At 03:50 PM 6/19/2007 -0700, John Townsend wrote: >I don't need to round the number, I just want it to drop everything >after the 6th decimal point. This should be easy, but I'm drawing a >blank. If u really need to truncate it and can't use sprintf for some reason u can do this. sub trunc { my ($num, $places) = @_; my ($int, $frac) = split /\./, $num; return $num if length $frac == $places; if ($places > length $frac) { $frac .= "0" x $places; } $frac = substr $frac, 0, $places; return "${int}.${frac}" if $frac; return $int; } ### print trunc 11.23456, 4; print "\n"; print trunc 5.6, 3; ^D 11.2345 5.600 -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Changing space to escaped space
John Townsend wrote: > I’m trying to change a space to an escaped space. > > I've tried something like this: > > $string = "._\\agmptestapp.exe_ -i > ._\\performance_in\\3Pages3Squares.pdf_ > -o ._\\performance_out\\_ > -1 -dic never -t ps3 -s irs -ppd AdobePDF > 8.0 -timer > timer.txt"; > > $string =~ s, ,\ ,g; > print "string after\n$string\n"; > > However it does not appear to work. > > Can someone suggest a reg ex that works? Or perhaps there is a better > way to approach the problem? You have to double your escape: $string =~ s/ /\\ /g; ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Changing space to escaped space
I'm trying to change a space to an escaped space. I've tried something like this: $string = ".\\agmptestapp.exe -i .\\performance_in\\3Pages3Squares.pdf -o .\\performance_out\\ -1 -dic never -t ps3 -s irs -ppd AdobePDF 8.0 -timer > timer.txt"; $string =~ s, ,\ ,g; print "string after\n$string\n"; However it does not appear to work. Can someone suggest a reg ex that works? Or perhaps there is a better way to approach the problem? Thanks in advance ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Truncating decimal number
Hi John, What about the function sprintf ? I think you can use something like my $decimale = 10.2345678879; The number sprintf("%.6f", $decimale) is what you are look for, isn't? I did this test my $number = 10.5432634657656; my $result = 0; $result = sprintf("%.6f", $number); print "$result"; Cheers, On 19/06/07, John Townsend <[EMAIL PROTECTED]> wrote: I'm trying to truncate a number, 10.25233006477356, to 6 decimal points. E.g. 10.252330. I don't need to round the number, I just want it to drop everything after the 6th decimal point. This should be easy, but I'm drawing a blank. Thanks ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Truncating decimal number
John, Have you thought of using the SPRINTF function? e.g.: my $temp1 = 10.25233006477356; my $temp2 = sprintf("%.6f", $temp1); print $temp2; >> 10.252330 I realize that the SPRINTF will round, but "not needing" and "not wanting" are two different situations. I use this function all the time, and it is easy to implement. If you do not "want" to round, than I don't know. Regards, Michael Cohen "John Townsend" <[EMAIL PROTECTED] om>To Sent by: <[EMAIL PROTECTED] perl-win32-users- ate.com> [EMAIL PROTECTED] cc ActiveState.com Chad Freeman <[EMAIL PROTECTED]> Subject Truncating decimal number 06/19/2007 06:50 PM I'm trying to truncate a number, 10.25233006477356, to 6 decimal points. E.g. 10.252330. I don't need to round the number, I just want it to drop everything after the 6th decimal point. This should be easy, but I'm drawing a blank. Thanks ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs <><><>___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Truncating decimal number
I'm trying to truncate a number, 10.25233006477356, to 6 decimal points. E.g. 10.252330. I don't need to round the number, I just want it to drop everything after the 6th decimal point. This should be easy, but I'm drawing a blank. Thanks ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: control characters in perl
At 09:40 AM 6/19/2007 -0700, Michael Higgins wrote: >> Do word processors insert any character for word wraps like >> they do for new lines(\n)? If yes, what is the corresponding >> perl control character? I need to split a multi line string >> from a word table cell at the word wraps. Not that I know of. AFAIK they calculate the wrap everytime. Check out the Text::Wrap module. -- REMEMBER THE WORLD TRADE CENTER ---=< WTC 911 >=-- "...ne cede malis" 0100 ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: control characters in perl
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On > Behalf Of jagdish eashwar > Sent: Tuesday, June 19, 2007 8:38 AM > To: perl-win32-users@listserv.activestate.com > Subject: control characters in perl > > Hi, > > Do word processors insert any character for word wraps like > they do for new lines(\n)? If yes, what is the corresponding > perl control character? I need to split a multi line string > from a word table cell at the word wraps. > > jagdish eashwar > > Some of the more commonly used ASCII codes: Chr(9) = tab Chr(11) = manual line break (shift-enter) Chr(12) = manual page break Chr(13) = vbCrLf (return) Chr(14) = column break Chr(30) = non-breaking hyphen Chr(31) = optional hyphen Chr(32) = space Chr(34) = quotation mark Chr(160) = nonbreaking space For more see also "Chr$" under VBA Help. USAGE EXAMPLE: Selection.TypeText text:=Chr(12) see: www.jojo-zawawi.com/code-samples-pages/code-samples.htm HTH, -- . . . . . . . . .. ... . . .``. .`. .`. . . .` . . . . .` .` . .`. . `. . ` . . .`..`` .```. . . .. . .. . . `.`. . . . . `. . . .`..` `..` . . . `..` ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
control characters in perl
Hi, Do word processors insert any character for word wraps like they do for new lines(\n)? If yes, what is the corresponding perl control character? I need to split a multi line string from a word table cell at the word wraps. jagdish eashwar ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs