Perl: modify the original file

Source: Internet
Author: User

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 $ ^ I
Example:
#! /Usr/bin/perl
Use strict;

$ ^ I = "";
While (<> ){
S/^ rate. */rate = 0 /;
S/^ testmode. */testmode = 0 /;
Print;
}

$ ^ The value of I can decide whether to rewrite the file or backup file. to rewrite the file, you only need to set the value to null. to back up the file, then $ ^ I = ". bak ", he will name the modified file filename. bak now

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.