ba1688 has asked for the wisdom of the Perl Monks concerning the following question:
All I'm trying to make this do splice out the files in the directory I specify. It's doing it but for some reason it's doing it to every other element in the directory. For example if I have @DIR= functions/myfunc.hml perltest/abs.hml perltest/abs3.hml perltest/abs4.hml perltest/acos2.hml perltest/zeros17.hml It finds myfunc abs abs4 and zeros17 yet abs3 and acos2 are in the specified directory. It splices out the abs and abs3 yet leaves everything else in that directory. I need it to delete the array elements in @DIR that contain the "perltest" for example. Somethings wrong but I can't see what.use strict; use warnings; use File::Copy; my @files = glob("*.hml"); my @DIR = glob ("*/*.hml"); my @array = ('', grep -d, glob '*'); print "Here's DIR @DIR"; my $argsucess = 0; foreach my $el (@ARGV){ print "\n\n\nheres el $el"; my $delele=0; foreach my $element (@DIR){ print "\n\n\nHERE'S ELE $element"; print "\n\n\n\n\n\n HERE'S DIR SO FAR @DIR\n\n\n"; my $re1='((?:[a-z][a-z]+))'; # Non-greedy match on filler my $re=$re1; my $path; if ($element =~m/$re/is){ $path = $1; } if ($el eq $path){ splice(@DIR, $delele, 1); $argsucess++; next; } $delele++; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Nested Foreach Loop skipping every other element??
by hdb (Monsignor) on Feb 19, 2014 at 16:36 UTC | |
by ba1688 (Novice) on Feb 19, 2014 at 16:38 UTC | |
by hdb (Monsignor) on Feb 19, 2014 at 16:47 UTC | |
by vinoth.ree (Monsignor) on Feb 19, 2014 at 17:00 UTC | |
|
Re: Nested Foreach Loop skipping every other element??
by Kenosis (Priest) on Feb 19, 2014 at 16:58 UTC | |
|
Re: Nested Foreach Loop skipping every other element??
by kennethk (Abbot) on Feb 19, 2014 at 17:44 UTC | |
by AnomalousMonk (Archbishop) on Feb 19, 2014 at 22:36 UTC |