#!/usr/bin/perl use strict; use File::Basename; use utf8; sub escMe($) { my $f1 = shift; my $f2 = '/etc/passwd'; my $f2 = "'/etc/passwd'"; my $f3 = '/etc/passwd';
$f1 = "'" . $f1 . "'"; if($f1 eq $f2) { print("Files are same $f1$f2\n"); } else { print("Files are NOT same $f1$f2\n"); } if (-e $f1) { printf "File exist $f1 !\n"; } else { printf "File not exist $f1 !\n"; } if (-e '$f2') { printf "File exist $f2 !\n"; } else { printf "File not exist $f2 !\n"; } if (-e '$f3') { printf "File exist $f2 !\n"; } else { printf "File not exist $f2 !\n"; } if (-e '/etc/passwd') { printf "File exist $f2 !\n"; } else { printf "File not exist $f2 !\n"; } return $f1; } escMe("/etc/passwd"); Output: lab# perl test3.pl Files are same '/etc/passwd''/etc/passwd' File not exist '/etc/passwd' ! File not exist '/etc/passwd' ! File not exist '/etc/passwd' ! File exist '/etc/passwd' ! W dniu 2016-11-10 11:52:46 użytkownik Jim Gibson <jimsgib...@gmail.com> napisał: > On Nov 10, 2016, at 2:30 AM, jaceke <jac...@op.pl> wrote: > > > > Hi, > > how can I check if file exist or not ? > > > > Here's a short test/example: > > > > if (-e '/etc/passwd') > > { > > printf "File exist !\n"; > > } else { > > printf "File not exist !\n"; > > } > > > > That works great ! > > > > but next a short test/example: > > > > my $f1 = '/etc/passwd'; > > > > if (-e $f1) > > { > > printf "File exist !\n"; > > } else { > > printf "File not exist !\n"; > > } > > > > and that NOT working ! Why ? > > > > I use quotes because my path contain special characters. > > Both of those versions work on my system. There is no reason for the version > using a scalar variable holding the file path not to work. > > Can you post a complete, short, working program that you think does not work? > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/