Solved

points for tomaugerdotcom

Posted on 2004-10-05
38
351 Views
Last Modified: 2013-12-25
Thanks Tom
0
Comment
Question by:Luxana
  • 14
  • 11
  • 6
38 Comments
 
LVL 11

Expert Comment

by:neester
ID: 12232653
Lucky Tom :)
0
 
LVL 10

Accepted Solution

by:
Luxana earned 0 total points
ID: 12232693
He deserve it because my books are crap and most anwers I found in his comment. He wrote in couple lines what is in my entire book without making any mistake, and I was thinking about something like this before your message:))
0
 
LVL 11

Expert Comment

by:neester
ID: 12232720
Yeah.
I have never purchased a book.
Because most of them are fat and huge - because the author thinks the bigger the book, the better...
And most readers think the same....
So the thin books which get to the point - are neglected - so the publishers would much rather publish a bulky fat book - which doesnt do much except confuse the reader.

If I had the time, I woudl write my own bookes on CSS, XHTML, PHP, SQL and WEBDEVELOPMENT - and get the published...
I mean - the ones out there now are utter garbage...
If someone wants to get in quick, learn fast, and have results - they cant have a 2000 page "reference" book.
Especially PHP...
www.php.net
is all you need after you have the right starting point.
0
 
LVL 10

Author Comment

by:Luxana
ID: 12232766
Yes I know what you are talking about. Lucky me that I did not buy those books I just borrow them :)) The worst is that if you are beginner and you have just base idea what is going on you alwasy and you need to rely on book I think that is point and whole idea of book.
But once you came acros mistake you stop trust that book and you are alwas worried waht will happend now.

Is nobody reading this books before they are published? I do not care if in my book is mistake as long as it is some romance story :)) but in programming it is different:))
0
 
LVL 11

Expert Comment

by:neester
ID: 12232810
LOL True.
And you should write a book and make sure that the reader knows what version of all the software youare running.
and how they can check theirs.
You should give them a warning of what might be different if they have a different version - eg. nothing will work, some functions might have different input requirements, some functons may not work, some methods may need altering etc...
And put that warning on the back, so they see if before they buy it...

that will stop them returning it later...
and stop them being dissapointed with your efforts...
0
 
LVL 10

Author Comment

by:Luxana
ID: 12232863
of course there can not be everything in book for something you need to use common sense for example if it say that you need to run script form c:\ and for me as linux user is this information worthless I will never find c:\ in my / directory:))

The best book what I came across was Bite into Java. This book is masterpiece. Complete introduction to java for dummy person as I am :)) I did not find mistake there and is easy to follow.
0
 
LVL 11

Expert Comment

by:neester
ID: 12232909
Yeah.
When I get the time.
I might seriously concider writing a book.
Although I still have a lot to learn, but what the reader doesnt need is a lot of definition from CPAN or whatnot.
They just want REAL LIFE examples of code...
They want to know the REAL LIFE issues they might come accross - and what they can do to fix it...
etc...

I would of loved a book - which had simple step by step information - and interesting functions that arent well documented...
Underestimated functions - and ones that are very important...
(I have one for PHP - I have told about 10 devs. about it, none had used it before: import_request_variables() -> i use it in every single script I code... and none had used it...)
0
 
LVL 10

Author Comment

by:Luxana
ID: 12232992
I like examples in book it tells you muchmore than hundreds pages. Your are right for people as me at the moment I do not need deep look on complex problem. If I done my job and I will be interested to have a look what is in background I will by reference or something similar. Books shops are full of tho books wich just cost too much and have the same information what doeas the book next to it have:))

I have here book instant CGI/PERL book. This book is based on some EXTROPIA thing:)) There is averything based on it. I have my own apache with cgi-bin directory and I thing I do not need 200 pages about setting up EXTROPIA.
0
 
LVL 11

Expert Comment

by:neester
ID: 12233020
Yeah :)
I have learnt Visual Basic, PERL, PHP, XHTML, HTML, CSS, SQL and a few others - purely from reading code and picking it up...
I dont like being instructed what I need to learn - I cannot learn that way.
I prefer to read something - and learn what I deem necessary.
Although it may not seem very efficent, I am not the type of person to learn something because I am told to...
I need to understand it, and then I can learn it - so someone outlining what NEEDS to be learnt doesnt make sense to me...
I will work out what I need to learn becuse - whatever script I write, will either work or not...
If I read a example.
I can work out what is needed etc...

But yeah.
This is turning into a great little conversation :)
0
 
LVL 10

Author Comment

by:Luxana
ID: 12233099
I have learnt visual, perl, html, java, asp, but this is too much and I need to go to deeps and thats way I'm concetring on one thing oe langugaes related. So a'm linux admin so i'm learning now:
c, perl, cgi with perl, shell scripting. This thinks are wery realted to ech other so it helps me to incerase my knowledge much efficent. Apart of the fact that i'm speaking english just second year and my books are only in english language because in my language I can't find so many books related to what I realy need I did big progress anyway:) I hope:))

Fore some basic programming skills you do not need book at all. Some online tutorials is enough to read and it helps you to get to the point.
0
 
LVL 11

Expert Comment

by:neester
ID: 12233187
You speak english very well for a 2nd year learner!
I am on my 18th year speaking english..
That is assuming I could speak on the day of my birth though...
But I am nearly 19 - so that would cancel it out :)

But yeah.
Tutorials are all you need really - people dont realise it is much easier learning by suggestion and example.
0
 
LVL 10

Author Comment

by:Luxana
ID: 12233498
Chris,

I need to go now , evening I will have a look on tom's suggestions and try to do something to get closer successful result:)

lubo
0
 
LVL 11

Expert Comment

by:neester
ID: 12233538
Luxana,

Thats fine.
Great discussion!
Best of Luck with all your learning!

- Chris
0
 
LVL 10

Author Comment

by:Luxana
ID: 12233602
Thanks Chris

best luck to you as well
We can continue in discusion as well as about some other topics:-) but not now because need to go to work and school.

lubo
0
 
LVL 11

Expert Comment

by:neester
ID: 12233887
Wow still in school?
I am at university.

Well yes - speak to you later!
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12243669
Thanks for the nice compliments guys! I'm always glad to help (and to get pointssssssssss :) hahahah )

Tom
0
 
LVL 11

Expert Comment

by:neester
ID: 12243676
:)
Nice.
Good work.
Deserve the points!
0
 
LVL 11

Expert Comment

by:neester
ID: 12243782
Could you leave the topic here, purely for the conversation on PERL and the PERL books out there...
0
 
LVL 11

Expert Comment

by:neester
ID: 12243919
Great thanks :)
It was just a good discussion, and if someone learns something from it by searching it.
That is better than deleting it.
0
 
LVL 10

Author Comment

by:Luxana
ID: 12246648
Hi COBOLdinosaur

in question http://www.experts-exchange.com/Web/Web_Languages/CGI/Q_21133551.html Tom answers my question wich is not part of my CGI with PERL -  quick start question. It wasmy fault because I should not ask him. But he answers and I wanted to reward him with another points when I solve my problem. Is it possible to  to make this question worth 500 back. And I will continue here solving the problem from CGI with PERL -  quick start question.

Please :-)

thanks

Tom:
 No problems.

The line my $sth = $dbh->prepare($sql) queries the database using the database handle ($dbh) that you need to set up first. This is usually done somewhere BEFORE this line using something like:

my $dbh = DBI->connect($data_source, $username, $auth);

$data_source is the name of the database (you might need to talk to your server administrator or web service to get the exact information)
$username is the username of the DATABASE user. This is sometimes the same as your logon for your website, but not always. Again, check with you web service provider.
$auth is the password for this username.

so usually the line looks something like:

my $dbh = DBI->connect("DBI:mysql:databaseName", "myUserName", "myPassword");

Replace the stuff in quotes with the appropriate information of course.

And don't forget, near the start of your script, make sure you have

use DBI;

Hope this helps! For more information on the DBI module, check out cpan (www.cpan.org). http://cpan.uwinnipeg.ca/htdocs/DBI/DBI.html


Cheers

Tom

Tom you probably mean this line
my $dbh = DBI->connect("DBI:CSV:f_dir=/usr/local/apache/data/address_book")
      or die "Cannot connect: " . $DBI::errstr;

Here I'm connecting DBI database using driver CVS. If this is wrong and database is not connectet why I did not get any error?
I'm trying to run this cript on my local apache by putting script to cgi-bin directory.

My database contain:
# cat address
lname,fname,debt,phone,location
and is
file address
address: ASCII text, with CRLF line terminators


thanks
0
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12248019
Yeah, that's the line that seems to be failing. I must admit I'm a little bit stumped. Let me give you some suggestions and see if that takes us any further...

One thought, without seeing your script, is that the $dbh variable falls out of scope. I'm not sure if this makes sense. When you use the "my" keyword, you're telling Perl that the $dbh variable exists within the current block and any sub-blocks it contains. It's possible (though unlikely) that based on the way the script is written, the $dbh variable no longer exists by the time you get to the $sth = $dbh.... part.

