in reply to Perl:Use of array elements in pattern matching

I am able to code the things for 1 and 2 but not not able to achieve my Point 3 If my @myarr = (ELEM-3,ITEM-1,ITEM-2,ITEM3)

Why not? Can you show what you have so far?

  • Comment on Re: Perl:Use of array elements in pattern matching

Replies are listed 'Best First'.
Re^2: Perl:Use of array elements in pattern matching
by rahulme81 (Sexton) on Aug 29, 2016 at 05:05 UTC

    Below is snippet what I have tried so far

    # this is called in foreach loop and stores returns the file in array for elem and item.

     my $ref_to_elem_entries = myfunction($itend_file);

    # This is the pattern which I look for in elem.txt if @myarr = "ELEM-3"

    my @intend_elem = (win,won,wion,wiin,woon,wiioon); foreach my $itend_elem (@intend_elem) { if ($ask =~ /^SA/ && (@myarr ==1 && $myarr[0] eq 'ELEM-3')) {push @m_ref_to_elem_entries, grep(/^reg\b/,@$ref_to_elem_entries) } else {@m_ref_to_elem_entries = @$ref_to_elem_entries} }

    With above piece of code If condition gives me only lines for ELEM-3 and lines which has pattern stored in @intend_elem.

    Else condition gives me all lines for Item & Elem files.

    So far - if @myarr contains only ELEM-3 I have my result else I have results for all.

      Hi,

      Does this give you any ideas? Questions?

      itemElemIt( '...items.txt', '...elem.txt', \@myarr ); sub itemElemenIt { my( $itemfile, $elemfile, $myarr ) = @_; for my $lookFor ( @$myarr ){ ... lookIn( $itemfile, $lookFor ); } } sub lookIn { my( $file, $keyword ) = @_; my @ret; while(<$fh>){ push @ret, $_ if /\Q$keyword\E/; } return @ret; }