So I have a nested for each loop
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++; } }
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.

In reply to Nested Foreach Loop skipping every other element?? by ba1688

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.