The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to store values into variable in perl chittiprasad15 Linux 3 05-07-2008 09:21 PM
Need help to write a Perl script user_prady Shell Programming and Scripting 10 03-25-2008 11:38 PM
how to get last value in an array in perl meghana Shell Programming and Scripting 7 02-04-2008 02:12 PM
formating array file output using perl seismic_willy Shell Programming and Scripting 4 03-21-2007 11:23 PM
need help to write perl code getdpg Shell Programming and Scripting 0 09-20-2006 06:24 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Posts: 56
perl -write values in a file to @array in perl

Hi

can anyone suggest me how to write a file containing values,... say

19
20
21
22
..
40

to an array @array = (19, 20, ... 40)

-- Thanks
Reply With Quote
Forum Sponsor
  #2  
Old 02-04-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Code:
open(FILE, "<", "file");

while(<FILE>) {
  chomp;
  push(@arr, $_);
}

close(FILE);
Reply With Quote
  #3  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Posts: 56
thanks for the reply.. but it dint work... do u have any further suggestions???
Reply With Quote
  #4  
Old 02-04-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
Originally Posted by meghana View Post
thanks for the reply.. but it dint work... do u have any further suggestions???
Why it didn't work ?

What is the expected output ?

Do you want to print the array elements ? If so, add the following snippet at the end

Code:
foreach(@arr) {
  print "array element: $_\n";
}
Reply With Quote
  #5  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Posts: 56
i dont know but.. this one worked for me...

open(FILE, "<", "tmpfile");
my @values = <FILE>;
close(FILE);

i just wanted to write the values of a file into @array... but still.. ur example helped me as a start point... appreciate it.. thanks again...
Reply With Quote
  #6  
Old 02-04-2008
Registered User
 

Join Date: Feb 2008
Posts: 56
can you help me on this... i try to print them($count, $last_rec) in two different lines but they get printed in one line if i use this script.....

open (fh,">>","file");
print fh "$count";
print fh "$last_rec";
close(fh);

can you suggest any solution for this...thanks
Reply With Quote
  #7  
Old 02-04-2008
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
Quote:
Originally Posted by meghana View Post
i dont know but.. this one worked for me...

open(FILE, "<", "tmpfile");
my @values = <FILE>;
close(FILE);

i just wanted to write the values of a file into @array... but still.. ur example helped me as a start point... appreciate it.. thanks again...
Well, this is also one of the way to do that.

The other one I had posted should also work
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:46 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0