Thanks for everyone's patience and continued help. The full script in its current form is below:
#!/usr/bin/perl use strict; use warnings; use IO::File; #The program should prompt the user to specify the path where the #subject directories reside. print "\nPlease specify the path to where the case file data resides: "; my $datapath = <STDIN>; $datapath =~ s/^\s+//; $datapath =~ s/\s+$//; #This checks to ensure the user-specified path exists, that it is a #directory, and that the directories therein are named according to the #naming convention (e.g., a four-digit number). die ("$datapath isn't a valid path. Exiting program.\n\n") unless (-e $datapath); die ("$datapath isn't a directory. Exiting program.\n\n") unless (-d $datapath); opendir(CHCKDIR, $datapath) || die ("Can't open $datapath. Exiting program.\n\n"); while (my $dirlstng = readdir(CHCKDIR)) { if ((-d "$datapath/$dirlstng") and ($dirlstng !~ m/^\./)) { die ("One of more of the directories residing within $datapath \rdoes not match the four-digit naming convention. This will \rcause the program to run in unexpected and terrible ways. \rPlease check the path, or rename the offending directories \raccordingly. Exiting program.\n\n") unless $dirlstng =~ /\d\d\d\d/; } } closedir(CHCKDIR); #Everything below this line needs to be wrapped within code that will #run it recursively. opendir(MAINDIR, $datapath) || die ("Can't open $datapath. Exiting program.\n\n"); while (my $lvl1stng = readdir(MAINDIR)) { if ((-d "$datapath/$lvl1stng") and ($lvl1stng !~ m/^\./)) { my $lvl1path = "$datapath\/$lvl1stng"; opendir(LVL1DIR, $lvl1path) || die ("Can't open $lvl1path. Exiting program.\n\n"); while (my $lvl2stng = readdir(LVL1DIR)) { if ((-d "$lvl1path/$lvl2stng") and ($lvl2stng !~ m/^\./)) { my $lvl2path = "$lvl1path\/$lvl2stng\/contacts"; opendir(CNTCSDIR, $lvl2path) || die ("Can't open $lvl2path. Exiting program.\n\n"); my $filecnt = 1; while (my $filestng = readdir(CNTCSDIR)) { if ((-f "$lvl2path/$filestng") and ($filestng =~ m/.txt$/)) { #Step : Determine number of distinct words in the contact. my $fh = new IO::File("$lvl2path/$filestng", "r") || die ("Can't open .txt file named at $lvl2path. Exiting program.\n\n"); while (my $line = $fh->getline()) { chomp $line; my @words = split / /, $line; my $nr_words = @words; print "$line\n"; print "The line above has " . scalar @words . " occurrences of something.\n\n"; } $fh->close(); } } closedir(CNTCSDIR); } } closedir(LVL1DIR); } } closedir(MAINDIR); #The if statement below prints "Success!" to the command prompt if no #errors (e.g., $! is undefined) occurred when running the program. if (defined($!)) { print "\nSuccess!\n\n"; } This reflects some of the changes suggested by Owen and as can be seen, I am using strict and warnings, as suggested by others. Again, this works just as I would like in Ubuntu 9.10 (x64) with the latest version of perl on the repository (5.10.0-247ubuntu4). The whitespace introduction as detailed in the original post occurs in Windows 7 Ultimate (x64) and Windows Vista Ultimate SP2 (32-bit), both running Strawberry Perl 5.10.1.1. The unicode / UTF16 issues presented by Thomas and Dr. Rudd are a little beyond me. I'm reading up now, but can someone shed some light? How can this be resolved in Windows with Strawberry Perl? === Douglas Cacialli, M.A. - Doctoral candidate Clinical Psychology Training Program University of Nebraska-Lincoln Lincoln, Nebraska 68588-0308 === On Wed, Mar 31, 2010 at 8:23 AM, Doug Cacialli <doug.cacia...@gmail.com> wrote: > Thank you all for your outpouring of support!! I'll post the full > code when I finish up with work late this afternoon, as well as > implement the suggestions I received. > > We are a little closer to solving this, and my novice impression > (disclaimer: I've been using perl less than a month) is that this > might be a bug. The phenomenon I posted occurred repeatedly last > night using Strawberry Perl 5.10.1.1 in Win 7 Ultimate (x64). This > morning I booted into Ubuntu 9.10 (x64) where I'm running the latest > perl package on the Synaptic Package Manager (5.10.0-247ubuntu4) and > ran the script - it performed *exactly* as I expected it would. No > extra whitespace anywhere. > > Hopefully that information is helpful to someone out there; I'd like > to be able to run this in Windows and Linux distros and get the same > results (or understand why I can't get the same results). I'll post > the full code later this afternoon. Thanks again for all the help!! > > === > Douglas Cacialli, M.A. - Doctoral candidate > Clinical Psychology Training Program > University of Nebraska-Lincoln > Lincoln, Nebraska 68588-0308 > === > > > > On Wed, Mar 31, 2010 at 4:08 AM, Dr.Ruud <rvtol+use...@isolution.nl> wrote: >> Doug Cacialli wrote: >> >>> V e r y t r u l y y o u r s , >> >> Looks like UTF-16 to me. >> >> -- >> Ruud >> >> -- >> To unsubscribe, e-mail: beginners-unsubscr...@perl.org >> For additional commands, e-mail: beginners-h...@perl.org >> http://learn.perl.org/ >> >> >> > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/