Summarize:
Q (), QQ (), QW (), QX (), respectively, are single quotes, double quotes, create string lists, and capture command output.
9th hours other functions and operators
One thing can be done in a variety of ways.
The main contents of this section:
- How do I perform a simple string search on a scalar? (Before using regular expressions)
- How do I replace a character?
- How to use the print function
- How to use arrays as stacks and queues
10th UI files and directories
- Get directory Listing
- Creating and deleting files
- Creating and deleting Catalogs
- Get file information
How do I get a list of directories? (Open Directory read directory) the limitation of this step is that you can only view the file directory list information under the specified directory .
Open the file and open the directory is not the same, open the directory is to obtain a list of information in the directory, and can not be written or modified.
# open Directory
opendir (DIR, ‘./‘) or die $ !;
# Read the directory in scalar form
while (readdir (DIR)) {
print $ _. "\ n";
}
# Read the directory as an array
@dir = readdir (DIR);
foreach (@dir) {
print $ _. "\ n";
}
# The directory handle must be closed after it is used up
close (DIR);
# Usually use grep to filter out (.) And (..) directories
@files = grep (! / ^ \. \.? $ /, readdir (DIR));
How to browse directory, switch directory, create directory, delete directory?
# Use the Cwd package to get the current working directory
use Cwd;
print cwd, "\ n";
chdir ‘../‘ or warn $ !; # change the current directory
print getcwd;
print "DIrectory to create?";
my $ newdir = <STDIN>;
chomp $ newdir;
mkdir ($ newdir, 0755) or die $ !; # Create a directory with permission 755
rmdir ($ newdir) or die $ !; #Delete directory
How to delete files? Rename the file?
unlink <*. bat>; #Delete matching files
$ erased = unlink ‘old.exe’, ‘a.out’, ‘personal.txt’; #Delete the list file and return the deleted quantity
unlink @badfiles; #Delete files in the list
unlink; #Delete files in $ _
if (! rename "myfile.txt", "archive.txt") {
warn $ !;
}
11th hour Interoperability between systems
system () function
Capture output
The 12th class hour uses the command line tool of Perl
13th class hours Citation and Structure
14th hour using modules
15th class hour Understand the running performance of the program
The 16th class hour
other:
use Cwd ‘abs_path’; #Get the absolute address of the specified file and directory
use warnings;
$ myfile = "fastq_R1.txt";
$ mydir = "./ 1";
print (abs_path ($ myfile). "\ n"); #Use abs_path function
print (abs_path ($ 0). "\ n");
print (abs_path ($ mydir). "\ n");
Following is the syntax to open file.txt in read-only mode. Here is less than <signe indicates that the file must be run in read-only mode to end
open (DATA, "<file.txt");
doubt:
1. The list connected by qq () seems to have only one element, because only one element is found when connected by scalar () and join () ? ?
Perl syntax-advanced features