[Chicago-talk] scalar question

Scott Sexton scott.sexton at gmail.com
Mon Jan 31 13:56:18 PST 2011

It looks like you're just trying to get the 3321 part of the whole 3321-1.pdf
name. If so, you should do this:

$fl2=~/^(\d{4})/; # This matches the first 4 digits in the string and puts
them into $1
my $root_name = $1;

Or to use what you had, you'd need to copy the variable first since the
regex replace always happens in place.

$root_name = $f12;
$root_name =~s/\-.*//; # replaces the hyphen and everything after with

On Mon, Jan 31, 2011 at 3:40 PM, Richard Reina <richard at rushlogistics.com>wrote:

> I know I should no this, but I don't and was wondering if someone could
> enlighten me.  I have some scalars that represent filenames and look like
> this
> my $fl1=3321-1.pdf
> my $fl2=3321-2.pdf
> my $fl3=3432-1.pdf
> I can get everything before the "-" like this:
> $fl2=~s/\-.*//; # get the root of the filename
> but how can I do it without changing the contents of the original scalar?
> I'd like to put the result directly in a new scalar.
> $root_name= $f12=~s/\-.*//; # get the root of the filename
> Thanks.
> --
> Richard Reina
> Rush Logistics, Inc.
> Watch our 3 minute movie:
> http://www.rushlogistics.com/movie
> _______________________________________________
> Chicago-talk mailing list
> Chicago-talk at pm.org
> http://mail.pm.org/mailman/listinfo/chicago-talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/chicago-talk/attachments/20110131/b3bd17d6/attachment.html>

More information about the Chicago-talk mailing list