This is a small program I wrote to compile web resources I have read in the past. Feel free to add on and improve it any way you desire as long as you repost it. You can ask me questions about it as well because I don't comment my programming.
Please don't be too rude about my programming. I have taken two programming classes in C++ and that is about it. This is written in Perl.
Please don't be too rude about my programming. I have taken two programming classes in C++ and that is about it. This is written in Perl.
Code:
#!/usr/bin/perl -w
use warnings;
use strict;
sub writeURL{
my $key=shift()."@@@".time();
my $url=shift();
dbmopen(my %db,"urp",0644)||die"Cannot open DBM: urp $!\n";
$db{$key}=$url;
my($printkey,$timerunoff)=split(/@@@/,$key);
print $url . " added to " . $printkey . "\n";
dbmclose(%db);
}
sub readURL{
my $key=shift();
dbmopen(my %db,"urp",0644)||die"Cannot open DBM: urp $!\n";
while(my($dbkey,$dburl)=each %db){
my($tskey,$tstime)=split(/@@@/,$dbkey);
if($tskey eq $key){
print $dburl . "\n";
}
}
dbmclose(%db);
}
sub removeURL{
my $key=shift();
my $url=shift();
my $tog;
dbmopen(my %db,"urp",0644)||die"Cannot open DBM: urp $!";
while(my($dbkey,$dburl)=each %db){
my($tskey,$tstime)=split(/@@@/,$dbkey);
if($tskey eq $key){
my $tsurl = $db{$dbkey};
if($tsurl eq $url){
delete($db{$dbkey});
print $url . " has been deleted.\n";
$tog=1;
}
}
}
if($tog==0){
print $url . " was not found.\n";
}
}
my $usr = shift;
my $key = shift;
if($usr eq "-a"){
writeURL($key,shift());
}
if($usr eq "-w"){
readURL($key);
}
if($usr eq "-r"){
removeURL($key,shift());
}