perl tips

To substitute text in files in place:
perl -pi -e 's/old_value/new_value/g' (file filter)

To substitute text in files in place, recursively:
find . -name '(file filter)' | xargs perl -pi -e 's/old_value/new_value/g'

To install CPAN modules:
perl -MCPAN -e 'install Chocolate::Belgian'

Use the CPAN shell:
perl -MCPAN -e 'shell'

To set values in the configuration (in the CPAN shell)
o conf urllist shift (removes the top value)
o conf urllist push

To match a regex across multiple lines:
$string =~ m/(regex)/s;
undef $/
open( FILE, $name );
$file = <FILE>;
$file =~ m/(regex)/;

Updated Mar 07, 2024