# Julia can process text similar to Perl

**URL:** <https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201>\
**Category:** New to Julia\
**Tags:** question, strings\
**Created:** [March 19, 2020, 5:10pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201 "2020-03-19T17:10:31Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marks](https://avatars.discourse-cdn.com/v4/letter/m/ce73a5/32.png) [@Marks](https://discourse.julialang.org/u/Marks)\
**Post date:** [March 19, 2020, 5:10pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/1 "2020-03-19T17:10:31Z")

</div>

Does Julia have the same word processing functions as Perl?

---

<div class="post-metadata">

**Author:** ![js135005](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/js135005/32/8219_2.png) [@js135005](https://discourse.julialang.org/u/js135005)\
**Post date:** [March 19, 2020, 5:23pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/2 "2020-03-19T17:23:15Z")

</div>

I’m not sure what you are looking for.

I converted a major log parser from Perl to Julia. The Julia version is running 10 times as fast as was the Perl one. Some of that speedup was from algorithm changes but much was from the inherent efficiency of the Julia compiler.

Julia has very good support for regexes…

---

<div class="post-metadata">

**Author:** ![tkluck](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkluck/32/15769_2.png) [@tkluck](https://discourse.julialang.org/u/tkluck)\
**Post date:** [March 19, 2020, 7:02pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/3 "2020-03-19T19:02:21Z")

</div>

@js135005 that’s very interesting experience! Nice to see Julia shine there.

No doubt the Julia compiler is a big advantage. Perl does have the advantage of in-place string operations, as strings are mutable in Perl and immutable in Julia. Did you notice the effects of that on you algorithms?

Another very nice thing that perl has are the command line options `-i`, `-n` and `-p` which make it very nice to just edit files line-by-line without writing the boilerplate loops. @Marks if that’s what you are looking for, I think Julia doesn’t have it.

I just spent a few days moving [`StatProfilerHTML`](https://github.com/tkluck/StatProfilerHTML.jl) from Perl to Julia. It has far, far fewer lines of code now 🙂 but I haven’t done any performance benchmarking.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 20, 2020, 6:36am UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/4 "2020-03-20T06:36:07Z")

</div>

> [@Marks](#):
>
> same word processing functions as Perl?

It is unclear what you mean here, please explain. Julia has the standard string handling functionality most languages have, including regular expressions. You may want to read

[https://docs.julialang.org/en/v1/manual/strings/](https://docs.julialang.org/en/v1/manual/strings/)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 20, 2020, 1:21pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/5 "2020-03-20T13:21:48Z")

</div>

I used to do a lot of Perl programming, including lots of text processing, and yes, you can do everything in Julia that you can do in Perl.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [March 20, 2020, 2:19pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/6 "2020-03-20T14:19:37Z")

</div>

> [@tkluck](#):
>
> Another very nice thing that perl has are the command line options `-i` , `-n` and `-p` which make it very nice to just edit files line-by-line without writing the boilerplate loops. @Marks if that’s what you are looking for, I think Julia doesn’t have it.

This is the only reason why I still write some Perl these days:

```julia
perl -pn -i.bak -e "SOME ONE-LINER;" INPUT_FILE

```

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 20, 2020, 2:34pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/7 "2020-03-20T14:34:32Z")

</div>

I suspect the same could be accomplished in Julia by a combination of:

- a command line flags for loading certain modules
- macros that do those one-liners

But of course, Perl’s startup time is unbeatable (0.01s). Julia’s is not bad by itself (0.07s), but if you’re loading a package as well then it gets slower. So I still write one-liners in Perl.

---

<div class="post-metadata">

**Author:** ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)\
**Post date:** [March 20, 2020, 3:59pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/8 "2020-03-20T15:59:38Z")

</div>

Practical Extraction and Reporting Language of course. It’s Camels for Courses.

I will fetch my own coat.  
(To explain the joke, the English expression is horses for courses. The Oreilly Perl book had a camel on the front page.)

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [March 20, 2020, 4:34pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/9 "2020-03-20T16:34:12Z")

</div>

I can’t get Julia 1.3.1 to startup faster than 0.13 seconds (`-O0` and `--compile=no`). Are there improvements in that dimension in 1.4/1.5?

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [March 20, 2020, 6:06pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/10 "2020-03-20T18:06:23Z")

</div>

Don’t forget `-startup=no`. I did at first. I’m assuming you didn’t though, because 0.13s is pretty good.

```nohighlight
> time -p julia -E 'VERSION'
v"1.5.0-DEV.463"
real 0.29
user 0.23
sys 0.05
> time -p julia --startup=no -E 'VERSION'
v"1.5.0-DEV.463"
real 0.13
user 0.07
sys 0.04
> time -p julia --startup=no --compile=min -E 'VERSION'
v"1.5.0-DEV.463"
real 0.10
user 0.03
sys 0.04

```

Not quite 0.07s. Repeating it a total of 6 times, I hit 0.08s twice.  
If the computer were faster, it could’ve hit 0.07s.  
This desktop has 4.6 GHz sse speed, so not too many computers should be faster. Many laptops will be twice as slow or more.

---

<div class="post-metadata">

**Author:** ![non-Jedi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/non-jedi/32/3645_2.png) [@non-Jedi](https://discourse.julialang.org/u/non-Jedi)\
**Post date:** [March 20, 2020, 6:14pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/11 "2020-03-20T18:14:44Z")

</div>

Fwiw, I edited my post. I had accidentally typed `-O3` when I meant `-O0` which makes a small but measurable difference.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [March 20, 2020, 6:20pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/12 "2020-03-20T18:20:07Z")

</div>

Ah. I just wrote a loop to run it 10 times, adding `-O0` to the above. The first one returned 0.10s. Out of the remaining nine, 3/9 were 0.07s and 6/9 were 0.08s.

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [March 20, 2020, 6:44pm UTC](https://discourse.julialang.org/t/julia-can-process-text-similar-to-perl/36201/13 "2020-03-20T18:44:43Z")

</div>

Sorry, I was reading the wrong number in zsh’s time output:

```julia
bash-3.2$ time julia -e0

real	0m0.158s
user	0m0.086s
sys	0m0.079s

```
