in reply to Regex for splitting a string on a semicolon (conditionally)

... use Text::CSV; ... sub breakup { ...

Why aren't you using Text::CSV inside sub breakup {?

Including "use Text::CSV;" isn't some magic spell that will avoid the suggestion that you actually use it

  • Comment on Re: Regex for splitting a string on a semicolon (conditionally) (use Text::CSV;)

Replies are listed 'Best First'.
Re^2: Regex for splitting a string on a semicolon (conditionally) (use Text::CSV;)
by grouse (Initiate) on Feb 12, 2015 at 08:43 UTC
    I'm using it in the larger context of my code to output the data (once broken up into individual references, then into author, year, etc columns) into a .csv file. It has nothing to do with this subroutine--I just copied the beginning of the script verbatum. Sorry for the confusion!
      Ok :) here you go, "Rome: IPGRI" gets seperated from its owner, then its put back
      sub breakup { my $filename = $_[0]; my $text = $_[1]; my @stuff = split /;\s?/, $text; my @parts ; while( @stuff ){ if( $stuff[0] =~ m{ ^ \w+ : \s \w+ $ }xms ){ $parts[-1] .= ";".$stuff[0]; } else { push @parts, $stuff[0]; } shift @stuff; } return \@parts; }