Like this?
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11149097 use warnings; my $line = '11/21/2022,Payment,"Transfer to Smith, account 2",,USD,,123.60,'; print " $line\n"; my ( $fDate, $fType, $fDetails, $fRef, $fCurrency, $fAmount, $fPaidOut, $fFees ) = "$line," =~ /(".*?"|[^,]*),/g; # NOTE # = split( /,/, $line ); printf("\n Date: %s; Type: %s; \n" ." Details: %s\n Reference: %s\n" ." Currency: %s; Amount: %s; PaidOut: %s; Fees: %s;\n", $fDate, $fType, $fDetails, $fRef, $fCurrency, $fAmount, $fPaidOut, $fFees );
Outputs:
11/21/2022,Payment,"Transfer to Smith, account 2",,USD,,123.60, Date: 11/21/2022; Type: Payment; Details: "Transfer to Smith, account 2" Reference: Currency: USD; Amount: ; PaidOut: 123.60; Fees: ;
In reply to Re: Splitting a string on commas except when inside quotes
by tybalt89
in thread Splitting a string on commas except when inside quotes
by anadem
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |