fluticasone has asked for the wisdom of the Perl Monks concerning the following question:

It is just that I need to change FILE timestamp without having to login every time. Since scripts are not secure in maintaning username/password; I have seen an answered given by the monks to use Net::FTP; without using a login information opening the directory (remote machine w/ IP) like a file

#!/usr/bin/perl use strict; my %count; my $directory = "\\Test"; opendir( DIR, $directory ) || die "Unable to open directory - $!\n"; my @files = grep /\.txt/, readdir( DIR ); closedir( DIR ); open( OUTFILE, ">> $directory\\COID_LIST.txt" ) || die "Unable to open write file! - $!\n"; foreach my $file (@files) { open( FH, "$directory\\$file" ) || die "Unable to open $file - $!\n"; while( <FH> ) { my $ID = substr( $_, 260, 5 ); print OUTFILE "$ID\n"; $count{$ID}++ if ( defined( $ID ) ); } close( FH ); } print "Number of company ID = " . scalar keys %count; sub process_files { if ($File::Find::dir ne $dir) { $File::Find::prune = 1; return 0; } return 0 if ($_ !~ /\.txt$/); copy($File::Find::name, "\\temp\\$_") or die "Failed to copy $_: $ +!\n"; return 1; } find(\&process_files, $dir); Sub renaming_files { foreach my $file (glob "*.old") { my $newfile = $file; $newfile =~ s/\.old$/.new/; if (-e $newfile) { warn "can't rename $file to $newfile: $newfile exists\n"; } elsif (rename $file, $newfile) { ## success, do nothing } else { warn " rename $file to $newfile failed: $!\n"; } }
But opening the remote server like a file. Thus it requires time and specific information unless I do a quick search. I would like to know a routine to open this mode and not get kick-out with "connection close by remote server" message. Also estimated wait time on large files or logs are very hard to asses not impossible. I will thank any response by the monks.

Replies are listed 'Best First'.
Re: Open Remote Directory
by aitap (Curate) on Aug 23, 2012 at 12:38 UTC
    The "\" symbol has a special meaning in Perl: it helps to escape other symbols (like quotes) and gives some letters the special meaning (for example, "\n" is a newline). You have either to use single quotes, or to escape both slashes with another slashes (so '\\' eq "\\\\"). Read Quote and Quote like Operators for more information.
    Sorry if my advice was wrong.