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
114
votes
12 answers

Regular expression to validate username

I'm trying to create a regular expression to validate usernames against these criteria: Only contains alphanumeric characters, underscore and dot. Underscore and dot can't be at the end or start of a username (e.g _username / username_ / .username…
mohsen dorparasti
  • 8,107
  • 7
  • 41
  • 61
113
votes
7 answers

What is the proper way to check if a string is empty in Perl?

I have been using this code to check if a string is empty: if ($str == "") { // ... } And also the opposite with the not equals operator... if ($str != "") { // ... } This seems to work (I think), but I'm not sure it's the correct way, or if…
Nick Bolton
  • 38,276
  • 70
  • 174
  • 242
111
votes
8 answers

Why use strict and warnings?

It seems to me that many of the questions in the Perl tag could be solved if people would use: use strict; use warnings; I think some people consider these to be akin to training wheels, or unnecessary complications, which is clearly not true,…
TLP
  • 66,756
  • 10
  • 92
  • 149
111
votes
4 answers

How are nested capturing groups numbered in regular expressions?

Is there a defined behavior for how regular expressions should handle the capturing behavior of nested parentheses? More specifically, can you reasonably expect that different engines will capture the outer parentheses in the first position, and…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
111
votes
6 answers

Best way to iterate through a Perl array

Which is the best implementation(in terms of speed and memory usage) for iterating through a Perl array? Is there any better way? (@Array need not be retained). Implementation 1 foreach (@Array) { SubRoutine($_); } Implementation…
Jean
  • 21,665
  • 24
  • 69
  • 119
108
votes
9 answers

How can I remove text within parentheses with a regex?

I'm trying to handle a bunch of files, and I need to alter then to remove extraneous information in the filenames; notably, I'm trying to remove text inside parentheses. For example: filename = "Example_file_(extra_descriptor).ext" and I want to…
Technical Bard
  • 4,395
  • 7
  • 31
  • 32
108
votes
9 answers

What is the meaning of @_ in Perl?

What is the meaning of @_ in Perl?
Andrei
  • 1,862
  • 4
  • 15
  • 15
108
votes
27 answers

How do I get a list of installed CPAN modules?

Aside from trying perldoc individually for any CPAN module that takes my fancy or going through the file system and looking at the directories, I have no idea what modules we have installed. What's the easiest way to just get a big…
David McLaughlin
  • 5,108
  • 4
  • 34
  • 35
107
votes
9 answers

How can Perl's print add a newline by default?

In Perl most of my print statements take the form print "hello." . "\n"; Is there a nice way to avoid keeping all the pesky "\n"s lying around? I know I could make a new function such as myprint that automatically appends \n, but it would be nice…
Mike
  • 58,961
  • 76
  • 175
  • 221
106
votes
6 answers

Using output from a previous job in a new one in a GitHub Action

For (mainly) pedagogical reasons, I'm trying to run this workflow in GitHub actions: name: "We Perl" on: issues: types: [opened, edited, milestoned] jobs: seasonal_greetings: runs-on: windows-latest steps: - name: Maybe…
jjmerelo
  • 22,578
  • 8
  • 40
  • 86
106
votes
11 answers

Easy way to print Perl array? (with a little formatting)

Is there an easy way to print out a Perl array with commas in between each element? Writing a for loop to do it is pretty easy but not quite elegant....if that makes sense.
funk-shun
  • 4,331
  • 11
  • 32
  • 41
106
votes
4 answers

How can I combine hashes in Perl?

What is the best way to combine both hashes into %hash1? I always know that %hash2 and %hash1 always have unique keys. I would also prefer a single line of code if possible. $hash1{'1'} = 'red'; $hash1{'2'} = 'blue'; $hash2{'3'} =…
mleykamp
  • 1,356
  • 2
  • 9
  • 11
106
votes
6 answers

Differences between Perl and PHP

I'm planning to learn Perl 5 and as I have only used PHP until now, I wanted to know a bit about how the languages differ from each other. As PHP started out as a set of "Perl hacks" it has obviously cloned some of Perls features. What are the main…
lok
  • 1,077
  • 2
  • 8
  • 3
105
votes
8 answers

How can I troubleshoot my Perl CGI script?

I have a Perl CGI script that isn't working and I don't know how to start narrowing down the problem. What can I do? Note: I'm adding the question because I really want to add my very lengthy answer to Stack Overflow. I keep externally linking to…
brian d foy
  • 129,424
  • 31
  • 207
  • 592
103
votes
11 answers

Which version of Perl should I use on Windows?

The win32.perl.org web site provides references to several Perl distributions for MS Windows. For a long time I have been using ActivePerl from ActiveState but recently I switched to Strawberry Perl. IMHO The only advantage that Active Perl still…
szabgab
  • 6,202
  • 11
  • 50
  • 64