Link to home
Start Free TrialLog in
Avatar of Luxana
LuxanaFlag for Australia

asked on

points for tomaugerdotcom

Thanks Tom
Avatar of neester
neester
Flag of Australia image

Lucky Tom :)
ASKER CERTIFIED SOLUTION
Avatar of Luxana
Luxana
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Avatar of Luxana

ASKER

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:))
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...
Avatar of Luxana

ASKER

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.
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...)
Avatar of Luxana

ASKER

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.
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 :)
Avatar of Luxana

ASKER

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.
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.
Avatar of Luxana

ASKER

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
Luxana,

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

- Chris
Avatar of Luxana

ASKER

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
Wow still in school?
I am at university.

Well yes - speak to you later!
Thanks for the nice compliments guys! I'm always glad to help (and to get pointssssssssss :) hahahah )

Tom
:)
Nice.
Good work.
Deserve the points!
Could you leave the topic here, purely for the conversation on PERL and the PERL books out there...
Great thanks :)
It was just a good discussion, and if someone learns something from it by searching it.
That is better than deleting it.
Avatar of Luxana

ASKER

Hi COBOLdinosaur

in question https://www.experts-exchange.com/questions/21133551/CGI-with-PERL-quick-start.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
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
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
Avatar of Luxana

ASKER

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
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
Avatar of Luxana

ASKER

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
Avatar of Luxana

ASKER

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? :))
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
Avatar of Luxana

ASKER

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.

https://www.experts-exchange.com/questions/21160918/Newbie-need-help-with-CGI-PERL-script.html

thanks

Luxana

Tom:

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

Avatar of Luxana

ASKER

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

Avatar of Luxana

ASKER

I did not know that, thanks again.

./lubo
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