亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? flat databases in perl.html

?? a collection of mega hacking tools
?? HTML
?? 第 1 頁 / 共 2 頁
字號:

<table width="750" bgcolor="gray" cellpadding="1" cellspacing="1" align="center"><tr><td><table width="750" bgcolor="silver"><tr><td>
<font face="courier new, verdana"><center>
my ($data1, $data2, $data3, $data4, $data5) = @array; # there is no $data6, therefore it's been nudged, and lost
</center></font>
</td></tr></table></td></tr></table><p>

So how do I fix this kind of problem? By replacing! Since we know we don't want extra septerators, we could can a hidden character no one knows about, or we can use a 'word' replacement, and fix it back a little later. Using a 'word' is preferred, as it leaves no room for accidental errors... Lets have a look:<p>

<table width="750" bgcolor="gray" cellpadding="1" cellspacing="1" align="center"><tr><td><table width="750" bgcolor="silver"><tr><td>
<font face="courier new, verdana">
<pre>
<xmp>

sub write_entry {
	# my apologies if there is an easier way of doing this?
	my $i = 0;
	my $value;
	foreach $value (@_) {
                @_[$i] = $value if (s/$sep/__BAR__/ig);
		$i++;
	}
	my ($forename, $surname, $city, $telephone) = @_;

	my $cid = scalar keys %database;

	open(OUT, '>>' . $db_file) or die "Sorry, we could not open the database for writing, $!";
	print OUT $cid . $sep . $forename . $sep . $surname . $sep . $city . $sep . $telephone . "\n";
	close(OUT);		
}
</xmp>
</pre>
</font>
</td></tr></table></td></tr></table><p>

We'll also need a modification to the read function to reverse the process:<p>

<table width="750" bgcolor="gray" cellpadding="1" cellspacing="1" align="center"><tr><td><table width="750" bgcolor="silver"><tr><td>
<font face="courier new, verdana">
<pre>

if (-e $db_file) {
	open(hDB, $db_file) or die "Sorry, we couldn't open the file specified: $_";
	@db_lines = <hDB>;
	close(hDB);

	foreach $db_line (@db_lines) {
		chomp $db_line;
		my @record = split($sep, $db_line);

		my $i = 0;
		my $value;
		foreach $value (@record) {
               		@record[$i] = $value if (s/__BAR__/$sep/ig);
			$i++;
		}

		if (&chk_validation(@record) == 1) {
			die "Sorry, there was an error parsing the database input :(";
		}
		$database{$record[0]} = [@record[1..$#record]];	
	}
}
</pre>
</font>
</td></tr></table></td></tr></table><p>

<h3>Searching through your database</h3>

This is where our hash information comes into play, but not as evidently as I demonstrated. To search our hash, we need to exact the key and value pair. Because Perl is so wonderful, it has a lovely operator called 'each' - lets have a look:<p>

<table width="750" bgcolor="gray" cellpadding="1" cellspacing="1" align="center"><tr><td><table width="750" bgcolor="silver"><tr><td>
<font face="courier new, verdana">
<pre>
<xmp>
sub search {
	my ($term) = @_;
	while (my ($key, $value) = each(%database)) {
		foreach (@{$value}) {
			return $key if (/$term/i);
		}
	}
	return undef;
}
</xmp>
</pre>
</font>
</td></tr></table></td></tr></table><p>

This function will return undef if no match is found. It's also case insensitive. Also, this is where our hash tuition comes into play - if you remember, I said a hash holds an array of scalars (or pointers!). Since the value of the key is <i>$value</i>, <i>$value</i> at any point would be exactly the same as <i>$database{$key}</i>, therefore, we simply reference it as an array with <i>@{$value}</i>, and do away with <i>@{$database{$key}}</i>.<p>

<h3>Finishing off</h3>

We've now covered everything we need to make the database backend to an interactive phonebook database system.<p>

Some differences:<br>
<ul>
<li>I have used the tab character to delimit the database</li>
<li>I have added a menu system</li>
<li>I have added an addition system</li>
</ul><p>

So, without further ado, lets produce the final script...<p>

<table width="750" bgcolor="gray" cellpadding="1" cellspacing="1" align="center"><tr><td><table width="750" bgcolor="silver"><tr><td>
<font face="courier new, verdana">
<pre>
<xmp>

#!/usr/bin/perl
# fdb_phonebook.pl
#
# DESC: A flatfile database phone book by Matt 'QX' Melton
# HTTP: http://blacksun.box.sk
# DATE: 25/10/01

# LNCE: You may not use this on your own site without pior permission

@validation = ('NUM', 'TEXT', 'TEXT', 'TEXT', 'TELEPHONE');
$db_file 	= "database.txt";
$sep		= "\t";

&load_database;
&main_menu;
exit;

# ---------------------------------------------------------------------

##
## Display the main menu, and prompts for input
##
sub main_menu {

my $main_screen = <<END;
 The Phone book - by Matt
--------------------------

What you you like to do:
	1) Add a new entry
	2) Display an entry
	3) Search for an entry

	x) Exit

END

        # 1st timers...
        print $main_screen;
        print "\t=";
       
	while ($choice = <STDIN>)  {
		chomp $choice;
		exit if ($choice eq 'x');
		&add_entry if ($choice eq '1');
		&show_entry if ($choice eq '2');
		&search_entry if ($choice eq '3');

		# Returns WIN32 usually, but you can never be
		# too sure with NT and 2K :)
		if ($^O =~ /WIN/i) {
			system('cls');			
		} else {
			system('clear');
		}

		print $main_screen;
		print "\t=";
	}

}

# 
# Prompts for new data input and validates, then runs write_entry
#
sub add_entry {
	my @newrecord;
	print "Forename: ";
        my $forename = <STDIN>; chomp $forename; 
	print "Surname: ";
        my $surname = <STDIN>; chomp $surname; 
	print "City: ";
        my $city = <STDIN>; chomp $city;
	print "Telephone number: ";
        my $telephone = <STDIN>; chomp $telephone;

	if (&chk_validation(0, $forename, $surname, $city, $telephone) == 1) {
		print "Data entered was not valid. Please try again\n\n";
		print "\n Entry NOT added.\n\nHit any key to continue...\n";
		my $null = <STDIN>;
		return;
	}

	&write_entry($forename, $surname, $city, $telephone);

	print "\n Added entry.\n\nHit any key to continue...\n";
	my $null = <STDIN>;

	return;
}

#
# Prompts for key, then runs display_entry
#
sub show_entry {
	print "Entry key number: ";
	my $key = <STDIN>; chomp $key;
	print "\n";

	&display_entry($key);

	print "\nHit any key to continue\n";
	my $null = <STDIN>;
}

#
# Retrieves records, checks for existance, then displays
#
sub display_entry {
	my ($key) = @_;

	my $record = $database{$key};

	if ($record == undef) {
		print "That record does not exist\n";
		return;
	}

	print "ID........... $key\n";
	print "Name......... $$record[0]\n";
	print "Surname...... $$record[1]\n";
	print "City......... $$record[2]\n";
	print "Telephone.... $$record[3]\n";

}

#
# Prompts for search term, runs the search sub, display entry if only 1, or displays
# entry keys if more
#
sub search_entry {
 	print "Please type the search phrase [Name, partial number]: ";
	my $term = <STDIN>;
	chomp $term;
	print "\n";

	my ($matches) = &search($term);

	if (@$matches == undef) {
		print "Sorry, no matches found\n\nHit any key to continue...\n";
		my $null = <STDIN>;
		return;
	}

	if ($#$matches == 1) {
		print "Found one matching entry:\n";
		&display_entry($$matches[1]);
		print "\nHit any key to continue.\n";
		my $null = <STDIN>;
		return;
	}	

	print "Found " . $#$matches . " matching entries: " . substr(join(', ', @$matches), 2) . "\n\nHit any key to continue...\n";
	my $null = <STDIN>;
}

#
# If the db file exists, it will read it and split the lines into records, and then
# fields. The adds to $database hash
#
sub load_database {
	if (-e $db_file) {
		open(hDB, $db_file) or die "Sorry, we couldn't open the file specified: $_";
		@db_lines = <hDB>;
		close(hDB);

		foreach $db_line (@db_lines) {
			chomp $db_line;
			next if $db_line eq "";
			my @record = split(/$sep/, $db_line);

			my $i = 0;
			my $value;
			foreach $value (@record) {
               		@record[$i] = $value if (s/__BAR__/$sep/ig);
				$i++;
			}

			if (&chk_validation(@record) == 1) {
				die "Sorry, there was an error parsing the database input :(";
			}
                  $database{$record[0]} = [@record[1..$#record]]; 
		}
	}
}

#
# Concurrently parses the records with the array @validation
# returns 1 if there is a validation error
#
sub chk_validation {
	my @arraytocheck = @_;
	my $pos = 0;

	foreach $value (@arraytocheck) {
		if ($validation[$pos] eq 'NUM') {
			return 1 if ($value !~ /^\d+$/); # returns the value 1
		} 
		
		if ($validation[$pos] eq 'TELEPHONE') {
			return 1 if ($value =~ /[^\d|\+| |\(|\)]/);
		}
		# We don't care about text :)	
		$pos++;
	}
	return 0;
}


#
# Parses, replaces, the $sep character in a string and prints to the end of the db file
#
sub write_entry {
	my $i = 0;
	my $value; 

	# my apologies if there is an easier way of doing this
	foreach $value (@_) {
      	@_[$i] = $value if (s/$sep/__BAR__/ig);
		$i++;
	}

	my ($forename, $surname, $city, $telephone) = @_;

	my $cid = (scalar keys %database) + 1;

	open(OUT, '>>' . $db_file) or die "Sorry, we could not open the database for writing, $!";
	print OUT $cid . $sep .  $forename . $sep . $surname . $sep . $city . $sep . $telephone . "\n";
	close(OUT);		

	&load_database; 	# reload the db, but we could do it straight to the array, but it'd be
				# an active memory db and not a flat file one :)
}

#
# Cycles each key/value pair and sees if they match the term, if so, adds to array and
# returns list of matches
#
sub search {
	my ($term) = @_;
	my @found = undef;
	while (($key, $value) = each(%database)) {                
                foreach $field (@{$value}) {
                        push (@found, $key) if ($field =~ /$term/i);
		}
	}
	return undef if ($#found == 0);
	# else
	return \@found;
}
</xmp>
</pre>
</font>
</td></tr></table></td></tr></table><p>

<h3>Parting quotes:</h3>
<font color="#969696">
<pre>
[@AZTEK] i have to admit
[@AZTEK] us americans are greedy bastards :)
[Matt] quoted :)
[@AZTEK] i am glad thats going into the tutorial and not any of my relevant answers :)
[Matt] anyone bar Az want to say anything before I finish it?
...
[Matt] right, I'll go watch Sabrina then
</pre>
</font><p>

QX-Mat - 28/10/2001 - matt@guysjs.org		
		</font>
		</td>
	</tr>
</table>


</body>
</html>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区二区剧情av在线| 亚洲一区二区三区四区五区黄 | 国产色综合久久| 国产视频911| 日本不卡一区二区三区高清视频| 国产精品资源站在线| 欧美日韩精品一区二区三区蜜桃 | 欧美性一二三区| 国产精品久久久久影院老司| 久久成人免费网站| 欧美日韩美少妇| 亚洲精品免费在线| 成人综合婷婷国产精品久久蜜臀 | 色婷婷久久99综合精品jk白丝 | 亚洲综合在线电影| 不卡电影一区二区三区| 久久亚洲二区三区| 免费观看在线色综合| 欧美精品在线一区二区三区| 一区二区视频免费在线观看| www.久久久久久久久| 国产免费成人在线视频| 国产一区二区不卡| 2020国产精品久久精品美国| 久久国产麻豆精品| 日韩欧美电影一区| 美女性感视频久久| 日韩美女视频一区二区在线观看| 视频一区欧美日韩| 欧美亚洲高清一区二区三区不卡| 中文字幕一区二区在线观看 | 精品视频一区 二区 三区| 一区二区三区国产| 欧美影院一区二区| 亚洲观看高清完整版在线观看| 欧美亚洲一区三区| 午夜视频一区二区| 日韩欧美一区二区三区在线| 久草这里只有精品视频| www国产成人| 国产成a人无v码亚洲福利| 欧美精彩视频一区二区三区| 不卡视频免费播放| 一区二区三区高清不卡| 欧美日韩不卡一区二区| 久久国产成人午夜av影院| 精品第一国产综合精品aⅴ| 韩国视频一区二区| 国产精品五月天| 日本道色综合久久| 奇米一区二区三区| 精品动漫一区二区三区在线观看| 丁香激情综合五月| 亚洲影院在线观看| 精品久久久久久无| 91香蕉国产在线观看软件| 天堂成人免费av电影一区| 久久伊人蜜桃av一区二区| 成人福利视频在线| 亚洲成人自拍偷拍| 国产肉丝袜一区二区| 色综合天天做天天爱| 蜜臂av日日欢夜夜爽一区| 国产精品人人做人人爽人人添| 欧美三级中文字| 国产美女av一区二区三区| 亚洲精品少妇30p| 日韩欧美在线观看一区二区三区| 国产99久久久久| 亚洲v中文字幕| 国产精品卡一卡二卡三| 91精品国产综合久久久久久久 | 久久精品999| 国产精品国产三级国产有无不卡| 欧美视频三区在线播放| 国产乱子伦视频一区二区三区 | 国产精品中文有码| 午夜欧美电影在线观看| 国产精品久久久久久久久免费丝袜 | 日韩国产精品久久久久久亚洲| 欧美激情在线观看视频免费| 欧美欧美欧美欧美首页| 99久免费精品视频在线观看| 麻豆精品蜜桃视频网站| 夜夜精品浪潮av一区二区三区| 久久久久久久久久电影| 91精品国产乱码| 91福利视频网站| caoporen国产精品视频| 久久99久久99小草精品免视看| 一区二区三区欧美激情| 国产精品高清亚洲| 久久久久久久久岛国免费| 精品日韩在线观看| 6080午夜不卡| 欧美日韩国产综合视频在线观看 | 岛国一区二区三区| 国内精品视频一区二区三区八戒| 亚洲大片精品永久免费| 亚洲综合色成人| 亚洲人一二三区| 国产精品的网站| 国产日韩精品久久久| 久久青草欧美一区二区三区| 日韩一级大片在线| 欧美精品粉嫩高潮一区二区| 欧美日韩亚洲综合一区二区三区 | 99在线视频精品| 成人免费高清视频在线观看| 国产suv精品一区二区6| 成人手机电影网| 成人sese在线| 成人av电影免费在线播放| 成人福利在线看| 色综合视频一区二区三区高清| 波多野结衣在线aⅴ中文字幕不卡| 岛国一区二区三区| 94-欧美-setu| 色嗨嗨av一区二区三区| 欧洲色大大久久| 欧美精品乱码久久久久久 | 久久精品视频网| 国产精品网站在线| 国产精品免费aⅴ片在线观看| 日韩毛片精品高清免费| 亚洲综合激情另类小说区| 亚洲一区欧美一区| 日本欧美在线观看| 韩国成人精品a∨在线观看| 国产精品资源在线看| av不卡在线观看| 欧美日韩午夜在线视频| 日韩免费观看2025年上映的电影 | 亚洲午夜日本在线观看| 亚洲电影中文字幕在线观看| 日本午夜一本久久久综合| 国产精品一区三区| 91一区二区在线| 日韩一区二区免费在线观看| 久久噜噜亚洲综合| 亚洲日本青草视频在线怡红院 | 国产美女娇喘av呻吟久久| 成人成人成人在线视频| 欧美美女黄视频| 国产欧美日韩不卡| 午夜久久久久久久久| 国产.欧美.日韩| 欧美日韩亚洲丝袜制服| 国产日产欧美一区| 亚洲第一会所有码转帖| 国产酒店精品激情| 欧美日韩中文字幕精品| 国产亚洲制服色| 三级精品在线观看| 不卡影院免费观看| 日韩欧美一区二区免费| 一区二区三区 在线观看视频| 麻豆久久久久久| 91福利在线导航| 国产午夜亚洲精品不卡| 五月婷婷久久综合| 91香蕉视频黄| 久久精品一二三| 青椒成人免费视频| 91丝袜美女网| 精品国产1区二区| 亚洲1区2区3区视频| 不卡在线视频中文字幕| 精品黑人一区二区三区久久| 亚洲一区二区三区国产| 成人动漫精品一区二区| 亚洲精品一区二区三区精华液| 亚洲午夜免费电影| 成人99免费视频| 久久免费看少妇高潮| 秋霞影院一区二区| 欧美日韩一区二区欧美激情| 亚洲欧美日韩一区| 成人99免费视频| 欧美国产精品一区| 国内精品在线播放| 精品国内二区三区| 麻豆精品蜜桃视频网站| 日韩视频中午一区| 午夜精品123| 欧美日韩一区精品| 亚洲美女偷拍久久| 一本久久综合亚洲鲁鲁五月天 | 97久久久精品综合88久久| 国产区在线观看成人精品| 久草精品在线观看| 精品伦理精品一区| 韩国三级在线一区| 精品免费国产一区二区三区四区| 日本aⅴ精品一区二区三区 | 欧美国产精品一区| 丁香激情综合国产| 亚洲欧洲国产专区| 99国产麻豆精品| 一区二区在线观看视频|