"i had to write a csv sorting code for which i used the following code :"
i wrote this multithreaded program to sort files in parallel ,this was actually the subroutine part (sort of).initial code which i tried would append sorted line to previous line, so 2 lines would be clubbed in 1 line ; hence i found THIS code on net
initial code below
foreach(@csvfiles) { $csvfile=$_; open(hanr,"D:\\stock\\".$csvfile) or die"error read $!\n"; open(hanw,">D:\\stock\\sorted".$csvfile) or die"error write $!\n"; @lines = (); @lines = <hanr>; shift(@lines);#remove header csv @sorted = sort multisort @lines; sub multisort { ($field1a, $field2a, $field3a)=split(/\,/, $a); ($field1b, $field2b, $field3b)=split(/\,/, $b); $field1a cmp $field1b or $field2a cmp $field2b; } print hanw @sorted; close(hanw); close(hanr); }
In reply to Re^2: what is @$varname in perl
by sandy105
in thread what is @$varname in perl
by sandy105
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |