CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Whats the problem?

 



yotam_k
Deleted

Feb 13, 2001, 11:28 AM

Post #1 of 13 (1333 views)
Whats the problem? Can't Post

I'v activated this in my system and it's returned 500 INTERNAL ERROR
Whats wrong here ?

#!/usr/bin/perl
print "Content-type:text/html\n\n" ;
open(INPUT, "forum1-0.data") || die "error";
while (<NPUT>) { # Read line by line
chop; # Remove the \n
@data = split("|");
# Split the line with : as delimiter
$key = shift($data);
# Remove the first element from the
# array and save it in $key
$hash{$key} = [ @data ];
}
print $hash{"1000000003"}[5];


Is it unclosing the file?
Yotam.



muinatit
Deleted

Feb 13, 2001, 2:44 PM

Post #2 of 13 (1320 views)
Re: Whats the problem? [In reply to] Can't Post

A lot.


Code
#!/usr/bin/perl  
print "Content-Type: text/html\n\n";

open (INPUT, "forum1-0.data") || die $!;
while (INPUT) {
chomp;
push (@data, $_);
$key = shift($data);
$hash{$key} = @data;
}
close (INPUT);

print $hash{'1000000003'}[5];

Might work.

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


yotam_k
Deleted

Feb 14, 2001, 8:04 AM

Post #3 of 13 (1312 views)
Re: Whats the problem? [In reply to] Can't Post

I didnt...

#!/usr/bin/perl
print "Content-Type: text/html\n\n";

open (INPUT, "data/forums/forum1-0.data") || die $!;
while (INPUT) {
chomp;
push (@data, $_);
$key = shift($data);
$hash{$key} = @data;
}
close (INPUT);

print "$hash{'1000000003'}";


Didnt work...



slycer
stranger

Feb 14, 2001, 8:50 AM

Post #4 of 13 (1311 views)
Re: Whats the problem? [In reply to] Can't Post

Shouldn't while (INPUT) be more like while (<INPUT>)?

I don' t think the first actually reads the filehandle



muinatit
Deleted

Feb 14, 2001, 12:27 PM

Post #5 of 13 (1307 views)
Re: Whats the problem? [In reply to] Can't Post

slycer is right, I can't see how I forgot that. Also, don't quote your variable when you print it.

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


yotam_k
Deleted

Feb 15, 2001, 4:37 AM

Post #6 of 13 (1300 views)
Still Does not work... [In reply to] Can't Post

#!/usr/bin/perl
print "Content-Type: text/html\n\n";

open (INPUT, "data/forums/forum1-0.data")
while (<INPUT>) {
chomp;
push (@data, $_);
$key = shift($data);
$hash{$key} = @data;
}
close (<INPUT>);

print $hash{'1000000003'} ;

Still Does not work...



muinatit
Deleted

Feb 15, 2001, 12:30 PM

Post #7 of 13 (1293 views)
Re: Still Does not work... [In reply to] Can't Post

Alright, why dont you try explaining exactley what the hell you're trying to do here, because you got me.

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


yotam_k
Deleted

Feb 15, 2001, 1:15 PM

Post #8 of 13 (1291 views)
Re: Still Does not work... [In reply to] Can't Post

I am trying to call a row in a flat-database like this:
the first variable in my row will be the key of the hash like this:
if i have in line 5 this :

934|yotam|o@m.c|774389489

I want to call it (say I have a hesh called %forum)
$forum('934')
So i can split and everything

could someone help?

and after that explain to me how to reverse the action so I can make changes and save it back to the flat-text-file im the format it where before...
thank you....





muinatit
Deleted

Feb 15, 2001, 3:19 PM

Post #9 of 13 (1287 views)
Re: Still Does not work... [In reply to] Can't Post

Let me get this straight. You have a database of a bunch of things looking like this:


Code
934|yotam|o@m.c|774389489

And you want to split this stuff up into usuable form? If so I would use something like this...


Code
open (INF, "database.dat") || die $!; 
while (<INF>) {
($fieldone[$_], $fieldtwo[$_], $fieldthree[$_]) = split(/\|/, $_);
}
close (INF);

print $fieldtwo[5];

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


sleuth
Enthusiast

Feb 16, 2001, 12:41 AM

Post #10 of 13 (1283 views)
Re: Still Does not work... [In reply to] Can't Post

 I get it,

What he wants to do is assign the first field of each line to a hash, then he wants to call that line by the name of the first field through the hash then slpit the fields and do other stuff with them. At least that what I came up with outta that explantation. Anway, if it helps to do what I just said you'd have to do this,

open(data, "database.dat");
while(<data>){
(@fields)=split(/\|/, $_);
$fields{$fields[0]}=$_;
}
close(data);

Now you can call your lines by the number in the first field,

print "$fields{'934'}";

OUTPUT:
934|yotam|o@m.c|774389489

Tony



yotam_k
Deleted

Feb 16, 2001, 5:07 AM

Post #11 of 13 (1279 views)
Tony , you are the man!!! [In reply to] Can't Post

Thanks man , it where just great !

but the next thing I'll need is the reverse action -
put the data back into my ordinary form of data like :
934|yotam|o@m.c|774389489
so I can rewrite my datafile and save the changes.

but it were realy great , thank you very much.





muinatit
Deleted

Feb 16, 2001, 5:29 AM

Post #12 of 13 (1277 views)
Re: Tony , you are the man!!! [In reply to] Can't Post

Easy. (I think)..


Code
open (DATA, >"database.dat") || die $!; 
flock (DATA, 2);
print DATA %fields;
close (DATA);

Jeffrey "muinatit" Lamoureux
muinatit@hotpop.com


yotam_k
Deleted

Feb 16, 2001, 7:21 AM

Post #13 of 13 (1276 views)
Re: Tony , you are the man!!! [In reply to] Can't Post

Thanks Man !



 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives