Whats the variable holding the dir seperator?

I

ipellew

Hi all;

Whats the Perl variable that holds the directory file seperator,
IE "/" or "\"

Is there a variable that holds the dot character?
Usually "."
EG perl.exe
A

Regards
Ian
 
G

gargoyle

Whats the Perl variable that holds the directory file seperator,
IE "/" or "\"
Is there a variable that holds the dot character?
Usually "."

There's no variable for that stuff. Use the File::Spec module to work
with paths, if you need to. Though generally it's ok to just use / as a
separator in your code, when calling open(), etc.
 
L

Leonard Challis

There's no variable for that stuff. Use the File::Spec module to work
with paths, if you need to. Though generally it's ok to just use / as a
separator in your code, when calling open(), etc.

Does anyone think that this could be a nice addition to the built in
variables in Perl, such as $`, $^0 etc? It would cerrtainly make life a lot
easier IMO.

Lenny Challis
 
B

Big and Blue

Leonard said:
Does anyone think that this could be a nice addition to the built in
variables in Perl, such as $`, $^0 etc? It would cerrtainly make life a lot
easier IMO.

In what way would it make your life easier?

What is the pathname separator on, say, VMS? (Does Perl run on
VMS???). You are assuming that suhc concepts are universal.

Likewise the comment about the '.' in pathnames. On Unix systems this
is just a dot - it has no special meaning at all.
 
L

Leonard Challis

Big and Blue said:
In what way would it make your life easier?

Well, instead of using something like the File::Spec module for
platform-independent path handling, we could simply do something like:

my $file = "dir1$*dir2$*file.ext";
#where $* is the seperator

Just a thought.
Lenny
 
L

Leonard Challis

"A. Sinan Unur wrote
On the other hand, if $dir1, $dir2 and $file are variables, you end up
with:

my $path = $dir1.$*.$dir2.$*.$file.'.ext';

I agree it is a little bit unpretty.
I am hoping that I am not the only one who thinks

use File::Spec::Functions 'catfile';

my $path = catfile $dir1, $dir2, "$file.ext";

is vastly clearer.

Clearer to a certain extent. For the Perl newbie, playing with modules is a
little daunting although I do agree with you.
Another thing to note it speed. How much time would you save having the
variable built in insted of using a module?
File::Spec provides a lot in the way of platform neutral file name and
path handling -- more than just a simple variable holding the directory
separator character.

Of course, however sometimes you don't need all that stuff, so why open it
_all_ up when not using any of it? Does using modules in perl take up alot
more resources and/or time?
Additionally, one is usually more interested in using the correct
character(s) for the OS than the actual character(s) themselves.

Thats also true, however it is a slight contradiction when many people feel
that portability must be strongly considered when writing "good" code.

Thanks for your comments Sinan,
Lenny
 
A

A. Sinan Unur

"A. Sinan Unur wrote


Thats also true, however it is a slight contradiction when many people
feel that portability must be strongly considered when writing "good"
code.


There is no contradiction. When I write:

use File::Spec::Functions 'catfile';

my $path = catfile $install_dir, $conf_dir, $conf_file;

I know that no matter which my script is executed on, the correct
character(s) will be used, but I still cannot remember what those would be
on a VMS system.

Sinan
 
T

Thomas Kratz

A. Sinan Unur said:
There is no contradiction. When I write:

use File::Spec::Functions 'catfile';

my $path = catfile $install_dir, $conf_dir, $conf_file;

I know that no matter which my script is executed on, the correct
character(s) will be used, but I still cannot remember what those would be
on a VMS system.

A VMS Path would look like this:

USER:[DIR1.DIR2.DIR3]file.ext

The File::Spec function 'splitpath' will correctly split this into the
volume, directory and file part. Handling volumes correctly is another
important issue when trying to write portable code dealing with directory
structures.

Thomas


--
$/=$,,$_=<DATA>,s,(.*),$1,see;__END__
s,^(.*\043),,mg,@_=map{[split'']}split;{#>J~.>_an~>>e~......>r~
$_=$_[$%][$"];y,<~>^,-++-,?{$/=--$|?'"':#..u.t.^.o.P.r.>ha~.e..
'%',s,(.),\$$/$1=1,,$;=$_}:/\w/?{y,_, ,,#..>s^~ht<._..._..c....
print}:y,.,,||last,,,,,,$_=$;;eval,redo}#.....>.e.r^.>l^..>k^.-
 
L

Leonard Challis

"Chris Mattern" wrote
Apparently your definition of "platform-independent" is "It works in
Windows/DOS, and it works in Unix/Unix-like clones. Isn't that the
entire universe?" (And I might point out that "/" works just fine
on ALL such platforms, outside of the Windows/DOS command interpreter)

I guess I was being a bit byast :D
Thanks for your pointers guys

Leonard
 
T

Tad McClellan

Leonard Challis said:
Well, instead of using something like the File::Spec module
Just a thought.


You put things in the perl core that must be in the perl core.

If it can be done in a module, then it does not need to bloat the core.
 
G

gargoyle

Clearer to a certain extent. For the Perl newbie, playing with modules is a
little daunting although I do agree with you.

The good thing is File::Spec is a "standard" module, so there's no need
to go download it from CPAN, run make, etc.
Another thing to note it speed. How much time would you save having the
variable built in insted of using a module?

There's always overhead for method/function calls, but you'll only
notice if the code is in a really, really tight loop. Of course that
applies to your own functions too! At that point you have to inline
code in the loop, and make sure you're using the best possible algorighm
for the job. I've got some code like that, but it only operates on data
strutures in memory, and makes an occasional system call, but no disk
access. The moment you're doing disk or network I/O, the overhead of
calling File::Spec::catfile & friends will be insignificant.

And usually somebody calls catfile before going to access a file... ;)
 
A

Anno Siegel

Leonard Challis said:
"A. Sinan Unur wrote


I agree it is a little bit unpretty.

If that were the only problem, it could be amended:

my $path = join $* => $dir1, $dir2, $file;

For full qualified path names,

my $path = join $* => '', $dir1, $dir2, $file;

would do.

But, as the rest of the thread states, "the" directory delimiter is only
a small part of making filenames portable, too small to be useful.

Also, you couldn't name the variable anything but $/, and that's taken :)

Anno
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top