Hi meaculpa, On Wednesday 01 December 2010 09:25:43 meaculpa wrote: > I have a csv file, and iam checking for a condition like : > > if (@columns=parse_csv($_)) > { > #print $columns[11]."__\n"; > > if($columns[11] =~ m/$field/i && $columns[12] ge "$\rating" ) > { > writeLog("Name: $columns[5] \n\t Rating: $columns[12]\n"); > > OpenCv($columns[5]); > > Instead of this index I need to use the header names, without adding > any new module. Please tell me a solution . >
You can map a header name to a column index using a hash: http://perl-begin.org/topics/hashes/ [code] my @headers = ("Foo", "Bar", "Baz"...); my %headers_to_indexes = (map { $headers[$_] => $_ } (0 .. $#headers)); [/code] Regards, Shlomi Fish > > > PS : Column 11 is Class > > Column 12 is Age > > Column 5 is Name. -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Public Domain Photos - http://www.flickr.com/photos/shlomif/ <rindolf> She's a hot chick. But she smokes. <go|dfish> She can smoke as long as she's smokin'. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/