Two questions on making a Perl script work on PC

R

Rong Hu

I'm writing a tool to auto-detect untranslated messags in M-code. I have two
qestions to make it work on PC (DOS command window).

1. I use "find" to collect all M-code. $_ should be the same as
$File::Find::name when I use "no_chdir => 1".
On Unix, it's true. Both give fullpathes. However, on PC, $_ gives relative
pathes while $File::Find::name gives fullpathes.

2. I'm using either slash or backslash [/\\] as a file separator to find the
existing translation file. Is there a better way?
Btw, I found a useful function to glue path and filename together based on
the running platform. It's File::Spec::catfile.

Thanks in advance,

Rong
 
A

A. Sinan Unur

1. I use "find" to collect all M-code. $_ should be the same as
$File::Find::name when I use "no_chdir => 1".
On Unix, it's true. Both give fullpathes. However, on PC, $_ gives
relative pathes while $File::Find::name gives fullpathes.

#!/usr/bin/perl

use strict;
use warnings;

use File::Find;

find({ wanted => \&wanted, no_chdir => 1}, $ARGV[0]);

sub wanted {
unless ($File::Find::name eq $_ ) {
print "$File::Find::name\n$_\n\n";
}
}

__END__

D:\Home\asu1\UseNet\clpmisc> ff D:/Dload

D:\Home\asu1\UseNet\clpmisc>

D:\Home\asu1\UseNet\clpmisc> ff ..

D:\Home\asu1\UseNet\clpmisc>

Do you get different results?
2. I'm using either slash or backslash [/\\] as a file separator to
find the existing translation file. Is there a better way?
Yes.

Btw, I found a useful function to glue path and filename together
based on the running platform. It's File::Spec::catfile.

Use it.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 
B

Brian McCauley

A. Sinan Unur said:

Only use File::Spec on those rare occasions there you _need_ the path
in native form. Otherwise you should stick with the canonical (Unix)
form. In particular File::Find always uses the canonical '/' directory
separator.
 
R

Rong Hu

Hi Sinan,

1. Yes, I got different results when I use an obsolute path as the input
argument.
On Unix:
/sandbox/rhu/Acontrol_14p0_Nov17/matlab/tools/i18n/diff.txt
/sandbox/rhu/Acontrol_14p0_Nov17/matlab/tools/i18n/diff.txt
On PC:
S:\Acontrol_14p0_Nov17\matlab\tools\i18n\diff.txt
diff.txt

2. What is the better solution rathan than do something like:
($sdir) = $path =~ m[(.*toolbox[/\\].*?[/\\].*?[/\\])]

Thanks,
Rong

A. Sinan Unur said:
1. I use "find" to collect all M-code. $_ should be the same as
$File::Find::name when I use "no_chdir => 1".
On Unix, it's true. Both give fullpathes. However, on PC, $_ gives
relative pathes while $File::Find::name gives fullpathes.

#!/usr/bin/perl

use strict;
use warnings;

use File::Find;

find({ wanted => \&wanted, no_chdir => 1}, $ARGV[0]);

sub wanted {
unless ($File::Find::name eq $_ ) {
print "$File::Find::name\n$_\n\n";
}
}

__END__

D:\Home\asu1\UseNet\clpmisc> ff D:/Dload

D:\Home\asu1\UseNet\clpmisc>

D:\Home\asu1\UseNet\clpmisc> ff ..

D:\Home\asu1\UseNet\clpmisc>

Do you get different results?
2. I'm using either slash or backslash [/\\] as a file separator to
find the existing translation file. Is there a better way?
Yes.

Btw, I found a useful function to glue path and filename together
based on the running platform. It's File::Spec::catfile.

Use it.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top