Results 1 to 3 of 3
Hello all
I have a csv file filled with content like this
1111111|2222222|3333333
4444444|5555555|6666666
7777777|6666666|4444444
How can I read the content of the file and assign the first column value ...
- 01-27-2012 #1Just Joined!
- Join Date
- Aug 2009
- Location
- Toronto
- Posts
- 31
Perl help!
Hello all
I have a csv file filled with content like this
1111111|2222222|3333333
4444444|5555555|6666666
7777777|6666666|4444444
How can I read the content of the file and assign the first column value from each line as array element.
To be something like
@array = (1111111,4444444,777777)
your help is highly appreciated
Thank you
- 01-27-2012 #2Linux Engineer
- Join Date
- Apr 2006
- Location
- Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
- Posts
- 1,117
Hi.
One method:
producing:Code:#!/usr/bin/env perl # @(#) p1 Demonstrate split. use strict; use warnings; my (@array) = (); while (<>) { push @array, ( split( /[|]/, $_, 2 ) )[0]; } print " Content of array \"@array\"\n"; exit(0);
See perldoc -f split for details.Code:% ./p1 data1 Content of array "1111111 4444444 7777777"
Best wishes ... cheers, drlWelcome - get the most out of the forum by reading forum basics and guidelines: click here.
90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
We look forward to helping you with the challenge of the other 10%.
( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )
- 01-27-2012 #3Just Joined!
- Join Date
- Aug 2009
- Location
- Toronto
- Posts
- 31


Reply With Quote
