Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Data::Table showing error

by kevbot (Vicar)
on Oct 27, 2015 at 06:45 UTC ( [id://1146066]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Data::Table showing error
in thread Data::Table showing error

The default separator for the fromCSV command is a comma, i.e. comma-separated values. Your file appears to contain pipe-separated values, so you need to define the delimiter. The Data::Table documentation for the fromCSV command states,
if the delimiter or the qualifier is a special symbol in regular expre +ssion, you must escape it by '\'. For example, in order to use pipe s +ymbol as the delimiter, you must specify the delimiter as '\|'.
Try this with your file,
my $t = Data::Table::fromCSV("ravi.csv", 0, undef, { delimiter => '\|' + });

Replies are listed 'Best First'.
Re^4: Data::Table showing error
by ravi45722 (Pilgrim) on Oct 27, 2015 at 06:51 UTC
    #!/usr/bin/perl use strict; use warnings; use Data::Table; my $t = Data::Table::fromCSV("/root/prac/Telenor_CDR/SMSCDR_POSTPAID_1 +51013000000_10.84.0.29_AS.log", 0, undef, { delimiter => '\|'}); my $t2 = $t->group(["col1","col9"]); print $t2->csv;

    Errors

     Can't use string ("94") as an ARRAY ref while "strict refs" in use at /root/perl5/lib/perl5/Data/Table.pm line 1308, <$SRC> line 1.
      I think you may have stumbled upon a bug in Data::Table. It does not appear to be handling the trailing blank columns properly. If I use your example data, I get the same error as you.
      Tue Oct 13 00:10:00 2015|33594|959796245242|08211019|Tue Oct 13 00:10: +00 2015|Tue Oct 13 00:10:00 2015|CMT|Undelivered|none|Submit|0|SMSC_P +R_LC_SMSC_InvalidDestAddress|GSM|INVALID|ASCII|92|92|no||no|no||None| +No|NO|no|no|0|0|0|0||959790000028||8|0||0|no|no|default_billing|-1|0| +no|no|1|1|1|1|0|1|0|0|||||Tue Oct 13 06:10:00 2015|SR|||IV|0118096144 +46716000046|||0|0||0|0||0||||08211019||||||||||||||||||
      However, if I add a value to the end of the line (to give a non-empty column), then it works. For example, if I add aaa as the last column,
      Tue Oct 13 00:10:00 2015|33594|959796245242|08211019|Tue Oct 13 00:10: +00 2015|Tue Oct 13 00:10:00 2015|CMT|Undelivered|none|Submit|0|SMSC_P +R_LC_SMSC_InvalidDestAddress|GSM|INVALID|ASCII|92|92|no||no|no||None| +No|NO|no|no|0|0|0|0||959790000028||8|0||0|no|no|default_billing|-1|0| +no|no|1|1|1|1|0|1|0|0|||||Tue Oct 13 06:10:00 2015|SR|||IV|0118096144 +46716000046|||0|0||0|0||0||||08211019||||||||||||||||||aaa
      then the code runs without errors. I will try to take a closer look at this, and perhaps submit a bug report if I can't find a work around.

        Thanks. Is "Text::CSV" works like an alternative for me???

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1146066]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-23 21:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found