473,386 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

PERL Array fails to read in complete text file.

I'm trying to read in a data file into an array. And split it into lines. I've a for loop which will parse the array, split the line (on ",") and execute another command. Here is the code.

Problem is that PERL will parse only the last 11 lines from the data file.

Expand|Select|Wrap|Line Numbers
  1. open TestList, "Testlist.dat" or die "Cannot open file to read data\n";
  2. @array = <TestList>;
  3. close TestList;
  4. print (@array);   <<< This prints the complete data file - all 22 line >>>
  5.  
  6.         $test = pop (@array);
  7. foreach $array (@array ) {
  8.         @tests = split(/,/,$test);
  9.         print @test;    <<< This prints the last 11 lines only >>
  10.         $telnet->print("cd /root/kal/ameritec/");
  11.         $telnet->print("mkdir $tests[0]");
  12.         $telnet->print("cd $tests[0]");
  13.         $TNdir = $tests[0];
  14.         $TN1 = $tests[1];
  15.         $TN2 = $tests[2];
  16.         print ("$TNdir is being run - $TN1, $TN2");
  17. #       $telnet->print("nohup ../analyzeTrace.sh /root/kal/AM/$TNdir $TN1
  18. $TN2 &");
  19. #       sleep (300);
  20.         $test = pop (@array);
  21.         $n++;
  22.         }
  23.  
  24.  
Aug 30 '10 #1
2 1844
RonB
589 Expert Mod 512MB
Why are you needlessly slurping the file into an array?

Expand|Select|Wrap|Line Numbers
  1.         print @test;    <<< This prints the last 11 lines only >>
Based on the code you posted, that won't print anything.

Why are you using:
Expand|Select|Wrap|Line Numbers
  1.         $test = pop (@array);
The net effect of that will be that you're processing every other line.

Obviously you're not running under strictures. Please add these 2 lines near the beginning of the script and remove those pop lines.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
Aug 30 '10 #2
Thank you Ron. I took out the pop statements and I modified the code as follows and it works now.

Expand|Select|Wrap|Line Numbers
  1.  
  2. foreach (@array) {
  3.         my @tests = split(/,/,$_);
  4.         print $tests;
  5.         $telnet->print("cd /root/kal/ameritec/");
  6.         $telnet->print("mkdir $tests[0]");
  7.         $telnet->print("cd $tests[0]");
  8.         my $TNdir = $tests[0];
  9.         my $TN1 = $tests[1];
  10.         my $TN2 = $tests[2];
  11.         print ("$TNdir is being run - $TN1, $TN2");
  12.         $telnet->print("nohup ../analyzeTrace.sh /root/kal/ameritec/$TNdir $TN1 $TN2
  13. &");
  14. #       sleep (300);
  15. }
  16.  
Aug 30 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Jongmin | last post by:
Hi Everybody, I have to read text files which resides in cab file. How can I read the text file by C#? Help me!!! thanks, Jongmin
6
by: G.Esmeijer | last post by:
Friends, I would like to read a text file (fixed length formaated) really fast and store the data into an Access database (2003). Using the streamreader and reading line by line, separating the...
4
by: who be dat? | last post by:
I feel stupid for asking this but I can't figure this out. I've got some text files I want my website to read. The text files are located in a subdirectory of my application. Physically, the...
2
by: Johan Wendelstam | last post by:
Hi I am trying to let the users select a txt file on their drive and then import all the text in it to a textbox ? I have figured out how to access a file on the server and import it but not how...
3
by: ad | last post by:
I have a text file in the directory of my web application. How can I read this text file into a string vaiable?
5
by: jannordgreen | last post by:
I use windows 2000 and Visual Studio 2003. I have a vbnet web application on our intranet that needs to read a text file that sits on a different server. The general user does not have access to...
6
Atran
by: Atran | last post by:
Hello: In this article: You will learn to Write or Read A Text File. Let's Begin: First Create a new project (ConsoleApp or WinApp). And Make sure your program uses these namespaces: using...
1
by: sandy2481 | last post by:
Hi Friends, I'm a beginner in perl. Can anyone please provide me with a perl code to read a HTML file and write into excel file. Regards, Sandy
3
by: Raymond Chiu | last post by:
Dear all, Now I have the simple task to read text file line by line into database (SQL Server 2000). If the text file is divided into different fields according to the number of characters,...
4
by: Prisms | last post by:
I am trying to read a text file into an array and I'm having some trouble doing so. here is the code that I have so far. Any help would be much appreciated. #include <stdio.h> #include...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.