Created
March 23, 2023 13:29
-
-
Save tobyink/7e62bdc7acd2e9ae0e5d1671c4254e22 to your computer and use it in GitHub Desktop.
Demonstration of some Perl punctuation variables which affect `print`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
{ | |
local $\ = "\n"; # output record separator | |
local $| = 1; # autoflush | |
print "Hello"; | |
print "World"; | |
} | |
# or for better clarity... | |
{ | |
use English; | |
local $OUTPUT_RECORD_SEPARATOR = "\n"; | |
local $OUTPUT_AUTOFLUSH = 1; | |
print "Hello"; | |
print "World"; | |
} | |
# Because we used `local` to set them, the changes were | |
# locally scoped, so they went back to the defaults at | |
# the end of each block. | |
print "Hello"; # no new line! | |
print "World\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oh, I forgot
$,
(a.k.a.$OUTPUT_FIELD_SEPARATOR
) but Perl has that too.