deleting ./ from ./filename

deleting ./ from ./filename

am 17.01.2006 23:07:15 von kelly

Hi,
Me again, I'm trying to delete the ./ from string ./filename.
The result of find below is...
../file.c
../encrypt.c
../decrypt.cl.c

my loop deletes all the ., which is not what I want.
I want the final print to be printing
file.c
encrypt.c
decrypt.cl.c

#!/usr/bin/perl
use strict;
use warnings;
# deal with multiple c files???
my @files = qx(find . -name "*.c");
for my $file (@files) {
$file =~ tr/.//d;
print "file is $file\n";
}

tx

Re: deleting ./ from ./filename

am 18.01.2006 00:17:47 von Paul Lalli

kelly wrote:
> Hi,
> Me again, I'm trying to delete the ./ from string ./filename.
> The result of find below is...
> ./file.c
> ./encrypt.c
> ./decrypt.cl.c
>
> my loop deletes all the ., which is not what I want.
> I want the final print to be printing
> file.c
> encrypt.c
> decrypt.cl.c
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> # deal with multiple c files???
> my @files = qx(find . -name "*.c");
> for my $file (@files) {
> $file =~ tr/.//d;

Can you please explain what made you think that line would do your
stated goal?

> print "file is $file\n";
> }
>

Please look up:
perldoc File::Basename

Paul Lalli

Re: deleting ./ from ./filename

am 18.01.2006 00:24:33 von Matt Garrish

"kelly" wrote in message news:43CD6A93.6060504@some.com...
> Hi,
> Me again, I'm trying to delete the ./ from string ./filename.
> The result of find below is...
> ./file.c
> ./encrypt.c
> ./decrypt.cl.c
>
> my loop deletes all the ., which is not what I want.
> I want the final print to be printing
> file.c
> encrypt.c
> decrypt.cl.c
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> # deal with multiple c files???
> my @files = qx(find . -name "*.c");
> for my $file (@files) {
> $file =~ tr/.//d;

If you want to get rid of './', why are you using the transliteration
operator? Of course it gets rid of all the periods; that's what you're
telling it to do. Did you read the documentation, or did you just grab some
code from somewhere and hope it would work? I don't feel like spoonfeeding
today, so go read read up on s/// in perlop. While you're there, keep
reading on to the tr/// section once you're done.

Matt

Re: deleting ./ from ./filename

am 18.01.2006 08:44:59 von Tintin

"kelly" wrote in message news:43CD6A93.6060504@some.com...
> Hi,
> Me again, I'm trying to delete the ./ from string ./filename.
> The result of find below is...
> ./file.c
> ./encrypt.c
> ./decrypt.cl.c
>
> my loop deletes all the ., which is not what I want.
> I want the final print to be printing
> file.c
> encrypt.c
> decrypt.cl.c
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> # deal with multiple c files???
> my @files = qx(find . -name "*.c");
> for my $file (@files) {
> $file =~ tr/.//d;
> print "file is $file\n";
> }

Presumably your Perl script is much bigger than the above.

If your files are in a single directory

#!/usr/bin/perl
use strict;
use warnings;

chdir '/path/with/files' or die "Can not cd to /path/with/files $!\n";
foreach my $file (<*.c>) {
print "file is $file\n";
}

or if you really want to use find (I'd write a shell script instead)

my @files = qx(find * -name "*.c");