in reply to regex assistance

You realize @array has only one element, the long single-quoted string?

Perhaps this:

use strict; my @array=('GAP_SPAN09 - GAP SPAN base (Scratch Testing [TSMC11] : tsm +c11 +_wld(sxfatd12j)) GAP_SPAN03 - GAP SPAN base (DFD E2E Testing [TSPAN04 +] : tspan04-dfdint-wld(sxfamd6f)) POS_WLI02 - POS_WLI02 Web Logic Int +egrator'); my @newarray = $array[0] =~ /(\S+) - /g; print "$_\n" for @newarray;

Replies are listed 'Best First'.
Re^2: regex assistance
by Anonymous Monk on Oct 20, 2010 at 13:01 UTC
    Apologies the example given should have looked like this
    my @array=('GAP_SPAN09 - GAP SPAN base (Scratch Testing [TSMC11] : tsm +c11_wld(sxfatd12j))','GAP_SPAN03 - GAP SPAN base (DFD E2E Testing [TS +PAN04] : tspan04-dfdint-wld(sxfamd6f))','POS_WLI02 - POS_WLI02 Web Lo +gic Int +egrator');
    So there are 3 elements. This was purely an example though since there could be upto 20 elements in the original array
      Ahh, the question becomes clearer though the logic is largely similar

      use strict; use warnings; my @records=('GAP_SPAN09 - GAP SPAN base (Scratch Testing [TSMC11] : t +smc11_wld(sxfatd12j))', 'GAP_SPAN03 - GAP SPAN base (DFD E2E Testing [TSPAN04] : tspan04-d +fdint-wld(sxfamd6f))', 'POS_WLI02 - POS_WLI02 Web Logic Integrator)'); my @record_ids; for my $record (@records){ $record=~m/^(\S+)(?= - )/g; push @record_ids , $1; } for my $record_id (@record_ids){ print "$record_id\n"; } __END__ GAP_SPAN09 GAP_SPAN03 POS_WLI02
      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
      my @newarray = map /^(\S+) +- /, @array;