How to get to run a minimal Clojure app with boot-clj and Emacs?
I installed the Boot application and ran boot -h twice. Then I got this
s#Lux:~$ boot -V
#http://boot-clj.com
#Mon Feb 04 00:23:28 CET 2019
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_CLOJURE_VERSION=1.8.0
BOOT_VERSION=2.8.2
s#Lux:~$
My Emacs is of the version as follows
GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-09-15, modified by Debian
I installed cider, clojure-mode and projectile.
I configured Emacs with a tutorial of this https://github.com/boot-clj/boot/wiki/Cider-REPL#a-better-way
and got a configuration file:
s#Lux:~$ cat ~/.emacs.d/init.el
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)
(custom-set-variables
'(cider-boot-parameters (quote "cider repl -s wait"))
'(package-selected-packages (quote (projectile clojure-mode-extra-font-locking cider))))
s#Lux:~$
Then I typed out this
C-x C-f ~/Dropbox/Clojure/myapp2/src/myapp2/core.clj
and the file opened.
Here you are the file's code:
s#Lux:~$ cat ~/Dropbox/Clojure/myapp2/src/myapp2/core.clj
(ns myapp2.core
(:gen-class))
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!"))
s#Lux:~$
The file is in a project generated by a boot-clj command boot -d boot/new new -t app -n myapp2
Then I typed out this M-x cider-jack-in and got an error:
line: 1
error in process sentinel: Could not start nREPL server: Classpath conflict: org.clojure/clojure version 1.8.0 already loaded, NOT loading version 1.10.0
Classpath conflict: org.clojure/clojure version 1.8.0 already loaded, NOT loading version 1.10.0
Classpath conflict: org.clojure/clojure version 1.8.0 already loaded, NOT loading version 1.10.0
java.lang.Thread.run Thread.java: 748
java.util.concurrent.ThreadPoolExecutor$Worker.run ThreadPoolExecutor.java: 624
java.util.concurrent.ThreadPoolExecutor.runWorker ThreadPoolExecutor.java: 1149
java.util.concurrent.FutureTask.run FutureTask.java: 266
...
clojure.core/binding-conveyor-fn/fn core.clj: 1938
boot.core/boot/fn core.clj: 1032
boot.core/run-tasks core.clj: 1022
boot.task.built-in/fn/fn/fn/fn built_in.clj: 492
clojure.core/deref core.clj: 2228
...
boot.task.built-in/fn/fn/fn built_in.clj: 489
clojure.core/apply core.clj: 646
...
boot.core/launch-nrepl core.clj: 1313
boot.repl/launch-nrepl repl.clj: 60
boot.repl-server/start-server repl_server.clj: 68
boot.repl-server/->mw-list repl_server.clj: 59
...
clojure.core/mapcat core.clj: 2674 (repeats 2 times)
clojure.core/apply core.clj: 646
...
clojure.core/map/fn core.clj: 2644
boot.repl-server/->mw-list repl_server.clj: 55
boot.repl-server/->var repl_server.clj: 49
...
clojure.core/require core.clj: 5796 (repeats 2 times)
clojure.core/apply core.clj: 648
...
clojure.core/load-libs core.clj: 5758
clojure.core/load-libs core.clj: 5774
clojure.core/apply core.clj: 648
...
clojure.core/load-lib core.clj: 5717
clojure.core/load-lib core.clj: 5736
clojure.core/load-lib/fn core.clj: 5737
clojure.core/load-one core.clj: 5697
...
clojure.core/load core.clj: 5876
clojure.core/load core.clj: 5892
clojure.core/load/fn core.clj: 5893
...
refactor-nrepl.middleware/eval2021 middleware.clj: 1
refactor-nrepl.middleware/eval2021/loading--auto-- middleware.clj: 1
...
clojure.core/require core.clj: 5796 (repeats 2 times)
clojure.core/apply core.clj: 648
...
clojure.core/load-libs core.clj: 5758
clojure.core/load-libs core.clj: 5774
clojure.core/apply core.clj: 648
...
clojure.core/load-lib core.clj: 5717
clojure.core/load-lib core.clj: 5736
clojure.core/load-lib/fn core.clj: 5737
clojure.core/load-one core.clj: 5697
...
clojure.core/load core.clj: 5876
clojure.core/load core.clj: 5892
clojure.core/load/fn core.clj: 5893
...
refactor-nrepl.ns.resolve-missing/eval14613 resolve_missing.clj: 1
refactor-nrepl.ns.resolve-missing/eval14613/loading--auto-- resolve_missing.clj: 1
...
clojure.core/require core.clj: 5796 (repeats 2 times)
clojure.core/apply core.clj: 648
...
clojure.core/load-libs core.clj: 5758
clojure.core/load-libs core.clj: 5774
clojure.core/apply core.clj: 648
...
clojure.core/load-lib core.clj: 5717
clojure.core/load-lib core.clj: 5755
clojure.core/apply core.clj: 648
...
clojure.core/refer core.clj: 4087
clojure.core/refer core.clj: 4119
java.lang.IllegalAccessError: info-clj does not exist
clojure.lang.ExceptionInfo: info-clj does not exist
line: 1
But when I removed the
'(cider-boot-parameters (quote "cider repl -s wait"))
line from the configuration, restarted Emacs, run cider-jack-in, cider started successfully. So I could run Clojure commands such as (range 5) etc.
But when I tried to run the application and put out (-main) it crashed and an info that an error took place and the main symbol could not be resolved:
user> (-main)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: -main in this context, compiling:(*cider-repl Clojure/myapp2:localhost:45545(clj)*:43:7)
user>
Show: Project-Only All
Hide: Clojure Java REPL Tooling Duplicates (24 frames hidden)
2. Unhandled clojure.lang.Compiler$CompilerException
Error compiling *cider-repl Clojure/myapp2:localhost:45545(clj)* at (43:7)
Compiler.java: 6688 clojure.lang.Compiler/analyze
Compiler.java: 6625 clojure.lang.Compiler/analyze
Compiler.java: 3766 clojure.lang.Compiler$InvokeExpr/parse
Compiler.java: 6870 clojure.lang.Compiler/analyzeSeq
Compiler.java: 6669 clojure.lang.Compiler/analyze
Compiler.java: 6625 clojure.lang.Compiler/analyze
Compiler.java: 6001 clojure.lang.Compiler$BodyExpr$Parser/parse
Compiler.java: 5380 clojure.lang.Compiler$FnMethod/parse
Compiler.java: 3972 clojure.lang.Compiler$FnExpr/parse
Compiler.java: 6866 clojure.lang.Compiler/analyzeSeq
Compiler.java: 6669 clojure.lang.Compiler/analyze
Compiler.java: 6924 clojure.lang.Compiler/eval
Compiler.java: 6890 clojure.lang.Compiler/eval
core.clj: 3105 clojure.core/eval
core.clj: 3101 clojure.core/eval
main.clj: 240 clojure.main/repl/read-eval-print/fn
main.clj: 240 clojure.main/repl/read-eval-print
main.clj: 258 clojure.main/repl/fn
main.clj: 258 clojure.main/repl
main.clj: 174 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 83 nrepl.middleware.interruptible-eval/evaluate/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 646 clojure.core/apply
core.clj: 1881 clojure.core/with-bindings*
core.clj: 1881 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 81 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 50 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 221 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
interruptible_eval.clj: 189 nrepl.middleware.interruptible-eval/run-next/fn
AFn.java: 22 clojure.lang.AFn/run
ThreadPoolExecutor.java: 1149 java.util.concurrent.ThreadPoolExecutor/runWorker
ThreadPoolExecutor.java: 624 java.util.concurrent.ThreadPoolExecutor$Worker/run
Thread.java: 748 java.lang.Thread/run
1. Caused by java.lang.RuntimeException
Unable to resolve symbol: -main in this context
Util.java: 221 clojure.lang.Util/runtimeException
Compiler.java: 7164 clojure.lang.Compiler/resolveIn
Compiler.java: 7108 clojure.lang.Compiler/resolve
Compiler.java: 7069 clojure.lang.Compiler/analyzeSymbol
Compiler.java: 6648 clojure.lang.Compiler/analyze
Compiler.java: 6625 clojure.lang.Compiler/analyze
Compiler.java: 3766 clojure.lang.Compiler$InvokeExpr/parse
Compiler.java: 6870 clojure.lang.Compiler/analyzeSeq
Compiler.java: 6669 clojure.lang.Compiler/analyze
Compiler.java: 6625 clojure.lang.Compiler/analyze
Compiler.java: 6001 clojure.lang.Compiler$BodyExpr$Parser/parse
Compiler.java: 5380 clojure.lang.Compiler$FnMethod/parse
Compiler.java: 3972 clojure.lang.Compiler$FnExpr/parse
Compiler.java: 6866 clojure.lang.Compiler/analyzeSeq
Compiler.java: 6669 clojure.lang.Compiler/analyze
Compiler.java: 6924 clojure.lang.Compiler/eval
Compiler.java: 6890 clojure.lang.Compiler/eval
core.clj: 3105 clojure.core/eval
core.clj: 3101 clojure.core/eval
main.clj: 240 clojure.main/repl/read-eval-print/fn
main.clj: 240 clojure.main/repl/read-eval-print
main.clj: 258 clojure.main/repl/fn
main.clj: 258 clojure.main/repl
main.clj: 174 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 83 nrepl.middleware.interruptible-eval/evaluate/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 646 clojure.core/apply
core.clj: 1881 clojure.core/with-bindings*
core.clj: 1881 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 81 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 50 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 221 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
interruptible_eval.clj: 189 nrepl.middleware.interruptible-eval/run-next/fn
AFn.java: 22 clojure.lang.AFn/run
ThreadPoolExecutor.java: 1149 java.util.concurrent.ThreadPoolExecutor/runWorker
ThreadPoolExecutor.java: 624 java.util.concurrent.ThreadPoolExecutor$Worker/run
Thread.java: 748 java.lang.Thread/ Show: Project-Only All
So it looks like cider cannot find the -main function. Perhaps I should type cider-jack-in command in another place? But where? And the cider-boot-parameters issue is also strange. How to run any Clojure application with boot-clj and emacs-25. (The problem occurred also at emacs26 and emacs27).
I reinstalled Debian, installed boot and emacs25.
Then created a configuration file:
s#Windown:~/Dropbox/Clojure/myapp2$ cat ~/.emacs.d/init.el
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/") t)
(package-initialize)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(cider-boot-parameters (quote "repl -s wait"))
'(package-selected-packages
(quote
(clojure-mode projectile clojure-mode-extra-font-locking cider))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
s#Windown:~/Dropbox/Clojure/myapp2$
Then installed cider, clojure-mode and projectile. Then it worked.
Version Info
s#Windown:~/Downloads2$ boot -V
#http://boot-clj.com
#Mon Feb 04 13:34:49 CET 2019
BOOT_CLOJURE_NAME=org.clojure/clojure
BOOT_CLOJURE_VERSION=1.8.0
BOOT_VERSION=2.8.2
s#Windown:~/Downloads2$
This is GNU Emacs 25.1.1 (x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
of 2017-09-15, modified by Debian
Emacs Package Library
projectile 20190126.1117 installed Manage and navigate projects in Emacs easily
clojure-mode 20190105.1043 installed Major mode for Clojure code
cider 20190125.1339 installed Clojure Interactive Development Environment that Rocks
Related
I am trying to create a simple script that imports old records to a new PostgreSQL database using the same Schema as the old one.
My initial idea was to read the contents of the .csv and create a map data structure. After that, insert it to the newly created database, using something like Honey SQL. Hopefully that makes sense.
I might be doing something wrong, or I probably am overthinking something here.
Let's say I have a script with the following functions:
(defn csv-data->map
"Takes the data from the csv file and
and stores it in a map structure."
[csv-data]
(map zipmap
(->> (first csv-data)
(map keyword)
repeat)
(rest csv-data)))
;; the map structure
(def big-map (with-open [reader (io/reader "my-file.csv")]
(doall
(csv-data->map (csv/read-csv reader)))))
So, I want to get the information stored in this map structure and import it in a PostgreSQL database.
Is there a way I can do that?
Also, here are the dependencies I am using, which are mostly from the official documentation for each lib.
(:require [clojure.data.csv :as csv]
[clojure.java.io :as io]
[next.jdbc :as jdbc]
[honey.sql :as sql]
[honey.sql.helpers :refer [select select-distinct from
join left-join right-join
where for group-by having union
order-by limit offset values columns
update insert-into set composite
delete delete-from truncate] :as h]
[clojure.core :as c])
It'll be great to see your critique and proposals!
My honey code is fairly simple:
(-> (h/insert-into :account)
(h/values [big-map])
(sql/format {:pretty true}))
The error message I get when trying to evaluate in the REPL is this
Unhandled clojure.lang.ExceptionInfo
These SQL clauses are unknown or have nil values: :ID,
:BILLINGLONGITUDE... etc
and under it, I get the real objects like so:
{:ID "000123456000000",
:BILLINGLONGITUDE "",... etc
Adding a little update on the problem:
So I am connected to the PG database and I can perform a simple query to get some count from a table account, but I get the following problem:
Unhandled org.postgresql.util.PSQLException ERROR: relation "account" does not exist Position: 13
QueryExecutorImpl.java: 2477 org.postgresql.core.v3.QueryExecutorImpl/receiveErrorResponse
QueryExecutorImpl.java: 2190 org.postgresql.core.v3.QueryExecutorImpl/processResults
QueryExecutorImpl.java: 300 org.postgresql.core.v3.QueryExecutorImpl/execute
PgStatement.java: 428 org.postgresql.jdbc.PgStatement/executeInternal
PgStatement.java: 354 org.postgresql.jdbc.PgStatement/execute PgPreparedStatement.java:
169 org.postgresql.jdbc.PgPreparedStatement/executeWithFlags
PgPreparedStatement.java: 158
org.postgresql.jdbc.PgPreparedStatement/execute
result_set.clj: 669 next.jdbc.result-set/stmt->result-set
result_set.clj: 664 next.jdbc.result-set/stmt->result-set
result_set.clj: 944 next.jdbc.result-set/eval9989/fn
protocols.clj: 34 next.jdbc.protocols/eval9066/fn/G
result_set.clj: 1023 next.jdbc.result-set/eval10028/fn
protocols.clj: 34 next.jdbc.protocols/eval9066/fn/G
jdbc.clj: 250 next.jdbc/execute!
jdbc.clj: 237 next.jdbc/execute!
REPL: 43 csv-lein.core/eval11779
REPL: 43 csv-lein.core/eval11779
Compiler.java: 7194 clojure.lang.Compiler/eval
Compiler.java: 7149 clojure.lang.Compiler/eval
core.clj: 3215 clojure.core/eval
core.clj: 3211 clojure.core/eval
interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 667 clojure.core/apply
core.clj: 1990 clojure.core/with-bindings*
core.clj: 1990 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 87 nrepl.middleware.interruptible-eval/evaluate/fn
main.clj: 437 clojure.main/repl/read-eval-print/fn
main.clj: 437 clojure.main/repl/read-eval-print
main.clj: 458 clojure.main/repl/fn
main.clj: 458 clojure.main/repl
main.clj: 368 clojure.main/repl
RestFn.java: 1523 clojure.lang.RestFn/invoke
interruptible_eval.clj: 84 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 56 nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 152 nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
AFn.java: 22 clojure.lang.AFn/run
session.clj: 218 nrepl.middleware.session/session-exec/main-loop/fn
session.clj: 217 nrepl.middleware.session/session-exec/main-loop
AFn.java: 22 clojure.lang.AFn/run
Thread.java: 833 java.lang.Thread/run
I'm using imaplib, and trying to fetch emails with a certain subject header value.
My code:
res, tmp = self.mail.uid('search', None, 'HEADER Subject "SUBJECT_HERE"')
print(tmp)
print(res)
print("test 2 goes:")
rr, tt = self.mail.search(None, 'HEADER Subject "SUBJECT_HERE"')
print(tt)
print(rr)
Result:
[b'225 232 323 324 346 366 382 419 420 425 450 463 517 607 670 751 833
911 1043 1129 1133 1134 1287 1350 1799 1854 1957 1960 1962 1991 2005
2040 2071 2110 2119 2121 2153 2158 2182 2188 2189 2228 2230 2239 2249
2334 2335 2372 2378 2396 2435 2497 2567 2568 2573 2574 2575 2632 2633
2634 2648 2649 2709 2785 2819 2821 2828 2829 2868 2885 2895 2902 2906
2920 2993 2997 2998 3000 3001 3009'] OK test 2 goes:
[b'220 227 318 319 340 360 376 413 414 419 444 457 511 601 664 745 827
905 1037 1123 1127 1128 1281 1344 1793 1848 1951 1954 1956 1985 1999
2034 2065 2104 2113 2115 2147 2152 2176 2182 2183 2222 2224 2233 2243
2328 2329 2366 2372 2390 2429 2491 2561 2562 2567 2568 2569 2625 2626
2627 2641 2642 2702 2778 2812 2814 2821 2822 2861 2878 2888 2895 2899
2913 2986 2990 2991 2993 2994 3002'] OK
I thought that those two commands result in the same results.
But as shown above, those two fetch different emails.
What is the difference??
One (SEARCH) returns message sequence numbers (MSN), which are numbered from 1 to N and change as messages are added and deleted. A message that is number 5 now could be number 4 tomorrow if you delete a message before it.
The other (UID SEARCH) returns UIDs, which do not change as messages are deleted. They're two completely different set of identifiers. A message with UID 5 will remain UID 5 until it is deleted it (or moved, etc.).
The UID will never reused in that incarnation of a folder. If the folder is deleted and recreated, or the mail server is rebuilt, the folder's UIDVALIDITY should change so you can detect that your cache is no longer valid.
I have more than one image open, and I'd like to run scrip-fu functions on the currently selected image. How can I get the image reference number to the currently selected image so I can use the reference in other functions (e.g. (gimp-image-width 7))? I'm using GIMP 2.10.12.
Using (gimp-image-list) lists all the image references:
> (gimp-image-list)
(12 #(12 11 10 9 8 7 6 5 4 3 2 1))
I've been using (gimp-image-latest) for this, which should work for the general case
(define (gimp-image-list-items)
(cadr (gimp-image-list)))
(define (gimp-image-latest)
(aref (gimp-image-list-items) 0))
(define img (gimp-image-latest))
Then it's in img. E.g.:
> (gimp-image-get-layers img)
(283 #(770 769 768 767 766 765 764 763 762 761 760 759 758 757 756 755 754 753 752 751 750 749 748 747 746 745 744 743 742 741 740 739 738 737 736 735 734 733 732 731 730 729 728 727 726 725 724 723 722 721 720 719 718 717 716 715 714 713 712 711 710 709 708 707 706 705 704 703 702 701 700 699 698 697 696 695 694 693 692 691 690 689 688 687 686 685 684 683 682 681 680 679 678 677 676 675 674 673 672 671 670 669 668 667 666 665 664 663 662 661 660 659 658 657 656 655 654 653 652 651 650 649 648 647 646 645 644 643 642 641 640 639 638 637 636 635 634 633 632 631 630 629 628 627 626 625 624 623 622 621 620 619 618 617 616 615 614 613 612 611 610 609 608 607 606 605 604 603 602 601 600 599 598 597 596 595 594 593 592 591 590 589 588 587 586 585 584 583 582 581 580 579 578 577 576 575 574 573 572 571 570 569 568 567 566 565 564 563 562 561 560 559 558 557 556 555 554 553 552 551 550 549 548 547 546 545 544 543 542 541 540 539 538 537 536 535 534 533 532 531 530 529 528 527 526 525 524 523 522 521 520 519 518 517 516 515 514 513 512 511 510 509 508 507 506 505 504 503 502 501 500 499 498 497 496 495 494 493 492 491 490 489 488))
I have a huge 1.1 GB File. It contains only 1 line and 1167889705 characters. I want to replace all the occurences of "LFENT" by "\nLFENT".
I am using
perl 5, version 18, subversion 1 (v5.18.1) built for x86_64-linux –
Perl Script
perl -ne 's/LFENT/\nLFENT/g; print;' queries.txt
Sample
22 serialization::archive 10 0 0 0 0 134477 0 0 0 9 LFENT_1_1 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 12 barack obama 0 0 1 0 12 barack obama 0 0 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9 LFENT_1_2 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 5 obama 2 0 12 barack obama 5 obama 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9 LFENT_1_3 6 LFDOC1 20 documents/LFDOC1.xml 4 MISC 8 american 1 0 8 american 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236
Problem
The script will work on the sample that I posted. But when I try it on the whole line I get the following error:
Substitution loop at -e line 1, <> line 1.
It is simplest to use LFENT as the record separator. That reduces the blocks to a more manageable size and ensures that there is no more than one LFENT to be replaced in each block
Command-line perl allows for setting the record separator with the -0 modifier, but the value of the parameter must be the code point in octal of a single character, and you can't specify a string. So here you have to set it once in a BEGIN block
Like this
perl -p -e'BEGIN{$/="LFENT"} s/LFENT/\nLFENT/'
output
22 serialization::archive 10 0 0 0 0 134477 0 0 0 9
LFENT_1_1 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 12 barack obama 0 0 1 0 12 barack obama 0 0 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9
LFENT_1_2 6 LFDOC1 20 documents/LFDOC1.xml 6 PERSON 5 obama 2 0 12 barack obama 5 obama 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236 0.12948024 20390 0.12416928 20795 0.11188922 23777 0.13165452 23887 0.10065161 27644 0.1620737 73361 0.16295943 75521 0.17926371 9
LFENT_1_3 6 LFDOC1 20 documents/LFDOC1.xml 4 MISC 8 american 1 0 8 american 6 LFDOC1 0 76 127 0.11599133 151 0.11042373 331 0.057491675 389 0.05621225 396 0.065223008 398 0.12416559 421 0.10331947 502 0.055213902 641 0.08908961 642 0.084330745 690 0.11456303 699 0.16876614 720 0.080576144 791 0.077269703 792 0.077503696 849 0.08224529 854 0.074629158 1028 0.11078026 1039 0.091981322 1300 0.070129424 1359 0.06072164 1390 0.05564769 1424 0.076605573 1461 0.15357952 1467 0.083702087 1583 0.069745384 1960 0.088143557 2118 0.064093992 2192 0.054430917 2304 0.089718938 2417 0.10173298 2436 0.069064997 2683 0.12296619 2700 0.068218805 2715 0.14005794 2786 0.084942013 3016 0.08474879 3113 0.083180025 3183 0.07413847 3202 0.081254445 3351 0.21241546 3587 0.061469007 3711 0.068944298 3949 0.10349752 5284 0.087500088 5775 0.092185706 5816 0.20625457 6320 0.11784423 6435 0.076852165 6794 0.094336778 6805 0.063363358 6946 0.11133534 7277 0.074097082 7588 0.12458359 7590 0.099151991 7629 0.28773388 7790 0.1194713 8137 0.11009126 8214 0.10754209 8889 0.12056628 9326 0.13841057 9701 0.25610805 9863 0.11877144 9908 0.11499001 10500 0.12205271 11917 0.11144774 12750 0.11285295 13453 0.13751692 19236[Finished in 0.2s]
By the way, it is unlikely to cause a problem but LFENT is always preceded by a space character in your example data. You may want to remove it by using s/\s*LFENT/\nLFENT for your substitution
And a look-ahead might be more appropriate too s/\s*(?=LFENT)/\n/ so that you don't have to remove and replace the unchanged part of the match
Try updating your perl to a more current version.
This was a known bug for a long time (fixed in v5.22.0): perl #123071: substitution loop issue with long strings
You can do so with the following commands (assuming you are on linux):
wget http://www.cpan.org/src/5.0/perl-5.22.1.tar.gz
tar -xzf perl-5.22.1.tar.gz
cd perl-5.22.1
./Configure -des -Dprefix=$HOME/localperl
make
make test
make install
Then test it by running $HOME/localperl/bin/perl -v and add it to your PATH using this: export PATH=$HOME/localperl/bin/:$PATH.
I am using clojure in Emacs with cider and the cider repl (0.7.0). This is pretty fine, but whenever I run cider-referesh (or hit C-c C-x), I get an exception:
ClassNotFoundException clojure.tools.namespace.repl java.net.URLClassLoader$1.run (URLClassLoader.java:372)
1. Unhandled java.lang.ClassNotFoundException
clojure.tools.namespace.repl
URLClassLoader.java: 372 java.net.URLClassLoader$1/run
URLClassLoader.java: 361 java.net.URLClassLoader$1/run
AccessController.java: -2 java.security.AccessController/doPrivileged
URLClassLoader.java: 360 java.net.URLClassLoader/findClass
DynamicClassLoader.java: 61 clojure.lang.DynamicClassLoader/findClass
ClassLoader.java: 424 java.lang.ClassLoader/loadClass
ClassLoader.java: 357 java.lang.ClassLoader/loadClass
Class.java: -2 java.lang.Class/forName0
Class.java: 340 java.lang.Class/forName
RT.java: 2065 clojure.lang.RT/classForName
Compiler.java: 978 clojure.lang.Compiler$HostExpr/maybeClass
Compiler.java: 756 clojure.lang.Compiler$HostExpr/access$400
Compiler.java: 6583 clojure.lang.Compiler/macroexpand1
Compiler.java: 6613 clojure.lang.Compiler/macroexpand
Compiler.java: 6687 clojure.lang.Compiler/eval
Compiler.java: 6666 clojure.lang.Compiler/eval
core.clj: 2927 clojure.core/eval
main.clj: 239 clojure.main/repl/read-eval-print/fn
main.clj: 239 clojure.main/repl/read-eval-print
main.clj: 257 clojure.main/repl/fn
main.clj: 257 clojure.main/repl
RestFn.java: 1096 clojure.lang.RestFn/invoke
interruptible_eval.clj: 56 clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
AFn.java: 152 clojure.lang.AFn/applyToHelper
AFn.java: 144 clojure.lang.AFn/applyTo
core.clj: 624 clojure.core/apply
core.clj: 1862 clojure.core/with-bindings*
RestFn.java: 425 clojure.lang.RestFn/invoke
interruptible_eval.clj: 41 clojure.tools.nrepl.middleware.interruptible-eval/evaluate
interruptible_eval.clj: 171 clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
core.clj: 2402 clojure.core/comp/fn
interruptible_eval.clj: 138 clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
AFn.java: 22 clojure.lang.AFn/run
ThreadPoolExecutor.java: 1142 java.util.concurrent.ThreadPoolExecutor/runWorker
ThreadPoolExecutor.java: 617 java.util.concurrent.ThreadPoolExecutor$Worker/run
Thread.java: 745 java.lang.Thread/run
What is the reason for this, and how can I fix it?
It seems that this exception was a bug, that has now been fixed in cider.
Try adding [org.clojure/tools.namespace "0.2.5"] to your project.clj