Skip to main content
added 1 character in body
Source Link
jubilatious1
  • 3.4k
  • 9
  • 18

Perl:

~$ perl -pe ''  Sonnet_18.txt

Raku:

~$ raku -pe ''  Sonnet_18.txt

Sample Output:

Shall I compare thee to a summer’s day?
Thou art more lovely and more temperate.
Rough winds do shake the darling buds of May,
And summer’s lease hath all too short a date.
Sometime too hot the eye of heaven shines,
And often is his gold complexion dimmed;
And every fair from fair sometime declines,
By chance or nature’s changing course untrimmed.
But thy eternal summer shall not fade
Nor lose possession of that fair thou ow’st,
Nor shall Death brag thou wand’rest in his shade,
When in eternal lines to time thou grow’st.
 So long as men can breathe or eyes can see,
 So long lives this, and this gives life to thee.

Clearly, cat is going to be the most popular answer to this question, but the code examples above will also provide the desired output (file courtesy of Shakespeare, via Project Gutenberg). However learning basic one-liners using Perl and/or Raku has its merits, simply because you can get an awful lot of work done with them.

Grep through a file, return matching lines:

~$ #Perl:
~$ perl -ne 'print if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

~$ #Raku:
~$ raku -ne '.put  if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

Substitute one bit of text with another, redirect output to a new file:

~$ #Perl:
~$ perl -pe 's/eternal/forevermore/g'   Sonnet_18.txt > new_sonnet.txt

~$ #Raku:
~$ raku -pe 's:g/eternal/forevermore/'  Sonnet_18.txt > new_sonnet.txt

https://perldoc.perl.org
https://docs.raku.org

Perl:

~$ perl -pe ''  Sonnet_18.txt

Raku:

~$ raku -pe ''  Sonnet_18.txt

Sample Output:

Shall I compare thee to a summer’s day?
Thou art more lovely and more temperate.
Rough winds do shake the darling buds of May,
And summer’s lease hath all too short a date.
Sometime too hot the eye of heaven shines,
And often is his gold complexion dimmed;
And every fair from fair sometime declines,
By chance or nature’s changing course untrimmed.
But thy eternal summer shall not fade
Nor lose possession of that fair thou ow’st,
Nor shall Death brag thou wand’rest in his shade,
When in eternal lines to time thou grow’st.
 So long as men can breathe or eyes can see,
 So long lives this, and this gives life to thee.

Clearly, cat is going to be the most popular answer to this question, but the code examples above will also provide the desired output (file courtesy of Shakespeare, via Project Gutenberg). However learning basic one-liners using Perl and/or Raku has its merits, simply because you can get an awful lot of work done with them.

Grep through a file, return matching lines:

~$ #Perl:
~$ perl -ne 'print if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

~$ #Raku:
~$ raku -ne '.put  if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

Substitute one bit of text with another, redirect output to a new file:

~$ #Perl:
~$ perl -pe 's/eternal/forevermore/g'  Sonnet_18.txt > new_sonnet.txt

~$ #Raku:
~$ raku -pe 's:g/eternal/forevermore/'  Sonnet_18.txt > new_sonnet.txt

https://perldoc.perl.org
https://docs.raku.org

Perl:

~$ perl -pe ''  Sonnet_18.txt

Raku:

~$ raku -pe ''  Sonnet_18.txt

Sample Output:

Shall I compare thee to a summer’s day?
Thou art more lovely and more temperate.
Rough winds do shake the darling buds of May,
And summer’s lease hath all too short a date.
Sometime too hot the eye of heaven shines,
And often is his gold complexion dimmed;
And every fair from fair sometime declines,
By chance or nature’s changing course untrimmed.
But thy eternal summer shall not fade
Nor lose possession of that fair thou ow’st,
Nor shall Death brag thou wand’rest in his shade,
When in eternal lines to time thou grow’st.
 So long as men can breathe or eyes can see,
 So long lives this, and this gives life to thee.

Clearly, cat is going to be the most popular answer to this question, but the code examples above will also provide the desired output (file courtesy of Shakespeare, via Project Gutenberg). However learning basic one-liners using Perl and/or Raku has its merits, simply because you can get an awful lot of work done with them.

Grep through a file, return matching lines:

~$ #Perl:
~$ perl -ne 'print if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

~$ #Raku:
~$ raku -ne '.put  if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

Substitute one bit of text with another, redirect output to a new file:

~$ #Perl:
~$ perl -pe 's/eternal/forevermore/g'   Sonnet_18.txt > new_sonnet.txt

~$ #Raku:
~$ raku -pe 's:g/eternal/forevermore/'  Sonnet_18.txt > new_sonnet.txt

https://perldoc.perl.org
https://docs.raku.org

Source Link
jubilatious1
  • 3.4k
  • 9
  • 18

Perl:

~$ perl -pe ''  Sonnet_18.txt

Raku:

~$ raku -pe ''  Sonnet_18.txt

Sample Output:

Shall I compare thee to a summer’s day?
Thou art more lovely and more temperate.
Rough winds do shake the darling buds of May,
And summer’s lease hath all too short a date.
Sometime too hot the eye of heaven shines,
And often is his gold complexion dimmed;
And every fair from fair sometime declines,
By chance or nature’s changing course untrimmed.
But thy eternal summer shall not fade
Nor lose possession of that fair thou ow’st,
Nor shall Death brag thou wand’rest in his shade,
When in eternal lines to time thou grow’st.
 So long as men can breathe or eyes can see,
 So long lives this, and this gives life to thee.

Clearly, cat is going to be the most popular answer to this question, but the code examples above will also provide the desired output (file courtesy of Shakespeare, via Project Gutenberg). However learning basic one-liners using Perl and/or Raku has its merits, simply because you can get an awful lot of work done with them.

Grep through a file, return matching lines:

~$ #Perl:
~$ perl -ne 'print if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

~$ #Raku:
~$ raku -ne '.put  if /eternal/'  Sonnet_18.txt
But thy eternal summer shall not fade
When in eternal lines to time thou grow’st.

Substitute one bit of text with another, redirect output to a new file:

~$ #Perl:
~$ perl -pe 's/eternal/forevermore/g'  Sonnet_18.txt > new_sonnet.txt

~$ #Raku:
~$ raku -pe 's:g/eternal/forevermore/'  Sonnet_18.txt > new_sonnet.txt

https://perldoc.perl.org
https://docs.raku.org