Total Pageviews

Friday, April 13, 2012

repetition operator in perl

Another very handy operator is the repetition operator. Let's say you want to underline some output. You might be tempted to code it like this:
    $underline = '--------------------';
    print $underline;
But Perl lets you define a single character and then how many times you want to repeat it:
    $underline = '-' x 20;
    print $underline; # displays '--------------------'

No comments:

Post a Comment