Find file and add to classpath

Discussion in 'Perl Misc' started by Mikael Petterson, Feb 1, 2008.

  1. Hi,

    I am trying to find files in a directory (recursive in other directories)
    that matches the following expression, org.eclipse.equinox.launcher_*.jar:

    I have tried the following:

    my $classpath;

    find(\&equinox, '.');


    sub equinox {
    my $file = $File::Find::name;
    #return unless -f $file;
    if ($file =~ m/org.eclipse.equinox.launcher_*.jar/){
    print "$file";
    }


    }

    However it does not show the name of the files that I am searching for.

    Problem 1: Find files in directories ( subdirectories ) matching
    'org.eclipse.equinox.launcher_*.jar'.

    Problem 2: Add each found entry ( full path ) to $classpath variable.

    cheers,

    //mikael

    --
    Mikael Petterson
    Software Designer


    Ericsson AB, Stockholm, Sweden
    Visiting address: Isafjordsgatan 15, Kista
    Phone: +46 70 2673044
    E-mail:
     
    Mikael Petterson, Feb 1, 2008
    #1
    1. Advertising

  2. Mikael Petterson <> wrote:
    >Hi,
    >
    >I am trying to find files in a directory (recursive in other directories)
    >that matches the following expression, org.eclipse.equinox.launcher_*.jar:
    >
    >I have tried the following:
    >
    >my $classpath;
    >
    >find(\&equinox, '.');
    >
    >
    >sub equinox {
    > my $file = $File::Find::name;
    > #return unless -f $file;
    > if ($file =~ m/org.eclipse.equinox.launcher_*.jar/){


    I have a feeling this RE doesn't do what you seem to think it is doing.
    Are you really looking for
    the text 'org', followed by any single character,
    followed by the text 'eclipse', followed by any single character
    [.....]
    followed by the text 'launcher',
    followed by zero or more underscore characters
    [...]

    It appears to me that you do NOT want the RE capabilities but a simple
    textual comparison. If so then try a simple text equal 'eq' or index().

    jue
     
    Jürgen Exner, Feb 1, 2008
    #2
    1. Advertising

  3. Mikael Petterson wrote:
    >
    > I am trying to find files in a directory (recursive in other directories)
    > that matches the following expression, org.eclipse.equinox.launcher_*.jar:
    >
    > I have tried the following:
    >
    > my $classpath;
    >
    > find(\&equinox, '.');
    >
    >
    > sub equinox {
    > my $file = $File::Find::name;
    > #return unless -f $file;
    > if ($file =~ m/org.eclipse.equinox.launcher_*.jar/){


    The expression 'org.eclipse.equinox.launcher_*.jar' is a file glob. The
    expression m/org.eclipse.equinox.launcher_*.jar/ is a regular
    expression. So you are saying match the literal string 'org' followed
    by (.) any character except newline followed by the literal string
    'eclipse' followed by any character except newline followed by the
    literal string 'equinox' followed by any character except newline
    followed by the literal string 'launcher' followed by zero or more of
    the '_' character followed by any character except newline followed by
    the literal string 'jar' located anywhere in the string in $file.

    Since $_ contains the file name you want to do this:

    print $File::Find::name if
    /\Aorg\.eclipse\.equinox\.launcher_.*\.jar\z/;


    > print "$file";
    > }
    >
    >
    > }
    >
    > However it does not show the name of the files that I am searching for.
    >
    > Problem 1: Find files in directories ( subdirectories ) matching
    > 'org.eclipse.equinox.launcher_*.jar'.
    >
    > Problem 2: Add each found entry ( full path ) to $classpath variable.


    Do you want to use concatenation?

    $classpath .= $File::Find::name

    Or did you really want to use an array instead:

    push @classpath, $File::Find::name




    John
    --
    Perl isn't a toolbox, but a small machine shop where you
    can special-order certain sorts of tools at low cost and
    in short order. -- Larry Wall
     
    John W. Krahn, Feb 1, 2008
    #3
  4. John W. Krahn wrote:

    Thanks for the good advice. I forgot the escaping and now I find the correct
    jar file.

    cheers,

    //mikael

    > Mikael Petterson wrote:
    >>
    >> I am trying to find files in a directory (recursive in other directories)
    >> that matches the following expression,
    >> org.eclipse.equinox.launcher_*.jar:
    >>
    >> I have tried the following:
    >>
    >> my $classpath;
    >>
    >> find(\&equinox, '.');
    >>
    >>
    >> sub equinox {
    >> my $file = $File::Find::name;
    >> #return unless -f $file;
    >> if ($file =~ m/org.eclipse.equinox.launcher_*.jar/){

    >
    > The expression 'org.eclipse.equinox.launcher_*.jar' is a file glob. The
    > expression m/org.eclipse.equinox.launcher_*.jar/ is a regular
    > expression. So you are saying match the literal string 'org' followed
    > by (.) any character except newline followed by the literal string
    > 'eclipse' followed by any character except newline followed by the
    > literal string 'equinox' followed by any character except newline
    > followed by the literal string 'launcher' followed by zero or more of
    > the '_' character followed by any character except newline followed by
    > the literal string 'jar' located anywhere in the string in $file.
    >
    > Since $_ contains the file name you want to do this:
    >
    > print $File::Find::name if
    > /\Aorg\.eclipse\.equinox\.launcher_.*\.jar\z/;
    >
    >
    >> print "$file";
    >> }
    >>
    >>
    >> }
    >>
    >> However it does not show the name of the files that I am searching for.
    >>
    >> Problem 1: Find files in directories ( subdirectories ) matching
    >> 'org.eclipse.equinox.launcher_*.jar'.
    >>
    >> Problem 2: Add each found entry ( full path ) to $classpath variable.

    >
    > Do you want to use concatenation?
    >
    > $classpath .= $File::Find::name
    >
    > Or did you really want to use an array instead:
    >
    > push @classpath, $File::Find::name
    >
    >
    >
    >
    > John


    --
    Mikael Petterson
    Software Designer


    Ericsson AB, Stockholm, Sweden
    Visiting address: Isafjordsgatan 15, Kista
    Phone: +46 70 2673044
    E-mail:
     
    Mikael Petterson, Feb 1, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip
    Replies:
    3
    Views:
    7,280
    Tony Morris
    Feb 9, 2004
  2. Gabe
    Replies:
    3
    Views:
    1,078
  3. Replies:
    2
    Views:
    756
  4. Replies:
    2
    Views:
    1,113
    Mike Schilling
    Mar 2, 2008
  5. Stryder
    Replies:
    8
    Views:
    841
    Arne Vajhoej
    Oct 17, 2012
Loading...

Share This Page