Gossamer Forum
Home : General : Perl Programming :

Printing large chunks of Perl code...

Quote Reply
Printing large chunks of Perl code...
I am aware about the q| , qq| and qq~ etc functions, but is there any way to actually print out Perl code properly?

For example, I want to print about 25 lins of code, but it gets screwed up when trying to input the data into a variable :(

Anyone got any suggestions? I have even got to the point of using

q|code|;
q|code|;
q|code|;
q|code|;

..etc for every single one of those 30 lines, but the code is still getting screwed up :(

Any ideas?

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Printing large chunks of Perl code... In reply to
I'm not clear what you mean, please show an example.
Quote Reply
Re: [Paul] Printing large chunks of Perl code... In reply to
Ok, hopfully this will make it a bit clearer. I have some example code;

Code:
#!/usr/bin/perl
# ==================================================================

$code = q|#!/usr/bin/perl

$var = "test";

open(FILE,">$var.html") || die "Cannoot write. Reason: $!";
print FILE "Test file to write to";
close(FILE);

print "Content-type: text/html \n\n";
print "Done...";
|;

open(FILE,">test.cgi") || die "Cannoot write. Reason: $!";
print FILE $code;
close(FILE);

print "Content-type: text/html \n\n";
print "Done";


This gives the following error;

Quote:
syntax error at c:\PROGRA~1\NUSPHERE\APACHE\NSCGI-~1\TEST.CGI line 16, near "|"
Execution of c:\PROGRA~1\NUSPHERE\APACHE\NSCGI-~1\TEST.CGI aborted due to compilation errors.

As you can se, certain charachters are causing problems. Is there something I can use, to wrap around a load of Perl code, so that it isn't parsed?

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Printing large chunks of Perl code... In reply to
POD. :-)

- wil
Quote Reply
Re: [Wil] Printing large chunks of Perl code... In reply to
Unsure

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Printing large chunks of Perl code... In reply to
The error is because you are using qq| | but the code within also has pipes in it such as:

open( ... ) || die( ... )

...so it's clashing.

You can either pick a delimiter that's not in your code, such as:

qq[ ]

Or use __DATA__ ..eg...

Code:
#!/usr/bin/perl

my $data = join("", <DATA>);

__DATA__
Put all your code here

Or use HEREDOCS.

Code:
my $data = <<'SOME_CRAP';
All your code here
SOME_CRAP
Quote Reply
Re: [Paul] Printing large chunks of Perl code... In reply to
Interesting. With your first example, you put the code after the ___TAG___, so how does the script know it is finished?

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Printing large chunks of Perl code... In reply to
Because it hits' __DATA__ and knows whatever is below is just data and not to be compiled.
Quote Reply
Re: [Paul] Printing large chunks of Perl code... In reply to
WOW! I didn't know that :)

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Paul] Printing large chunks of Perl code... In reply to
OMG..It works like a charm Smile Thanks again Paul.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Printing large chunks of Perl code... In reply to
I see in LinksSQL's install.cgi file, they have stuff like this;

BEGIN { $INC{"GT/Base.pm"} = "GT/Base.pm" }

I need to define more than 1 bit of code to a variable, so I really need something that will hold more than one piece of code. i.e;[/code]__DATA__

perl code here

__DATA__;
__DATA2__

other code

__DATA2__;[/code]
Is this valid syntax? I had a bit of a look around, and couldn't find anything relating to my question Frown

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates
Quote Reply
Re: [Andy] Printing large chunks of Perl code... In reply to
__DATA__ is special so you can't use __DATA2__ etc. You could do as install.cgi does but you can only do it with modularized code as it is adding modules into @INC so I'm not sure it won't work for plain code.

What are you wanting to do/achieve?
Quote Reply
Re: [Paul] Printing large chunks of Perl code... In reply to
>>>What are you wanting to do/achieve? <<<

I have several bits of Perl code, that don't need to be run, but simply held in a variable. Basically, what I need to do is some checking, and depending on what the result is, one or the other of the code variables are written to a file.

Cheers

Andy (mod)
andy@ultranerds.co.uk


IMPORTANT: I've now moved to ultranerds.co.uk, and the .com will no longer work!
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package (plugins total "value" $3,325 & rising, for just $350)| GLinks ULTRA Package PRO (plugins total "value" $5,625 & rising, for just $500)
Support Forum | Links SQL Plugins | DMOZ Dumps | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Compare our different Plugin packages *new* Free CSS Templates