if (something)
{
  my $dbh = ......

  if (something else)
  {
     $dbh... is still okay, however...
  }
}

$dbh... now no longer exists because it's OUTSIDE the block in which it was defined.

-----
The solution in that case, is to define the $dbh variable in the outer block like this:

my $dbh;
if (something)
{
   $dbh = DBI->connect.....
}

my $sth = $dbh..... it's still in scope so we're okay.

--------------

So that's one thing you might quickly look into.

Another thing is of course, that the connect string isn't working, and then the question is "why aren't you getting an error?"
According to the docs, if the DBI->connect() method call fails, it returns undef, which should trigger the second part of your statements (the die part). You can, if you like, explicitly check for an error condition on the next line, though I'm not sure what good that would do:

my $dbh = DBI->connect(...);
die ("Can't connect:" . $DBI->errstr) if $DBI->errstr;

---------------


More specifically, you're working with a CSV table, which means you need the DBD::CSV module to be installed on your server. You might want to check on this quickly to make sure that you have the latest version of DBD::CSV. I found the documentation here:
http://www.perldoc.com/perl5.6.1/lib/DBD/CSV.html

Also, check the separator being used in the actual address_book file. Is it really comma-separated? You can manually define the separator like this:

my $dbh = DBI->connect(qq{DBI:CSV:csv_sep_char=\\|}); # define the "|" as the separator instead of a comma
$dbh->{'csv_tables'}->{'address'} = { 'file' => '=/usr/local/apache/data/address_book'};

....
and then query against the "address" table we just read in from the CSV file:
my $sth = $dbh->prepare("SELECT name, street, city FROM address");
... etc...

I'm sorry I don't have anything more for you at this time - try some of my suggestions out and get back to me on what turns up.

Cheers

Tom
0
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12248065
I just found this little scriptlet that will help you list all the drivers and datasources you have installed. Check that CSV is in there...

use DBI;

# Probe DBI for the installed drivers
my @drivers = DBI->available_drivers();

die "No drivers found!\n" unless @drivers; # should never happen, otherwise you're in deep doo-doo
 
# Iterate through the drivers and list the data sources for each one
foreach my $driver ( @drivers ) {
    print "Driver: $driver\n";
    my @dataSources = DBI->data_sources( $driver );
    foreach my $dataSource ( @dataSources ) {
        print "\tData Source is $dataSource\n";
    }
    print "\n";
}

#------
Give this a shot.

T
0
 
LVL 10

Author Comment

by:Luxana
ID: 12248671
Hi Tom

I create my database with this script:
if this cript is working I assume that driver is installed!?!
#!/usr/bin/perl -wT

use strict;

use DBI;

my $dbh = DBI->connect("DBI:CSV:f_dir=/usr/local/apache/data/address_book")
or die "cannot connect: " . $DBI::errstr;

my $sth = $dbh->prepare(qq`
        CREATE TABLE address_new
        (lname  CHAR(15),
        fname   CHAR(15),
        dept    CHAR(15),
        phone   CHAR(15),
        location CHAR(15))`)
        or die "Cannot prepare: " . $dbh->errstr();
        $sth->execute() or die "Cannot execute: " . $dbh->errstr();
        $sth->finish();

        $dbh->disconnect();

so I assume that CSV driver is presented on my system. When I mess up driver in cript I get output:
install_driver(test) failed: Can't locate DBD/test.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.8.4 /usr/local/share/perl/5.8.4 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.8 /usr/share/perl/5.8 /usr/local/lib/site_perl) at (eval 1) line 3.
Perhaps the DBD::test perl module hasn't been fully installed,
or perhaps the capitalisation of 'test' isn't right.
Available drivers: AnyData, CSV, DBM, ExampleP, File, Proxy, Sponge, XBase.
 at ./test.cgi line 7

look at Available drivers above !

Here I tryed your script:
./driver
Driver: AnyData
Undefined subroutine &Symbol::gensym called at /usr/lib/perl5/DBD/File.pm line 120.

-------------------

now about "my"

script in book says that :
$dbh = DBI->connect("DBI:CSV:f_dir=/usr/local/apache/data/address_book")
      or die "Cannot connect: " . $DBI::errstr;
      
@FIELD_NAMES = ("fname", "lname", "phone", "dept", "location");

@FIELD_DESCRIPTIONS = ("First Name", "Last Name", "Phone", "Department", "Location");

$TABLE= "address";

