|
From: hyper-sensitive on 14 Oct 2006 01:35 Hi, I want the Perl script to pass $folders to CreateArray subroutine. Once the forech loop is over and an array is created in the CreateArray I want it to be passed to the Process subroutine , and then to the hash_grep subroutine .Then the array is printed. #!\iw-home/iw-perl/bin/iwperl -w #use strict; use warnings; use TeamSite::Config; my $iwhome = TeamSite::Config::iwgethome(); my $iwmount = TeamSite::Config::iwgetmount(); my @branches; find_branches("$iwmount/intranet/main"); #print join("\n", @branches) . "\n"; foreach my $folder_path(@branches) { my $main_path=join("\n", $folder_path) . "\n"; #print $main_path; if($main_path=~/\/main\/.+\/WORKAREA\/.+\/.+/) { #print $main_path; my @split_main_path = split(/\// , $main_path); pop(@split_main_path); my $folders=join("\/" , @split_main_path)."\n"; #createArray1($folders); print $folders ; } if($main_path=~/\/main\/WORKAREA\/.+\/.+/) { } } #hash_grep(); #print @all_folders; #my $results = process(\@all_folders); #print "RESULTS:\n\t" . join("\n\t", sort(@$results)) . "\n"; #---------------------------------------------------- sub find_branches { my $dir = shift; push(@branches, $dir); opendir(DIR, $dir) ;#|| die("[opendir] '$dir' ($!)"); my @entries = grep { !/^(?:\.|STAGING|EDITION)/ } readdir(DIR); closedir(DIR); find_branches("$dir/$_") foreach(@entries); } sub createArray1 #This will create an array from the $folders ,being passed to it. { my $folder = shift; my @all_folders; push(@all_folders , $folder); #print @all_folders ; } sub process{ my $full_list = shift; my %seen; my @results = grep(m|^.*/WORKAREA/[^/]+$| && !$seen{$_}++, @$full_list); ENTRIES: foreach my $entry (@$full_list){ foreach my $wapath (keys(%seen)){ next ENTRIES if ($entry =~ m|^$wapath|); } push(@results, $entry); } #print @results ; return \@results; } sub hash_grep{ my $full_list = shift; my %seen; my @new_list = grep(!$seen{$_}++, @$full_list); return \@new_list; }
From: Brian McCauley on 14 Oct 2006 03:45 On Oct 14, 6:35 am, "hyper-sensitive" <123imemys...(a)gmail.com> wrote: > I want the Perl script to pass $folders to CreateArray subroutine. Once > the forech loop is over and an array is created in the CreateArray I > want it to be passed to the Process subroutine , and then to the > hash_grep subroutine .Then the array is printed. > sub createArray1 > { > my $folder = shift; > my @all_folders; > push(@all_folders , $folder); > } Each call to your CreateArray creates a new array, puts one element in it and then discards it. You need to add each folder to the _same_ array. You could use a global array or pass the array as an argument to CreateArray. Of course if you were to make CreateArray take the array as an argument it would just be the same as the buitin push() so you may as well get rid of it completely and just use push() directly. This would be the right thing to to.
From: usenet on 14 Oct 2006 03:48 hyper-sensitive wrote: [snip multipost] Please don't multipost. It's rude. -- David Filmer (http://DavidFilmer.com)
From: Tad McClellan on 14 Oct 2006 09:43 hyper-sensitive <123imemyself(a)gmail.com> wrote: > #!\iw-home/iw-perl/bin/iwperl -w What is "iwperl"? -- Tad McClellan SGML consulting tadmc(a)augustmail.com Perl programming Fort Worth, Texas
From: Matt Garrish on 14 Oct 2006 21:31 Tad McClellan wrote: > hyper-sensitive <123imemyself(a)gmail.com> wrote: > > > #!\iw-home/iw-perl/bin/iwperl -w > > > What is "iwperl"? > The perl executable that comes with Interwoven's clunky Teamsite content management system (if you can really call it that without laughing). Matt
|
Pages: 1 Prev: Net::SSH stuck Next: FAQ 4.47 How do I handle circular lists? |