[Chicago-talk] scalar question
Andy_Bach at wiwb.uscourts.gov
Andy_Bach at wiwb.uscourts.gov
Mon Jan 31 15:09:06 PST 2011
> But if you prefer regex:
my $fl1="3321-1.pdf";
my ($pref,$suff,$ext) = ($fl1 =~ m/(\w+)-(\w+)\.(\w+)/);
One thing it's well worth always doing (no matter how sure you are about
your data) is to test your match rather than assume it works:
my ($pref,$suff,$ext);
if ($fl1 =~ m/(\d+)-(\d+)\.(\w+)/ ) {
($pref,$suff,$ext) = ($1, $2, $3);
}
else {
warn("Data doesn't match format: $fl1\n");
}
or, a little less verbose:
my $fl1="3321-1.pdf";
my ($pref,$suff,$ext);
unless ( ($pref,$suff,$ext) = ($fl1 =~ m/(\d+)-(\d+)\.(\w+)/) ) {
warn("Data doesn't match format: $fl1\n");
}
----------------------
Andy Bach
Systems Mangler
Internet: andy_bach at wiwb.uscourts.gov
Voice: (608) 261-5738, Cell: (608) 658-1890
Proposed email program pre-post warning msg:
"Warning: Your mail program have not even shown you the
entire message yet. Logically it follows that you cannot
possibly have read it all and understood it. "
Bike Shed wisdom Poul-Henning Kamp
http://www.webcitation.org/5ZZaDOxyW
-----chicago-talk-bounces+andy_bach=wiwb.uscourts.gov at pm.org wrote: -----
To: "Chicago.pm chatter" <chicago-talk at pm.org>
From: imran javaid <imranjj at gmail.com>
Sent by: chicago-talk-bounces+andy_bach=wiwb.uscourts.gov at pm.org
Date: 01/31/2011 04:01PM
Subject: Re: [Chicago-talk] scalar question
split is one way
But if you prefer regex:
my $fl1="3321-1.pdf";
my ($pref,$suff,$ext) = ($fl1 =~ m/(\w+)-(\w+)\.(\w+)/);
-imran
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
_______________________________________________
Chicago-talk mailing list
Chicago-talk at pm.org
http://mail.pm.org/mailman/listinfo/chicago-talk
More information about the Chicago-talk
mailing list