in reply to Re^2: create array of empty files and then match filenames
in thread create array of empty files and then match filenames
my @confs = (); push (@confs, $confs); my @sortedconfs; @sortedconfs = sort {$a cmp $b} @confs; print @sortedconfs; print "\n";
So I put all my conformations ($confs) in an array (@confs) and then I want to sort them numerically. However the output I get is only one file, the biggest number one, not a row of numbers sorted numerically. What do you think might be going wrong?
I'm also concerned by the fact that if I do "sort {$b cmp $a}" I get the same result as with {$a cmp $b}, shouldn't I get the reversed order? The variable $confs is my numbered chemical conformations, which is always 4 characters long in the style of B001, B002, B003 and so on. This variable is in my filenames along with other similar ones (similar to a filename like MOLEC1-B001-OPT-FREQ2), so I want to sort my files, according to their chemical conformations, numerically. But if I do "sort {$a <=> $b}" it complains that "it's not a numerical value", that's why I tried with cmp as seen here http://www.perlmonks.org/?node_id=259465. Any thoughts?
edit: I read a bit more and found that in mixed strings I should extract the numerical value and sort the substring, so I changed the previous "sort" line with "{ substr($a, 1) <=> substr($b, 1) }" but I get the same output :(
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: create array of empty files and then match filenames
by kcott (Archbishop) on Jan 15, 2016 at 00:12 UTC | |
|
Re^4: create array of empty files and then match filenames
by poj (Abbot) on Jan 14, 2016 at 15:52 UTC | |
by angela2 (Sexton) on Jan 14, 2016 at 16:16 UTC |