Perl 生成随机字符的字符串

前端之家收集整理的这篇文章主要介绍了Perl 生成随机字符的字符串前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

随机字符组成的字符串在很多场景有应用,比如生成随机密码等


#!/usr/bin/perl

use strict;
use warnings;

my $maxLenth=1024;
my @dataSource = (0..9,'a'..'z','A'..'Z','~','!','@','#','$','%','^','&','*','-','+','_','=','(',')','{','}','[',']',':',';','"',','.','<','>','?','/','\\','|','\'');
my $randomString = join '',map { $dataSource[int rand @dataSource] } 0..($maxLenth-1);
print "$randomString\n";

猜你在找的Perl相关文章