Ken Lehman wrote: > Say I have a foreach loop that I used to modify elements when they match a > pattern that I am searching for, but there is one special case where I get > a match and I need the index for that element. Can I get that index or do > I have to go with a for() loop. If this can be done how would I use it? > Thanks in advance > Ken > > > # something along these lines > foreach $temp_string (@array_of_strings) > { > if ($temp_string =~ /^CRASH/) > { > $array_of_strings[$this_is_what_I_need - 1] = "LOOK OUT!"; > } > > > } >
sorry i might be missing your point but why not just: #!/usr/bin/perl -w use strict; my @array_of_strings = qw(CRASH Windoes use linux); s/^CRASH/LOOK OUT!/ for(@array_of_strings); print join("\n",@array_of_strings),"\n"; __END__ prints: LOOK OUT! windoes use linux david -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]