If a module is not installed on your system, then it is almost always better to install the module then it is to reinvent the wheel. Wheel reinvention usually turns out square wheels that repeat the mistakes of earlier attempts (such as not accounting for commas in the data itself, and thus spliting in the middle of a piece of data).
See Installing Modules
| [reply] |
I 100% concur with dorward -- this is something that modules like Text::CSV were born to do. The split solution works for simple cases, but once you start trying to deal with text delimiters, quotes within delimiters, and commas within text, you'll be aching for that module.
I'm not 100% certain what you're aiming for, so let me first mention that .csv files should open in Excel with no trouble, in most cases. That kind of auto-convert might save you a lot of trouble, so if all you need to do is open your .csv file in Excel, I recommend that approach strongly.
Otherwise...my understanding, and please correct if I'm wrong, is that you've written a split based conversation already, yes? If it's broken, and you simply cannot install the Text::CSV module, please edit your post here w/the text of the code that's not working, so we can help you properly.
That good for you?
----Asim, known to some as Woodrow.
| [reply] [d/l] [select] |
somehow my script shows no output
Somehow my mum forgot to teach me mind reading. Seriously, how can you expect us to help you without code and error message?
See How (Not) To Ask A Question.
| [reply] |
| [reply] |
I feel your intrigue, my man. If you're trying to do this for your own fun- go for it.
The code hack beneath is a start to doing it from scratch, keep in mind this code is untested.:
If you are doing this and you actually need it to work for some reason: especially over and over.. Then you have got to use the provided tools, csv modules on cpan.
If they are not installed...
Do you have root access to this box?
Run # cpan
then # install The::Module::Name
should be all good.
The other thing you can do , depending on the module , is download then source , put it in a place you have write access to, and use a # use lib '/path/to/my/modules' line in your script.
The other thing is, as the host/sysadmin for the modules you want. Most times you get what you want! :) But try hard as you can to use already made modules. Although.. you can learn a lot from trying to do this yourself. For example you can learn respect and awe for your fellow coders when you finally give up and use somethingon CPAN!! :)
| [reply] [d/l] |
ok , here's how to extract info from the file line by line
# open the file
open(FH,$filename) or die $!;
# loop through the file till the end of it line by line
while ( my $line = <FH> ) {
#remove "\n" from the end of the line
chomp($line);
# now Extract values from line in array
my @array = split(/,/,$line);
#here you can do whatever you want in the valus you have , $array[0] i
+s the first element
}
close(FH);
Hope that helps | [reply] [d/l] |