[ABE.pm] mapping with an enclosure
Ted Fiedler
fiedlert at gmail.com
Fri Apr 4 02:44:59 PDT 2008
Couldnt you do something like
for (@data)
{
$_ =~ s/\s+/g;
}
or
my @newdata;
for (@data)
{
s/\s+/g;
push @newdata, $_;
}
I haven't tested, but both should work.
How was the tech meeting on Wednesday? $Work is usurping all my time :(
Ted
On Thu, Apr 3, 2008 at 8:39 PM, Faber J. Fedor <faber at linuxnj.com> wrote:
>
> I'm reading in a CSV file line by line. I need to trim leading and
> trailing whitespace out of each comma-delimited field. So I figured I'd
> use map an enclosure like so:
>
> my @data = split(/,/, $_);
>
> map { $_ => s/^\s+//;
> $_ => s/\s+$//;
> } @data;
>
> ($sku,$warehouse,$quantity,$row,$product_type,$stack_location,$price)
> = @data ;
>
>
> Two things I don't understand:
>
> 1) why is map editing my array in place? It's supposed to return an
> array. The array it does return has extra empty data elements in
> between each original element.
>
> 2. Why do I get a "Useless use of a variable in void context at
> at_test.pl line 19." (line 19 being the line map is on)?
>
> Is there a better way of stripping the data?
>
>
>
> --
>
> Regards,
>
> Faber Fedor
> President
> Linux New Jersey, Inc.
> 908-320-0357
> 800-706-0701
>
> http://www.linuxnj.com
>
>
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
> _______________________________________________
> ABE-pm mailing list
> ABE-pm at pm.org
> http://mail.pm.org/mailman/listinfo/abe-pm
>
--
When I do good, I feel good; when I do bad, I feel bad, and that is my
religion.
- Abraham Lincoln
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/abe-pm/attachments/20080404/25aff2ee/attachment.html
More information about the ABE-pm
mailing list