<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">It looks like you&#39;re just trying to get the 3321 part of the whole 33</span><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">21-1.pdf name. If so, you should do this:</span></div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; "><br></span></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">$fl2=~/^(\d{4})/; # This matches the first 4 digits in the string and puts them into $1</span></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<span class="Apple-style-span" style="border-collapse: separate; font-family: arial; font-size: small; ">my $root_name = $1;</span></div><div><br></div><div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; ">
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Or to use what you had, you&#39;d need to copy the variable first since </span>the regex replace always happens in place.</div>
<div style="border-collapse: collapse; font-family: arial, sans-serif; font-size: 13px; "><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div>
<font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">$root_name = $f12;</span></font><div><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><span class="Apple-style-span" style="font-size: 13px; ">$root_name =~s/\-.*//; # replaces the hyphen and everything after with nothing</span><br>
</span></font><br></div><div><br><div class="gmail_quote">On Mon, Jan 31, 2011 at 3:40 PM, Richard Reina <span dir="ltr">&lt;<a href="mailto:richard@rushlogistics.com">richard@rushlogistics.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I know I should no this, but I don&#39;t and was wondering if someone could enlighten me.  I have some scalars that represent filenames and look like this<br>
<br>
my $fl1=3321-1.pdf<br>
my $fl2=3321-2.pdf<br>
my $fl3=3432-1.pdf<br>
<br>
I can get everything before the &quot;-&quot; like this:<br>
$fl2=~s/\-.*//; # get the root of the filename<br>
<br>
but how can I do it without changing the contents of the original scalar? I&#39;d like to put the result directly in a new scalar.<br>
<br>
$root_name= $f12=~s/\-.*//; # get the root of the filename<br>
<br>
Thanks.<br>
--<br>
Richard Reina<br>
Rush Logistics, Inc.<br>
Watch our 3 minute movie:<br>
<a href="http://www.rushlogistics.com/movie" target="_blank">http://www.rushlogistics.com/movie</a><br>
<br>
_______________________________________________<br>
Chicago-talk mailing list<br>
<a href="mailto:Chicago-talk@pm.org">Chicago-talk@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/chicago-talk" target="_blank">http://mail.pm.org/mailman/listinfo/chicago-talk</a><br>
</blockquote></div><br></div>