in reply to Parse string and extract word after specific pattern
Not that fancy, but straightforward.
#!/usr/bin/perl -w use strict; my $string = "stash_ST1.2.3.4_1.ROLLBACK.check.20170228-101051.435944. +txt"; my $action = ''; my @parts = split(/\./, $string); # split on dot for (0..$#parts){ # slot after ROLLBACK $action = $parts[$_+1] if $parts[$_] eq "ROLLBACK"; } print "$action\n";
I'm sure this can be golfed down a bit.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parse string and extract word after specific pattern
by RonW (Parson) on Mar 24, 2017 at 18:55 UTC | |
by choroba (Cardinal) on Mar 25, 2017 at 09:56 UTC | |
by RonW (Parson) on Mar 27, 2017 at 17:27 UTC | |
by choroba (Cardinal) on Mar 28, 2017 at 07:58 UTC |