Persistent include arguments and Perl, oh my

23 views
Skip to first unread message

Neil Faiman

unread,
Nov 25, 2019, 9:39:08 AM11/25/19
to BBEdit Talk Mailing List
I've been staring at this for hours. I must be doing something really stupid, because this behavior seems impossible.

I have an HTML file, "site_menu.html",  that persistent-includes a text file, "Navigation Bar-html5",  that persistent-includes a Perl script, "Generate Navigation Bar-html5".

In site_menu.html

<!-- #bbinclude "Navigation Bar-html5" #MODE#="standalone" -->

Navigation Bar-html5:

<!-- #bbinclude "Generate Navigation Bar-html5.pl" #MENUMODE#="#MODE#" #PAGES#=", Home, The ZBA Home Page
notices, Notices, Application deadlines and notices of future meetings
about_zoning, About Zoning, All about Zoning and the ZBA
members, Members, The members of the Zoning Board
how_to_apply, How to apply, How to apply to the ZBA
abutters, Abutters, Abutter lists and how to create them
ordinance/, Ordinance, The Wilton Zoning Ordinance
bylaws, Bylaws, The Zoning Board Rules of Procedure
cases/, Cases, Decisions and other records from individual Zoning Board cases
minutes/, Minutes, Minutes of past meetings
links, Links, State laws and more zoning information"
-->
<!-- end bbinclude -->

Generate Navigation Bar-html5.pl:

#! /usr/bin/perl -w

use strict;
use Data::Dumper;

print join("\n", @ARGV). "\n";
my ($file, %args) = @ARGV;
$file =~ s/\\ / /g;
my $root = $ENV{BBEditRootDirectory};

print Dumper(\%args);
my $s = $args{"MENUMODE"};
print $s . "\n";
print length($s) . "\n";
foreach (0..length($s)) {
    print substr($s, $_, 1) . "\n";
}

So, the intermediate include file gets the parameter #MODE#="standalone" and passes it on to the Perl script as #MENUMODE#="#MODE#".

In the Perl script I print the incoming arg vector

print join("\n", @ARGV). "\n";

and as expected, in the expanded bbinclude I see

/Users/neil/Library/Mobile\ Documents/com~apple~CloudDocs/zba/zba/site_menu.html
MENUMODE
standalone
PAGES
, Home, The ZBA Home Page
notices, Notices, Application deadlines and notices of future meetings
about_zoning, About Zoning, All about Zoning and the ZBA
members, Members, The members of the Zoning Board
how_to_apply, How to apply, How to apply to the ZBA
abutters, Abutters, Abutter lists and how to create them
ordinance/, Ordinance, The Wilton Zoning Ordinance
bylaws, Bylaws, The Zoning Board Rules of Procedure
cases/, Cases, Decisions and other records from individual Zoning Board cases
minutes/, Minutes, Minutes of past meetings
links, Links, State laws and more zoning information

Then the Perl script converts the argument vector, less the initial file path argument, to a hash:

my ($file, %args) = @ARGV;
$file =~ s/\\ / /g;
my $root = $ENV{BBEditRootDirectory};

print Dumper(\%args);

which is again what I expect:

$VAR1 = {
          'MENUMODE' => 'standalone',
          'PAGES' => ', Home, The ZBA Home Page
notices, Notices, Application deadlines and notices of future meetings
about_zoning, About Zoning, All about Zoning and the ZBA
members, Members, The members of the Zoning Board
how_to_apply, How to apply, How to apply to the ZBA
abutters, Abutters, Abutter lists and how to create them
ordinance/, Ordinance, The Wilton Zoning Ordinance
bylaws, Bylaws, The Zoning Board Rules of Procedure
cases/, Cases, Decisions and other records from individual Zoning Board cases
minutes/, Minutes, Minutes of past meetings
links, Links, State laws and more zoning information'
        };

I assign the MENUMODE entry from the $args hash to a scalar variable:

my $s = $args{"MENUMODE"};
print $s . "\n";

and print it, and it is still what I expect:

standalone

Then everything goes pear-shaped. Remember, I've just printed $s, and gotten "standalone" as I expected. But now I print the length of $s and its individual characters:

print length($s) . "\n";
foreach (0..length($s)) {
    print substr($s, $_, 1) . "\n";
}

And this is the output!

6
#
M
O
D
E
#

What the ???

Again, to put it all together, here is the expanded bbeinclude:

<!-- #bbinclude "Navigation Bar-html5" #MODE#="standalone" -->
/Users/neil/Library/Mobile\ Documents/com~apple~CloudDocs/zba/zba/site_menu.html
MENUMODE
standalone
PAGES
, Home, The ZBA Home Page
notices, Notices, Application deadlines and notices of future meetings
about_zoning, About Zoning, All about Zoning and the ZBA
members, Members, The members of the Zoning Board
how_to_apply, How to apply, How to apply to the ZBA
abutters, Abutters, Abutter lists and how to create them
ordinance/, Ordinance, The Wilton Zoning Ordinance
bylaws, Bylaws, The Zoning Board Rules of Procedure
cases/, Cases, Decisions and other records from individual Zoning Board cases
minutes/, Minutes, Minutes of past meetings
links, Links, State laws and more zoning information
$VAR1 = {
          'MENUMODE' => 'standalone',
          'PAGES' => ', Home, The ZBA Home Page
notices, Notices, Application deadlines and notices of future meetings
about_zoning, About Zoning, All about Zoning and the ZBA
members, Members, The members of the Zoning Board
how_to_apply, How to apply, How to apply to the ZBA
abutters, Abutters, Abutter lists and how to create them
ordinance/, Ordinance, The Wilton Zoning Ordinance
bylaws, Bylaws, The Zoning Board Rules of Procedure
cases/, Cases, Decisions and other records from individual Zoning Board cases
minutes/, Minutes, Minutes of past meetings
links, Links, State laws and more zoning information'
        };
standalone
6
#
M
O
D
E
#
<!-- end bbinclude -->

I mean, if the argument vector entry had been "MENUMODE", "#MENU#", I just would have said, "OK, BBEdit doesn't substitute an incoming parameter value into an outgoing parameter, sighed, and solved my problem some other way. But it does substitute it! The parameter value in the Perl script is clearly "standalone" ... until it isn't.

I can't even.

Can anybody make sense of this?

Thanks,

Neil

Charlie Garrison

unread,
Nov 25, 2019, 5:49:03 PM11/25/19
to BBEdit Talk Mailing List

On 25 Nov 2019, at 12:57, Neil Faiman wrote:

Can anybody make sense of this?

It is very weird behaviour. Send me a zip of the files so I can run locally and I should be able to figure out what's going on.

-cng

--

Charlie Garrison                   <cha...@garrison.com.au>
Garrison Computer Services      <http://www.garrison.com.au>
PO Box 380
Tumbarumba NSW 2653  Australia
Reply all
Reply to author
Forward
0 new messages