$CGI = new CGI();

but when I run script I get error :

Software error:

Global symbol "$dbh" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 11.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 14.
Global symbol "@FIELD_DESCRIPTIONS" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 16.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 235.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 241.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 308.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 320.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 357.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 358.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 395.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 410.
Global symbol "@FIELD_NAMES" requires explicit package name at /usr/lib/cgi-bin/address_book.cgi line 411.
Execution of /usr/lib/cgi-bin/address_book.cgi aborted due to compilation errors.

I serched rof this error on internet and I put "my" in frot of it because I thought is correct:))

so haw can I make this variables and arrays available to whole scritp?

lubo
0
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12248742
Heya lubo. Looks like you're right - CSV is definitely installed. Cool. That's one thing out of the way.

For the other script..
you either need to put the "my" back in in front of $dbh (also @FIELD_NAMES, @FIELD_DESCRIPTIONS, $TABLE and $CGI), OR take out the "use strict" near the top of your script.

Personally, my advice to you is to get used to the "my" lexical scoping of variables because it's a really good practice. Just remember to put "my" in front of the variable the FIRST time you use the variable.

To make the variable available to the whole script, just make sure you define it within the main block (outside of any blocks defined by "{" and "}" that you might have.)
But don't make a variable available to the whole script if you don't need it to be. In the particular case of the script you've given me above, these DO look like script-global variables, so yeah, scope them from the outer block.

Does this make any sense or am I rambling?

T
0
 
LVL 10

Author Comment

by:Luxana
ID: 12248804
Hi COBOLdinosaur

I have no other choise only to agree with you:-) So what is your suggestion to me? How can I Tom let finish what he started? Should I create new question?

thanks

Luxana
0
 
LVL 10

Author Comment

by:Luxana
ID: 12249097
Tom ,

I think we make step futher again..

Some problem was here:
previous
$dbh = DBI->connect("DBI:CSV:f_dir=/usr/local/apache/data/address_book")
     or die "Cannot connect: " . $DBI::errstr;
current
$DBH = DBI->connect("DBI:CSV:f_dir=/usr/local/apache/data/address_book")
     or die "Cannot connect: " . $DBI::errstr;

in whole script is varilable $dbh and here it is $DBH :-)
after this I get error about permitions for database file address so I chmod it to 777 and after that:

I'm getting error:

Cannot execute: Unknown column: address.dept at /usr/share/perl/5.8/CGI/Carp.pm line 314, <GEN0> line 1.
sub doAdd {
      my $cgi = shift;
      my $dbh = shift;
      
      my @value_array = ();
      my @missing_fields = ();
      
      my $field;
      foreach $field (@FIELD_NAMES) {
            my $value = $cgi->param($field);
            if ($value) {
                  push(@value_array, "'" . $value . "'");
            } else      {
            push(@missing_fields, $field);
            }                                                       -> line 314
      }

as I understand push is trying to push all entries in array and add new one. Or not? Unknown column: address.dept why? :))
0
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12249290
Looks like this is just a simple case of having a field in your table that is not named the same as the field in your form? Check in your HTML form whether you have a "dept" input field and then check to see if it's a match in your table structure (your @FIELD_NAMES defines it as "Department"). Make sure they are identical!

T
0
 
LVL 10

Author Comment

by:Luxana
ID: 12258205
to: COBOLdinosaur

Hi COBOL I still believe that it was just some misunderstanding between us, but anyway if I done something wrong I'm sorry is not my point to abuse this great webpage which is helping me very well. So because I still did not get my script work I created new question as you suggested.

http://www.experts-exchange.com/Web/Web_Languages/CGI/Q_21160918.html

thanks

Luxana

Tom:

you right it was problem in fields order ! :))

0
 
LVL 10

Author Comment

by:Luxana
ID: 12801775
Hi COBOL

Is it possible to remove your comment from my profile and finish this misunderstanding please? I took your advice and now both questions are closed so nothing is related to your comment.

THANK YOU

0
 
LVL 10

Author Comment

by:Luxana
ID: 12801997
I did not know that, thanks again.

./lubo
0
 
LVL 14

Expert Comment

by:tomaugerdotcom
ID: 12809064
Hey folks. I'm sorry I sort of abandoned this thread. Things got stupid busy at work and I couldn't find the time to give the issue the consideration it deserved. Plus this whole thread left a bad taste in my mouth. I think it could have been handled more diplomatically.

At any rate - Luxana how are you on this issue now?  <edited to remove an offer of help by email and the email address by COBOLdinosaur>

Cheers

Tom
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now