Deb wrote: > > Hi Guys, > > I have an array in which each element is a line commandline data. It looks > something like this - > > @Array contains lines: > > post1: -r [EMAIL PROTECTED] -x cat-100 -h post1 > post2: -x tel -h post2 > post3: -h post3 -x hifi > > And so on. The order of the options varies, and there may or may not be a > -r $arg on the line. > > These lines are parsed from a file with more lines, of which I extracted all > the lines with -h: > > open (F, "<$File"); > > while (<F>) { > if ($_ =~ / -h /) { > # remove crud > s/ \"\|//; > s/\/some\/crud\/path argument //; > s/\"$//; > # store what's left > push @Array, $_; > } > } > > What I really need to do is build a relationship between the first field > (which is the same as the argument to -h) and the argument to -x. The -x flag > can be dropped, as they're not needed. > > So it looks like I need to build a hash based.
If you want to put the data into a hash this may do what you want: $ perl -le' @array = ( "post1: -r [EMAIL PROTECTED] -x cat-100 -h post1", "post2: -x tel -h post2", "post3: -h post3 -x hifi" ); for ( @array ) { %hash = /(-[a-z])\s*((?!-)\S*)/g; $" = " <*> "; print "*> @{[%hash]} <*"; }' *> -r <*> [EMAIL PROTECTED] <*> -h <*> post1 <*> -x <*> cat-100 <* *> -h <*> post2 <*> -x <*> tel <* *> -h <*> post3 <*> -x <*> hifi <* John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]