ActiveState Community

brackets

Posted by mymail on 2009-08-19 12:30

[author]
firstname=Doug
lastname=Sheppard

[site]
name=Perl.com
url=http://www.perl.com/

I get this message when I step though the debugger.
Semicolons are missing on lines 1 and 7.
so I put semicolons. I get more line errors
this is active 5.10 build 1005. I am setting up a test enviroment and need this. I have never seen Dougs stuff fail.
any thoughts?

ericp | Thu, 2009-08-20 10:19

It's hard to answer your question without more info.

- Eric

mymail | Thu, 2009-08-20 10:22

what info would you like? I will be happy to supply any and all you need. This is of the highest importance to me

troyt | Thu, 2009-08-20 10:26

I'm guessing that you're following along with tutorial:

http://www.perl.com/lpt/a/497

The section you're quoting here is not perl, it's just text. It's a sample config file for the stuff that comes later in the tutorial (which you should be able to debug in Komodo).

mymail | Thu, 2009-08-20 10:34

Yes I am following the page to a t. he calls it a class a container.
Yet it still tells me that I need semicolons and then when I put them in
it gets even worst. I am using 5.10 activestate. I dont know anything about komodo. Really. so what would komodo have to say do you think???
Thank you

troyt | Thu, 2009-08-20 10:41

So far, we've put the code for setting various options in our programs directly in the program's source code. This isn't a good approach. You may want to install a program and allow multiple users to run it, each with their own preferences, or you may want to store common sets of options for later. What you need is a configuration file to store these options.

We'll use a simple plain-text format...

That section is supposed to be saved in a separate, text file:

http://www.perl.com/2000/12/tutc.txt

... which is read by the example program:

http://www.perl.com/2000/12/sample.pl

... which uses this module:

http://www.perl.com/2000/12/TutorialConfig.pm

mymail | Thu, 2009-08-20 10:44

ok I think I get it. Thank you so much

mymail | Thu, 2009-08-20 10:41

#Here is the pm
package TutorialConfig;

sub new {
my ($class_name) = @_;

my ($self) = {};
warn "We just created the variable...\n";

bless ($self, $class_name);
warn "and now it's a $class_name object!\n";

$self->{'_created'} = 1;
return $self;
}

sub read {
my ($self, $file) = @_;
my ($line, $section);

open (CONFIGFILE, $file) or return 0;

# We'll set a special property that tells what filename we just read.
$self->{'_filename'} = $file;

while ($line = ) {

# Are we entering a new section?
if ($line =~ /^\[(.*)\]/) {
$section = $1;
} elsif ($line =~ /^([^=]+)=(.*)/) {
my ($config_name, $config_val) = ($1, $2);
if ($section) {
$self->{"$section.$config_name"} = $config_val;
} else {
$self->{$config_name} = $config_val;
}
}
}

close CONFIGFILE;
return 1;
}

sub get {
my ($self, $key) = @_;

return $self->{$key};
}

sub set {
my ($self, $key, $value) = @_;

$self->{$key} = $value;
}

warn "TutorialConfig is successfully loaded!\n";
1;

#now here is the confile

[author];
firstname=Doug
lastname='Sheppard'

[site];
name=Perl.com
url=http://www.perl.com/
#now I have tried it both ways just in case I misunderstood something.
meaning I put the text in the pm to see if that would work and did not.
so I made the config file and it still does the same thing.
Thank you

mymail | Thu, 2009-08-20 10:46

you know when I click on the sample config file it show the text we have been talking about.

troyt | Thu, 2009-08-20 11:00

Take the module and sample configuration file from above (or download the configuration file here and the module here), put it in a file called tutc.txt, and then run this simple program

mymail | Thu, 2009-08-20 11:17

I did just that no kidding.

mymail | Thu, 2009-08-20 11:20

I am on a windows box. if I make a file called tutc.txt I would have to copy both files and I get the same results. you cant save to seperate files to one file. the problem does not go away.

troyt | Thu, 2009-08-20 12:00

