Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

parse a simple string 1

Status
Not open for further replies.

wcman

Technical User
May 6, 2004
2
0
0
US
$_ = "Hello World";
How do I remove "Hello" from the string?
I want to transform variable to $_ = "World"

Thanks,

Wcman
 
Several ways to do that, but the easiest is a regular expression:

$_ =~ s/Hello //;

--G
 
It occurs to me you probably would like a more general expression to remove the first word from any string:

$_ =~ s/^.+? //; # removes first word and space from $_

--G
 
Thanks G, Actually I wanted it to parse a line like below where the first two words get removed and replaced by space.
$_ = "05/06/2004 19:53:32 BEGINNING OF STATS";

Remove 05/06/2004 19:53:32
and leave: BEGINNING OF STATS


Thank you,
Wcman
 
Ah. Helps if you post the actual problem first. :)

You can just extend my first regex to do what you want:

$_ =~ s/^.+? .+? //; # removes first 2 words from $_

--G

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top