in reply to Simple way to split on last match?
Update: I guess I should say that the parens around ($last) are necessary to put $last into a list context, otherwise you just get 1 or 0 value. Here we want the actual value that was captured rather than whether it the expression "worked" or "not.#!/usr/bin/perl -w use strict; my $line ='last -- From --00--SPLIT ?--11452'; my ($last) = (split(/--/, $line))[-1]; print "using split: $last\n"; ($last) = $line =~ /(\d+)\s*$/; print "using regex: $last\n"; __END__ Prints: using split: 11452 using regex: 11452
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Simple way to split on last match?
by aturtle (Novice) on Aug 05, 2012 at 20:36 UTC | |
by Marshall (Canon) on Aug 08, 2012 at 04:39 UTC |