Hello expert,
This Perl code works when the path used for the target
file is in the same directory as the Perl executable.
But when I change to a shared drive on the network
open (MYFILE, '>>I:\Internal_Processes\S
ervice_Now
_Discovery
\CMDB_data
\data2.txt
');
I get
Backslash found where operator expected at open_ie4.pl line 18, near "Internal_Processes"
Obviously it doesn't like the the backslashes in the file path but how do I tell it
where the target file is without using backslashes in the file path?
Thanks
Allen
+++++++++++++++complete code+++++++++++++++++++++
#!/strawberry perl
use v5.10.0;
use warnings;
#use strict;
# go to url that is the table of servers in ServiceNow configuration
# read the table into variable $req
use LWP::UserAgent;
$ua = LWP::UserAgent->new;
$req =
HTTP::Request->new(GET => '
https://lhphgtst.service-now.com/cmdb_ci_datacenter.do?XML');
$req->authorization_basic(
'allen.pit
ts', 'password');
# write the table into a file on a local disk
open (MYFILE, '>>I:\Internal_Processes\S
ervice_Now
_Discovery
\CMDB_data
\data2.txt
');
print MYFILE $ua->request($req)->as_str
ing;
close (MYFILE);
++++++++++++++++++++++end complete code++++++++++++++++++++++
++
1) Commenting out the 'use strict; statement is a bad idea. Ignoring the errors that it would point out is never a good idea.
2a) You should use a lexical var for the filehandle instead of a bareword.
2b) You should use the 3 arg form of open
2c) You should always check the return code of an open call to verify that is was successful and take proper action if it failed. That normally means adding a 'die' statement which includes the filename and reason it failed.
Open in new window