Home: Perl Programming Help: Beginner:
Path ??



Fredrik
Deleted

Feb 27, 2001, 4:10 PM


Views: 228
Path ??

Hi
I am working on an upload script
Uploading with Unix client works great but when it comes to win it just erase
my file


$file =~ s{.*/} {} if $file =~ m{^/};##Removes unix path

$file =~ s{.*\\} {} if $file =~ m{[A-Z]:\\};##Removes Win path


What it wrong with my Win path, it just empties my file to 0kb
Thanks /Fredrik



Rivotti
User

Mar 2, 2001, 4:59 AM


Views: 208
Re: Path ??

Hi Fredrik,

Try this:

# Match the name file without the path.
# Regex: [^/:\\]* - Match anything that is not / or : or \, zero or more times.

$file =~ m!([^/:\\]*)$!;
my $short_name = $1; # put the filename in the string $short_name
my $size;

open (SAVE,">$short_name") || die $!; # now saves the files
while ($size = read($file,$data,1024)) {
print SAVE $data;
}
close SAVE;

Rivotti