Hi,
I have file: data.log.1
### s1
main.build.3495
main.build.199
main.build.3408
###s2
main.build.3495
main.build.3408
main.build.199
I want to read this file and store in two arrays in Perl.
I have following command, which is working fine on command prompt.
perl -n -e '/^###/ and open FH, ">output_".$n++; print FH;' data.log.1
But I want to use this command in Perl file, so that I can store output ###s1 (part) and ###s2 (part) in two different arrays.
Any help will be appreciated.
Thanks
Here's one way to do it in Perl:
$
$ cat data.log.1
###s1
main.build.3495
main.build.199
main.build.3408
###s2
main.build.3495
main.build.3408
main.build.199
$
$ ##
$ perl -ne 'chomp;
> if (/^###s1/) {$s1=true} elsif(/^###s2/) {$s2=true}
> if ($s2) {push @s2,$_} elsif($_ ne "" && $s1) {push @s1,$_}
> END {print "Array \@s1:\n";foreach $i (@s1) {print $i,"\n"}
> print "Array \@s2:\n";foreach $i (@s2) {print $i,"\n"}}' data.log.1
Array @s1:
###s1
main.build.3495
main.build.199
main.build.3408
Array @s2:
###s2
main.build.3495
main.build.3408
main.build.199
$
tyler_durden