I'm sure some of these have formal names and I'm just not aware of them.
- If you have a while loop (or a for loop you can make into a while loop) you can define the "while" after the command:
print $n++ while ($n < 10)
- If you need to read everything from STDIN into a string:
$var = join('',<>)
- As CeilingSpy pointed out, using $/ instead of \n is faster in some situations:
print ('X'*10) . "\n";
is longer thanprint ('X'*10) . $/;
- Perl's
say
function is shorter thanprint
, but you'll have to run the code with-M5.10.0E
instead of-e
- Use ranges like
a..z
or evenaa..zz
. If needed as a string, usejoin
. - Incrementing strings:
$z = 'z'; print ++$z;
will displayaa
That's all I can think of right now. I may add some more later.