in reply to taking file from user

Something like this should work:

#!/usr/bin/perl use strict; use warnings; print STDERR "Enter filename: "; my $fileName = <STDIN>; chomp $fileName; while (!-e $fileName) { print STDERR "\n$fileName not found.\nRe-enter filename, or +q to quit: "; $fileName = <STDIN>; chomp $fileName; exit() if $fileName eq "q"; } print STDERR "$fileName exists!\n" if -e $fileName; # <-- true if the +file exists

-Michael

UPDATE: it'd probably be worth your while putting in a quit option too!

Replies are listed 'Best First'.
Re^2: taking file from user
by ww (Archbishop) on Jul 15, 2013 at 19:46 UTC
    If I read OP's intent correctly, the object is to accept a file upload to a server... but michaeltmccarthy's solution appears to be for the visitor/user to download an extant file from the server.

    IMPORTANT: One more observation, in case my interp is correct: OP had best find a way to sandbox the uploads and test their content for nasties. In this day (and most previous days since ARPA-Net was the latest and greatest) allowing users effective free rein to dump garbage onto one's server/host/whatever is waaaay! to dangerous to even consider.

    If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.