Perl's operations on files are similar to those of other languages, nothing more than open, read, and write operations.1. Open the file
#! C:/perl/bin/perl-w use
UTF8;
Use strict;
Use warnings;
My $filename = ' test.txt '; # or with an absolute path, such as: C:/perl/learn/test.txt
if (open (MYFILE, $f
,
Put the record in $ _ instead of $ record:
While (){
# $ _ Each time it is a record in the file
}
In Perl 5.004 _ 04, we can do this:
While ($ record = ){
# $ Record each time is a record in the file
}
Defined () is automatically added. In versions earlier than Perl 5.004 _ 04, this command provides a warning. To und
This post compares the three methods of folder traversal.
1. Use File: Find;
2. Recursive traversal. (The traversal function is LSR)
3. Use Queue or stack traversal. (The traversal function is lsr_s)
1. Use File: Find[Copy to clipboard] [-]
Code:#! /Usr/bin/perl-W
#
# File: Find. pl
# Author: Lu Xiaojia
# License: GPL
Tags: Resolution type img Number requires test head file type otherI. File rename and move (MV) In Linux, renaming files is called moving (moving). The MV command can move files and directories to another location or rename them. 1.1 Using the MV RenameBelow/usr/local create an empty
Document directory
Unzip the tar command in Linux
Find-name 'xixi. php' | xargs Perl-pi-E's | Hello | AA | G'
Find-name '*. html' | xargs Perl-pi-E's | AA | Hello | G'
Find-name '*. HTML '| xargs Perl-pi-E's | | G' (Note: It seems that only one row can be matched)
In Linux, this method is used to replace a large number of files with Trojans (JS files.
Sea
Copy CodeThe code is as follows:
/**
* Manipulating file Classes
*
Example
* Fileutil::createdir (' A/1/2/3 '); Test build folder Build a A/1/2/3 folder
* Fileutil::createfile (' B/1/2/3 '); Test build file Build a 3 file under the b/1/2/folder
* Fileutil::createfile (' b/1/2/3.exe '); Test build file Build a 3.exe
(Please help) php, perl, and other script software split one file into multiple TXT files. Php, perl, and other script software split a file into multiple TXT files. The file content is as follows: IP, MOIndex, className, fdn, latitude, longpolling, matchVersion, name, neID,
Most of the time, we want to modify the content of the original file. Although the powerful text editing command sed exists in Linux, however, he can only generate new files or print them to the screen (perhaps sed also has the ability to modify the original file, which is not easy to learn. Please let me know ), but in Perl, there is such a command $ ^ IExample:
Operators and meanings of file tests in perl
Test file permissions:
-R files or directories are currently (valid) readable for users.
-W files or directories are writable to current (valid) users.
-X files or directories are executable to (valid) users currently.
-O files or directories are available to (valid) users currently.
-R files or directories are readabl
So that some characters (especially wide characters) cannot be correctly displayed, that is, they are no longer in UTF-8 format.
Solution:When the output file is opened, the encoding format is specified, so no garbled characters will occur after the output file is opened.
Common default open output files:
Copy codeThe Code is as follows: open (OUTPUT, '> output.txt') | die "can not open the
The existing file Test.txt, the content is: "123\n456"1, Open Text test.txt#!/usr/bin/perlOpen D, "test.txt";D is the file handle, pointing to the open file2, read text line by row Test.txt#!/usr/bin/perlOpen D, "while (Print $_;}Close D;Results: 123456Or: Print Results: Ibid.3, write content to Test111.txt#!/usr/bin/perlOpen D, ">test111.txt";Print F "Hello,world\nsee you\n";Close D;If Test111.txt original
The mv command is short for moving files. it can be used to move files or rename files. it is a common command in Linux and is often used to back up files or directories.
The mv command is short for moving files. it can be used to move files or rename files. it is a common command in Linux and is often used to back up files or directories.
1. command format:
Mv [option] source
Perl file handling: open, read, write and close files #======================== opening files
Solution 1:
Opening a file in Perl
open FILE, "filename.txt" or die $!; # read
open FILEHANDLE, MODE, EXPR
The available modes are the following:
Mode
Operand
Create
Release date:Updated on:
Affected Systems:Perl MARC: File: XML 1.xDescription:--------------------------------------------------------------------------------CVE (CAN) ID: CVE-2014-1626
Perl is a high-level, general, literal, and dynamic programming language.
The MARC: File: XML module earlier than version 1.0.2 of Perl
In Perl there are several ways to use the handle, where open is the most basic use of the method, the following I encountered the use of several handles to make a small summary:Use of the Open method:The Open method is the most basic opening file handle method in the tutorial, which is more commonThere are three ways to use it in the tutorialOpen filehandle,exprOpen Filehandle,mode,listOpen FileHandleI'm on
SQL scripts in bulk to avoid duplicate copy and paste@echo offEcho ***************************************************Echo * *echo * This script is used for the AWR report file of the database *Echo * *Echo ***************************************************Echoecho follow the instructions in [] to enter parameters, if not entered, automatically set as defaultEcho.REM-------------------------------------------------------%~d0CD%~dp0Set Setup=setup.sq
window to read a file in the following format:Open (Filehand, "path E.g:d:\\data.txt");
The open content is then assigned to a variable:$protein =
Attached: A program for reading protein sequences.
Copy Code code as follows:
#!/bin/perl
Open (Proteinfile, "F:\\perl\\data.txt") | | Die ("Can not open the file
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.