perlperl
asked on
file
is there a command line to make sure file exits or not?
ASKER
i cannot use if(-e $filename)
because sometimes i execute my file on remote host....so i need the command line which can work on both unix and windows
because sometimes i execute my file on remote host....so i need the command line which can work on both unix and windows
Why do you think that -e does not work on both unix and windows?
If you want to check for the existence of a *file*, you are better off using the -f flag. -e will be true if $filename is a directory, link, device etc.
if (-f $filename)
is 100% portable/compatible across *all* operating systems that Perl runs on (at that's a big list)
if (-f $filename)
is 100% portable/compatible across *all* operating systems that Perl runs on (at that's a big list)
Please show us what steps you've used to determine it doesn't work on windows and unix servers?
Putting my ESP hat on, I'm guessing it's a path issue.
Putting my ESP hat on, I'm guessing it's a path issue.
ASKER
i know u r correct but u didn't get my question....i know -e works on both....
but i m looking for a command line (and not inside the perl script)
but i m looking for a command line (and not inside the perl script)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Excellent!!!
what does shift does??
what does shift does??
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also the following FAQ is relevant
perldoc -q one-liners
Found in /usr/local/lib/perl5/5.8.5 /pod/perlf aq3.pod
Why don't Perl one-liners work on my DOS/Mac/VMS system?
The problem is usually that the command interpreters on
those systems have rather different ideas about quoting than
the Unix shells under which the one-liners were created. On
some systems, you may have to change single-quotes to double
ones, which you must NOT do on Unix or Plan9 systems. You
might also have to change a single % to a %%.
For example:
# Unix
perl -e 'print "Hello world\n"'
# DOS, etc.
perl -e "print \"Hello world\n\""
# Mac
print "Hello world\n"
(then Run "Myscript" or Shift-Command-R)
# MPW
perl -e 'print "Hello world\n"'
# VMS
perl -e "print ""Hello world\n"""
The problem is that none of these examples are reliable:
they depend on the command interpreter. Under Unix, the
first two often work. Under DOS, it's entirely possible that
neither works. If 4DOS was the command shell, you'd
probably have better luck like this:
perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
Under the Mac, it depends which environment you are using.
The MacPerl shell, or MPW, is much like Unix shells in its
support for several quoting variants, except that it makes
free use of the Mac's non-ASCII characters as control
characters.
Using qq(), q(), and qx(), instead of "double quotes",
'single quotes', and `backticks`, may make one-liners easier
to write.
There is no general solution to all of this. It is a mess.
perldoc -q one-liners
Found in /usr/local/lib/perl5/5.8.5
Why don't Perl one-liners work on my DOS/Mac/VMS system?
The problem is usually that the command interpreters on
those systems have rather different ideas about quoting than
the Unix shells under which the one-liners were created. On
some systems, you may have to change single-quotes to double
ones, which you must NOT do on Unix or Plan9 systems. You
might also have to change a single % to a %%.
For example:
# Unix
perl -e 'print "Hello world\n"'
# DOS, etc.
perl -e "print \"Hello world\n\""
# Mac
print "Hello world\n"
(then Run "Myscript" or Shift-Command-R)
# MPW
perl -e 'print "Hello world\n"'
# VMS
perl -e "print ""Hello world\n"""
The problem is that none of these examples are reliable:
they depend on the command interpreter. Under Unix, the
first two often work. Under DOS, it's entirely possible that
neither works. If 4DOS was the command shell, you'd
probably have better luck like this:
perl -e "print <Ctrl-x>"Hello world\n<Ctrl-x>""
Under the Mac, it depends which environment you are using.
The MacPerl shell, or MPW, is much like Unix shells in its
support for several quoting variants, except that it makes
free use of the Mac's non-ASCII characters as control
characters.
Using qq(), q(), and qx(), instead of "double quotes",
'single quotes', and `backticks`, may make one-liners easier
to write.
There is no general solution to all of this. It is a mess.
ASKER