gnu-misc-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Run a shell command in Perl


From: Billy O'Connor
Subject: Re: Run a shell command in Perl
Date: Fri, 18 Apr 2014 02:21:57 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Richard Stallman <rms@gnu.org> writes:

> [[[ To any NSA and FBI agents reading my email: please consider    ]]]
> [[[ whether defending the US Constitution against all enemies,     ]]]
> [[[ foreign or domestic, requires you to follow Snowden's example. ]]]
>
> In Perl, how could I write a variable's value into a file,
> then run a program and get the output from it into a variable?

I'm printing 3 vars here and reading them back.

--8<---------------cut here---------------start------------->8---
#!/usr/bin/perl -w

use strict;
# declare your variables
my ($var1, $var2, $var3);

# Write the variables
open(my $varFile, '>', 'variables.txt') or die;
print $varFile "111111|2222222|3333333";
close $varFile;


# open the file
my $inFile = "variables.txt";
open DATA, $inFile or die "Can't open file: $!";
while (<DATA>) {
# chomp the line
    chomp;
# split the line into values and assign them to your variables
    ($var1,$var2,$var3) = split /\|/;
    print $var1, $var2, $var3
}
close DATA;
--8<---------------cut here---------------end--------------->8---



reply via email to

[Prev in Thread] Current Thread [Next in Thread]