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

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

Replies are listed 'Best First'.
Re^5: Read the lines until a string exists in the array
by rovf (Priest) on Aug 14, 2009 at 09:47 UTC
    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
        $_ .= exists $hash{$1};

        This catenates whatever exists $hash{$1} evaluates to to $_. That is, it catenates the stringified version of the boolean which exists returns.