SoFunction
Updated on 2025-04-07

Simple example of Perl reading and writing files

Simple example of Perl reading and writing files

Updated: April 14, 2015 09:28:12 Submission: junjie
This article mainly introduces simple examples of Perl reading and writing files. This article directly gives the implementation code. Friends who need it can refer to it.

!/usr/bin/perl -w
 use strict;
 
 #print "please input a string\n";
 #my $line = <STDIN>;
 #print $line;
 
 #wirte a file
 open(FH, ">") or die $!; 
 print FH "hello\n";#Write content to the file print FH "OK\n";
 
 close(FH);
 
 #open a file
 open(FH, "") or die $!;
 my @f = <FH>;#Read the file content print @f;
 
 close(FH);

  • Perl
  • Read and write files

Related Articles

  • Comparative analysis of Perl and JS (arrays, hashs)

    Below, the editor will bring you a comparative analysis of Perl and JS (arrays, hash). The editor thinks it is quite good, so I will share it with you now and give you a reference. Let's take a look with the editor
    2016-07-07
  • Perl Concise Tutorial Perl Tutorial Collection

    What is perl and what is it for? Perl's original designer's intention was to process characters. 80% of its strengths were to process characters, and of course many others were OK. Nowadays, many web pages also use perl, and usually require a CGI environment
    2015-10-10
  • Some problems encountered in cpan installing Net::SSH::Perl

    Some problems encountered in installing Net::SSH::Perl in cpan, friends who need it can refer to it
    2013-02-02
  • Small example of perl processing csv files

    Perl is a small example of processing csv files. Friends who need it can refer to it.
    2013-02-02
  • Analysis of the difference between my and our in perl

    Analysis of the difference between my and our in perl. Friends who need it can refer to it
    2013-04-04
  • Perl and shell get code for yesterday, tomorrow or several days ago

    This article mainly introduces the code for obtaining the dates of perl and shell yesterday, tomorrow or several days ago. Friends who need it can refer to it
    2014-04-04
  • Perl ping detection function script code

    The leader has a task, and gives a batch of IP lists, ping each machine, and sends an email notification if there is no response. The notification emails need to be separated. You cannot notify a list, and you will need a notification one by one.
    2013-02-02
  • Introduction to the built-in special variables of perl

    The built-in special variables about perl are very comprehensive. If you need it, please bookmark it.
    2013-02-02
  • Perl uses grep map to find the instance code of intersection, union, and complement

    Perl Use grep map to find examples of intersection, union, and complementary collection. Friends in need can refer to it.
    2013-02-02
  • Common symbols and operations in Perl

    This article mainly introduces common symbols and operations in Perl. Friends who need it can refer to it.
    2017-10-10

Latest Comments