in reply to store rest of the lines in a array after a matching pattern is found
You don't specifically ask a question, but since you say "rest of the line", I'm guessing your problem is that you're printing too much after "my string".
I'd suggest changing your regular expression to:
if ( $str =~ m/^ServiceCategoryName=(.*)/) {
which will, if the expression matches, put the rest of the line (i.e., the stuff after the '=') into the $1 capture buffer. From there you could extract the stuff you're interested in, like so:
if ( $str =~ m/^ServiceCategoryName=(.*)/) { print $str; # Extract the array from "the rest of the line" my @array = split /,/, $1; print "my string ", $array[0], "\n"; }
Notes:
- You're not providing a format string, so I changed printf to print.
- You should use cut & paste to put your actual code, rather than retyping it. That'll help you avoid typos, like the missing comma in your split statement.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: store rest of the lines in a array after a matching pattern is found
by Anonymous Monk on May 17, 2018 at 17:35 UTC | |
by roboticus (Chancellor) on May 17, 2018 at 17:41 UTC | |
by AnomalousMonk (Archbishop) on May 17, 2018 at 19:07 UTC |
In Section
Seekers of Perl Wisdom