Currently I am using
system("echo $panel_login $panel_password $root_name $root_pass $port $panel_type >> /home/shared/ftp");
What is the easiest way to do the same thing using Perl? IE: a one-liner.
In order to write to the file, it is opened in write mode as shown below: open (FH, '>', “filename. txt”); If the file is existing then it truncates the old content of file with the new content.
Syntax To Open File in write mode To write a file in Perl it is important to open a file. Filename state that open specified file for write mode to write any content into the file. Print() function is very important in Perl to write content into the file. We have written content into the file using a print function.
Multiline String using Single & Double QuotesUser can create a multiline string using the single(”) quotes and as well as with double quotes(“”).
Step 1: Opening a file in read mode to see the existing content of the file. Step 2: Printing the existing content of the file. Step 3: Opening the File in Append mode to add content to the file. Step 6: Reading the file again to see the updated content.
Why does it need to be one line? You're not paying by the line, are you? This is probably too verbose, but it took a total of two minutes to type it out.
#!/usr/bin/env perl
use strict;
use warnings;
my @values = qw/user secret-password ftp-address/;
open my $fh, '>>', 'ftp-stuff' # Three argument form of open; lexical filehandle
or die "Can't open [ftp-stuff]: $!"; # Always check that the open call worked
print $fh "@values\n"; # Quote the array and you get spaces between items for free
close $fh or die "Can't close [ftp-stuff]: $!";
You might find IO::All to be helpful:
use IO::All;
#stuff happens to set the variables
io("/home/shared/ftp")->write("$panel_login $panel_password $root_name $root_pass $port $panel_type");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With