Skip to main content
Mod Removes Wiki by Doorknob

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 than print ('X'*10) . $/;
  • Perl's say function is shorter than print, but you'll have to run the code with -M5.10.0E instead of -e
  • Use ranges like a..z or even aa..zz. If needed as a string, use join.
  • Incrementing strings: $z = 'z'; print ++$z; will display aa

That's all I can think of right now. I may add some more later.

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 than print ('X'*10) . $/;
  • Perl's say function is shorter than print, but you'll have to run the code with -M5.10.0
  • Use ranges like a..z or even aa..zz. If needed as a string, use join.
  • Incrementing strings: $z = 'z'; print ++$z; will display aa

That's all I can think of right now. I may add some more later.

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 than print ('X'*10) . $/;
  • Perl's say function is shorter than print, but you'll have to run the code with -E instead of -e
  • Use ranges like a..z or even aa..zz. If needed as a string, use join.
  • Incrementing strings: $z = 'z'; print ++$z; will display aa

That's all I can think of right now. I may add some more later.

Source Link
Mr. Llama
  • 2.4k
  • 20
  • 20

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 than print ('X'*10) . $/;
  • Perl's say function is shorter than print, but you'll have to run the code with -M5.10.0
  • Use ranges like a..z or even aa..zz. If needed as a string, use join.
  • Incrementing strings: $z = 'z'; print ++$z; will display aa

That's all I can think of right now. I may add some more later.