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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I remoove all words in a line except one

Status
Not open for further replies.

zaza230

Technical User
Joined
Feb 14, 2002
Messages
8
Location
FR
this is the content of $error :

$error="error on SnmpMgrRequest 10065"

I would like to remoove all word, except "error"

my goal is to make $error=error

how can I do it
thank very much in advance
 
So you just want the first word in the string?

$error = "error on SnmpMgrRequest 10065";
$error =~ s/^(\w+).+/$1/;
 
You can use split to force the string into two strings, one having the first word and the other having what is to be discarded.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top