Find file and add to classpath

  • Thread starter Mikael Petterson
  • Start date
M

Mikael Petterson

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: (e-mail address removed)
 
J

Jürgen Exner

Mikael Petterson said:
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

John W. Krahn

Mikael said:
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
 
M

Mikael Petterson

John W. Krahn wrote:

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

cheers,

//mikael
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/;



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: (e-mail address removed)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top