deleting ./ from ./filename

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 [at] files = qx(find . -name "*.c");
for my $file ( [at] files) {
$file =~ tr/.//d;
print "file is $file\n";
}

tx
kelly [ Di, 17 Januar 2006 23:07 ] [ ID #1145808 ]

Re: deleting ./ from ./filename

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 [at] files = qx(find . -name "*.c");
> for my $file ( [at] 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
Paul Lalli [ Mi, 18 Januar 2006 00:17 ] [ ID #1145809 ]

Re: deleting ./ from ./filename

"kelly" <kelly [at] some.com> wrote in message news:43CD6A93.6060504 [at] 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 [at] files = qx(find . -name "*.c");
> for my $file ( [at] 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
Matt Garrish [ Mi, 18 Januar 2006 00:24 ] [ ID #1145810 ]

Re: deleting ./ from ./filename

"kelly" <kelly [at] some.com> wrote in message news:43CD6A93.6060504 [at] 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 [at] files = qx(find . -name "*.c");
> for my $file ( [at] 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 [at] files = qx(find * -name "*.c");
Tintin [ Mi, 18 Januar 2006 08:44 ] [ ID #1147529 ]
Perl » alt.perl » deleting ./ from ./filename

Vorheriges Thema: *main:: added to function result
Nächstes Thema: system() question