Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Why does this script not work
Hi all


I MUST point out that I'm no perl programmer

I have this script but it does not work  and I cannot find out what I have g
ot wrong
here is the code

Code:

#!C:\Perl\bin\Perl.exe

$addir = "c:/1/35"; #no trailing slash

$nameoffile = "name.xls"; #Change this for each of the directories i do.
#Because I do not know how to code it to search subfolders as well

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

opendir(THEDIR, "$addir") || &oops("Unable to open directory: $!");
readdir THEDIR;readdir THEDIR;
print qq~<H2><b>Mailing List</b></H2><pre>\n~;
my $totalusers;
if($form{createfile}){
print qq~<form name="f1"><textarea name="t1" rows="8" cols="40" wrap="off" s
tyle="background-color:white;color:black;font-family:monospace">Creating fil
e...\n\n~;
unless (open(FILE, ">$nameoffile")){ print "$!\n\nFile could not be created.
</textarea></form></td></tr></table>"; die }
select FILE;
}
foreach my $file (sort readdir THEDIR) {
unless (open(ADFILE, "$addir/$file")){ print "Unable to open file: $!</td></
tr></table>"; die }
my ($title, $rgt, $rht, $desc, $image, $url, $city, $state, $ctry, $hair, $e
yes, $eth, $relig, $occu, $life, $height, $body, $hob, $kids, $kids2, $rela,
 $poli, $cust, $mar,
$smoke, $drink, $edu, $ast, $incm, $occu2, $reloc, $age, @rft) = <ADFILE>;
chomp($title, $rgt, $rht, $desc, $image, $url, $city, $state, $ctry, $hair, 
$eyes, $eth, $relig, $occu, $life, $height, $body, $hob, $kids, $kids2, $rel
a, $poli, $cust, $mar,
$smoke, $drink, $edu, $ast, $incm, $occu2, $reloc, $age, @rft);
close ADFILE;
$file =~ s/\.dat$//;
print  qq~$file\t$title\t$rgt\t$rht\t$desc\t$im
age\t$url\t$city\t$state\t$ctr
y\t$hair\t$eyes\t$eth\t$relig\
 t$occu\t$life\t$height\t$body\t$hob\t$ki
ds\t$kids2\t$rela\t$poli\t$cust\t$ma
r\t$smoke\t$drink\t$edu\   t$ast\t$incm\t$occu2\t$reloc\t$age\t@rft
\n~;

$totalusers++;
}
if($form{createfile}){
select STDOUT;
close(FILE);
print "$nameoffile has been created!\n</textarea></form>";
}
closedir THEDIR;

END OF CODE

The fault is that it runs all ok BUT it will not make the xls file "name.xls
"

It only prints out to html format in Netscape

I have ran this from the browser line also from Perl Builder

The error_log does NOT show any errors

I have OS Winxp , apache and perl all install on my puter

Many thanks

Report this thread to moderator Post Follow-up to this message
Old Post
hope@hope.com
11-18-04 01:57 AM


Re: Why does this script not work
In article <bbenp0hobm51g3kshs02thoab44i3h7u0j@4ax.com>, hope@hope.com wrote:
>Hi all
>
>I MUST point out that I'm no perl programmer

Noted.

>$nameoffile = "name.xls"; #Change this for each of the directories i do.

> opendir(THEDIR, "$addir") || &oops("Unable to open directory: $!");
> readdir THEDIR;readdir THEDIR;

That's a mistake.  Never -assume- the first two entries of a directory will
be . and .. off the bat.  It's 99.9% likely, but it's -not- a guarantee.
Instead of an arbitrary double-readdir where you toss the contents without
observing them, you should throw your entire file processing into a loop:

foreach my $dirent (readdir(THEDIR)) {
next if ${dirent} =~ /^\.\.?$/;  # Skip . and .. entries.
# Then whatever you want to really happen goes here.
}

Assuming . and .. always return first may yield undesirable results.

> if($form{createfile}){

Is $form{createfile} actually set?  That's a hash key.  You should actually
be using exists() on it as well, not -just- testing for a positive value.

>  unless (open(FILE, ">$nameoffile")){ print "$!\n\nFile could not be created.</tex
tarea></form></td></tr></table>"; die }

I'd say that if you're not getting the error message, you're not hitting
the condition.  And I'd like to know where you think it's getting set.  You
never call any CGI library in the code you presented, nor do you parse the
file manually, nor do you explicitly set the value.  I don't see how it
could -ever- be set with the code you have.  Seeing as it should always
test false, you skip this part of the code, and thus get no file, no errors.

There's your problem.

--
Vorxion - Founder of the knocking-shop of the mind.

"You have it, you sell it, you've still got it--what's the difference?"
--Diana Trent, "Waiting for God", on why a modelling agency is really a
knocking-shop.  Applied by me to the field of consulting.  :)

The Sci-Fi fan's solution to debt:  Reverse the polarity on your charge card
.

Report this thread to moderator Post Follow-up to this message
Old Post
Vorxion
11-18-04 08:56 AM


Re: Why does this script not work
Hi thank you for getting back to me

Please see below comments


On 17 Nov 2004 19:50:18 -0500, vorxion@knockingshopofthemind.com (Vorxion) w
rote:

>In article <bbenp0hobm51g3kshs02thoab44i3h7u0j@4ax.com>, hope@hope.com wrot
e: 
>
>Noted.

Well yes VERY new to it all

I have done search with google to find out how to do things to what I want

I have picked up bits from other peoples info from the search from google

######################


> 
> 
>
>That's a mistake.  Never -assume- the first two entries of a directory will
>be . and .. off the bat.  It's 99.9% likely, but it's -not- a guarantee.
>Instead of an arbitrary double-readdir where you toss the contents without
>observing them, you should throw your entire file processing into a loop:
>
>foreach my $dirent (readdir(THEDIR)) {
>     next if ${dirent} =~ /^\.\.?$/;  # Skip . and .. entries.
>     # Then whatever you want to really happen goes here.
>}

>Assuming . and .. always return first may yield undesirable results.

Ok thank you I have now put that in the top part of the code as you say
 #######################################[
color=darkred]
> 
>
>Is $form{createfile} actually set?[/color]

hmmmmm  well I do not know if it is set, do not how to check it

#################################

> That's a hash key.
What do you mean? I have done a search to what you have said but came up wit
h nothing
 ########################################

>You should actually be using exists() on it as well, not -just- testing for a posit
ive value.
There again I have done a search to find out what you mean.
######################
 
>
>I'd say that if you're not getting the error message, you're not hitting
>the condition.

Yes when I ran it inside Perl Builder it did look if it skipped that part, b
ut did not know why
 #######################################[
color=darkred]
> And I'd like to know where you think it's getting set.[/color]
As I said up above do not know where it gets set or how to make it get set

 ###################################[colo
r=darkred]
> You never call any CGI library in the code you presented  nor do you parse
 the
