I am currently trying to add speech marks onto the start and end of a line which I have an edited from a CSV file and is currently stored in an array; I am currently trying to use push and unshift.
use warnings;
use Text::CSV;
use Data::Dumper;
use constant debug => 0;
use Text::CSV;
print "Running CSV editor......\n";
#my $csv = Text::CSV->new({ sep_char => ',' });
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n";
my $fileextension = substr($file, -4);
#If the file is a CSV file then read in the file.
if ($fileextension =~ m/csv/i)
{
print "Reading and formating: $ARGV[0] \n";
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
my @fields;
while (my $line = <$data>)
{
#Clears the white space at the end of the line.
chomp $line;
#Splits the line up and removes the <br />.
my @lines = split qr{<br\s?/>}, $line;
#Removes the control character.
shift (@lines);
print "\n";
print $_,$/ for @lines;
push (@lines, "\"");
unshift (@lines, "\"");
When I try and use the final two lines it doesn’t add anything onto the start and end.
How do you know that the quotes aren’t getting added to the array? Your syntax is correct, so they are definitely working. Try something like this.
and see what that prints, I bet the quotes will be there 🙂