Skip to content

Perlembed: split code snippet, normalize indentation#24573

Open
bbrtj wants to merge 2 commits into
Perl:bleadfrom
bbrtj:docs/perlembed
Open

Perlembed: split code snippet, normalize indentation#24573
bbrtj wants to merge 2 commits into
Perl:bleadfrom
bbrtj:docs/perlembed

Conversation

@bbrtj

@bbrtj bbrtj commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

While reading perlembed docs, I noticed the snippet under https://perldoc.perl.org/perlembed#Maintaining-a-persistent-interpreter is not very readable - this is because one snippet mixes both Perl and C, and C part (the more important one in this document) gets syntax-colored according to Perl syntax rules, which makes it very unpleasant to read.

This PR splits that code snippet into two so that this should no longer be the case. While at it, I also noticed the indentation of code snippets is all over the place, with even occasional tab characters mixed in. I normalized that to be 4 spaces deep, and each code block is also started by 4-space indent, which hopefully helps plaintext readability.

While changing indentation I had to re-justify a few parts in the code, so I took the liberty to do it slightly differently than it was before, though the differences should be minimal.


  • This set of changes does not require a perldelta entry.

@bbrtj

bbrtj commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

Seems like consistent 4 spaces to start a code block is not feasible because of the 78 character limit here. So I reverted that to 1 space for big code blocks, while others consistently use 4 spaces. Also slightly reorganized Fiddling with the Perl stack from your C program code snippet since that character limit was reducing its readability.

@leonerd leonerd left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looking a good improvement. But while you're here editing it anyway, there's a few more edits that would be nice. Commented inline.

Comment thread pod/perlembed.pod
Comment on lines +757 to +761
local *FH;
open FH, $filename or die "open '$filename' $!";
local($/) = undef;
my $sub = <FH>;
close FH;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're going for making more edits than just strictly whitespace, I'd like to see this updated to not use global filehandles or 2-arg open.

As a first cut, maybe go for 3-arg open into a lexical:

open my $fh, ">", $filename or die ...

Though maybe consider if we want to use File::Slurp::Tiny or somesuch to simplify further.

Comment thread pod/perlembed.pod
my $sub = <FH>;
close FH;

#wrap the code into a subroutine inside our unique package

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Common style on other lines is to put a space after the # character:

# wrap the code ...

Comment thread pod/perlembed.pod
my $eval = qq{package $package; sub handler { $sub; }};
{
# hide our variables within this block
my($filename,$mtime,$package,$sub);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also some whitespace here:

my ($filename, $mtime, $package, $sub);

@bbrtj

bbrtj commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Right, I did not want to get my PR too large in case it gets rejected. If you want me to freshen up the code examples a bit here as well, I can do that.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants