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

Hi Monks , if I have these paths like this:
/main23/loge/do.pl /main22/loges/de.pl
in my script , I have to be under main23 directory , but I would like to grep for stuff under main22 but it complains because it can't find or see main22. how can I do this ,, my grep command looks like this
system (qq(grep $file /main23/loge/do.pl /main22/loges/de.pl > out.txt));
when running the script , i get somthing like this
grep: /main23/loge/do.pl: No such file or directory grep: /main22/loges/de.pl: No such file or director
again I have to be under main23 to run it ,, Thanks

Replies are listed 'Best First'.
Re: greping from directories
by redsquirrel (Hermit) on Jul 23, 2002 at 15:03 UTC
    If you are using absolute paths as you have shown above, it shouldn't matter what directory you are in. Are you sure the paths are correct?

    --Dave

Re: greping from directories
by Aristotle (Chancellor) on Jul 23, 2002 at 15:04 UTC
    I don't see any obvious mistake. Are you sure you have execute permissions on all directories in play as well as the proper read permissions?

    Makeshifts last the longest.

Re: greping from directories
by agentv (Friar) on Jul 23, 2002 at 16:00 UTC

    ...my suggestion stems from the time-honored principle, "divide and conquer."

    From a prompt, and while currently in the main23 directory, run the grep by hand. I'm betting that this is a problem that will reproduce when you do the operation by hand. If it does recur, then you can consider things like directory permissions and so forth.

    If the grep command works from your shell prompt, but does not when you run your script, then you want to consider the effects of your quotation of the command, and you may also want to do some exploration to determine if the instance of grep that you run from your script is the same that runs when you use your shell.

    I'll experiment here and see if I can see the same effect you are seeing.

    ---v

      ...FYI, I tried this approach on my own system and I reproduced the problem.

      But what I found is that I had supplied bad path names. When I used correct path names in my experiment, the code you supplied worked fine.

      The differences in my setup were that I created directories as you showed, but mine were beneath my home directory rather than immediately below the root directory. Otherwise, everything else was probably the same.

      Here's what I did:

      $ mkdir main22 main23 $ mkdir main22/loges main23/loge $ echo "john\nfile2" >main22/loges/de.pl $ echo "john1\nfile3" >main23/loge/do.pl $ grep file2 /home/flame/main23/loge/do.pl /home/flame/main22/loges/de +.pl $ perl -e 'system qq{grep file2 /home/flame16/main23/loge/do.pl /home/ +flame16/main22/loges/de.pl}'

      ---v