>file manually, nor do you explicitly set the value.[/color]
there again not got a clue to what you mean with out a example on the above
 ###################################[colo
r=darkred]
> I don't see how it could -ever- be set with the code you have.  Seeing as 
it should always
>test false, you skip this part of the code, and thus get no file, no errors
.
>
>There's your problem.[/color]

Yes I have done some more searching on faults and found out I should have pu
t at the top of my script this for errors

use strict ;
use warnings ;
use CGI :: CARP qw (fatelsToBrowers) ;


Which I ran the script and it did print out these errors

Global symbol "$addir" requires explicit package name at C:/apache/Apache2/c
gi-bin/convertads _bob.cgi line 7.
Global symbol "$nameoffile" requires explicit package name at C:/apache/Apac
he2/cgi-bin/convertads _bob.cgi line 11.
Global symbol "$addir" requires explicit package name at C:/apache/Apache2/c
gi-bin/convertads _bob.cgi line 21.
Global symbol "%form" requires explicit package name at C:/apache/Apache2/cg
i-bin/convertads _bob.cgi line 25.
Global symbol "$nameoffile" requires explicit package name at C:/apache/Apac
he2/cgi-bin/convertads _bob.cgi line 27.
Global symbol "$addir" requires explicit package name at C:/apache/Apache2/c
gi-bin/convertads _bob.cgi line 31.
Global symbol "%form" requires explicit package name at C:/apache/Apache2/cg
i-bin/convertads _bob.cgi line 40.
Global symbol "$nameoffile" requires explicit package name at C:/apache/Apac
he2/cgi-bin/convertads _bob.cgi line 43.
Execution of C:/apache/Apache2/cgi-bin/convertads _bob.cgi aborted due to co
mpilation errors.

Oh Dear  it looks like I have to find out how to go and put those right now


As always, any and all help is greatly appreciated.

Thank you in advance.

John



Report this thread to moderator Post Follow-up to this message
Old Post
hope@hope.com
11-18-04 08:58 PM


