[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Omaha.pm] perl
On Apr 25, 2012, at 9:11 PM, Klinkebiel, David L wrote:
> Jay, Why do you have the | separator for chr9-10 in your perl?
>
> my %parts = (
> 1 => qr/^chr[1-2]$/,
> 2 => qr/^chr[3-4]$/,
> 3 => qr/^chr[5-6]$/,
> 4 => qr/^chr[7-8]$/,
> 5 => qr/^chr(9|10)$/,
> 6 => qr/^chr1[1-2]$/,
> 7 => qr/^chr1[3-4]$/,
> 8 => qr/^chr1[5-6]$/,
> 9 => qr/^chr1[7-8]$/,
The code above doesn't make much sense. (I should know since apparently I wrote it :) Here's some info about Perl regular expressions:
Square brackets are sets of characters. Like [aeiouy] for "any vowel." Dashes let you specify a range.
So [1-2] says "any single character in the ASCII chart between 1 and 2, inclusive."
[12] says "any single character, either 1 or 2."
[21] says "any single character, either 2 or 1."
So those 3 all do the exact same thing. Only "1" or "2" match.
Usually ranges (dashes) are used for larger ranges. e.g.: [a-y] means "any lower case letter except "z".
Parens and pipes let you have give options of varying lengths. Like (apple|pear|dog).
So (9|10) means "9" or "10".
Does that help?
Cheers,
j