1826251 Members
4112 Online
109692 Solutions
New Discussion

An Easy one in Perl

 
SOLVED
Go to solution
Shahul
Esteemed Contributor

An Easy one in Perl

Hi,

I need to check if a directory is a symbolic link or not, in ksh we use -h to check the link. What about Perl?

TIA
Shahul
5 REPLIES 5
H.Merijn Brand (procura
Honored Contributor

Re: An Easy one in Perl

-l

See file test operators in perlfunc

# man perlfunc

search for 'file test'


Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Muthukumar_5
Honored Contributor
Solution

Re: An Easy one in Perl

#!/usr/bin/perl
print "Enter directory | filename to check symbolic link or not: \n"
$filename=;
chomp($filename);

if ( -l $filename )
{
print $filename . " is made up of symbolic link";
}
else
{
print $filename . " is not made up of symbolic link";
}

###
Use -l instead of -h in ksh.

--
Muthu
Easy to suggest when don't know about the problem!
Peter Godron
Honored Contributor

Re: An Easy one in Perl

Shahul,
#!/usr/bin/perl
unless (open(MYFILE,"file.txt")){
if (!(-l "file.txt")){
die("File is not a link\n");
}
}
Muthukumar_5
Honored Contributor

Re: An Easy one in Perl

You can use stat module in perl.

$ perldoc -f stat

which is giving an example for this to use S_ISLNK().

--
Muthu
Easy to suggest when don't know about the problem!
Shahul
Esteemed Contributor

Re: An Easy one in Perl

This is resolved now. Thanks to all.