mlux has asked for the wisdom of the Perl Monks concerning the following question:
I also tried a regular expression, but again no success. There seemed to be many ways to do remove newlines with a regex, but the code I tried was:#!/usr/bin/perl $filename="p1"; #input file into array open(plate_file,$filename.".csv") or die "Can't open: $!"; $firstline=<plate_file>; #remove first line while(<plate_file>) { chomp(); #remove newlines??? @row=split(/,/); #split row into array elements shift(@row); #remove first column push(@data,@row); #append current row to data array } close(plate_file); #create file structure mkdir($filename, 0777) || print "$!\n"; foreach(@data){ if(-d "$filename/$_"){ } else { mkdir("$filename/$_",0777) || print "$!\n"; } }
As a side question, there must be a more direct way to use the $1 value from the regular expression than the if statement I used. What would be the advised way? Thanks.while(<plate_file>) { if(/(.*)\n/){ @row=split(/,/,$1); shift(@row); push(@data,@row); } }
|
|---|