Questions tagged [perl]

Perl is a procedural, high-level, general-purpose, dynamic programming language, known for its native support of regular expressions and string parsing capabilities. Please use this tag for questions about Perl in general. For things related to the new (but related) language Raku (formerly "Perl 6"), please use the raku tag. For Perl-style regular expressions in other languages, use the regex tag, or, if they are based on the PCRE library, the pcre tag.

Perl is a highly capable, feature-rich programming language with over 25 years of development. Perl runs on over 100 platforms from portables to mainframes and is suitable for both rapid prototyping and large-scale development projects.

Perl can also refer to a family of high-level, general-purpose, interpreted, dynamic programming languages. The languages in this family include Perl and Raku (formerly known as Perl 6). For Raku-related questions, please use the tag . For "Perl-style" regular expressions in other languages, often based on the PCRE library, do not use tag , but tag or a more specific tag such as tag .

Related Resources

Perl-related Blogs and Bloggers

Free Perl Programming Books

Perl Programming Books

Related tags

Date & Time

Libraries for working with dates and times

Devices

Libraries to talk to physical devices

DevOps Tools

Libraries that help when you want to deploy software across networks on several hosts that are working across computer networks

  • Rex - Remote Execution

FAQs

Frequently ask questions

More information

67820 questions
87
votes
1 answer

Why don't I get any syntax errors when I execute my Python script with Perl?

I just wrote some testing python code into test.py, and I'm launching it as follows: perl test.py After a while I realized my mistake. I say "after a while", because the Python code gets actually correctly executed, as if in Python interpreter! Why…
Dacav
  • 13,590
  • 11
  • 60
  • 87
87
votes
6 answers

Multiline search replace with Perl

I know this kind of questions have been asked already many times before. The reason why I come here again is that I feel like I've missed something simple and fundamental. Is it possible to make this kind of search-replace routine better. For…
user44556
  • 5,763
  • 5
  • 30
  • 27
85
votes
6 answers

How do I sleep for a millisecond in Perl?

How do I sleep for shorter than a second in Perl?
ˈoʊ sɪks
  • 897
  • 1
  • 7
  • 10
85
votes
5 answers

How can I use CPAN as a non-root user?

I want to install perl modules on a shared server on which I do not have root access. How can I do this? They also seem to have an older version of CPAN (it complains about that when running the command), is it possible to update the CPAN command…
Juan A. Navarro
  • 10,595
  • 6
  • 48
  • 52
85
votes
9 answers

Is there a Perl shortcut to count the number of matches in a string?

Suppose I have: my $string = "one.two.three.four"; How should I play with context to get the number of times the pattern found a match (3)? Can this be done using a one-liner? I tried this: my ($number) = scalar($string=~/\./gi); I thought that…
Geo
  • 93,257
  • 117
  • 344
  • 520
85
votes
12 answers

"inappropriate ioctl for device"

I have a Perl script running in an AIX box. The script tries to open a file from a certain directory and it fails to read the file because file has no read permission, but I get a different error saying inappropriate ioctl for device. Shouldn't it…
someguy
  • 1,193
  • 1
  • 12
  • 17
84
votes
14 answers

In Perl, how do I create a hash whose keys come from a given array?

Let's say I have an array, and I know I'm going to be doing a lot of "Does the array contain X?" checks. The efficient way to do this is to turn that array into a hash, where the keys are the array's elements, and then you can just say if($hash{X})…
raldi
  • 21,344
  • 33
  • 76
  • 86
84
votes
8 answers

How can I call a shell command in my Perl script?

What would be an example of how I can call a shell command, say 'ls -a' in a Perl script and the way to retrieve the output of the command as well?
Yang
  • 9,794
  • 15
  • 44
  • 52
83
votes
1 answer

The recognizing power of "modern" regexes

What class of languages do real modern regexes actually recognise? Whenever there is an unbounded length capturing group with a back-reference (e.g. (.*)_\1) a regex is now matching a non-regular language. But this, on its own, isn't enough to match…
tobyodavies
  • 27,347
  • 5
  • 42
  • 57
82
votes
4 answers

How do I enable automatic folds in Vim?

How do I enable automatic folding in Vim? set foldmethod=syntax doesn't seem to do much of anything.
Eric Johnson
  • 17,502
  • 10
  • 52
  • 59
82
votes
2 answers

What does the <<'m'=~m>> syntax mean in perl?

So I understand that perl has much unusual syntax, but I came across a code snippet at work that other day that has left me confused. Could someone please explain to me what it means: <<'m'=~m>> print $a unless $b; return; m ; It looks like HEREDOC…
AliceHemp
  • 593
  • 4
  • 7
82
votes
10 answers

Perl: if ( element in list )

I'm looking for presence of an element in a list. In Python there is an in keyword and I would do something like: if element in list: doTask Is there something equivalent in Perl without having to manually iterate through the entire list?
Jonathan
  • 3,464
  • 9
  • 46
  • 54
82
votes
4 answers

String compare in Perl with "eq" vs "=="

I am (a complete Perl newbie) doing string compare in an if statement: If I do following: if ($str1 == "taste" && $str2 == "waste") { } I see the correct result (i.e. if the condition matches, it evaluates the "then" block). But I see these…
hari
  • 9,439
  • 27
  • 76
  • 110
81
votes
9 answers

Command line: search and replace in all filenames matched by grep

I'm trying to search and replace a string in all files matched by grep: grep -n 'foo' * will give me output in the form: [filename]:[line number]:[text] For each file returned by grep, I'd like to modify the file by replacing foo with bar.
Michael Kristofik
  • 34,290
  • 15
  • 75
  • 125
81
votes
8 answers

Programmatically read from STDIN or input file in Perl

What is the slickest way to programatically read from stdin or an input file (if provided) in Perl?
syker
  • 10,912
  • 16
  • 56
  • 68