> -----Original Message-----
> From: Darren Simpson [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 07, 2002 11:17 AM
> To: Perl List
> Subject: RE: simple question
>
>
>
> what do the below actually do? they look like dutch to me
> $VisaCard = /^4\d{15}/;
/^4\d{15}/ is a regular expression match operation. Documented
in "perldoc perlop" starting at a heading that looks like this:
m/PATTERN/cgimosx
Since neither the =~ nor !~ operators appear before this, the
match operation is applied to the default variable, $_.
So here the contents of $_ are tested to see whether they
match the pattern:
^4\d{15}
Which means:
^ = beginning of string
4 = the digit 4
\d{15} = a sequence of 15 digits
The results of this match are assigned to the variable $VisaCard.
Since the left-hand side of the assignment is a scalar, the assignment
is made in scalar context. Per the docs, the m// operator in scalar
context will return 1 (true) for a match, or '' (false) for no match.
So, in plain English, $VisaCard is set to 1 if $_ starts with a 4 and
is followed by 15 more digits. Otherwise, $VisaCard is set to ''.
Note that no checking of $_ is done beyond the first 16 positions, so there
can be anything beyond that and $VisaCard will still be 1.
> $BankCard = /^(6565\d{12})|(555[10]00\d{10})/;
This is just a more complex version of the previous statement. $_ is
tested for a pattern, and $BankCard will be set to 1 if it matches the
pattern, or '' if it doesn't.
For the specific syntax of the regular expression, see "perldoc perlre".
Whether these expressions are "right" is another subject. Personally, I
would use a module like Business::CreditCard for this kind of thing...
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]