>From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf >Of Rothenmaier, Deane C. >Sent: Friday, January 27, 2012 2:08 PM >To: perl-win32-users@listserv.ActiveState.com >Subject: Isn't there a way to set variables in a loop? > >Gurus, all > >Im sure theres a way to do it using some kind of for, or foreach, loop, but for the life of me, Im not seeing it. What I >want to do is stick the same drive letter/directory path on the front of several filenames. Right now, Im doing it like this: > > $ap_data_file = join '\\', $in_path, $ap_data_file; > $ck_data_file = join '\\', $in_path, $ck_data_file; > $cs_data_file = join '\\', $in_path, $cs_data_file; > $ct_data_file = join '\\', $in_path, $ct_data_file; > $ie_data_file = join '\\', $in_path, $ie_data_file; > $mr_data_file = join '\\', $in_path, $mr_data_file; > $ts_data_file = join '\\', $in_path, $ts_data_file; > >Where $in_path has a value like E:\\. So, for example, $cs_data_file would end up like E:\Training\CS_Values.txt, usw. > >Somebody have a spare moment to show me the light? > >Thanks! >Deane Rothenmaier >Programmer/Analyst IT-StdCfg >Walgreens Corp. >2 Overlook Point #N51022D >MS 6515 >Lincolnshire, IL 60069 >224-542-5150
There are probably many ways to do it. I think setting up a hash might be the way to go: use strict; use warnings; my %fileHash = ( apData => 'Dir1\ap_data.txt', ckData => 'Dir2\ck_data.txt', csData => 'Dir3\cs_data.txt', ); my $in_path = 'E:'; foreach my $type ( keys %fileHash ) { $fileHash{$type} = "$in_path\\$fileHash{$type}"; print "$fileHash{$type}\n"; } --------------------- You can always loop over the variables: Use strict; Use warnings; my $ap_data_file = 'Dir1\ap_data.txt'; my $ck_data_file = 'Dir2\ck_data.txt'; my $cs_data_file = 'Dir3\cs_data.txt'; foreach my $file ( $ap_data_file, $ck_data_file, $cs_data_file ) { $file ="$in_path\\$file"; print "$file\n"; } print $ap_data_file . "\n"; ---------------------- You could just store the names in an array, but I'm assuming you need to access a specific file at some point. HTH, Ken _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs