Re: How do I trim UTF-8 strings?

2009-07-23 Thread Chas. Owens
On Thu, Jul 23, 2009 at 18:43, Jenny Chen wrote: > Hi All, > > I need some help with utf-8 string handling in Perl. I tried to trim utf-8 > strings using Perl. Follow is the main portion of the codes, but it does not > work. Any help will be greatly appreciated. > > J

trim (was: Re: use vs require)

2009-01-24 Thread Dr.Ruud
Chas. Owens wrote: > [trim] $string =~ s/^[ ]*(.*)[ ]*$/$1/; That changes the string when not necessary. I prefer this: s/\s+$//, s/^\s+// for $string; # rtrim + ltrim -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginner

Re: trim

2004-07-08 Thread John
Thanks a lot! It worked! - Original Message - From: "Bob Showalter" <[EMAIL PROTECTED]> To: "'John'" <[EMAIL PROTECTED]>; "Perl Beginners" <[EMAIL PROTECTED]> Sent: Thursday, July 08, 2004 7:07 PM Subject: RE: trim > Joh

Re: trim

2004-07-08 Thread Gunnar Hjalmarsson
John wrote: Is there any trim function that trims the spaces before and the end of the string? Not built-in in the Perl compiler. But you can use your own; I'm using this for instance: sub trim{ for ( grep defined, @_ ){ s/^\s+//;

RE: trim

2004-07-08 Thread Bob Showalter
John wrote: > Is there any trim function that trims the spaces before and the end > of the string? There's probably a module somewhere with such a function. You can also write one simply. I usually use the following: s/^\s+//, s/\s+$// for $variable; I like that form because you

Re: trim

2004-07-08 Thread Wiggins d Anconia
> > Is there any trim function that trims the spaces before and the end of the string? > perldoc -q 'strip blank space' http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <

trim

2004-07-08 Thread John
Is there any trim function that trims the spaces before and the end of the string?

RE: trim function

