Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

Code function.

Quote Reply
Code function.
Hi.

We appear to be a bit confused as to what this is for. We consider it is a means of writing code so that the code displays to show a user how to do something, i.e. strikethrough, but instead of displaying the code, it just strikes through !

So what is it for then, cos I tested in the forum below on here and that just strikes through too?

*Confused*
Quote Reply
Re: [bluesnavigator] Code function. In reply to
Its for doing stuff like;

Code:
#!/usr/bin/perl

use strict;
use CGI;
my $IN= new CGI;

my @test = qw/test foo bar/;

print $IN->header;
foreach (@test) {
chomp;
print $_ . "\n";
}

print "testing!!!";

It basically puts a <pre>..</pre> tag around the code, as well as a "code" section just above it, so people know what type of code it is.

Hope that helps.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Code function. In reply to
The code tags can still break, though, even if it's used for non markup presentation. Consider, for example regex syntax in perl. I appreciate that this is a highly contrived example, but it illustrates the point that the code tags should disable the interpretation of the markup tags even though the code being presented:

Code:
#! /usr/bin/perl

# Read from STDIN, and print each line out when it begins with 'i',
# or ends with either '/' or 'i'. Case insensitive.

use strict;
use warnings;

while (<STDIN>)
{
print if (m|^|i || m||i);
}

As you can see, the code between the code tags is not faithfully reproduced, becuase the [i] and [/i] are being interpreted as markup, and not as part of the source code. This is clearly wrong behaviour.

Cheers Smile

Last edited by:

twist: Nov 22, 2004, 5:48 AM
Quote Reply
Re: [twist] Code function. In reply to
True, but if you put a . in the tag, i.e [i] [/i], then it DOESN'T get interpreted as a tag, and is shown as its meant to Smile (not that well know, but quite a cool feature =)).

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Code function. In reply to
Putting a '.' in the [ ] also breaks my perl -- what I have to type isn't what I mean, and on top of that, it's inconvenient. Tongue... like I said, it's a (very) contrived example, but ./i is mot the same as /i. If, in order to get your code to display correctly, you have to manually edit it, why bother providing the code tags at all?

Have another example, this time in C... now, adding a '.' to the [ ] part doesn't just change the meaning of the program, it introduces an actual error -- it's something my brain balks at. And having the markup interpreted results in a program that doesn't do what I wanted it to do.

Again, I suggest that having the markup interpreted within code tags is a misfeature Wink

Code:
#include <stdio.h>

int
main(void)
{
int arr[25] = { 1, 1 };
int i;

for (i = 2; i < sizeof arr / sizeof arr[0]; i++)
arr = arr[i - 1] + arr[i - 2];

printf("The %dth Fibonacci number is %d", 25, arr[24]);

return 0;
}