Re: symlink to "pack"
Hi on 2019/9/10 3:18, John W. Krahn wrote: The operating system is written in C. The symlink(2) function is part of the operating system and is written in C. Therefore, when perl calls symlink(2) it has to send a valid C type string. Because your string starts with a NULL character it is a C string with zero characters. Good answer John. I have another question that, since perl is typeless language, how does perl know send the correct C type string to C's function? thanks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: symlink to "pack"
On 2019-09-08 12:20 p.m., Jorge Almeida wrote: On Sun, Sep 8, 2019 at 8:08 PM John W. Krahn wrote: On 2019-09-07 1:25 p.m., Jorge Almeida wrote: On Unix/Linux a character in a file name can be any character except a slash '/' character because that is used to separate path elements, or a null "\0" character because that is what the C language uses to signify the end of a string. Yes, but does a symlink target counts as a "file name"? Probably, but it's not very clear. (I didn't want to dereference the symlink, only readlink() it...) Jorge So your Perl string "\0\f" is read by C as a zero length string. The operating system is written in C. The symlink(2) function is part of the operating system and is written in C. Therefore, when perl calls symlink(2) it has to send a valid C type string. Because your string starts with a NULL character it is a C string with zero characters. John -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: symlink to "pack"
On 2019-09-07 1:25 p.m., Jorge Almeida wrote: Sorry about the title, it's the best I can do... #!/usr/bin/perl use strict; use warnings; my $num=12; my $target=pack('n', $num); symlink($target, "foo") || die $!; It dies with "No such file or directory" No symlink is created. What I want is a symlink named "foo" pointing to a 2-byte string. Yes, it would be a broken symlink. (Yes, this is how I want it). Symlink() can create broken links, the problem is the target. What to do? (And why doesn't it work?) $ perl -le' use warnings; use strict; use Data::Dumper; $Data::Dumper::Useqq = 1; my $num = 12; my $target = pack "n", $num; print Dumper $target; ' $VAR1 = "\0\f"; On Unix/Linux a character in a file name can be any character except a slash '/' character because that is used to separate path elements, or a null "\0" character because that is what the C language uses to signify the end of a string. So your Perl string "\0\f" is read by C as a zero length string. John -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: symlink to "pack"
On 9/7/19 8:35 PM, Mike wrote: Maybe you should simplify to: #!/usr/bin/perl use strict; use warnings; symlink('ab', "foo") || die $!; If that doesn't work try it after changing 'symlink' to 'link' symlink and link are very different functions so changing it likely won't help. see my other post on why this is likely failing. IMO link would fail for the same reason as symlink as the pack is putting in null bytes in the filename. uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: symlink to "pack"
Maybe you should simplify to: #!/usr/bin/perl use strict; use warnings; symlink('ab', "foo") || die $!; If that doesn't work try it after changing 'symlink' to 'link' Printing your $target gives a space and this symbol: https://www.fileformat.info/info/unicode/char/2640/index.htm I am on Strawberry Perl, so I can't really help debug this. Mike On 9/7/2019 3:25 PM, Jorge Almeida wrote: Sorry about the title, it's the best I can do... #!/usr/bin/perl use strict; use warnings; my $num=12; my $target=pack('n', $num); symlink($target, "foo") || die $!; It dies with "No such file or directory" No symlink is created. What I want is a symlink named "foo" pointing to a 2-byte string. Yes, it would be a broken symlink. (Yes, this is how I want it). Symlink() can create broken links, the problem is the target. What to do? (And why doesn't it work?) TIA Jorge Almeida -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: symlink to "pack"
On 9/7/19 4:25 PM, Jorge Almeida wrote: Sorry about the title, it's the best I can do... #!/usr/bin/perl use strict; use warnings; my $num=12; my $target=pack('n', $num); symlink($target, "foo") || die $!; It dies with "No such file or directory" No symlink is created. What I want is a symlink named "foo" pointing to a 2-byte string. Yes, it would be a broken symlink. (Yes, this is how I want it). Symlink() can create broken links, the problem is the target. What to do? (And why doesn't it work?) my main question is, why?? when newbies want to do something wacky like this, there is usually a different larger goal. this is known as the XY problem. they ask about X but really need to do Y. so what is your real goal? it likely has nothing to do with symlinks but you seem to think that is a solution. and a quick guess is that you have 0 bytes in your packed string and filenames can't have 0 bytes. packing a small number into an int will have 0 bytes in it. uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
symlink to "pack"
Sorry about the title, it's the best I can do... #!/usr/bin/perl use strict; use warnings; my $num=12; my $target=pack('n', $num); symlink($target, "foo") || die $!; It dies with "No such file or directory" No symlink is created. What I want is a symlink named "foo" pointing to a 2-byte string. Yes, it would be a broken symlink. (Yes, this is how I want it). Symlink() can create broken links, the problem is the target. What to do? (And why doesn't it work?) TIA Jorge Almeida -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/