Closed Tux closed 8 years ago
Current status / TODO:
2016-05-03 21:57 GMT+02:00 H.Merijn Brand notifications@github.com:
- All invocations like ::error "foo"; need parens:
$ node perlito5.js -I src5/lib -I /pro/lib/perl5/site_perl/5.22.0 ../Text-CSV6/csv-test-pp.pl Can't call method Perlito5::Compiler::error on unblessed reference at ../Text-CSV6/csv-test-pp.pl line 143
to start:
vi +18 Perlito5/Grammar/Attribute.pm vi +273 Perlito5/Grammar/Sigil.pm vi +123 Perlito5/Grammar/Scope.pm vi +3205 Perlito5/Java/Emitter.pm
- All modules need a true value at the end
Perlito5/Macro.pm needs a 1; on line 407
The script I started to test with is
!/usr/bin/perl
use strict; use warnings;
use Text::CSV_PP;
my @rows; my $csv = Text::CSV_PP->new ({ binary => 1, auto_diag => 1 } ) or die "Cannot use CSV: ", Text::CSV->error_diag ();
my $sum = 0; while (my $row = $csv->getline (*ARGV)) { $sum += scalar @$row; } print "$sum\n";
where the input is a valid CSV file
Alternatively this is smaller PP code:
!/usr/bin/perl
use strict; use warnings;
use Text::CSV::Easy_PP qw(csv_parse);
my $sum = 0; while (my $line = <>) { my @row = csv_parse ($line); $sum += @row; } print "$sum\n";
— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/fglock/Perlito/issues/43
I think there is something wrong with Text::CSV::Easy_PP, a zero at the end of line gives an error:
$ cat > csv2.pl
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV::Easy_PP qw(csv_parse);
my $sum = 0;
while (my $line = <>) {
my @row = csv_parse ($line);
$sum += @row;
}
print "$sum\n";
Run:
$ perl csv2.pl
1,2,3
1,2,0
invalid line: 1,2,0
at csv2.pl line 10.
Yes, that is plain wrong. That is not my module, so I filed a ticket
Regex and readline are working now; Exporter is not yet implemented.
Testing with a tweaked version to avoid Exporter: https://gist.github.com/fglock/0c91002af68a7ba074886edc196eea20
Performance needs to improve (tested with a 2MB csv file):
Perl-to-Java:
$ perl perlito5.pl -I src5/lib -Cjava mtest.pl > Main.java ; javac Main.java
$ time java Main csv.txt
508033
real 0m4.345s
user 0m8.917s
sys 0m0.604s
Perl:
$ time perl mtest.pl csv.txt
508033
real 0m2.344s
user 0m2.313s
sys 0m0.010s
This works now (at commit 9f0ed678b60cd9bcc1828e56):
file "csv1.pl":
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV::Easy_PP;
my $sum = 0;
while (my $line = <>) {
my @row = Text::CSV::Easy_PP::csv_parse ($line);
$sum += @row;
}
print "$sum\n";
file "text.csv":
1,"a",123,"567"
"x",text,2,4
env:
$ echo $PERL5LIB
/usr/local/lib/perl5/site_perl/5.20.1
$ perldoc -l Text::CSV::Easy_PP
/usr/local/lib/perl5/site_perl/5.20.1/Text/CSV/Easy_PP.pm
compile:
perl perlito5.pl -I src5/lib -Cjava csv1.pl > Main.java
javac Main.java
run:
$ java Main text.csv
8
Perlito-git 503 > perl perlito5.pl -I src5/lib -Cjava ../Text-CSV6/csv-easy-pp.pl >Main.java
Perlito-git 504 > javac Main.java
Perlito-git 505 > java Main /tmp/hello.csv
Exception in thread "main" PlDieException: Can't use an undefined value as a subroutine reference
at PlCORE.die(Main.java:554)
at PlCORE.die(Main.java:565)
at PlUndef.apply(Main.java:5211)
at PlLvalue.apply(Main.java:3664)
at Main.main(Main.java:6456)
which means that the
use Blah qw( foo );
syntax still is unsupported.
If I remove the import list and use the fully qualified name as your example does, the test passes. I'll include the results on my speed compare page.
And I am missing something else too :/
Perlito-git 527 > zip -9 csv-pi-easy-pp.jar Main.class
adding: Main.class (deflated 51%)
Perlito-git 528 > time java -cp csv-pi-easy-pp.jar Main /tmp/hello.csv
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: PlReturnException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: PlReturnException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
0.046u 0.009s 0:00.05 80.0% 0+0k 0+72io 0pf+0w
Perlito-git 529 > time java -cp csv-pi-easy-pp.jar:. Main /tmp/hello.csv
50000
1.345u 0.044s 0:00.41 336.5% 0+0k 0+72io 0pf+0w
http://tux.nl/Talks/CSV6/speed5.html - neat! 0.400
to start:
Perlito5/Macro.pm needs a 1; on line 407
The script I started to test with is
where the input is a valid CSV file
Alternatively this is smaller PP code: