Front page | perl.perl5.porters |
Postings from August 2009
Qs on smartmatch & when/given...
Thread Next
From:
Linda W
Date:
August 7, 2009 12:34
Subject:
Qs on smartmatch & when/given...
Message ID:
4A7C81D2.80702@tlinx.org
I found myself having some Q's on some of the new features (as I've been
trying to figure out how to integrate/use some of them into some
programming...) Anyone more familiar with these? I'm trying to
'port' old code to using the new features...
"How smart is 'smart' (as in a 'smart match')?
for example, if I am matching mailing list names, sometimes people type
in capitalized spellings.
if I have ~~ 'listname', will that reject if some part is capitalized
(am wanting to replace various places where I currently have /listname/i.
In most case a simple lower case match will work, but every once in a while
someone has to capitalize something.
Second) -- if I really want a Regexp match, do I need to include the
// (or m{} or qr{})? or is smart match smart enough to see
'foobar@[\W\.]*.topdom.com' as an 'RE'? Would it be different w/double q's?
3) Sorta 'sad' in a way that I can't special case 'when(...)' to allow
barewords....
4) It mentions using 'when' in a loop having an implicit 'next'.
Is that the same with 'given'?
given (a b c){
when(xx)...
}
i.e. does 'last' break you out of a 'given' as well?
Would that imply that 'given' is a pseudonym for 'foreach'?
--------------
5) "Semantically", (if I hadn't read the man page), I would have though:
given (@addresses_in_favorites) {
when(@address_in_list) {
would match for cross-section addresses in list and
that were in favorites...
}
The perlsyn manpage says that says it's true only if the
arrays are equalalent.
Is there a syntax for the 1st meaning? Like :
given (@list1){
when(@list2)
print "xsection=", (join ", ", $_), "\n";
OR
print "xsection=", (join ", ", (split /\n|\000/,$_)),"\n";
OR
print "xsection=", (join ", ", @_), "\n";
...
}
Thanks much! I'm a bit unfamiliar with the intricacies of
some of the new :5.10 features...(as I try to make use of them).
(Also wish I could use "#!/usr/bin/perl -E :thisprog:, as a shortcut
to using the "use features '5.10';... (Philosophical Q:
why don't pragma statements use a 'pragma' keyword?...
pragma 'enable5.10'? ... I just think of 'pragmas' as using
that word, pragmatically speaking...;)
Linda
Thread Next
-
Qs on smartmatch & when/given...
by Linda W