john.tm has asked for the wisdom of the Perl Monks concerning the following question:

what does this warning mean,

Path::Tiny paths require defined, positive-length parts at C:\testscripts\dir.pl line 30.

could someone please explain what is being requested or what i need to change at line 30
#!/usr/bin/perl -- ## ## 2014-05-29-18:05:27 ## ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use POSIX qw/ strftime /; use Path::Tiny qw/ path /; Main( @ARGV ); Main( "C:\\TEMP\\DAILY.csv", "C:\\TEMP\\MONTHLY.csv" ); exit( 0 ); sub Main { my( $infile, $outfile ) = @_; if( not has_today( $outfile ) ) { append_today( $infile, $outfile ); ... ## make noise on STDOUT } else { ... ## make noise on STDOUT } } ## end sub Main sub has_today { my( $infile ) = @_; my $today = strftime( '%d %b %Y', localtime ); my $fh = path( $infile )->openr_raw; ... ## read last 8k, check for $today } ## assumes infile will fit in memory, if it don't, write more code :) sub append_today { my( $infile, $outfile ) = @_; path( $outfile )->append_raw( path( $infile )->slurp_raw ); }
updated code

Replies are listed 'Best First'.
Re: Path::Tiny paths require defined, positive-length parts
by Old_Gray_Bear (Bishop) on Jun 19, 2014 at 01:49 UTC
    Line 30 reads sub append_today {. Please post the code that you actually are running when you get the error.

    Nota Bene:

    Main( @ARGV ); Main( "C:\\TEMP\\DAILY.csv", "C:\\TEMP\\MONTHLY.csv" );
    Does not do what you probably think it does. See the documentation on subroutine prototypes.

    UPDATE

    After your update to your code, line 30 is now  my $fh = path( $infile )->openr_raw;. Much more reasonable.

    So, why is $infile empty? You might try printing @_ before and after line 18, and before line 28. Or just fire up the Perl Debugger (perl -d insert_my_code_here) and step through the code.

    UPDATE^2

    Stepping through the code with the debugger is most enlightening. You call the main() routine twice. What happens if there are no command-line arguments?

    ----
    I Go Back to Sleep, Now.

    OGB

Re: Path::Tiny paths require defined, positive-length parts
by Anonymous Monk on Jun 19, 2014 at 04:15 UTC