Chomp vs Chop in Perl

By Pat Natali

use strict;use warnings;#The difference between chomp and chop is that chomp only removes newlinesmy $test = “123n”;print “Original: ” . $test . ” Chomped: ” . chomp($test);#chop doesn’t care what it removesdo { print “Iterating: $testn”;} while (chop($test) ne “”);#outputs:#Original: 123# Chomped: 1Iterating: 123#Iterating: 12#Iterating: 1#Iterating: Next is a slightly more elegant way to take…

What I Learned about Perl Today

By Pat Natali

Today I ran into an issue where I needed to redirect STDERR to STDOUT in a Perl script. So, I figured the easiest way would be to redirect those two files somehow. Perl provides a relatively elegant way to do so. Running open(STDERR, ‘>&STDOUT’) will do the trick by overwriting the STDERR filehandle with a…