Transposing CSV data in Perl

后端 未结 2 694
臣服心动
臣服心动 2020-12-21 06:42

I am a Perl beginner and currently working on a Perl script to automate some of our tasks. One script that I\'m working on involves extracting performance data from our syst

2条回答
  •  臣服心动
    2020-12-21 07:16

    You made one simple, but critical mistake.

    split [ /,/ ] 
    

    should be

    [ split /,/ ]
    

    The syntax for split is

    split /PATTERN/, EXPR, LIMIT
    

    Where the latter two are optional. What you are doing is passing an anonymous array ref as PATTERN, which most likely gets stringified into something like ARRAY(0x54d658). The result is that the line is not split, and the whole line is pushed onto the array. Later on, that will cause the dereference of $row to fail with the error

    Can't use string ("29-Aug-2013,3.68,3.63,3.75,3.65,"...) as an ARRAY ref while "
    strict refs" in use at foo.pl line 18,  line 7.
    

提交回复
热议问题