3/17 Been RTFM, but I can't figure this out in Perl: How do I search
a string for a specific pattern, eg. [0-9][0-9]/[0-9][0-9],
and return just that pattern to another variable?
\_ No need to make it personal:
$str =~ /([0-9][0-9]\/[0-9][0-9])/ ; $v = $1 ;
\_ $str =~ m|\d{2}/\d{2}|; $v = $&;
\_ You are telling me it took less effort to write this motd question
than to look this up?
\_ It's not a trivial thing to look up. -tom
\_ I was reading the camel book. I still haven't come across
where it says matches go to $1. But thanx to the person
who answered!
\_ You must not have read very far. Its on page 28 of
the pink camel book.
\_ Oh fuckin' spare me. Like anyone except nweaver
can memorize the whole book or is willing reread the
goddamn thing for something that may or may not be
near the beginning.
\_ I'm not nweaver, but I've been using perl
since v3.0 and I did perl programming for
a living for several years before moving
to java/c++ and now back to c.
\_ s,nweaver,mconst,g
\_ yes, he's more nerdy than smart.
\_ Get real. This is totally trivial. This is one of
the first perl-ish things I learned. -not nw/mc
\_ So exactly how advanced does a question have to
be so it can be asked on the motd without flames?
Heck, if a question is hard, it shouldn't even be
asked cuz we're all so smart here. This question
may be trivial or basic to some, but not to
everyone. Telling the guy he's stupid for not being
able to find it in the book is pointless & childish
\_ It can't be helped...no matter how intelligent they
may be, you have to remember that at heart, too many
csua-ers are immature egomaniacs...*sigh*
\_ It's easy to look up if you know what it is. If
you don't, what do you look up? "pattern matching"
is a huge topic. -tom
\_ It's only one chapter. Read it.
\_ or, another way: ($v) = $str =~ m/($pattern)/;
if you couldn't find this in the manual, you didn't look --
it's one of the basic features of regular expresions. it's
also easy to find in the camel book. or : 'perldoc perlre'
-kurtz, working with perl now, though i'd rather use java or c
\_ It apparently wasn't spoon fed enough from the book.
\_ Oh, yes, "perldoc perlre" should be so obvious to a new perl user. |