473,387 Members | 1,295 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,387 software developers and data experts.

Query about Split function

Hi all
I have a file with below contents I need to store all the values in leftside into an array and right side into another array.
Filename:list.txt

ram,kriz
rakesh,ssss
perl,unix

If we assume the array name as ltemp then ltemp[0] should have "ram"
ltemp[1] should have rakesh and ltemp[2] should have "perl".

I tried the same,

Expand|Select|Wrap|Line Numbers
  1. open(FP,"list.txt") or die "cannot open the list file";
  2. while (<FP>) {
  3.     $temp = $_;
  4.     @ltemp = split(/,/ ,$temp);
  5.     print @ltemp[0];
  6. }
  7. close(FP);
  8.  
here ltemp[0] contains all the three elements and ltemp[1] has "kriz,rakesh,unix"

How can I store each value in seperate array Index..

Hope you can get my question
Jun 4 '07 #1
2 1179
miller
1,089 Expert 1GB
Hello kriz,

I believe that makes sense enough. However, if you really want those values in two different arrays, why have you not defined two different arrays? Putting that question aside, maybe this is what you are aiming at.

Expand|Select|Wrap|Line Numbers
  1. my (@array1, @array2);
  2.  
  3. my $file = 'list.txt';
  4. open(FP, $file) or die "Cannot open $file: $!";
  5. while (<FP>) {
  6.     my ($col1, $col2) = split ',';
  7.     push @array1, $col1;
  8.     push @array2, $col2;
  9. }
  10. close(FP);
  11.  
  12. print @array1 . "\n";
  13. print @array2 . "\n";
  14.  
- Miller
Jun 4 '07 #2
KevinADC
4,059 Expert 2GB
here ltemp[0] contains all the three elements and ltemp[1] has "kriz,rakesh,unix"
Actually your code is not storing anything except the last line of the file in the @ltemp array. I have a feeling you really want to use a hash but maybe not.
Jun 4 '07 #3

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

Similar topics

3
by: Dr. Oz | last post by:
Hi, I am trying to read in a query string from one page and build a link to another page based on the query string. Here's the code I am using to read in the query string: <script...
2
by: Justin Koivisto | last post by:
I am attempting to execute a *long* query string via a ADODB.Recordset.Open (queryStr) call. Most of the time, the query string will be less than 100 characters, but in some cases, it may be up to...
3
by: Janross | last post by:
I'm having trouble with a query that's prohibitively slow. On my free-standing office computer it's fine (well, 2-4 seconds), but on the client's network, it takes at least 5 minutes to run. ...
2
by: Alex Scollay | last post by:
Let's say I have a column whose values are all 2-digit integers, e.g. 82 (though it's actually a varchar field). From now on, the column will be able to have 2-digit as well as 3-digit integers....
11
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive...
2
by: patrick beyries | last post by:
fair Warning - Admittedly I'm far from an access expert, but I'm not a beginner either. I want to split a value into multiple parts as delimited by a character - all as part of a query. For...
3
by: Phil Stanton | last post by:
I have a number of queries which use code for the output of 1 or more fields. For example Address:GetAddress(AddressID, True, 60) Address ID Points to an Address in a table - Address Line1, Line...
3
by: Alexander Higgins | last post by:
Hi, I am working on an NNTP Client via windows forms and am actually try to login into this group to no avail. I am sending AUTHINFO USER username <where username=myemail address AUTHINFO...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
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: 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
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.