Find file and add to classpath

Find file and add to classpath

am 01.02.2008 09:56:32 von 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: mikael.petterson@ericsson.com

Re: Find file and add to classpath

am 01.02.2008 10:19:32 von jurgenex

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

Re: Find file and add to classpath

am 01.02.2008 10:27:06 von someone

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

Re: Find file and add to classpath

am 01.02.2008 12:33:43 von 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

> 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@ericsson.com