Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks - For some reason,the following for loop is not getting entered for the given input,any idea what could be the reason?

@folder_mk =./AACBaseFileLib/common.mk: $(PROJECT_ROOT)/../FilemuxIn +ternalDefs/inc \ foreach $mk(@folder_mk) { print "IN\n"; }

Replies are listed 'Best First'.
Re: FOR LOOP not entered
by davido (Cardinal) on Mar 21, 2011 at 06:53 UTC

    The snippet you posted doesn't even compile. You state that it does, but fails to enter the loop. That offers to me the clue that you have posted something that is different from the code you're experiencing trouble with. We can't help you with your problem if we can't look at the code, or at least a snippet of code that exhibits the problem you're having. The code posted here doesn't make any sense.


    Dave

Re: FOR LOOP not entered
by wind (Priest) on Mar 21, 2011 at 06:33 UTC
    Maybe because the code provided doesn't actually run? Just a thought.

      No,it reaches the for loop,but doesnot enter theloop

        Well, the code provided should not run (have not tried it myself, but do not see how you can avoid a syntax error). The most obvious reason for the foreach loop "not to be called" is if the list is empty. So the first thing to look at is how you are creating that list. And based on that horrible first line in your example, it's not hard to imagine you are accidentally passing in an empty list/array. Add "use strict; use warnings; " at the top of your program and resolve all of the issues they spit out. Will likely take care of your problem here along the way.

        Elda Taluta; Sarks Sark; Ark Arks

Re: FOR LOOP not entered
by Argel (Prior) on Mar 21, 2011 at 23:53 UTC
    Update: Good catch by je44ery regarding Makefiles!! Original text follows...

    Are you trying to merge a shell script with a Perl script or convert a shell script into a Perl script? That first line is pretty much not valid Perl. The ":" -- obvious separator used in shell PATH environment variables. And using \ to continue a line is also common in shell scripting (though I have no idea what you are continuing since the command appears to end there).

    Perl scripts are not like shell scripts and you cannot mix and match like you are apparently trying to above.

    Elda Taluta; Sarks Sark; Ark Arks

Re: FOR LOOP not entered
by jffry (Hermit) on Mar 22, 2011 at 14:54 UTC

    This looks like a snippet from a make file.

    This:

    @folder_mk =./AACBaseFileLib/common.mk

    ...is the target. That is, someone would type make @folder_mk to run this section of the make file.

    This:

    $(PROJECT_ROOT)/../FilemuxIn

    ...is dereferencing a make variable in the prerequistes section.

    The rest is perl code (probably) that seems to be in the recipe section. This is the code that gets run in order to build the @folder_mk target.

    You are going to have to understand make. Here is the link to docs: http://www.gnu.org/software/make/manual/make.html. Once you figure out the preprocessing that make is doing, then you can tell us the full code that is getting executed.