Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Code Review: Simple Credit Card Number Validation

by marquezc329 (Scribe)
on Oct 01, 2012 at 02:47 UTC ( #996572=note: print w/ replies, xml ) Need Help??


in reply to Re: Code Review: Simple Credit Card Number Validation
in thread Code Review: Simple Credit Card Number Validation

Thank you for your quick and thorough reply. After looking through your revision I can quickly see how my nested control structures were exaggerated nearly to the point of obnoxious. In particular I really liked your use of:

for my $i (map {$_ * 2} 0 .. $#cardNum / 2) { $cardNum[$i] *= 2; $cardNum[$i] -= 9 if $cardNum[$i] >= 10; }
to cycle through @cardNum. I had thought of trying to use map, but wasn't quite sure how to pick every other element. The only part I don't quite understand is:
return <<INFO; Card Number: $cardNum Issuer: $issuers{$iDigit} INFO
I can see that the subroutine is returning a block called INFO, but I don't quite get the syntax behind the way you defined that block. Is there a name for this style of definition that I can research for a better understanding? Thank you again for reviewing my code. I'm a bit disappointed with myself looking back, but I suppose sophisticated code comes with time and practice.


Comment on Re^2: Code Review: Simple Credit Card Number Validation
Select or Download Code
Re^3: Code Review: Simple Credit Card Number Validation
by GrandFather (Sage) on Oct 01, 2012 at 03:11 UTC

    The <<INFO syntax is (*nix) shell like here-doc line oriented quoting. It's really handy when you have multiple lines of quoted text you want to shovel into a parameter list. You'll want to search the linked documentation for here-doc.

    True laziness is hard work

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://996572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (9)
As of 2015-07-04 14:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls