OK, you need to search directory A recursively until you find the first sub-directory named org.apache.ant.x.y (where x and y are integers). The module File::Find::Rule is useful for this.

I created a directory structure like this:

862_SoPW |-- weblogic_5 |-- A |-- B |-- org.apache.ant.1.3 |-- bin |-- weblogic_6 |-- A |-- B |-- C |-- org.apache.ant.1.4 |-- bin

and ran the following script from directory 862_SoPW:

#! perl use strict; use warnings; use File::Find::Rule; for (5 .. 7) { my $ant_home = get_ant_home('weblogic_' . $_) // 'not found'; print "In weblogic_$_, ant home is: $ant_home\n"; } sub get_ant_home { my $test_dir = shift; my $module_dir = $test_dir . '/A'; my @subdirs = File::Find::Rule->directory->in($module_dir); for (@subdirs) { return $_ if /org\.apache\.ant\.\d+\.\d+$/; } }

Output:

1:45 >perl 862_SoPW.pl In weblogic_5, ant home is: weblogic_5/A/B/org.apache.ant.1.3 In weblogic_6, ant home is: weblogic_6/A/B/C/org.apache.ant.1.4 In weblogic_7, ant home is: not found 1:46 >

I think you should be able to adapt this to your requirements.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^3: How to find ant home/specific directory in Linux using perl by Athanasius
in thread How to find ant home/specific directory in Linux using perl by sandeepda

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.