but you can do something like this too:<br><br>$bar = join &quot; - &quot;, ($foo=~/(\w+-\d+)-(\d+)/g)[0,1];<br><br>or<br><br>$bar = join &quot; - &quot;, reverse $foo=~/(\w+-\d+)-(\d+)/g;<br><br>but <br><br>$bar=&quot;$2 - $1&quot; if $foo=~/(\w+-\d+)-(\d+)/;<br>
<br>is the better way<br><br>(sorry, i dont speak english...)<br><br><div class="gmail_quote">2008/7/8 Fernando Oliveira &lt;<a href="mailto:fernandocorrea@gmail.com">fernandocorrea@gmail.com</a>&gt;:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="Ih2E3d">$bar=&quot;$2 - $1&quot; if $foo=~/(\w+-\d+)-(\d+)/;<br>is the best way...<br><br></div><div class="gmail_quote"><div class="Ih2E3d">2008/7/8 Madison Kelly &lt;<a href="mailto:linux@alteeve.com" target="_blank">linux@alteeve.com</a>&gt;:<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
 &nbsp;So many people replied so quickly, thank you all!<div><div></div><div class="Wj3C7c"><br>
<br>
 &nbsp;I should have been more clear; &#39;$foo&#39; is set further up; I set in manually for this email only.<br>
<br>
 &nbsp;I&#39;ve got this working (real-world where I want two variables):<br>
<br>
my ($bar, $baz)=$foo=~/(\w+-\d+)-(\d+)/;<br>
<br>
 &nbsp;May I extend the question?<br>
<br>
 &nbsp;How would I go about working with &#39;$1&#39;, &#39;$2&#39;, etc if I wanted to do something odd, like say (totally fabricated, broken example):<br>
<br>
my $bar=&quot;$2 - $1&quot;=$foo=~/(\w+-\d+)-(\d+)/;<br>
<br>
 &nbsp;Again, thanks all. This list rocks, if only because of the enthusiasm shown for code optimization (of course, for more reasons, too!).<br>
<br>
Madi<br>
<br>
Madison Kelly wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi all,<br>
<br>
 &nbsp;I&#39;ve got a simple problem I often come across, and I&#39;ve got a way to make it work. However, I&#39;ve always felt there must be a more ... elegant way of doing it.<br>
<br>
For example, let&#39;s say I want to copy a variable and strip a bit off the end;<br>
<br>
my $foo=&quot;ABC-987-01&quot;;<br>
my $bar=$foo;<br>
$bar=~s/(\w+-\d+)-\d+/$1/;<br>
# $bar now &#39;ABC-987&#39;.<br>
<br>
That&#39;s three lines. Is there a way to do this in one line? Specifically, is there a way to assign &#39;$1&#39; to a new variable in one go?<br>
<br>
Thanks!<br>
<br>
Madi<br>
</blockquote>
<br>
_______________________________________________<br>
toronto-pm mailing list<br>
<a href="mailto:toronto-pm@pm.org" target="_blank">toronto-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/toronto-pm" target="_blank">http://mail.pm.org/mailman/listinfo/toronto-pm</a><br>
</div></div></blockquote></div><br><br clear="all"><div><div></div><div class="Wj3C7c"><br>-- <br>Just another Perl Hacker,<br>Fernando (SmokeMachine)<br><a href="http://perl-e.org" target="_blank">http://perl-e.org</a>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Just another Perl Hacker,<br>Fernando (SmokeMachine)<br><a href="http://perl-e.org">http://perl-e.org</a>