Rob, Thanks, this is a very clever solution. I will merge be murging files [ excel spread sheets saved in csv ], first line of files display's fileds. All files have same fields, but in different orders. Doe's anyone know of a way I can automate converssions of excel files to csv ??
Mark ----- Original Message ----- From: "Rob Dixon" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, February 13, 2004 7:26 AM Subject: Re: strings > Mark Goland wrote: > > > > I have a tring which contains 60 to 80 keywords, I need to know what position a > > keyword is in. I need an efficint way to extra position of key words, here is > > how I am currently finding positions, > > > > $string="type,model,color,date"; > > > > # this is how I am currently getting position, which is nto very efficiant > > @keys=split ",",$string; > > foreach( @keys ){ > > $position++; > > last if m/model/ig; > > } > > Hi Mark. > > If you build a hash where the keywords are the keys and their positions are > the values then you can just do a simple hash lookup: > > use strict; > use warnings; > > my $string = "type,model,color,date"; > > my @keys = split /,/, $string; > > my %position; > @[EMAIL PROTECTED] = 1 .. @keys; > > print $position{'model'}; > > It's important that your hash is static though, it's going to be a lot slower > to rebuild it each time you need it. > > HTH, > > Rob > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>