#!/usr/bin/perl use strict; use warnings; # this is a 'HERE' document # the scalar $program contains all text until the closing EOF my $program = <<'EOF'; #include int main(int argc, char** argv) { std::cout << "Hello World from C++ ;)\n"; } EOF # double quotes does variable interpolation print <<"EOF"; using double quotes here is the code: $program EOF # single quotes does not do variable interpolation print <<'EOF'; using single quotes here is the code: $program EOF ########################################################## # extra fun part my $code = qq!/tmp/code.cpp!; my $binary = qq!/tmp/tmp_binary!; open FILE, ">$code" or die "Can't open $code : $!"; print FILE $program; close FILE; print "\nCompilation:\n"; system "g++ $code -o $binary"; print "\nExecutiton:\n"; system "$binary"; ##########################################################