• Perl skips the first line to read the file’s implementation code


    Copy codeThe code is as follows: #!/usr/bin/perlopen( READ, “<$file” );readline READ; # skip the first linewhile (<READ>) {my ( $id, $axis1, $axis2, $axis3, $value ) = split / /;$line = sprintf ( “%d %d %d %d %d %d”,$id, $axis1, $axis2, $axis3, $value, $axis1 + $axis2 );print WRITE $line;}close READ; It’s foolish to say what I […]

  • Guide to the Use of Perl split String Partitioning Functions


    This article focuses on the use of Perl split function, a very useful function in Perl is the Perl split function, which divides strings and puts the results of segmentation into arrays. This Perl split function uses a regular expression (RE) and works on the $_variable if it is not specific. Perl split function One […]

  • Sample code for multi-digit subscripts of Perl arrays


    Normal subscript operations in Perl arrays must be familiar to everyone, but they are not explained here.In this paper, we want to say that the number of Perl array subscripts is chosen, which can greatly facilitate the operation of the array.Note: These numbers range from 0 to $# array. Subarray Copy codeThe code is as […]

  • Perl’s column-ordered code for m x n-like tables


    The operation of tables such as CSV is often encountered in Perl processing files. Such tables are similar to two-dimensional arrays, so they are actually operated on in two-dimensional arrays.For such a row-list table, we often need to sort by one column, or first by one column, then by another column, where we attach the […]

  • Instance code for initialization of Perl constants, multidimensional arrays and variables


    Example 1: Copy codeThe code is as follows: #!/usr/bin/perluse strict; use warnings;my $test = “asdf”;print “${test}_test2\n”;#constantuse constant {    AAA => “aaa”,    BBB=> “bbb”,    MIN_TOTAL => 12,    SCORE_PASS => 90,    SCORE_RED => 70,};print AAA;print SCORE_PASS;#two dimesion arraysmy @steps = (      [“aaa”, “aaavalue”],      [“bbb”,”bbbvalue”],      [“ccc”,”cccvalue”]);print “\n”;foreach my $i (0 .. $#steps){  print “$steps[$i][0]:$steps[$i][1]\n”;} Code 2: Copy codeThe […]

  • Perl’s logwrapper uses instance code


    Here are two small examples for your friends to learn. Record the time a function runs for any function. Copy codeThe code is as follows: #!/usr/bin/perluse warnings;use strict;no strict “refs”;sub testLogToStd{print “Test stdout : \n”;open LOG,”> 2.txt”;select LOG;print “just a test\n”;#recover STDOUTselect STDOUT;print “just a test2\n”;close LOG;}sub testFun{  print “From testFun\n”;  print STDERR “From TestFun […]

  • Several Functions of Processing Time in Perl


    1. Time function: Returns the number of seconds accumulated since January 1, 1970Use: my $t = time (); 2. Localtime function: Get local time zone timeUse: my $t = Localtime (time ()); 3. gmtime function: Get Greenwich timeUse: my $t = gmtime (time ()); Get the formatting time (take the Localtime function as an example):my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) […]

  • Perl Context Introduction


    My $para = @ is a scalar context, and $para gets the number of elements in @.My ($para) = @ This is the list context, and $para gets the element value in @. The specific context is determined by the type of variable on the left of the equal sign, the scalar context on the […]

  • INC Setup Analysis of Perl


    1) The default INC is as follows: Copy codeThe code is as follows:  @INC:   C:/Perl/site/lib   C:/Perl/lib 2) Set the environment variable PERL5LIB to increase to INC, for example:   set perl5lib=c:\perllibs After setting up perl5lib, Copy codeThe code is as follows: %ENV:    PERL5LIB=”c:\perllibs”  @INC:    c:\perllibs    C:/Perl/site/lib    C:/Perl/lib 3) Modify INC in Perl program, for example: […]

  • Knowledge Sharing in Perl Reference


    Why use references? In perl4, the value field in the hash table can only be scalar, not list, which is inconvenient for some cases, such as the following data:Chicago, USAFrankfurt, GermanyBerlin, GermanyWashington, USAHelsinki, FinlandNew York, USA We want to classify cities according to the country, and each country corresponds to the list of cities. If […]

  • Summary of knowledge about Perl debugging commands


    The default Perl debugger is the Perl interpreter itself, as well as the GUI debugger.Because telnet is usually used to access servers when developing programs, this paper mainly introduces the use of default command line debugger. Start the Perl interpreter with the – D command line option, for example,, which enters the interactive interface […]

  • Method of specifying path in Perl use command


    Note: Use lib can only be followed by directory, not file. Copy codeThe code is as follows: use lib ‘c:\perl\lib\xml’;use parser is a module under the directory c: perl lib xml.