freelanceprogrammers.org Forum Index » Perl
How to handle in perl?
Joined: 01 Jun 2005
Posts: 2
How to handle in perl?
Quick Question.
Lets say you have the following
$string = "http://www.ford.com/index.cgi?item=1"
I want to replace index.cgi?item=1
How do I do this.
I can`t figure out how to handle the ?.
Joined: 06 Apr 2005
Posts: 12
How to handle in perl?
> Lets say you have the following
>
> $string = "http://www.ford.com/index.cgi?item=1"
>
>
> I want to replace index.cgi?item=1
>
> How do I do this.
>
> I can`t figure out how to handle the ?.
Well a couple of ways to do it:
Rough unchecked code would go like this
@blownup = split ///, $string;
$blownup[$#blownup] = "new value";
$string = join("/", @blownup);
Alternatively if you new the complete string then you can always used s///
operator on the string.
Take care,
Paul Alapatt
http://www.bernardlabs.org/
________________________________________
Yahoo! Groups Links
• To visit your group on the web, go to:
http://groups.yahoo.com/group/perl_official/
• To unsubscribe from this group, send an email to:
perl_official-unsubscribe@yahoogroups.com
• Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Joined: 21 May 2004
Posts: 44
How to handle in perl?
>>>>> "Michael" == Michael Muff <customer_service@...> writes:
Michael> Quick Question.
Michael> Lets say you have the following
Michael> $string = "http://www.ford.com/index.cgi?item=1"
Michael> I want to replace index.cgi?item=1
Michael> How do I do this.
Michael> I can`t figure out how to handle the ?.
The URI module is good at these things.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Joined: 03 Jun 2005
Posts: 2
How to handle in perl?
On Wed, 1 Jun 2005, Michael Muff wrote:
> Date: Wed, 01 Jun 2005 14:19:32 -0000
> From: Michael Muff <customer_service@...>
> Reply-To: perl_official@yahoogroups.com
> To: perl_official@yahoogroups.com
> Subject: [Perl] How to handle in perl?
>
> Quick Question.
>
>
> Lets say you have the following
>
> $string = "http://www.ford.com/index.cgi?item=1"
@array=split("?", $string);
$first=$array[0];
$secon=$array[1];
$string_now=$first."*".$second;
print $string_now;
This code should output "http://www.ford.com/index.cgi*item=1"
> I want to replace index.cgi?item=1
>
> How do I do this.
>
> I can`t figure out how to handle the ?.
>
>
>
>
>
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
>
+-----------------------+
| Random Fortune Cookie |
+-----------------------+
Hackathon Raisin Rice
10 cups rice
5 Onions, chopped fine
10 cloves garlic, crushed
Butter
2.5 cups raisins
2.5 tsp oregano
22 cups water
40 chicken bouillon cubes (or equivalent - you want to make double
strength chicken stock - chicken-in-a-mug
works well made double strength).
Saute Rice, onion and garlic in a little butter until slightly brown.
I manage this in the (large) pot(s) necessary by throwing together
the onion, garlic, and butter to brown up, then faking it a bit with
the dry rice thrown in while threatening kitchen interlopers with
sharp instruments if they come in to ask how it`s going.
Dissolve bouillon in water, add along with remaining ingredients.
Cook until rice is done (for more intimate proportions, divide down
to an appropriate amount of rice for your occasion).
Joined: 21 May 2004
Posts: 44
How to handle in perl?
>>>>> "Ntina" == Ntina Triantafilidou <ntina23gr@...> writes:
Ntina> @array=split("?", $string);
I doubt that you tried that. Because "split" will treat the first
parameter as a regex.
Note for you in the future. *You* do not get to post untested code.
Always test before answering. Otherwise, I gotta come along to mop up
your mess. That makes you more of a hindrance than a help.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
Joined: 16 Jun 2004
Posts: 9
How to handle in perl?
The question mark is a special character, so you need to escape it with
$string = "http://www.ford.com/index.cgi?item=1";
print "$string
";
$string =~s/index.cgi?item=1/replacement string/ig;
print "$string
";
On 6/1/05 10:19 AM, Michael Muff at customer_service@...
wrote:
> Quick Question.
>
>
> Lets say you have the following
>
> $string = "http://www.ford.com/index.cgi?item=1"
>
>
> I want to replace index.cgi?item=1
>
> How do I do this.
>
> I can`t figure out how to handle the ?.
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







