jmcmillan1873 has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I just want to capture "string-to-capture" without the tags. The following code does that:
I've just started to learn Perl and I'm trying to improve my knowledge.
I've written some code that will capture a string of text from between two points... specifically: <name> string-to-capture </name>I just want to capture "string-to-capture" without the tags. The following code does that:
I imagine that there must be a better way of achieving this, could someone enlighten me please?if ( $_ =~ m/<name>/ ) { $var1=$_; $var1 =~ /<name>(.*?)<\/name>/i; $var1 = $1; $var1 =~ s/ //g; print "$var1\n"; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Editing the contents of a variable
by ww (Archbishop) on Aug 21, 2012 at 11:33 UTC | |
by flexvault (Monsignor) on Aug 21, 2012 at 12:58 UTC | |
by ww (Archbishop) on Aug 21, 2012 at 18:07 UTC | |
Re: Editing the contents of a variable
by Anonymous Monk on Aug 21, 2012 at 12:49 UTC | |
Re: Editing the contents of a variable
by jmcmillan1873 (Initiate) on Aug 21, 2012 at 14:54 UTC | |
by GrandFather (Saint) on Aug 22, 2012 at 03:52 UTC |
Back to
Seekers of Perl Wisdom