Re: Why does this script not work
In article <hcdpp0t6qk3nv750sm8q00a1nvdelju5rc@4ax.com>, hope@hope.com
wrote:
>Yes when I ran it inside Perl Builder it did look if it skipped that part,
>but did not know why

I told you why--it could never have been set to true (or anything other
than being undefined) because you're never setting it.

>As I said up above do not know where it gets set or how to make it get set

With all due respect, then you probably should hire someone to do CGI,
or invest in some books on perl with which to learn yourself.  With your
current neophyte status in perl in general, you're likely also entirely
unfamiliar with the security risks and pitfalls associated with working
from a CGI environment, which can -severely- affect your system security on
the whole, depending on what you implement and -how- you implement it.

>Which I ran the script and it did print out these errors

Those are from the strict module.  You haven't lexically scoped any of your
variables.

I would suggest the following books:

http://www.oreilly.com/catalog/lperl3
http://www.oreilly.com/catalog/pperl3

Get your basics down from at least the first book at the -very- least.

From there, `perldoc CGI` should give you more than enough concise
documentation to know what you should be doing.

I'd also read my security essay on CGI:

http://duran.fairlite.com/cgi-security.html

If you are under a time constraint, or are unwilling to go through the
process of learning perl's fundamentals, I then suggest you contract one of
the fine individuals that frequent this group.  Any of us should be able to
fix you up in short order, at reasonable rates.

Fixing a CGI problem is one thing.  Teaching someone the fundamentals of
perl from the ground up falls outside the scope of this group,
unfortunately.

--
Vorxion - Founder of the knocking-shop of the mind.

"You have it, you sell it, you've still got it--what's the difference?"
--Diana Trent, "Waiting for God", on why a modelling agency is really a
knocking-shop.  Applied by me to the field of consulting.  :)

The Sci-Fi fan's solution to debt:  Reverse the polarity on your charge card
.

Report this thread to moderator Post Follow-up to this message
Old Post
Vorxion
11-19-04 08:56 AM


Re: Why does this script not work
Hi
>With all due respect, then you probably should hire someone to do CGI
>or invest in some books on perl with which to learn yourself

Yes I have got my self some books also done a load of searches on the net
BUT when you are getting on for 66 the old grey matter does not gel so well

All so I take your point about hiring someone to do it for me But two things

1....I thought that it is so small a script that no one would want to do it

2....Also at my age money gets tight for these sort of things

 ########################################
#########

>unfamiliar with the security risks
Yes I agree BUT it will NEVER be on a live server so security is no problem

Let me explain what I'm trying to do
All I'm trying to do is pull data from some dat files from folders
Then put them in a excel file

I did take your point and read up on it BUT could not find any where it said
 about this

I then went on the net to do some searches with google and came up with bits
 and bobs of scripts

So this is where I have got to

I have found out now about the "My" statement and a few others things also a
bout how to put in the top lines

use strict
use warnings
use cgi::carp qw(fatalsToBrowers);

Which as helped a lot

I have also found out some info on the CGI.pm module

But that did help me much

Oh well just have to keep trying

Thank you for your help anyway

Regards



On 18 Nov 2004 20:37:25 -0500, vorxion@knockingshopofthemind.com (Vorxion) w
rote:

>In article <hcdpp0t6qk3nv750sm8q00a1nvdelju5rc@4ax.com>, hope@hope.com
>wrote: 
>
>I told you why--it could never have been set to true (or anything other
>than being undefined) because you're never setting it.
> 
>
>With all due respect, then you probably should hire someone to do CGI,
>or invest in some books on perl with which to learn yourself.  With your
>current neophyte status in perl in general, you're likely also entirely
>unfamiliar with the security risks and pitfalls associated with working
>from a CGI environment, which can -severely- affect your system security on
>the whole, depending on what you implement and -how- you implement it.





> 
>
>Those are from the strict module.  You haven't lexically scoped any of your
>variables.
>
>I would suggest the following books:
>
>http://www.oreilly.com/catalog/lperl3
>http://www.oreilly.com/catalog/pperl3
>
>Get your basics down from at least the first book at the -very- least.
>
>From there, `perldoc CGI` should give you more than enough concise
>documentation to know what you should be doing.
>
>I'd also read my security essay on CGI:
>
>http://duran.fairlite.com/cgi-security.html
>
>If you are under a time constraint, or are unwilling to go through the
>process of learning perl's fundamentals, I then suggest you contract one of
>the fine individuals that frequent this group.  Any of us should be able to
>fix you up in short order, at reasonable rates.
>
>Fixing a CGI problem is one thing.  Teaching someone the fundamentals of
>perl from the ground up falls outside the scope of this group,
>unfortunately.


Report this thread to moderator Post Follow-up to this message
Old Post
hope@hope.com
11-20-04 01:56 AM


Re: Why does this script not work
In article <1drsp013hrtnfjrd2v894ihrtum7pssolp@4ax.com>, hope@hope.com
wrote:
>Hi
> 
>
>Yes I have got my self some books also done a load of searches on the net
>BUT when you are getting on for 66 the old grey matter does not gel so
>well

Hey, I have a 67 year old friend whose grey matter can kick this 33yr
old's (going on 34) grey matter to the curb in a hot New York minute.  Age
doesn't have anything to do with it, really.

>All so I take your point about hiring someone to do it for me But two
>things
>
>1....I thought that it is so small a script that no one would want to do
>it

If it's simple enough, someone'll just charge a nominal fee for something
trivial.

>2....Also at my age money gets tight for these sort of things

Understood.  Been there, done that.  I've had my lean days/months/years.  I
sympathise.  Someone may even do it for next to nothing if they're bored,
don't have anything better to do with their leisure time, and/or are
feeling generous.  It does happen.  :)
 
>
>Yes I agree BUT it will NEVER be on a live server so security is no
>problem

That mindset is dangerous.  Security is always an issue, even at the
physical layer.  If you're not always thinking security to at least some
degree, your system is a hazard waiting to become an accident, period, the
end.

>Let me explain what I'm trying to do All I'm trying to do is pull data
>from some dat files from folders Then put them in a excel file

And you need CGI for this for what reason?  Sounds like a straightforward
perl program to me, with no need for CGI.  What user input do you need that
you figure you need CGI to collect?  Or, what do you want to kick back out
to the browser.  I didn't look at that particular bit--just the bit that
was broken.

>I did take your point and read up on it BUT could not find any where it
>said about this

It's been a few days inbetween here and I've been busy with my in-laws' new
computer (they're next to technologically illiterate), as well as three
major jobs and estimates for clients.  Define "this" in particular for me
again?  It's gotten lost in the shuffle back and forth.

>I then went on the net to do some searches with google and came up with
>bits and bobs of scripts

Often a good way to learn neat tricks, but you'll get a real stylistic
mix--some of which may confuse you at this point in your perl education.

>I have found out now about the "My" statement and a few others things also
>about how to put in the top lines

Also look at our().

>use strict use warnings use cgi::carp qw(fatalsToBrowers);
>
>Which as helped a lot

That would get rid of the warnings, assuming you used the correct
capitalisation and punctuation in the actual code.

>I have also found out some info on the CGI.pm module
>
>But that did help me much

You want to test for a value.  If you just want to see if a field name has
been defined, you could use:

$q = new CGI;
if (defined($q->param('my_field_name'))) {
# Field 'my_field_name' was defined here.  Do whatever.
}

If you find it's defined, you can just set a variable equal to the value of
the expression:  $q->param('my_field_name')

...Or store/use/test it however you like.

>Thank you for your help anyway

If the above helps you further, then post what else you need and I'll try
and squeeze in an answer.  :)  No promises on speed of reply, but I try to
check in here once every couple days, same as I check the Stargate groups.

--
Vorxion - Founder of the knocking-shop of the mind.

"You have it, you sell it, you've still got it--what's the difference?"
--Diana Trent, "Waiting for God", on why a modelling agency is really a
knocking-shop.  Applied by me to the field of consulting.  :)

The Sci-Fi fan's solution to debt:  Reverse the polarity on your charge card
.

Report this thread to moderator Post Follow-up to this message
Old Post
Vorxion
11-20-04 08:56 AM


Re: Why does this script not work
Hi

First let me thank you for sticking with me on this

