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
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
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
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+//;
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
>
> 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/> <
Is there any trim function that trims the spaces before and the end of the string?
> 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) = @_;
>
&
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
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
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
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
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
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,
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
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
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
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
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]
> 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).
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
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
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
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
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
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
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
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
[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
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:
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
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
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
$ 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
34 matches
Mail list logo