I am new to Perl and need help with this.
I want to read a config file and see if the first 10 lines of the file contents starts with #
and have or not have some particular string to do some automation in Perl.
I was able to open the file using:
$obj->cmd("path");
$a = ->obj(cat "/path/.config");
I don't know if we can save this to variable or is there any way I can copy it to the text file and search it.
Also how do I edit this file like adding or removing file content.
Thank you
To open a file for reading use:
open(my $fh, "<", "/path/.config") or die "Can't open < .config: $!";
To open a file for writing
open(my $fh, ">", "/path/.config") or die "Can't open > .config: $!";
the content of the file is then assigned to $fh
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.