I can see how the paragraph I quoted earlier could be confusing when taken out of context. You don't have to combine any of the sample files.

Download all three files, and save them to a convenient directory.

  • tutc.txt is a text file containing data - the CONFIGFILE
  • TutorialConfig.pm is a perl module which provides the ability to read the data in the format used in the CONFIGFILE (tutc.txt)
  • sample.pl is a perl program which loads TutorialConfig.pm so that it can parse tutc.txt, fetch the author's first name, and print it

Run the sample with: perl sample.pl

The output should be:

    TutorialConfig has been successfully loaded!
    We just created the variable... 
    and now it's a TutorialConfig object!
    The author's first name is Doug.

mymail | Thu, 2009-08-20 12:42

#Here is a work around that I found for the cgi errors.
#!Perl/site/lib/tutc.txt
use TutorialConfig;
print "content-type: image/jpeg\n\n";
binmode STDOUT;
print $image;

$tut = new TutorialConfig;
$tut->read('tutc.txt') or die "Couldn't read config file: $!";

print "The author's first name is ",
$tut->get('author.firstname'),
".\n";

#since you have been so cool about this I thought I would share it.
Thanks

mymail | Thu, 2009-08-20 11:42

CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

TutorialConfig is successfully loaded!
We just created the variable...
and now it's a TutorialConfig object!
Couldn't read config file: No such file or directory at c:\inetpub\wwwroot\sample.pl line 7.

Now I have the files in a folder in perl perl/site/lib/tutc.txt
Now yesterday I did not get the cgi errors now I have them. It was a pathing problem yesterday with the cgi.

troyt | Thu, 2009-08-20 12:45

I assumed you were stepping through the tutorial at the command line. If you're running this stuff on a web server, there additional things to think about.

Couldn't read config file: No such file or directory at c:\inetpub\wwwroot\sample.pl line 7.

Is tutc.txt saved in the webserver root directory? If not, sample.pl will not find it because it looks for it in the current directory:

...
$tut->read('tutc.txt') or die "Couldn't read config file: $!";
...

Now I have the files in a folder in perl perl/site/lib/tutc.txt

The config file does not belong there. You could put TutorialConfig.pm there, but perl will look in the current directory for modules too, so you could just put everything in C:\inetpub\wwwroot\ (if you're running a "private" development web server - in a production setting, keep modules somewhere that isn't accessible to the outside world).

mymail | Thu, 2009-08-20 12:52

Sorry I had tunnel vison on the index file not being found.
Yes I am running this under cgi. Yes it is a development box and I found out the hard way to put the pm in the www folder. One of the bugs in active 5.10 is some times it does not find the path as older versions did. I have seen a few post on this.

I have to recreate some of the funtions that our current site has
just to be able to send our quotes in pdf format. you know how development goes. 2 steps forwad 3 steps back.

got any ideas ? I am open

mymail | Thu, 2009-08-20 12:14

Now I get it. Thank you for the expliantion. I still have the cgi errors. I dont understand why. It work yesterday.
thank you so much.

mymail | Wed, 2009-08-26 12:45

Hi I have two strings one is for first name and the next is for last
I want to print them out but I want a space between them. what is the operator for this?
JoeBlow
Joe Blow
I want the later of the 2

troyt | Wed, 2009-08-26 13:42

The cleanest way to do this is:

print "$string1 $string2";

The double quoting allows for variable interpolation, but preserves the space between the strings. A more verbose but equally valid way would be:

print $string1 . " " . $string2;

Printing strings is one of the first things covered in almost all beginner Perl tutorials, so Google is your friend for this kind of question:

http://www.google.com/search?q=perl+space+between+strings

The first link is to this tutorial:

http://en.wikibooks.org/wiki/Perl_Programming/Strings

... which has a number of examples of string concatenation:

http://en.wikibooks.org/wiki/Perl_Programming/Strings#String_Operators

... though I notice that the second link is someone (you?) asking the same question on PerlMonks:

http://www.perlmonks.org/index.pl?node_id=791437

As the Monks note, there are many, many ways to concatenate strings in Perl.