Fog Creek Software
Discussion Board




Knowledge Base
Documentation
Terry's Tips
Darren's Tips

Handling Perl's foreach, and a couple more ?s

Hi,

I finally sat down and read the entire online help to work on my test site using the Beta5 copy of CD that I have.

First, an important issue that I haven't seen in what is left of the archives here:
1. I wrote an article on Perl, which as you know uses "foreach" as one of its instructions (eg. foreach $capword).

CityDesk chokes on this and refuses to publish my site. I can't tell CD to ignore any .html file for CD code as it will affect other files as well.

The online documentation says that you can use tricks like eg. {{$$}$ instead of ${ to keep CD happy, but no  mention of a way to tell CD to ignore Perl's foreach sections. Any work-around?

Lesser issues and questions:
2. Any way to import HTML files and have CD consider them as articles?
To give it a name and fill the Headline and Keywords sections, it could just read the <HEAD></HEAD> part if files contain relevant information.

As a matter of fact, I don't understand why CD makes a distinction between an Article and an HTML file. Ultimately, they're both files.

3. Anyone using CD intensively for groupware, ie. intensive concurrent accesses through SMB to a .CTY file located on a server?

4. What about making CD the dedicated client that PhpGroupware ( www.phpgroupware.org ) doesn't offer yet?

It seems like the PhpGroupware team is getting started playing with XML-RPC, but it's apparently still a proof of concept.

Fred.

Frederic Faure
Wednesday, February 13, 2002

RE: the difference between articles and HTML files

An *article* gets "poured" into a template when the site is published. You can change templates, publish using different template families, etc without needing to modify the article.

A *file* just gets published as is. There are no templates involved. Depending upon how you configure the CityDesk options, CityDesk may evaluate any CityScript code it finds in the file. HTML files are configured as potentially containing code by default, whereas .class, .jpg, .gif, etc files are not.

Darren Collins
Wednesday, February 13, 2002

A workaround would be to replace one of the letters with the HTML equivelant:

&#102;oreach

where &#102; replaces the f

In case this doesnt' show up right it's

& # 102 ; without the spaces.

See, clumsy, but should work.

Mark W
Wednesday, February 13, 2002

Hi!

Don't use the betas! They have bugs which we fixed. Anyway, the beta "officially" ended on Jan 1 so your license to use them has expired.

There is no problem using "foreach" anywhere in CityDesk. Unless it's inside {$ ... $}, it won't get parsed.

If you have perl scripts that you don't want to be parsed, you can put them in .pl files and then tell CityDesk not to parse .pl files at all. That will make all your {$'s go through intact. To tell CityDesk not to parse .pl files, use the File Types dialog.

Joel Spolsky
Wednesday, February 13, 2002

Hi Joel

>>Don't use the betas! They have bugs which we fixed. Anyway, the beta "officially" ended on Jan 1 so your license to use them has expired.

OK, I'll download the free version to keep on learning CD...

>>There is no problem using "foreach" anywhere in CityDesk. Unless it's inside {$ ... $}, it won't get parsed.

Er... Here's what my perl.html tutorial contains, and CD returns an error and refuses to publish the site:

foreach $capword (sort keys(%wordlist)) {
    print (&quot;$capword $wordlist{$capword}\n&quot;);
}

>>If you have perl scripts that you don't want to be parsed, you can put them in .pl files and then tell CityDesk not to parse .pl files at all.

It's a pain to have to create a small file just to externalize a few lines of code. Besides, it'd be clumsy for readers to have to click to see a sample. I guess I'll use the trick explained by Mark instead.

Thx
Fred.
        

Frederic Faure
Thursday, February 14, 2002

While I'm at it:

&#123; = {
&#125; = }
&#36;  = $

Mark W
Thursday, February 14, 2002

Fred,

its not the foreach that its choking on, its the part that says
{$capword}

change that to {{$$}$capword} and it should work.

this is because {$ is the start of cityscript to citydesk, so it tries to parse the capword and comes up confused...

Michael H. Pryor
Thursday, February 14, 2002

Thx everyone for the tips... but no go: replacing {$ with {{$$}$ doesn't work.

Just add an HTML file to a site, and stick the following in it, and publish your site:
foreach $capword (sort keys(%wordlist)) {
    print ("$capword: $wordlist{{$$}$capword}\n");
}

I guess the least painful way is to follow Mark's advice, but it sure is a pain to have to remember to use HTML encoding when copy/pasting Perl code into a document...

Considering how widespread Perl is, it's a bit strange that FG still went for Perl-specific keywords instead of coming with its own keywords to avoid this kind of issue.

Thx

Frederic Faure.
Thursday, February 14, 2002

I tested it and it works for me. here's my output (HTML page):

test
By joe shmoe
Thursday, February 14, 2002

foreach $capword (sort keys(%wordlist)) { print ("$capword: $wordlist{$capword}\n"); }

Mark W
Thursday, February 14, 2002

Publishes fine for me too.

Its probably b/c you're using the beta, and not the release.

Michael H. Pryor
Thursday, February 14, 2002

In XML, you can tell the parser to ignore any entities inside a block of text, by doing something like this (assume the <sourcecode> tag is something in my DTD):

Here's a tag to include an image:
<sourcecode><![CDATA[
<img src="foo.gif">
]]></sourcecode>

The CDATA marker sets the text apart so it doesn't mess with the parser. Maybe there could be something like this in CityDesk to isolate larger sections from the citydesk parser? Actually altering the text itself becomes very frustrating if you're trying to include code samples in a CityDesk-managed document and you want to be able to pull the code out of the document and run it (to test or debug it, etc.)

David Sklar
Thursday, February 14, 2002

Thx to Michael and Mark...  but even after uninstalling Beta5 (leaving an empty "D:\Progam Files\CityDesk\" save for an .INI file) and installing the Started edition, the {{$$}$ tricks only works if I stick a space before or after the {$$} part, ie. either "{ {$$}$capword" or "{{$$} $capword}".

Problem is, users will find it odd if there's an extra space, and I'm not sure Perl with compile something like that (haven't tried.)

Otherwise, CD terminates with "Script Error: undeclared variable or illegal identifier "capword" in \perl.html" and refuses the publish the rest of the site.

Do you guys confirm that creating an empty HTML document in CD, and sticking "print ("$capword: $wordlist{{$$}$capword}\n");" (without the extra quotes, obviously) anywhere in the BODY section works for you? Weird...

Thx

Frederic Faure.
Friday, February 15, 2002

I got it too:

Script Error: undeclared variable or illegal identifier "capword" in \index.html

The only thing that seemed to work is putting spaces around the {$$} .

Mark W
Friday, February 15, 2002

*  Recent Topics

*  Fog Creek Home