develooper Front page | perl.perl5.porters | Postings from August 2009

Qs on smartmatch & when/given...

Thread Next
Linda W
August 7, 2009 12:34
Qs on smartmatch & when/given...
Message ID:
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\.]*' 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

4) It mentions using 'when' in a loop having an implicit 'next'.  
Is that the same with 'given'?

given (a b c){

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){
    print "xsection=", (join ", ", $_), "\n";
    print "xsection=", (join ", ", (split /\n|\000/,$_)),"\n";
   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...;)


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About