in reply to Re^2: Read the lines until a string exists in the array
in thread Read the lines until a string exists in the array

How to read the data until the variable exists in an array

I guess you mean until the variable exists in a hash, because your question about testing the existence in an array was already answered. You can test whether a key exists in a hash using the - surprise, surprise! - exists function. If you want to know whether a certain value exist in the hash, use values, which gives you an array of the values, and see whether your string exists in that array.

BTW, your usage of the hash $ctr looks funny to me. As far I can see, your keys of the hash are just the numbers 1,2,3..., so from a usage point of view, your hash is not different from an array (only that you start counting by 1 instead of 0).

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^4: Read the lines until a string exists in the array
by Anonymous Monk on Aug 14, 2009 at 09:27 UTC
    print $fh "<$tag>$_</$tag>\n"; I have to print the output of
    <AUTHOR>author1</AUTHOR> <AUTHOR>staff1</AUTHOR> <HEADLINE>DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\</HEADLINE> <HEADLINE>STYLE AT A SPEED</HEADLINE> <HEADLINE>USUALLY ASSOCIATED WITH WARDROBE ITEMS.</HEADLINE>
    to
    <AUTHOR>author1 staff1<AUTHOR> <HEADLINE>DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\ STYLE AT A SP +EED SUALLY ASSOCIATED WITH WARDROBE ITEMS.</HEADLINE>
    So wanted to store the value of $_ until it reads some value which exists in an array. So that I may get the result which I wanted
      For getting this result, I would approach it differently. I would define a hash, %tags, which is initially empty. Whenever you encounter a tag, say AUTHOR, with some content, say 'author1', you have have two cases:
      1. If AUTHOR does not exist yet in your hash, create a new entry with AUTHOR as a key, and 'author1' as a value.
      2. If AUTHOR already exists in your hash, just append to the existing string your new value (separated by a space).

      -- 
      Ronald Fischer <ynnor@mm.st>
        %hash = map { $_ => 1 } @metadata_tags; $_ .= exists $hash{$1};
        I have created a hash of tags. I have appended the $_ if tag exists in an array. But still it doesnot concatenate