B
bayxarea-usenet
I had a routine that worked fine with a range operator while looping
through a filehandle... but I have since changed the data source and it
is now already in an array... and the range operator does not appear to
be working...
I am basically extracting lines of data from a larger set.
--------------------
before -------------
open(IN,"< $file");
while (<IN>) {
if (/$start_string/ .. /$end_string/) {
if (($_ !~ /$start_string/) && ($_ !~ /$end_string/)) {
....
.... do something with $_ ...
....
} # end if
} # end if
} # end while
close IN;
--------------------
now -------------
@data_from_file; # lines of data retrieved elsewhere
foreach (@data_from_file) {
if (/$start_string/ .. /$end_string/) {
if (($_ !~ /$start_string/) && ($_ !~ /$end_string/)) {
....
.... do something with $_ ...
....
} # end if
} # end if
} # end foreach
Also -- there are now multiple places within the @data_from_file array
that I want to extract the data for which I am searching.
So want to be able to go inside (between the start and end strings)
each time the pair occurs within the array.
I thought of using something like this:
while ($_ = shift @data_from_file) {
if (/$start_string/ .. /$end_string/)
....
.... etc
but it did not work either.
After reading the docs I thought perhaps a slice would work - but I am
not sure how to tie the range to the elements of the array.
@data_I_want = (/$start_string/ .. /$end_string/) # ????
Thanks for any clues as to how to change this to work from a while loop
on the file handle to looping through each element of the array.
And - as I mentioned - I need to do this multiple times as the block I
am searching for will occur several times - so ... multiple slices on
the same array? Is that possible?
Thanks,
John
through a filehandle... but I have since changed the data source and it
is now already in an array... and the range operator does not appear to
be working...
I am basically extracting lines of data from a larger set.
--------------------
before -------------
open(IN,"< $file");
while (<IN>) {
if (/$start_string/ .. /$end_string/) {
if (($_ !~ /$start_string/) && ($_ !~ /$end_string/)) {
....
.... do something with $_ ...
....
} # end if
} # end if
} # end while
close IN;
--------------------
now -------------
@data_from_file; # lines of data retrieved elsewhere
foreach (@data_from_file) {
if (/$start_string/ .. /$end_string/) {
if (($_ !~ /$start_string/) && ($_ !~ /$end_string/)) {
....
.... do something with $_ ...
....
} # end if
} # end if
} # end foreach
Also -- there are now multiple places within the @data_from_file array
that I want to extract the data for which I am searching.
So want to be able to go inside (between the start and end strings)
each time the pair occurs within the array.
I thought of using something like this:
while ($_ = shift @data_from_file) {
if (/$start_string/ .. /$end_string/)
....
.... etc
but it did not work either.
After reading the docs I thought perhaps a slice would work - but I am
not sure how to tie the range to the elements of the array.
@data_I_want = (/$start_string/ .. /$end_string/) # ????
Thanks for any clues as to how to change this to work from a while loop
on the file handle to looping through each element of the array.
And - as I mentioned - I need to do this multiple times as the block I
am searching for will occur several times - so ... multiple slices on
the same array? Is that possible?
Thanks,
John