Skip to main content



Perl KVM - Chad Granum - TPRC 2024 - Lightning Talk submitted by /u/briandfoy
[link] [comments]



This is my first attempt to create a Perl script.

This script is to convert Markdown files to plain text ones, with some "common" typographic substitutions.

When I finish it, it is assumed to work as follows:

  1. Single-hyphen dashes are replaced with three hyphens: that is, foo - bar is replaced with foo---bar
  2. Markdown-style italic is replaced with Org Mode-style italic: that is, foo *bar* baz is replaced with foo /bar/ baz
  3. Blank lines are replaced with first-line indents, that is:
    ``` FROM THIS This is a 500-character line of text.

    This is another 500-character line of text. ```

    TO THIS This is a 500-character line of text. This is another 500- character line of text.

  4. Lines are hard-wrapped at 72 characters, and additionally:
  5. Any single-letter word, such as "a" or "I", if it happened to be at the end of a hard-wrapped line, unless it is the last word in a paragraph, is moved to the next hard-wrapped line, that is:
    FROM THIS He knows that I love bananas.

    TO THIS He knows that I love bananas.

And now the first draft. Please don't laugh too loudly 😀

```

!/usr/bin/perl


perl -pi -e 's/ - /---/g' $1 # foo - bar to foo---bar perl -pi -e 's/*///g' $1 # foo to /foo/ perl -pi -e 's/\n{2}/\n /g' $1 # blank lines to first-line indents ```

The first two lines work fine.

But I really don't understand why the third line doesn't replace blank lines with first-line indents.

Also, maybe someone can point me to an existing Perl or Awk script that does all of this.

submitted by /u/No-Usual-9631
[link] [comments]



submitted by /u/niceperl
[link] [comments]


Per Context Catalyst Component - John Napiorkowski - TPRC 2024 - Lightning Talk submitted by /u/briandfoy
[link] [comments]


While refactoring some code with the usual desire to improve/simplify, I came by this interesting example on S.O. that uses the dispatch table structure:

ref _ https://stackoverflow.com/questions/844616/obtain-a-switch-case-behaviour-in-perl-5


my $switch = { 'case1' => sub { print "case1"; }, 'case2' => sub { print "case2"; }, 'default' => sub { print "unrecognized"; } }; $switch->{$case} ? $switch->{$case}->() : $switch->{'default'}->(); #($switch->{$case} || $switch->{default})->() # ephemient's alternative 

Dispatch tables are powerful and I use them often.

Gabor Szabo offered a post with an example of given/when, but in the end he suggests just using the if/else construct.

given ($num) { when ($_ > 0.7) { say "$_ is larger than 0.7"; } when ($_ > 0.4) { say "$_ is larger than 0.4"; } default { say "$_ is something else"; } } 

ref _ https://perlmaven.com/switch-case-statement-in-perl5

= = =

Which approach do you prefer? Or do you prefer some other solution? Saying no to all the above is a viable response too.

submitted by /u/singe
[link] [comments]



Why? (It is on Linux and with utf-8)
perl -CADS -le 'print $ARGV[0]' -- -v=αβγ -v=αβγ perl -CADS -sle 'print $v' -- -v=αβγ αβγ 

submitted by /u/appomsk
[link] [comments]


submitted by /u/niceperl
[link] [comments]


Are there new modern alternatives to PerlNET? I am using a Perl game automation library whose ui is built with Wx using Perl bindings. I want to create my own UI using C#(WPF) so wanted to kno if there are existing solutions to this?

submitted by /u/vizim
[link] [comments]



The Once and Future Perl - Damian Conway - TPRC 2024 submitted by /u/briandfoy
[link] [comments]