Vishza has asked for the wisdom of the Perl Monks concerning the following question:
HI All, I have the following data in a csv file:
DeviceID,FreeSpace,Size C:,95342874624,476216029184 E:,2119757824,2133852160 G:,3295703040,21425549312
I use the following code to load the txt file into an array.
open(my $fh, '<', $file) or die "Could not open '$file' $!\n"; while (my $line = <$fh>) { chomp $line; my ($drive, $sizegb, $freegb) = split (/,/,$line); print qq($sizegb); $sizegb /= 1024; print qq($sizegb); }
When I run the script:
The first print of size gb output: 9 5 3 4 2 8 7 4 6 2 4
The second print output: 0
I am not sure where i am going wrong with the spaces in the number of output 1 which I assume is why the division is not working. When i try to do an index for space i get -1 as the result.
Please assist.
Regards
Vishaal
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Arrays and division not working...
by poj (Abbot) on Jan 06, 2015 at 21:51 UTC | |
by Vishza (Initiate) on Jan 07, 2015 at 06:17 UTC | |
|
Re: Arrays and division not working...
by nlwhittle (Beadle) on Jan 06, 2015 at 21:40 UTC | |
|
Re: Arrays and division not working...
by pme (Monsignor) on Jan 06, 2015 at 21:42 UTC | |
|
Re: Arrays and division not working...
by Anonymous Monk on Jan 06, 2015 at 21:42 UTC |