Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created March 23, 2023 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyink/7e62bdc7acd2e9ae0e5d1671c4254e22 to your computer and use it in GitHub Desktop.
Save tobyink/7e62bdc7acd2e9ae0e5d1671c4254e22 to your computer and use it in GitHub Desktop.
Demonstration of some Perl punctuation variables which affect `print`
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";
@tobyink
Copy link
Author

tobyink commented Mar 23, 2023

Oh, I forgot $, (a.k.a. $OUTPUT_FIELD_SEPARATOR) but Perl has that too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment