【perl】hash tips and some perl usage

本文深入探讨Perl编程语言的实用技巧,包括使用哈希去重数组元素、系统命令调用、文件描述符重定向等,为读者提供了一系列提高编程效率的方法。

 

my %myHash = ("age"=>"25","name"=>"jayden");
my $val1 = \%myHash;
print ${$val1}{"age"};
if(`echo \$PWA` =~ /.*\/default$/){
  print <<END;

*********************************************************
      [ERROR] 
*********************************************************
END
exit(0);
}

<<END表示可以打印到END為止。

 

my $tl_path = "$p4client_root/dig/verif/$tl";
unless (-f $tl_path) {die "$tl_path is not found\n";}

my %hash;
my @uniq_name = grep{++$hash{$_}==1} @name;

`p4 client -o > client_info.txt`;

system qq(echo "    //ZZ/$proj_name/dig/COMMON/verif/testlists/$testlist       //$p4client_name/dig/COMMON/verif/testlists/$testlist" >> client_info.txt);

`p4 client -i < client_info.txt`

system qq(p4 sync $p4client_root/...#head 2>&1 | grep -v 'up-to-date');

 利用p4 client可以設定depot 和 local mapping 關係。

qq ( string ) function returns a double-quoted string

 grep function is used to filter lists. The basic syntax is

@out = grep { CODE } @in;

where CODE is some Perl code. For each element of @inCODE is executed with $_ set to the element.

If the code returns a true value, the element is placed in the output list; otherwise it is discarded.

my %hash;
my @uniq_name = grep{++$hash{$_}==1} @name;

上述代碼可實現去除數組中重複的元素。

 

2>&1:(combine stderr and stdout into the stdout stream)

File descriptor 1 is the standard output (stdout).
File descriptor 2 is the standard error (stderr)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值