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.:
my @fieldname = ('one','seat','three'); =pod the structure we are aiming for might be: @lines = ( { $fieldname => $value, $fieldname => $value, $fieldname => $value, }, { $fieldname => $value, $fieldname => $value, $fieldname => $value, }, { $fieldname => $value, $fieldname => $value, $fieldname => $value, }, ); thus.. line 3 field "seat" is gotten to like $lines[2]->{'seat'}; the order of the @lines array tells you which line it is, inside it ar +e anonymous hashes that have the key value pairs to what was found in +side. You're going to probably run into some undef problems, because of the +commas. you can ouput the scv diff ways, I would maybe output it with + forced quote chars, even if empty. Then all your values have the quo +te chars inside, which you could remove later. This whole thing would be paintful, but fun. =cut for (@lines){ my @vals = split(/,/,$_); my $line = {}; my $x=0; for (@vals){ $line->{$fieldname[$x]} = $_; $x++; } push @lines, $line; }
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!! :)
In reply to Re: Comma delimited file manipulation -- help required.
by leocharre
in thread Comma delimited file manipulation -- help required.
by swetashah23
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |