CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Trim

 



centrux
Deleted

Jun 14, 2000, 7:41 AM

Post #1 of 5 (631 views)
Trim Can't Post

How can I remove the other portion of this value, I need only the first 2 characters.

01%26%23Name%5FOKButton%3D++++OK++++



centrux
Deleted

Jun 14, 2000, 7:52 AM

Post #2 of 5 (631 views)
Re: Trim [In reply to] Can't Post

By the way, this value changes and again i need only the first 2 characters...

Thanks a lot in advance...


Kanji
User / Moderator

Jun 14, 2000, 1:25 PM

Post #3 of 5 (631 views)
Re: Trim [In reply to] Can't Post

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

my $value = '01%26%23Name%5FOKButton%3D++++OK++++';
$value = substr($value,0,2); # $value = 01</pre><HR></BLOCKQUOTE>


Cure
User

Jun 17, 2000, 2:25 PM

Post #4 of 5 (631 views)
Re: Trim [In reply to] Can't Post

my $cure = '++91%26%23Name%5FOKButton%3D++++OK++++';
$cure =~ m!(\w{2}|\W{2})! and print $1;


Cure


Kanji
User / Moderator

Jun 18, 2000, 3:01 PM

Post #5 of 5 (631 views)
Re: Trim [In reply to] Can't Post

I know TMTOWTDI, but I'm curious: why advocate a regexp when there's no need?

It doesn't appear to be for simplicity (when m!^(..)! would IMHO be clearer) or efficiency:-

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

#!/usr/bin/perl
use strict;
use Benchmark;

timethese ( 1_000_000 => {
regexp1 => sub {
local $_ = '01%26%23Name%5FOKButton%3D++++OK++++';
my ($x) = m!(\w{2}|\W{2})!;
},
regexp2 => sub {
local $_ = '01%26%23Name%5FOKButton%3D++++OK++++';
my ($x) = m!^(..)!;
},
substring => sub {
local $_ = '01%26%23Name%5FOKButton%3D++++OK++++';
my ($x) = substr($_,0,2);
},
});
__END__
Benchmark: timing 1000000 iterations of regexp1, regexp2, substring...
regexp1: 10 wallclock secs (11.12 usr + 0.00 sys = 11.12 CPU) @ 89950.81/s (n=1000000)
regexp2: 9 wallclock secs ( 9.21 usr + 0.00 sys = 9.21 CPU) @ 108566.58/s (n=1000000)
substring: 6 wallclock secs ( 5.53 usr + 0.00 sys = 5.53 CPU) @ 180790.96/s (n=1000000)</pre><HR></BLOCKQUOTE>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives