in reply to evaling code stored in database
mkpath($homeDir, 0, 0077); chdir $homeDir; mkpath($tmpDir, 0, 0077); chdir $tmpDir; system qq{wget "$mainSite/$torrentSite"}; open FILE, $torrentFile; open CMD, "ls *torrent |"; close CMD; system qq{transmissioncli -ep --download-dir $homeDir/$tmpDir + --uplimit number 0 --config-dir $homeDir/$tmpDir $torrent &}; open CMD, "transmission-remote --list |"; close CMD; system "transmission-remote -t 1 -S &";
You should ALWAYS verify that these system calls performed correctly before trying to use code that relies on their results.
if (! -d $homeDir ) { print "Making $homeDir.\n"; mkpath($homeDir, 0, 0077); } print "Entering $homeDir.\n"; chdir $homeDir; if (! -d $tmpDir ) { print "Making $tmpDir.\n"; mkpath($tmpDir, 0, 0077); } print "Entering $tmpDir.\n"; chdir $tmpDir;
Why not just use one step:
unless ( -d "$homeDir/$tmpDir" ) { print "Making $homeDir/$tmpDir.\n"; my $err; eval { mkpath "$homeDir/$tmpDir", { verbose => 0, mode => 0077, e +rror => \$err }; }; if ( $@ or @$err ) { die "mkpath failed because: ", $@ || @$err; } } print "Entering $homeDir/$tmpDir.\n"; chdir "$homeDir/$tmpDir" or die "Cannot chdir to '$homeDir/$tmpDir +' because: $!";
eval $code or die $!;
The $! variable will not have any useful information from eval. You need to use the $@ variable instead.
my @torrentFiles; open CMD, "ls *torrent |"; while (my $line = <CMD>) { chomp $line; push @torrentFiles, $line; } close CMD;
Or just:
my @torrentFiles = glob '*torrent';
|
|---|