Hi
Is that your real program, because it's rather odd?
The built-in variable `$@` holds the message from the latest error to be
trapped by `eval`, so since you have no `eval` blocks it will probably be
`undef`. Did you mean to assign the command-line parameter, like this?
my ($newdata) = @ARGV;
Also, your substitution
$data =~ s/some label.*/${1} $newdata} ]/x;
uses the capture variable `$1` in the replacement string, but there are no
captures in your regular expression, so it is likely to also be `undef`. It's
worth pointing out that the "extended syntax" modifier `/x` allows you to add
insignificant whitespace to your regex pattern so that you can make it more
readable, but you have no spaces in this case so it's not doing anything
useful; it won't do any harm, though.
You appear to want to change the values of the `USER` and `GROUP` items in the
config file `out.txt`, but it's far from clear where your new values come from.
Are they both in `$newdata` somehow? And how do you imagine your program will
make two unrelated changes with only a single substitution?
You say
> output file gets CHANGED to ownership by the SAME user & group
but changing something to the same data amounts to it being *unchanged*, surely?
Can you please show your real program and data input, together with the output
you want? We will also need to understand what parameters are being passed to
your program, and where it gets the new values for user and group.
Thanks.
Rob Dixon
On 15 January 2017 22:45:43 GMT+00:00, [email protected] wrote:
>I have an application that calls a perl script, feeding it input over
>STDIN.
>
>The perl script takes that input, processes it, and writes is as a
>change to an output file.
>
>I use Path::Tiny, and this works ok,
>
> use Path::Tiny qw(path);
>
> my $newdata = $@;
> $newdata = (some processing);
>
> my $file = path('/home/aj/out.txt');
> my $data = $file->slurp_utf8;
> $data =~ s/some label.*/${1} $newdata} ]/x;
> $file->spew_utf8( $data );
>
>The app runs as
>
> USER = "appuser"
> GROUP = "appgroup"
>
>and the perl-script's output file gets CHANGED to ownership by the SAME
>user & group, 'appuser'/'appgroup'.
>
>How do I get that output file written with owndership by some OTHER
>user, eg
>
> USER = "otheruser"
> GROUP = "othergroup"
>
>?
>
>AJ
>
>--
>To unsubscribe, e-mail: [email protected]
>For additional commands, e-mail: [email protected]
>http://learn.perl.org/
--
Sent from Kaiten Mail. Please excuse my brevity.