[ABE.pm] mapping with an enclosure

Faber J. Fedor faber at linuxnj.com
Thu Apr 3 17:39:26 PDT 2008


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.



More information about the ABE-pm mailing list