Is there a way to dynaically set the variables in an unpack statement? What I want to do is read in a load of CSV's, unpack each line and insert the data in a database.... everything is easy except trying to do the small problem...
here's my code in trying to genereate the unpack function.. <cut> $dollar = sprintf("%c", 044); # creates $ symbol. # build up unpack variables using the amount of fields required. my $i = 0; while ($i < $importfiles{$file}[2]) { $i ++; $fieldstring .= "${dollar}field${i},"; } $fieldstring = substr($fieldstring, 0, -1); print $fieldstring, "\n"; #<<<<<<<<<<<<<<<< this contains ""$field1,$field2,$field3,$field4" # Step through the file and break each line down with unpack and insert the info into the file. foreach my $line (@filedata) { ($$fieldstring ) = unpack ( $importfiles{$file}[0], $line ) ; print "$field1 - $field2 - $field3 - $field4\n"; } </cut> Now, I know this doesn't work becuase $fieldstring is the variable populated with the first value in the unpack... How would I go about this in a way that works.. thanks Geoff _______________________________________________ Perl-Unix-Users mailing list. To unsubscribe go to http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users