In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "what are the Perl programming skills?" in the operation of actual cases, many people will encounter such a dilemma, and then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Perl is a feature-rich computer programming language that runs on more than 100 computer platforms and is suitable for a wide range of applications, from mainframe to portable devices, from rapid prototyping to large-scale extensible development. Perl language has a wide range of applications. In addition to CGI, Perl is used in graphic programming, system management, network programming, finance, biology and other fields. Because of its flexibility, Perl is called the Swiss Army knife in scripting languages.
Debugging with comments: using the Smart::Comments module
There are two ways to debug Perl scripts: one is to use Perl's built-in debugger, and the other is to embed print statements in the script. If it's the second, you'll probably learn that the biggest problem with manual debugging like that is that once you remove bug, you have to remove debug statements altogether. But wouldn't it be better if these statements could be safely left in the code? After all, they are likely to be needed again, especially if there is another bug.
Now, there is a module in Perl that can use comments to open debug statements, which is the Smart::Comments module. The following is the simplest example, when using Smart::Comments, any comment that begins with three or more # becomes a debug statement and sends all the contents of the comment to the screen:
#! / usr/bin/perluse Smart::Comments;my @ ipaddr = split /\. /, "10.109.32.151"; # @ ipaddr
When this code is executed, Smart::Comments finds three sets of # comments and prints out everything they contain:
# @ ipaddr: [# @ 10 # 10 # 109 # # 39 # # 32 # # 151]
The use of Smart::Comments is not limited to printing variable values, it can even be dynamically realistic in the form of a progress bar in the loop part of the code. For a more detailed description, please refer to the perldoc documentation.
The skill of reading the whole file at once
I'm sure you know the diamond operator () in Perl. So if you want to read the file in at once, you should first modify the $/ variable:
Open CONF, ", $file;my $text = do {local $/;}
There are more ways to manipulate files in the module File::Slurp.
Encapsulate SQL statements: do not use SQL statements directly in your code
For inserting data into the database, you can implement the SQL statement using the following code:
Sub insert {my ($table, $data) = @ _; my $sql = "insert into `$table`"; my $insert_fields = join ",", map {"`$ _"} keys% $data; my $insert_values = join ",", map {"'$_'"} values% $data; $sql. = join "," (", $insert_fields,") "; $sql. = join", "values", "(", $insert_values, ")" # open a database and return $dbh my $sth = $dbh- > prepare ($sql); $sth- > execute () or die; $sth- > finish ();}
When calling, you only need to rely on the table name and hash data:
My% data = (name = > "Alice", age = > "23", country = > "variables.",); insert "student",\% data; uses list assignments to exchange the values of two variables
We know that in general, if you need to exchange the values of two variables, you need to use a temporary variable to do this, but in perl, you can do this:
My ($foo, $bar) = ("foo", "bar"); ($foo, $bar) = ($bar, $foo); that's all for Perl programming skills. Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.