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

%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

Replies are listed 'Best First'.
Re^7: Read the lines until a string exists in the array
by chromatic (Archbishop) on Aug 14, 2009 at 18:46 UTC
    $_ .= 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.

      {AUTHOR} author1 staff1 {HEADLINE} DISPOSABLE DECOR: THE CUTTING EDGE DULLS FAST\ STYLE AT A SPEED USUALLY ASSOCIATED WITH WARDROBE ITEMS.
      Can you please tell me how to concatenate lines between two variables. Here, {AUTHOR} and {HEADLINE} merge lines in to a single line before any start of another'{tagname}'.

        To catenate to variables $v and $w, you write something like

        my $catenated=$v.$w
        In your case, you more likely want to append a variable (for example, a new author which you find on a new line), to an existing variable (for example, the variable containing the authors you already have encountered so far). In this case, you use the .= operator:
        my $string_of_authors .= $next_author;
        One note on the side: May I ask you whether you have had already done any programming in whatever language before starting this project? Definitely no offense intended, but I get the impression that your primary problem is not so much related to Perl, but to programming as such, and if this is the case, you should say so; because in that case, we should approach the problem in general, by first discussing what algorithm to use in order to solve the problem (exressing the algorithm in high-level pseudo-code), and only THEN go ahead and translate it to Perl...

        -- 
        Ronald Fischer <ynnor@mm.st>