Path to another server

J

Joe

We are switching from one server to another for our PERL Scripts, and
so far everything is working, but I am having problems with on program
which works on the old server but not the new one.

The problem I have is creating a file in a directory on another
server. I use "\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\" as my
path to the serever, and to create it, I use open (TOT_TXT,
'>{servername and filename}').

But when I try to write print TOT_TXT "Hello\n";, it does not work.

Can anyone help? I print out the path and put it in Windows Explorer
and it goes right there, so I do not know why it cannot be accessed.

The code is below:
<code>
$relative_addy = "\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\";

$month_year = $date_month . "_" . $date_year . ".txt";

$tot_file = $relative_addy . $month_year;

open (TOT_TXT, '>$tot_file') || die "$tot_file open failed: $!";

print "File: $tot_file<p>";

print TOT_TXT "Hello\n";

close(TOT_TXT);
</code>
 
J

Joe

In what way does it not work?



Are you using 'strict'? If not, why not? If you are, where is this
variable declared?

Use forward slashes. With a few exceptions (notably paths passed to
cmd.exe and paths passed to Win32::process) they work perfectly well on
Win32 perl.

    my $relative_addy = "//gailbapps/cybraryn/TDmenu/A-Cyb_Stats/";



    my $tot_file = "$relative_addy$date_month\_$date_year.txt";


Presumably this line succeeds? It does not, however, do what you think
it does: single quotes don't interpolate, so you are trying to open a
file called (literally) '$tot_file' in the current directory. I didn't
think Win32 allowed filenames to have '$' in, but I may be
misremembering.

You should be using lexical filehandles and 3-arg open:

    open(my $TOT_TXT, ">", $tot_file)
        || die "$tot_file open failed: $!";




You also need to check the return value of close, to make sure the data
was actually written successfully. (Checking print is neither necessary
nor sufficient.)

    close($TOT_TXT) || die "writing $tot_file failed: $!";

Ben

I would love to use strict, but I have &FormInput; and when I put my
in front of it, I get an error.

But I do get the following error: \\gailbapps\cybraryn\TDmenu\A-
Cyb_Stats\05_2009.txt open failed: Invalid argument at C:\Inetpub
\wwwroot\cgi-bin\CybraryN\test.pl line 50.

Which led me here to ask for help. Below is the complete code:

#!/usr/bin/perl -w

use CGI qw:)standard :html3);
use CGI::Carp qw(fatalsToBrowser);
#use strict;

#Library file that will read the form data and store in
formdata{'value'} form
require '../lib/forminput.lib';

&FormInput;

#$comps = "ercomps_test.txt"; # Holder for computer txt file.
my $comps = "ercomps.txt"; # Holder for computer txt file.
my $date_month = "08"; # Holder for Testing Month.
my $date_year = "2009"; # Holder for Testing Year.
my $tot_file = $date_month . "_" . $date_year . ".txt";
my $month_year;
my $relative_addy = "\\\\gailbapps\\cybraryn\\TDmenu\A-Cyb_Stats\\";
my $cnt = 0;
my $dir_cnt = 0;
my $dir;
my $dirtoget;
my $formdata;
my @comps;

print "Content-type: text/html\n\n";
print "<html><body>";
print "<head><title>CybraryN ER Computer Statistics</title></head>";

$date_month = $formdata{'month'};
$date_year = $formdata{'year'};
$month_year = $date_month . "_" . $date_year . ".txt";
$tot_file = $relative_addy . $month_year;
print "<h2>CybraryN ER Computer Stats</h2>";
print "<h3>For Month-Year of: $date_month-$date_year</h3>";
print "<h3>Get Data for Excel File from <a href='file://V:/TDmenu/A-
Cyb_Stats/'>V:\\TDmenu\\A-Cyb_Stats\\$month_year</a></h3>";

##########################################################################
# Read in text file for the computers to be used, and set to an array.
#
open (COMPSLIST, $comps) || die "$comps open failed: $!";
while (<COMPSLIST>) {
chomp;
$comps[$cnt] = $_;
++$cnt;
}
close (COMPSLIST);

# open (TOT_TXT, '>$tot_file') || die "$tot_file open failed: $!";
open (TOT_TXT, '>\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\
$month_year') || die "$tot_file open failed: $!";

print "File: $tot_file<p>";

print TOT_TXT "Hello\n";

foreach $dir (@comps) {
$dirtoget = "\\\\gailbapps\\cybraryn\\TDmenu\\" . $dir . "\
\Meter.dba";
print "Directory: $dirtoget<br />";
++$dir_cnt;
print TOT_TXT $dir_cnt . "\n";
open (METER, '$dirtoget') || die "$dirtoget open failed: $!";

while (<METER>) {
chomp;
print "Record: $_<br />";
}
}
close(METER);
close($TOT_TXT) || die "writing $tot_file failed: $!";
 
S

smallpond

But I do get the following error: \\gailbapps\cybraryn\TDmenu\A-
Cyb_Stats\05_2009.txt open failed: Invalid argument at C:\Inetpub
\wwwroot\cgi-bin\CybraryN\test.pl line 50.

'>\\\\gailbapps\\cybraryn\\TDmenu\\A-Cyb_Stats\\$month_year'

I don't know about PERL, but in Perl variables are not
expanded inside single quotes, so your error does not match
the code which you included.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,233
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top