佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > perl哈希的一個實例分析

perl哈希的一個實例分析

熱門標(biāo)簽:Win7旗艦版 硅谷的囚徒呼叫中心 企業(yè)做大做強(qiáng) 百度AI接口 客戶服務(wù) 語音系統(tǒng) 電話運(yùn)營中心 呼叫中心市場需求

復(fù)制代碼 代碼如下:

#!/bin/perl
use strict; 
use warnings; 

my %movies; 
my $film; 
my %reverse_result; 
my $director; 
my @data; 

%movies = 

  'The Shining'       => 'Kubrick', 
  'Ten Commandments'  => 'DeMille', 
  'Goonies'           => 'Spielberg', 
); 

#輸出哈希的值,輸出的結(jié)果為Kubrick 
print $movies{'The Shining'}; 

#同時輸出鍵和值 
foreach $film(keys %movies) 

   print "$film was directed by $movies{$film}.\n"; 


#添加空格 
print "\n"; 

#哈希結(jié)構(gòu)的切換 
%reverse_result=reverse %movies; 
foreach $director(keys %reverse_result) 

   print "$director directe the $reverse_result{$director}.\n";  
}

#添加空格 
print "\n";

#當(dāng)哈希結(jié)構(gòu)用于列表環(huán)境中時,perl會將hash重新變?yōu)橛申P(guān)鍵詞和鍵值組成的普通列表 
@data=%movies; 
 print "@data\n"; 

#添加空格 
print"\n"; 

#得到的數(shù)組是一個分為奇數(shù)為film,偶數(shù)為director的數(shù)組,或者相反 
#然后我們將數(shù)組賦值給hash 
%movies=@data; 
foreach $director(keys %reverse_result) 

  print "$director directe the $reverse_result{$director}.\n";  
}     
print "The result is not change\n";

以下為輸出結(jié)果:
    F:\&;perl\a.pl 
    KubrickGoonies was directed by Spielberg. 
    The Shining was directed by Kubrick. 
    Ten Commandments was directed by DeMille. 

    DeMille directe the Ten Commandments. 
    Spielberg directe the Goonies. 
    Kubrick directe the The Shining. 

    Goonies Spielberg The Shining Kubrick Ten Commandments DeMille 

    DeMille directe the Ten Commandments. 
    Spielberg directe the Goonies. 
    Kubrick directe the The Shining. 

    F:\&;

#----測試哈希key的方法:
if(exists $hash{keyval}) 


#----刪除關(guān)鍵字:
delete hash {keyval};

#---清空哈希:
%hash=();

您可能感興趣的文章:
  • php-perl哈希算法實現(xiàn)(times33哈希算法)
  • Perl 哈希的創(chuàng)建和引用介紹
  • Perl哈希表用法解析
  • Perl 哈希Hash用法之入門教程
  • perl哈希hash的常見用法介紹
  • Perl與JS的對比分析(數(shù)組、哈希)

標(biāo)簽:濟(jì)南 安康 喀什 長沙 崇左 山西 海南 山西

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《perl哈希的一個實例分析》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    白山市| 吴川市| 蒲城县| 宿松县| 香河县| 十堰市| 衡东县| 邛崃市| 沈阳市| 庆阳市| 平原县| 增城市| 长丰县| 襄垣县| 巴塘县| 综艺| 定州市| 蕲春县| 清涧县| 崇信县| 忻城县| 绥化市| 江北区| 化隆| 巴南区| 神木县| 湘阴县| 乌兰察布市| 赣榆县| 西吉县| 济源市| 无棣县| 宜兰市| 澄江县| 普兰店市| 松溪县| 金乡县| 巴里| 桂林市| 资源县| 常熟市|