In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-19 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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.