Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > striped name to variable

Reply
Thread Tools

striped name to variable

 
 
blnukem
Guest
Posts: n/a
 
      04-12-2004
Hi All

How do I strip a word out of a phrase and save the striped part as a
variable example:

$phrase = "My name is Nick<br>";
$phrase =~ s/Nick//is;

Now how do I set a new variable that equals the striped part "Nick"


 
Reply With Quote
 
 
 
 
Sam Holden
Guest
Posts: n/a
 
      04-12-2004
On Mon, 12 Apr 2004 13:35:57 GMT, blnukem <(E-Mail Removed)> wrote:
> Hi All
>
> How do I strip a word out of a phrase and save the striped part as a
> variable example:
>
> $phrase = "My name is Nick<br>";
> $phrase =~ s/Nick//is;
>
> Now how do I set a new variable that equals the striped part "Nick"


$new_variable = 'Nick';

Or if we pretend Nick isn't a constant string:

if ($phrase =~ s/(Nick)//is) {
$new_variable = $1;
}

--
Sam Holden
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      04-12-2004
On Mon, 12 Apr 2004, blnukem wrote:

> Hi All
>
> How do I strip a word out of a phrase and save the striped part as a
> variable example:
>
> $phrase = "My name is Nick<br>";
> $phrase =~ s/Nick//is;
>
> Now how do I set a new variable that equals the striped part "Nick"



Save your matches with parentheses, then access them with the $1, $2, $3,
.... variables.

my $name;
if ($phrase =~ s/(Nick)//i){
$name = $1;
}


run `perldoc perlre` and search for 'capture' for more info.

On an unrelated note, why are you using the /s modifier in your RegExp?
It serves no purpose here.

Paul Lalli
 
Reply With Quote
 
GreenLight
Guest
Posts: n/a
 
      04-12-2004
"blnukem" <(E-Mail Removed)> wrote in message news:<1Xwec.5948$(E-Mail Removed) et>...
> Hi All
>
> How do I strip a word out of a phrase and save the striped part as a
> variable example:
>
> $phrase = "My name is Nick<br>";
> $phrase =~ s/Nick//is;
>
> Now how do I set a new variable that equals the striped part "Nick"


my $stripped = ($phrase =~ s/(Nick)//i);

--
my real address is perl - at - milbaugh - dot - com
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Kim Kardashian In A Striped Bikini newwen Python 0 02-17-2009 12:48 PM
"Variable variable name" or "variable lvalue" mfglinux Python 11 09-12-2007 03:08 AM
adding a variable name to a hash to name is part of the variable name Bobby Chamness Perl 2 04-22-2007 09:54 PM
monitor goes blank and striped Smerd Yakov Computer Support 4 06-10-2006 06:25 AM
Striped volume for windows without raid hardware controller Roberto Hernández Windows 64bit 1 12-08-2005 11:38 PM



Advertisments