Hi,
Im a new to perl and i hope there are people here that can help me!
I have a realy large file like this.
1,12,T,
2,13,B,
3,14,T,
4,15,B,
I want to use the 2nd and 3th column and put it into a hash like
with the 2nd column being the keys and the 3th column being the values.
This is what i have but i doesn't work!
open (data, 'data.csv');
my $hash_data = <data>;
my @hash_data = split (/,/, $hash_data);
@hash_Key = $hash_Data[1];
@hash_Values = $hash_Data[2];
%hash_data =($hash_Key => $hash_Values);
print %hash_data;
I hope someone can help me!
Iris
3 13871 arne 315
Expert 100+
Hi,
Im a new to perl and i hope there are people here that can help me!
I have a realy large file like this.
1,12,T,
2,13,B,
3,14,T,
4,15,B,
I want to use the 2nd and 3th column and put it into a hash like
with the 2nd column being the keys and the 3th column being the values.
This is what i have but i doesn't work!
open (data, 'data.csv');
my $hash_data = <data>;
my @hash_data = split (/,/, $hash_data);
@hash_Key = $hash_Data[1];
@hash_Values = $hash_Data[2];
%hash_data =($hash_Key => $hash_Values);
print %hash_data;
I hope someone can help me!
Iris
You could try something like -
open DATA, "data.csv";
-
-
my %hash;
-
-
while( <DATA> ) {
-
-
@elements = split /,/, $_;
-
-
if( $elements[1] ne '' ) {
-
$hash{ $elements[1] } = $elements[2];
-
}
-
}
-
@Iris83
Just another possibility: - open(DATA, "<", "data.csv") or die $!;
-
-
my %hash;
-
-
%hash = ( %hash, (split(/,/, $_))[1,2] ) while ( <DATA> );
Greetz, Doc
Sign in to post your reply or Sign up for a free account.
Similar topics
by: _DS |
last post by:
I'm currently using a switch with about 50 case statements in a
stretch of code that's parsing XML attributes. Each case is a string.
I'm told that switch statements will actually use hash tables...
|
by: sp |
last post by:
i have an xml file (an rss file)
<?xml version="1.0" ?>
<rss version="2.0">
<channel>
<title>CodeGuru.com</title>
<link>http://www.codeguru.com/</link>
<description>The number one developer...
|
by: EP |
last post by:
This inquiry may either turn out to be about the suitability of the
SHA-1 (160 bit digest) for file identification, the sha function in
Python ... or about some error in my script. Any insight...
|
by: John Wright |
last post by:
I want to create a file hash on my exe files and store the hash signature in
a database so I can retrieve the value to compare the file hash to ensure I
have an untampered file. How can this be...
|
by: mens libertina |
last post by:
Disclaimer: In addition to reading the skimpy entries at php.net, I've
searched this group and alt.php to no avail.
Basically, I'm trying to use a template to send email reminders, but I
can't...
|
by: joe2684 |
last post by:
I have got a file containing info abt node id and labels, which looks like this
-645 _1__46__1__46__1__46__145__45__RXN
-435 _3__45__OXOACYL__45__ACP__45__REDUCT__45__RXN
-1084 RXN__45__4262...
|
by: amittewarii |
last post by:
Hello Everybody ,
I need help in parsing the given file ,
#################################################################
<sample_cfg : 00FF_F000>
#f_name ...
|
by: subeen |
last post by:
Hi,
I am trying to parse a rss similar to the one found here (in example) http://www.feedforall.com/mediarss.htm
<!-- Snipped for Brevity -->
<item>
<title>FeedForAll's Show Tunes and...
|
by: whiteideal |
last post by:
hay, guys, i just want to create a svg file according to my data, but
i don't know whether there is some opensouce lib to do such things.
Can you tell me about it? Thanks.
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |