in reply to Editing the contents of a variable
Better? Who knows? That depends on your intent, your data, etc.
More concise (and less reliance on $_... which is easy to overuse):
#!/usr/bin/perl use 5.014; # 988698 my $str = "yada yada <name> string-to-capture </name> foo bar baz"; if ( $str =~ m!<name>(.*?)<\/name>! ) { my $var1=$1; $var1 =~ s/ //g; # removing spaces? print "$var1\n"; }
However, if the actual "tags" are intended to be html, xml or suchlike, your "better way" almost certainly involves using an appropriate parser.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Editing the contents of a variable
by flexvault (Monsignor) on Aug 21, 2012 at 12:58 UTC | |
by ww (Archbishop) on Aug 21, 2012 at 18:07 UTC |
In Section
Seekers of Perl Wisdom