i need somehelp with perl/cgi

liunx

Guest
how would i be able to store data similar to below

ghfdhfjd 1342
gdhhhjsj 3452
gteysjjs 7656

and then be able to display on a html page sorted according to the numerical value ?

i am new to perl (started yesterday) any help welcomed and very much needed :)

thanxfirst thing you absolutely must do is go buy the "camel book" and the "ram book" ("Programming Perl", "Perl Cookbook" by O'Reilly). seriously, just go get them.

(now)

# globals:
$file = '/home/users/blah/file.dat';


# write data to file stored in $myData HASH:
{
my($key, $val);
my $file = '/home/users/blah/file.dat';
open(DATAFILE, ">$file");
while(($key,$val) = each($myData)){
print DATAFILE $key, "\t", $val, "\n";
}
close(DATAFILE);
}


# read data:
{
my @fields;
open(DATAFILE, "<$file");
while(<DATAFILE>){
@fields = split /\t/, $_;
next if($#fields!=2);
$myData{$fields[0]} = $fields[1];
}
close(DATAFILE);
}

# sort & print
{
my $key;
foreach $key(sort keys %myData){
print "Key: $key, Value: " . $myData{$key} . "\n<BR>\n";
}
}


i haven't programmed perl in a while, and haven't tested this out - it's completely off the top of my head. guarantee there's an error or three in there, but it'll be good learning for ya to debug it out. lemme know how it works out for ya, but ONLY after you play with this for a while - i wanna help, but help you learn :)

cheers
blake_caldwell
Pluginbox.comAlternatively - if it's available to you - you could use MySql. It is (in my opinion) so much easier to store and manipulate data than using perl flat files.

I totally agree with Ruttigers comment about Larry Walls Programming perl - but I would like to add that Randall Schwartz Learning perl is pretty damned good also.

As far as I recall Larry himself said it contains the 30% of perl you need to use 90% of the time.
But don't shoot me if I'm wrong......Hi,
Do you know where I cna get these book, I know very little, if none, about perl and a book would really help.
Thank You,
Paulbook storewww.amazon.com have all the O'Reilly perl booksseriously tho, i go to Barnes and Noble...they have most all the O'Reilly's you need.

you can also order them directly from
<!-- m --><a class="postlink" href="http://www.oreilly.comOriginally">http://www.oreilly.comOriginally</a><!-- m --> posted by hacker
Hi,
Do you know where I can get these book, I know very little, if none, about perl and a book would really help.
Thank You,
Paul
Here are the ISBN nos., and cheapest merchant online.

Advanced Perl Programming
by Wall
Paperback
Published by O'Reilly & Associates, Incorporated, Aug 1997
ISBN: 1565922204
Cheapest Merchant: <!-- m --><a class="postlink" href="http://www.textbooksatcost.com/storeII/store.cgi?affiliate=MYSMN&isbn=1565922204">http://www.textbooksatcost.com/storeII/ ... 1565922204</a><!-- m -->
Price: $22.15
_______________________
Perl Cookbook
by Nathan Torkington, Potter
Paperback
Published by O'Reilly & Associates, Incorporated, Aug 1998
ISBN: 1565922433
Cheapest Merchant: <!-- m --><a class="postlink" href="http://www.bookpool.com/.x/rixnmad0b8/ss/1?qs=1565922433">http://www.bookpool.com/.x/rixnmad0b8/s ... 1565922433</a><!-- m -->
Price: $27.10
 
Back
Top