On Dec 6, [EMAIL PROTECTED] said:
>> #!/usr/bin/perl -p
>> $_ x=$.<11
>
>Can this one be explained please? (And can we keep explanations in the
>per-hole threads?)
I was using this too, until I reached the age of reason. ;)
I learned the trick from Larry Wall (indirectly). He had the $_ x= N
trick in some code I saw, and I thought it brilliant.
# for brevity, but this is technically incorrect
while (<>) {
$_ = $_ x ($. < 11);
print;
}
$. < 11 is true until $. >= 11, so $. < 11 returns 1 until then, so we get
$_ = $_ x 1; # or just $_
Once $. >= 11, we get:
$_ = $_ x ''; # or '';
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.