- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- how to get whole data from the file in perl?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 05:48 AM
тАО07-14-2009 05:48 AM
I have file like :
input.txt: contains list of dir.
JN001
JN002
JN003
JN004
******************************************
my $data_file = '/usr/symology/perl_get_put/data.txt';
# Open the file for reading.
open DATA, "$data_file" or die "can't open $data_file $!";
my @array_of_data = ;
close (DATA);
foreach $file(@array_of_data)
{
print "Dir listing is as :$file \n"
}
Output is :
Sucessfully cpoied files: JN001
Sucessfully cpoied files: JN002
Sucessfully cpoied files: JN003
Sucessfully cpoied files: JN004
}
After every print it is printing one blank line. Can some one suggest what is wrong?
Thanks
Solved! Go to Solution.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 06:04 AM
тАО07-14-2009 06:04 AM
Re: how to get whole data from the file in perl?
You need to 'chomp' your lines or drop the "\n" in your print().
Consider:
# perl -e 'chomp(@lines=<>);for $line (@lines) {print "$line\n"}' /etc/hosts
or:
# perl -e '@lines=<>;for $line (@lines) {print $line}' /etc/hosts
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-14-2009 09:38 PM
тАО07-14-2009 09:38 PM
Re: how to get whole data from the file in perl?
My code is working fine if i hard code the dirs in foreach loop like:
use Net::FTP;
use Cwd ;
use File::Basename ;
use POSIX ":sys_wait_h" ;
-->After connecting successfully i need to go each dir...
foreach my $name ('/Insight-Interface/Permits/JN001', '/Insight-Interface/Per
mits/JN002') {
$ftp->cwd("$name") or die "Can not change dir $name";
Printf" successfully change dir"
}
--> This code is fine. But i want to pass these dir path from input file like..
open DATA, "$data_file" or die "can't open $data_file $!";
my @array_of_data = ;
close (DATA);
foreach my $name (@array_of_data) {
$ftp->cwd("$name") or die "Can not change dir $name";
Printf" successfully change dir"
}
}
--> In this case it gives die error meesage Can not connect.
Can you please help me what is wrong if same structure i am passing from file?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-15-2009 04:00 AM
тАО07-15-2009 04:00 AM
Solution> In this case it gives die error meesage Can not connect.
Yes, of course. You need to re-read my first ressponse to you. You need to 'chomp' the newlines away when you stuff your array.
...
open(DATA, '<', $data_file) or die "can't open $data_file $!";
chomp( my @array_of_data = );
close (DATA);
foreach my $name (@array_of_data) {
$ftp->cwd($name) or die "Can not change dir $name";
print "successfully changed dir $name\n"
}
...
I also fixed a few other typos.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-19-2009 11:58 PM
тАО07-19-2009 11:58 PM
Re: how to get whole data from the file in perl?
Good Morning,
Appologies, i was in leave. Thanks it looks fine. But i still have problem. In my FTP server dir strucrute is like..
root/data/JN001
root/data/JN002
I have to CWD to each dir one by one. This input i want to give through input file. When i keeping inputs in data file like :
data.txt:
*************************************
root/data/JN001
root/data/JN002
*************************************
When i am passing these inputs to foreach loop it is not able to change the dir.
Not sure whether we should quote the path in file. Can you please suggect?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-20-2009 03:44 AM
тАО07-20-2009 03:44 AM
Re: how to get whole data from the file in perl?
> I have to CWD to each dir one by one. This input i want to give through input file. When i keeping inputs in data file like :
First, you need to specify absolute paths. The first change of directory sets your current working path to '/root/data/JN001'. The next, in your example, attempts to change the path to '/root/data/JN001/root/data/JN002'.
> When i am passing these inputs to foreach loop it is not able to change the dir.
Not sure whether we should quote the path in file.
This is explained above.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2009 03:37 AM
тАО07-22-2009 03:37 AM
Re: how to get whole data from the file in perl?
You are correct. Now i am passing absolute path from input file and paths are not quoted like
/root/JN001/
/root/JN002/
It is working now.
Thanks