I have an array that contains string which may contain whitespaces appended to the end. I need to remove those spaces using perl script. my array will look like this
@array = ("shayam "," Ram "," 24.0 ");
I need the output as
@array = ("shayam","Ram","24.0");
I tried with chomp (@array). It is not working with the strings.
#!/usr/local/bin/perl -w use strict; use Data::Dumper; my @array=('a ', 'b', ' c'); my @newarray = grep(s/\s*$//g, @array); print Dumper \@newarray;The key function here is grep(), everything else is just demo gravy.