in reply to Re^5: Clear the contents of the text file
in thread Clear the contents of the text file

There is no need to give append an empty array

1nickt: Not true according to testing:

When you give a function/method/sub an empty array as an argument, what do you think that sub gets/receives in the parameter list? Its nothing.

$ perl -le" sub f { print scalar @_ }; f(1,2); f( @ARGV ); " 2 0 $ perl -le" sub f { print scalar @_ }; f(1,2); f( @ARGV ); " a b c 2 3

Your test is not a self contained test

You also seems to be dealing with some kind of shell

It really doesn't show what you think it shows

#!/usr/bin/perl -- use strict; use warnings; use Data::Dump qw/ dd /; use Path::Tiny qw/ path /; my $goner = path( 'goner' ); $goner->spew("1\n\2\n\3\n"); dd( $goner->slurp_raw ); $goner->append( { truncate => 1 } ); dd( $goner->slurp_raw ); $goner->remove; __END__ "1\r\n\2\r\n\3\r\n" ""

Replies are listed 'Best First'.
Re^7: Clear the contents of the text file
by 1nickt (Canon) on Jul 22, 2015 at 03:18 UTC

    You can't have a "self-contained test" if you are testing writing to a file. You need to write to the file. The shell commands showed the output of cat. The test showed exactly what the output indicated:

    If you pass append() an empty string, as shown in the spew() example I was replying to, you will get an error.

    And the reason to do this in the OP's case is not for file permission preservation, but for file locking.

    The way forward always starts with a minimal test.

      You can't have a "self-contained test" if you are testing writing to a file. You need to write to the file. The shell commands showed the output of cat. The test showed exactly what the output indicated: If you pass append() an empty string, as shown in the spew() example I was replying to, you will get an error.

      Who suggested passing an empty string as in the spew example?

      That is the wrong way to try to use path()->append

      And the reason to do this in the OP's case is not for file permission preservation, but for file locking.

      The rest of the OPs program doesn't use advisory locking, so there is no benefit if Path::Tiny uses it

      Therefore there is no benefit to using append at all

        >>>And the reason to do this in the OP's case is not for file permission preservation, but for file locking.

        >>The rest of the OPs program doesn't use advisory locking, so there is no benefit if Path::Tiny uses it

        From the OP:
        > Once those actions are completed i need to clear out the contents of the files so that nobody resuses those same contents when the action is taken on new set of servers

        Whatever. The OP can't figure out how to install P::T so truncate() is a probably a better option for him anyway.

        The way forward always starts with a minimal test.