In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you how to use split in perl. I hope you will get something after reading this article. Let's discuss it together.
Split syntax perl-- when the split function uses spaces as delimiters, the # # syntax split / PATTERN/,EXPR split / PATTERN/ split split is used to separate the string EXPR, returns the delimited list in the list context, and returns the list length in the scalar context.
Split syntax
# # Syntax
Split / PATTERN/,EXPR split / PATTERN/ split
Split is used to separate the string EXPR, returning the delimited list in the list context and the list length in the scalar context.
Split separates strings with spaces:
#! / usr/bin/perl$_= "a b c d e"; # # string is preceded by a leading space, and the character'a' is preceded by a white space "|", split; # # default delimiter print "\ n"; print join "!", split /\ smatching print "\ n"; # # regular matching space print "\ n"; print join "|", split''; # # direct quantity space print "\ n" # output result # # a | b | c | d | eBay #! A! B! C! D! EBay # a | b | c | d | e
Both the default delimiter split and the direct quantity delimiter split''remove the leading space of the string, while the regular match split /\ sspaces / reserves the leading space and replaces it with a blank character''.
In the past, it was thought that split / / was the same as split', but now it seems to be different.
Why is this happening?!
Replace spaces with -:
#! / usr/bin/perl$_= "--a--b----c-d-e"; print join "!", split /-+ /; print "\ n"; # output result #! A! B! C! D! E
It can be understood that the perl string begins with an empty character'', so you can understand the result separated by split /\ skeeper / in the previous section.
Split''is a special case of split, which simulates the default behavior of awk, so before the splitting behavior starts, all leading spaces in the string are deleted, and then processed with split /\ sarguments /, which is why the two results are different.
In addition to the special case of split'', if other strings are provided, perl will also be interpreted as a regular expression to execute.
After reading this article, I believe you have a certain understanding of "how to use split in perl". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.