>It's been a few days inbetween here and I've been busy with my in-laws' new
>computer (they're next to technologically illiterate), as well as three
>major jobs and estimates for clients.  Define "this" in particular for me
>again?  It's gotten lost in the shuffle back and forth.

Ok let me explain in more detail for you

#################################
What I have is this

1....I have a load of dat files in a folder called users  this is in the cgi
 folder like

c:\apache\apache2\cgi-bin\data\users\1234.dat 5678.dat etc

2.....Inside each of these dat files I have information like
password
email
FullName
Street Address
City
Country
Zip
Phone
3.....Now what I want to do is fetch the above info out of the dat files and
 do one of two things

1......Put in a excel l file   OR
2......Make a text/csv file  with information all on one line with it separa
ted by a ","   I then can import that into a excel my self

If I could get that far I could find out how to do all the rest of the stuff
 my self ( I think )

As always, any and all help is greatly appreciated.

Thank you in advance.

John


 ########################################
###################

>In article <1drsp013hrtnfjrd2v894ihrtum7pssolp@4ax.com>, hope@hope.com
>wrote: 
>
>Hey, I have a 67 year old friend whose grey matter can kick this 33yr
>old's (going on 34) grey matter to the curb in a hot New York minute.  Age
>doesn't have anything to do with it, really.
> 
>
>If it's simple enough, someone'll just charge a nominal fee for something
>trivial.
> 
>
>Understood.  Been there, done that.  I've had my lean days/months/years.  I
>sympathise.  Someone may even do it for next to nothing if they're bored,
>don't have anything better to do with their leisure time, and/or are
>feeling generous.  It does happen.  :)
> 
>
>That mindset is dangerous.  Security is always an issue, even at the
>physical layer.  If you're not always thinking security to at least some
>degree, your system is a hazard waiting to become an accident, period, the
>end.
> 
>
>And you need CGI for this for what reason?  Sounds like a straightforward
>perl program to me, with no need for CGI.  What user input do you need that
>you figure you need CGI to collect?  Or, what do you want to kick back out
>to the browser.  I didn't look at that particular bit--just the bit that
>was broken.
> 
>
>It's been a few days inbetween here and I've been busy with my in-laws' new
>computer (they're next to technologically illiterate), as well as three
>major jobs and estimates for clients.  Define "this" in particular for me
>again?  It's gotten lost in the shuffle back and forth.
> 
>
>Often a good way to learn neat tricks, but you'll get a real stylistic
>mix--some of which may confuse you at this point in your perl education.
> 
>
>Also look at our().
> 
>
>That would get rid of the warnings, assuming you used the correct
>capitalisation and punctuation in the actual code.
> 
>
>You want to test for a value.  If you just want to see if a field name has
>been defined, you could use:
>
>$q = new CGI;
>if (defined($q->param('my_field_name'))) {
>     # Field 'my_field_name' was defined here.  Do whatever.
>}
>
>If you find it's defined, you can just set a variable equal to the value of
>the expression:  $q->param('my_field_name')
>
>...Or store/use/test it however you like.
> 
>
>If the above helps you further, then post what else you need and I'll try
>and squeeze in an answer.  :)  No promises on speed of reply, but I try to
>check in here once every couple days, same as I check the Stargate groups.
>
>--
>Vorxion - Founder of the knocking-shop of the mind.
>
>"You have it, you sell it, you've still got it--what's the difference?"
>--Diana Trent, "Waiting for God", on why a modelling agency is really a
>knocking-shop.  Applied by me to the field of consulting.  :)
>
>The Sci-Fi fan's solution to debt:  Reverse the polarity on your charge card.[/colo
r]

Report this thread to moderator Post Follow-up to this message
Old Post
hope@hope.com
11-21-04 01:56 PM


Re: Why does this script not work
hope@hope.com wrote:

(a lot)

Please don't multi-post. If your message is appropriate to multiple
groups, post one message to all of them, so that replies are also
directed to all the relevant groups.

This is a freelance group - you should post here if you want to hire a
freelancer to solve your problem for you. This question is on-topic and
appropriate for comp.lang.perl.misc - the other group where you posted
it - but not here.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

Report this thread to moderator Post Follow-up to this message
Old Post
Sherm Pendley
11-21-04 01:56 PM


Re: Why does this script not work
In article <PLadnZL-Wu0tFj3cRVn-qQ@adelphia.com>, Sherm Pendley wrote:
>
>This is a freelance group - you should post here if you want to hire a
>freelancer to solve your problem for you. This question is on-topic and
>appropriate for comp.lang.perl.misc - the other group where you posted
>it - but not here.

The only relevant part here is that data files should -never- be kept
anywhere under DocumentRoot, and really only programs belong under the
heirarchy of a ScriptAlias'd path.  Whoever designed the software that's
putting data under cgi-bin/data is pretty clueless.

--
Vorxion - Founder of the knocking-shop of the mind.

"You have it, you sell it, you've still got it--what's the difference?"
--Diana Trent, "Waiting for God", on why a modelling agency is really a
knocking-shop.  Applied by me to the field of consulting.  :)

The Sci-Fi fan's solution to debt:  Reverse the polarity on your charge card
.

Report this thread to moderator Post Follow-up to this message
Old Post
Vorxion
11-22-04 01:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL CGI Freelance archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:54 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.