Perl One Liner

Hi ,
Can anybody explain how this perl one liner works..
It is to test whether the number is prime or not

perl -le 'print "PRIME" if (1 x shift) !~ /^(11+)\1+$/' 19

Thanks in advance

Shihab

Wow. Amazing!!!! I haven't seen people test primes like that (but I guess it is not an efficient way to do so)!

It converts the number passed from the command line into a string consisting of a sequence of that number of '1's (1 x shift). Then try to divide that sequence into an integral number of equally-sized chunks, with each consisting of at least 2 '1's (/^(11+)\1+$/). If we cannot divide so, then it will be a prime (hence with the !~ operator)!

I will not have thought of tricks like that. :rolleyes:

Hi,
please tell me how to master your level of experience in reading shell scripts ?
Frankly speaking I would love parser application, generating
human HowItWorks output for any such script on input.

Darius