On Thu, 22 May 2014 14:37:01 -0700
Charles DeRykus <dery...@gmail.com> wrote:

> On Thu, May 22, 2014 at 1:40 PM, Manfred Lotz <manfred.l...@arcor.de>
> wrote:
> > Hi there,
> > I want to check if a file is a plain file but not a symlink.
> >
> > It seems because -f returns true for a symlink that I have to do
> > this: my $fname = 'somefile';
> >
> > if (  -f $fname  and not -l $fname ) {
> >         say "$fname is a plain file";
> > }
> > Is there a simpler way to do this?
> >
> 
> Potentially shorter and arguably simpler if you use the special
> underscore argument  to access file info for previous test, eg,
> 
>    if ( -f $fname  and  not -l _ ) {
>        say...
>    }
> 

Yes, you are right. I have to admit that I don't use _ very often but
this is a good place.

The strangest thing is that -f works differently to -type f in the find
command. I wasn't aware of it and this caused my script to behave
wrongly.

-- 
Manfred




-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to