2003-06-11 Thread Dan Muey
> Hi all, > > say that > > $directory = "C:\\directory\\*.*" > > and I am trying to remove the *.* from the end using > > $directory = trim($directory); > > > where > > trim is > > sub trim { >my( $result) = @_; > &

Re: trim function

2003-06-11 Thread Rob Dixon
Jair Santos wrote: > Hi all, > > say that use strict;# always use warnings; # usually > $directory = "C:\\directory\\*.*" Use single quotes for cuter code. my $directory = 'C:\directory\*.*'; > and I am trying to remove the *.* from the end usi

trim function

2003-06-11 Thread Jair Santos
Hi all, say that $directory = "C:\\directory\\*.*" and I am trying to remove the *.* from the end using $directory = trim($directory); where trim is sub trim { my( $result) = @_; $result =~ s/^\s+(.*?)\s+$/$1/; $result =~ s/\s//g; return $result; } Can anybody po

Re: use perl to trim out non text characters from a file

2002-09-26 Thread Korthrun
Assuming that you are on a *nix box you can open the file in ex and strip it example: I want to take all the ^M's out of a file. root - local#ex somefile.ext 1,$s/.^M//g[enter] w [enter] of course you have to replace ^M with that crazy acii character. try cutting and pasting if you cant

RE: use perl to trim out non text characters from a file

2002-09-26 Thread david
Tim Booher wrote: > I don't know if they are truly "valid, printable characters". When a text > file show this type of information, isn't ascii just approximating some > binary data? > > Why I think this is if I open with notepad I get a file that looks like > the: ÿÿÿ described earl

RE: use perl to trim out non text characters from a file

2002-09-26 Thread Timothy Johnson
r'; [EMAIL PROTECTED] Subject: RE: use perl to trim out non text characters from a file On Sep 26, Timothy Johnson said: >while(){ > $_ = tr/[^characterclass]//g; > print OUTFILE $_; >} > >putting a ^ at the beginning of a character class matches if the >character is NO

RE: use perl to trim out non text characters from a file

2002-09-26 Thread Jeff 'japhy' Pinyan
On Sep 26, Timothy Johnson said: >while(){ > $_ = tr/[^characterclass]//g; > print OUTFILE $_; >} > >putting a ^ at the beginning of a character class matches if the >character is NOT one of those in the brackets. That's not at all how tr/// works. tr/// ALREADY is a character class operator,

RE: use perl to trim out non text characters from a file

2002-09-26 Thread Timothy Johnson
along those lines if you just want to get rid of non-printable characters. -Original Message- From: Tim Booher [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 26, 2002 6:44 AM To: 'Timothy Johnson' Cc: [EMAIL PROTECTED] Subject: RE: use perl to trim out non text characters f

RE: use perl to trim out non text characters from a file

2002-09-26 Thread Tim Booher
Timothy Johnson [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 26, 2002 8:36 AM To: 'Tim Booher'; [EMAIL PROTECTED] Subject: RE: use perl to trim out non text characters from a file Someone out there may have a better answer, but this one seems tougher than average becaus

RE: use perl to trim out non text characters from a file

2002-09-26 Thread Timothy Johnson
e the following: [a-zA-Z0-9_-=()\[\]\\\/'";:>mailto:[EMAIL PROTECTED]] Sent: Thursday, September 26, 2002 5:37 AM To: [EMAIL PROTECTED] Subject: use perl to trim out non text characters from a file Hello – this should be really simple to the learned perl programmer, but I am trying to crea

use perl to trim out non text characters from a file

2002-09-26 Thread Tim Booher
Hello – this should be really simple to the learned perl programmer, but I am trying to create a simple script to trim all the ‘junk’ out of my email files. I get a lot of suspicious emails in outlook and normally drag them to the desktop and open with notepad. This works, but most of the message

Re: issue with chomp - chop need to trim()

2002-09-10 Thread david
Janek Schleicher wrote: > That's why the first one is only a matching, > while the second one is a substitution, > really removing something. > the first one is actually a syntax error. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]

Re: issue with chomp - chop need to trim()

2002-09-10 Thread Sudarshan Raghavan
> the chomp(EXP) function remove the last character from EXP(or $_) only if > that character is a newline for your OS. chomp() knows what newline your OS > uses so you don't have to worry about it. again, chomp doesn't remove > spaces(unless you happen to treat newline and space is the same).

Re: issue with chomp - chop need to trim()

2002-09-09 Thread Janek Schleicher
David wrote at Tue, 10 Sep 2002 03:22:52 +0200: >>> $line =~ /^\s+//; >> >>> $line =~ s/^\s+//; ^ > > even after looking at your reply for 20 seconds, i still didn't see the > differences... :-) how stupid i am? thanks for spot that. The difference is that the first one doesn't h

Re: issue with chomp - chop need to trim()

2002-09-09 Thread rob
u don't have to worry about it. again, chomp doesn't remove >spaces(unless you happen to treat newline and space is the same). > >to trim spaces, try: > >$line ="\t\tabcd\t \t\n"; >$line =~ /^\s+//; >$line =~ /\s+$//; #-- also remove \n >print "|$l

Re: issue with chomp - chop need to trim()

2002-09-09 Thread david
John W. Krahn wrote: >> $line =~ /^\s+//; > >> $line =~ s/^\s+//; even after looking at your reply for 20 seconds, i still didn't see the differences... :-) how stupid i am? thanks for spot that. david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROT

Re: issue with chomp - chop need to trim()

2002-09-09 Thread Michael Fowler
On Mon, Sep 09, 2002 at 08:04:24PM -0500, dizzy74 wrote: [snip] > I did perldoc -q trim and nothing. Of course chop and chomp were there > but diddnt seem to work in a pinch (or I couldnt understand how to apply > the function in my case. The FAQ entry you're looking for is per

Re: issue with chomp - chop need to trim()

2002-09-09 Thread John W. Krahn
David wrote: > > to trim spaces, try: > > $line ="\t\tabcd\t \t\n"; > $line =~ /^\s+//; $line =~ s/^\s+//; > $line =~ /\s+$//; #-- also remove \n $line =~ s/\s+$//; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED

Re: issue with chomp - chop need to trim()

2002-09-09 Thread John W. Krahn
Dizzy74 wrote: > > Hi All Hello, > Today I was trying to do some work with perl and needed to use a > function that would trim leading or trailing spaces from a string. perldoc -q "blank space" Found in /usr/lib/perl5/5.6.0/pod/perlfaq4.pod How do I stri

Re: issue with chomp - chop need to trim()

2002-09-09 Thread david
the chomp(EXP) function remove the last character from EXP(or $_) only if that character is a newline for your OS. chomp() knows what newline your OS uses so you don't have to worry about it. again, chomp doesn't remove spaces(unless you happen to treat newline and space is the sam

issue with chomp - chop need to trim()

2002-09-09 Thread dizzy74
Hi All Today I was trying to do some work with perl and needed to use a function that would trim leading or trailing spaces from a string. Looked on the web and found basicaly perl uses either chop or chomp each with their own features. When I tried to apply it to my $var it either

RE: How do I get trim or rounding on a float number ?

2002-02-08 Thread Jeff 'japhy' Pinyan
[Please do not top-post -- it makes the conversation difficult to follow] On Feb 8, John Edwards said: >>From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] >> >>If you're REALLY worried about whether 12.345 rounds to 12.34 or 12.35, >>then you should use a specific rounding function, but if no

RE: How do I get trim or rounding on a float number ?

2002-02-08 Thread John Edwards
ber $n = 2; # to this many places $rounded = int($number * (10 ** $n) + .5) / (10 ** $n); print $rounded; HTH John -Original Message- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED]] Sent: 08 February 2002 15:01 To: FLAHERTY, JIM-CONT Cc: Beginners (E-mail) Subject: Re:

RE: How do I get trim or rounding on a float number ?

2002-02-08 Thread John Edwards
Well, do you want to round or trim? The number you mention rounded to 2dp would be 25.00. Trimmed to 2dp would be 24.99. To round the number you could do this $number = "24.97"; $rounded = sprintf "%.2f",$number; print $rounded; To trim you could do $number = &q

Re: How do I get trim or rounding on a float number ?

2002-02-08 Thread Jeff 'japhy' Pinyan
On Feb 8, FLAHERTY, JIM-CONT said: >some times comes up with 24.97 . I would like to round or trim to >24.99 for example . any Ideas ?? perldoc -q round will tell you about whether or not Perl has a rounding function. If you're REALLY worried about whether 12.345 rounds

Re: How do I get trim or rounding on a float number ?

2002-02-08 Thread Brett W. McCoy
On Fri, 8 Feb 2002, FLAHERTY, JIM-CONT wrote: > $ aver = $total_hours/$total_jobs > > > some times comes up with 24.97 . I would like to round or trim to > 24.99 for example . any Ideas ?? my $aver = sprintf("%.2f", $total_hours/$total_jobs); per

How do I get trim or rounding on a float number ?

2002-02-08 Thread FLAHERTY, JIM-CONT
$ aver = $total_hours/$total_jobs some times comes up with 24.97 . I would like to round or trim to 24.99 for example . any Ideas ?? thanks Jim F