in reply to How can I print part of a line between two different lines

I can give you some inputs. Also like other monks suggested, please try what you have tried so far and where you are stuck
1. Read the line one by one from input file. You have to read more on +how to read input files in perl. 2. If the line matches word sample_char, then split it based on = and +take the second part. You have to read more on regular expression and + split functions to implement this. 3. Store the second part in an array. 4. Once all the lines are completed, display the output from array

Replies are listed 'Best First'.
Re^2: How can I print part of a line between two different lines
by ramukavuri (Initiate) on Jan 27, 2017 at 12:07 UTC

    #!/usr/bin/perl -w

    open IN, "data";

    while($file=<IN>)

    {

    @line = split(/ \= /,$file);

    if ($line[0] =~ m/^sample$/g)

    {

    @sample = $line[1];

    foreach (@sample)

    {

    print @line; unable to proceed from here

    }

    }

    }

      #!/usr/bin/perl use strict; use warnings; my @finalArray = (); while(<DATA>){ if ($_=~/^sample_char/){ my @line = split(/\=/,$_); #push (@finalArray, $line[1]); push @finalArray, $line[1]; } } print "Final data :: @finalArray"; __DATA__ sample = 123 sample_sub = info sample_char = abc sample_char = abc1 sample_char = abc2 sample_end sample = 124 sample_sub = info sample_char = bbc sample_char = bbc1 sample_char = bbc2 sample_end sample = 125 sample_sub = info sample_char = cbc sample_char = cbc1 sample_char = cbc2 sample_end
      OUTPUT
      Final data :: abc abc1 abc2 bbc bbc1 bbc2 cbc cbc1 cbc2