perl - Obtaining lines from an array and stopping at a particular character -


i'm looking assistance on script can go through lines of array, printing them screen , stopping when script detects specific character, in case ! mark. have tried using foreach statement ain't getting success...

example of array (@lines) contents is:

ip vrf test rd 2856:10000331 export map setaltmgmtrt route-target export 2856:10000331 route-target import 2856:10000331 maximum routes 1000 75 ! 

the script have far is:

elsif ( $action eq "show_vrf" ) {             $cmd = "show run | begin <vrf_name>";             $cmd = $cmd . " | $include" if($include) ;             @lines = $s->cmd(string => $cmd,                             prompt  => "/$enableprompt/",                             timeout => 10);             foreach $lines (@lines) {                     <statement, stuck>             }             print $lines; 

any appreciated :)

what criteria stopping? exclamation mark or 1 on own line? or line beginning exclamation mark?

you've got several things called lines need sort out.

my $output; foreach $line (@lines) {     last if $line =~ m/^!/; # leave loop if line starts exclamation mark     $output .= $line; } print $output; 

for additional requirements in comment below (the data has more 1 exclamation mark) you'd need this:

use data::dumper; @output; # assign output chunks array $i = 0; foreach $line (@lines) {     if ($line =~ m/^!/) {         $i++;         next;     }     $output[$i] .= $line; } print dumper(\@output); 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -