Paul Paul - 1 year ago 99
Perl Question

perl regex square brackets and single quotes

Have this string:


The data is repeated.

I need to remove the []' characters from the data so it looks like this:


I'm also trying to split the data to assign it to variables as seen below:

my($currency, $strike, $tenor, $tenor2,$ado_symbol) = split /,/, $_;

This works for everything but the ['TEST'] section. Should I remove the []' characters first then keep my split the same or is there an easier way to do this?


Answer Source

Something that's useful to know is this - that split takes a regex. (It'll even let you capture, but that'll insert into the returned list, which is why I've got (?: for non capturing groups)

I observe your data only has [' right next to the delimiter - so how about:

#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dumper;

while ( <DATA> ) {
  my @fields = split /(?:\'])?,(?:\[\')?/; 
  print Dumper \@fields;



$VAR1 = [
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download