Discuss Filesizes in the Perl Programming forum on Dev Shed. Filesizes Perl Programming forum discussing coding in Perl, utilizing Perl modules, and other Perl-related topics. Perl, the Practical Extraction and Reporting Language, is the choice for many for parsing textual information.
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones
09 F9 11 02
9D 74 E3 5B
D8 41 56 C5
63 56 88 C0
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. -- Jamie Zawinski
Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ... BIT COINS ANYONE
Posts: 506
Time spent in forums: 4 Days 19 h 5 m 2 sec
Reputation Power: 385
It seems to me that your code lacks a condition to check whether the file is more than 1024 kilobytes and also lacks the division by 1024 in such a case, so that when you write so many megabytes, you are actually printing the number of bytes.
Posts: 5
Time spent in forums: 8 h 2 m 34 sec
Reputation Power: 0
Thank you both.
Axweildr's snippet gets me further.
I now have this output using it:
Argument "118 kb" isn't numeric in numeric gt (>) at jj9.pl line 15
partial output # showing [km]b identifiers
Code:
/c9backups/c9bacula/c9bacula-ScriptedDump_11-04-2012.1352091301.tar.gz 118 kb
Argument "22651 kb" isn't numeric in numeric gt (>) at jj9.pl line 15.
/c9backups/c9wiki/c9wiki-ScriptedDump_11-01-2012.1351839301.tar.gz 22 mb
Argument "22651 kb" isn't numeric in numeric gt (>) at jj9.pl line 15.
/c9backups/c9wiki/c9wiki-ScriptedDump_11-02-2012.1351925701.tar.gz 22 mb
Argument "22651 kb" isn't numeric in numeric gt (>) at jj9.pl line 15.
/c9backups/c9wiki/c9wiki-ScriptedDump_11-03-2012.1352012101.tar.gz 22 mb
Argument "22651 kb" isn't numeric in numeric gt (>) at jj9.pl line 15.
/c9backups/c9wiki/c9wiki-ScriptedDump_11-04-2012.1352102101.tar.gz 22 mb
Argument "349132 kb" isn't numeric in numeric gt (>) at jj9.pl line 15.
/c9backups/c9zabbix/c9zabbix-ScriptedDump_11-01-2012.1351828501.tar.gz 340 mb
I could guess what I need to do all day long, but I prefer not to in this case.
But my gut and screen both scream at me the kb in the output is what is causing the "error" and I am not sure how to proceed to correct that.
Thank you both for your time,
Edit0:
I removed the -w on the shebang line and now it's "better".
It may not be 'correct' but I still await a solution with better 'form'.
Posts: 506
Time spent in forums: 4 Days 19 h 5 m 2 sec
Reputation Power: 385
Don't remove the -w from the shebang, or, rather, do it, but add a "use warnings;" line. And correct the reason for the warnings.
The point is that you should store the number of bytes, kB, etc. as a pure number, and, on the other side, without the string " kB") and add the " kB" thing when you print. But if you are trying to do a numeric comparison (< or >) on "22651 kb" and some other value), the program is telling quite rightly that it does not make much sense.
Posts: 5
Time spent in forums: 8 h 2 m 34 sec
Reputation Power: 0
Thanks Laurent_R:
I gathered this also.
Page 27 (6th Ed.) of the Llama book specifically covers this situation, but does specifically say how to deal with it. So I read on and look for a solution.
My code.fu tells me that the instruction I need to work on is "$filesize = -s $file;" or manipulate that output just after|below that line, or...something along those lines.
Posts: 5
Time spent in forums: 8 h 2 m 34 sec
Reputation Power: 0
Thanks FishMonger!
The code is "perfect" but what I need to know is if my logic was "on target" or not in my last reply/post?
I have been a shell script/bash coding enthusiast for years, and I took on the discipline of Perl with the hopes that my experience in the former could apply to the latter (being Perl).
I understand also if my "logic" doesn't register with anyone as I am an odd duck. Old(er) and rather particular in my methods. It is also known to me that there are many, many ways to skin a particular cat in Perl.
Posts: 1,645
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 51 m 15 sec
Reputation Power: 1170
The logic used in your opening post is wrong. If you're going to use > to test for greater-than, then you need to start at the upper end of the scale. Your logic states that all filesizes less than 1024 (1KB) are MB, which clearly is wrong.
Axweildr's logic is a little better but incomplete and creates a bug by turning the filesize into a string and then attempts to use that string in a numerical calculation/test.