Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Log rotaion for the files which are existed in the absolute paths from the config files

by Anonymous Monk
on Mar 27, 2014 at 21:11 UTC ( [id://1080006]=note: print w/replies, xml ) Need Help??


in reply to Log rotaion for the files which are existed in the absolute paths from the config files

First, why reinvent the wheel? logrotate

On to your code:

Assignments such as @ids = $id; are probably not doing what you expect, I suspect you want push instead: push @ids, $id;

For storing the values of the file, you might also want to look into a data structures such as "arrays of arrays" or "arrays of hashes" as described in perldsc.

For a simple way to list the contents of a directory, use glob: @files = glob("$path/*"); (there are several other ways but this one might be enough for your purposes). Also, if you do that, you won't need to concatenate the pathname and filename to get the absolute pathname, as you are currently doing.

To get the size of a file, it is enough to write -s $filename, i.e. in your case $flsize = -s $abspath; (see -X)

Lastly, the style of Perl you are writing in is a little outdated, you should begin your scrips with use warnings; use strict; to force yourself to stick to some less-error prone standards such as pre-declaring your variables.

Just one good resource of many is Modern Perl, available for free online.

  • Comment on Re: Log rotaion for the files which are existed in the absolute paths from the config files
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Log rotaion for the files which are existed in the absolute paths from the config files
by Anonymous Monk on Mar 27, 2014 at 21:21 UTC

    Minor correction: Since your $path already contains wildcard characters, it's enough to do @files = glob($path); (assuming the wildcards used in the config file are compatible with glob)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1080006]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found