The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-08-2008 12:21 AM
Need help to write a Perl script user_prady Shell Programming and Scripting 10 03-26-2008 02:38 AM
how to get last value in an array in perl meghana Shell Programming and Scripting 7 02-04-2008 05:12 PM
formating array file output using perl seismic_willy Shell Programming and Scripting 4 03-22-2007 02:23 AM
need help to write perl code getdpg Shell Programming and Scripting 0 09-20-2006 09:24 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 02-04-2008
meghana meghana is offline
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
  #2 (permalink)  
Old 02-04-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
Code:
open(FILE, "<", "file");

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

close(FILE);
  #3 (permalink)  
Old 02-04-2008
meghana meghana is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 56
thanks for the reply.. but it dint work... do u have any further suggestions???
  #4 (permalink)  
Old 02-04-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
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";
}
  #5 (permalink)  
Old 02-04-2008
meghana meghana is offline
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...
  #6 (permalink)  
Old 02-04-2008
meghana meghana is offline
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
  #7 (permalink)  
Old 02-04-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,953
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

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:57 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0