943,769 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 1645
  • Perl RSS
Nov 22nd, 2008
0

substitute a string

Expand Post »
i am reading a url and inthat i have an array that has stored the value of a string as follows

Perl Syntax (Toggle Plain Text)
  1. address=no+3%2C+oxford+street
  2.  
  3. in this wat i want is to display the address as
  4.  
  5. "no 3 oxford street"

some one please give me the code to write this as the output i want...
Similar Threads
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008
Nov 22nd, 2008
0

Re: substitute a string

There are other ways, but here is one:

Perl Syntax (Toggle Plain Text)
  1. my $string = 'address=no+3%2C+oxford+street';
  2. (my $key,$value) = split(/=/,$string);
  3. $value =~ tr/+/ /;
  4. $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  5. print $value;
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006
Nov 22nd, 2008
0

Re: substitute a string

Click to Expand / Collapse  Quote originally posted by KevinADC ...
There are other ways, but here is one:

Perl Syntax (Toggle Plain Text)
  1. my $string = 'address=no+3%2C+oxford+street';
  2. (my $key,$value) = split(/=/,$string);
  3. $value =~ tr/+/ /;
  4. $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  5. print $value;

it worked thanks !!
Reputation Points: 1
Solved Threads: 3
Junior Poster
localp is offline Offline
190 posts
since Apr 2008
Nov 22nd, 2008
0

Re: substitute a string

actually there was an error in this line:

(my $key,$value) = split(/=/,$string);

should have been:

my($key,$value) = split(/=/,$string);
Reputation Points: 246
Solved Threads: 67
Practically a Posting Shark
KevinADC is offline Offline
898 posts
since Mar 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: perl beginner question
Next Thread in Perl Forum Timeline: generating 'infinite' strings





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC