$string="Hello world";$result=$string=~s/Hello/Hi/;# replace Hello with Hiprint$result;# prints 1 (success)print$string;# prints Hi world$result=$string=~s/o/a/g;# replace all o with a globallyprint$result;# prints 2 (success)print$string;# prints Hia warld$result=$string=~s/z/...
if ($str1 eq $str2) { print "Both strings are equal.\n"; } 3.8. 多行字符串 my $text =qq{ This is a multiline string. }; 3.9. split和join函数 split 函数是 Perl 中用于将字符串分割成数组的主要工具。 基本语法: @array = split(/PATTERN/, $string); PATTERN:正则表达式,定义如何分割...
读取 csv 可能会编码错误,加参数 engine=“python”,或者指定编码 encoding=“utf-8/gbk/gb2312”,...
# splitting on string with Limit #!/usr/bin/perl usestrict; usewarnings; # string which is separated by !! sign my$str='GFG!!Geeks!!55!!GeeksforGeeks'; # using split function with Limit my@spl=split('!!',$str,3); # displaying string after splitting foreachmy$i(@spl) { print"...
joinoften pairs withsplitfor string processing. splitjoin.pl #!/usr/bin/perl use strict; use warnings; use v5.34.0; my $csv = "one,two,three,four"; my @parts = split(',', $csv); my $new_csv = join(';', @parts); print "Original: $csv\n"; ...
{print"$i\n"; } 输出: GFG Geeks 55 GeeksforGeeks Splitting among String with Limit 这也与角色拆分相同。字符串的数据用两个!!分隔。在此,用户可以通过在split函数中传递第三个参数(该参数为正整数)来限制字符串将拆分为的部分的数量。在下面的示例中,用户将Limit设置为3,这样即使出现4次!!,也将限制...
#!/usr/bin/perl use strict; use warnings; use JSON; my %data = ( name => "John", age => 30, city => "New York" ); my $json = JSON->new; my $json_string = $json->encode(\%data); print $json_string, "\n"; 在这个示例中,我们首先定义了一个Perl哈希表,然后使用JSON模块的...
perl 把xml文件转换成csv文件 #!/usr/local/bin/perl # use module use XML::Simple; use Data::Dumper; # create object $xml = new XML::Simple; # read XML file $data = $xml->XMLin("DebugInfo.xml", ForceArray => 1); # print output...
$dbh = DBI->connect ($connection_string, $userid, $passwd); $sth = $dbh->prepare (“SELECT * FROM tbl”); $sth->execute(); while (@row = $sth->fetchrow_array()) { print “Each record: @row \n”; } $sth->finish(); ...
my $array = $Sheet->Range("A8:B9"->{'Value'}; # get the contents $Book->Close; foreach my $ref_array (@$array) { # loop through the array # referenced by $array foreach my $scalar (@$ref_array) { print "$scalar\t"; } ...