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
143
votes
78 answers

Hidden features of Perl?

What are some really useful but esoteric language features in Perl that you've actually been able to employ to do useful work? Guidelines: Try to limit answers to the Perl core and not CPAN Please give an example and a short description Hidden…
Adam Bellaire
  • 108,003
  • 19
  • 148
  • 163
141
votes
9 answers

How can I pass command-line arguments to a Perl program?

I'm working on a Perl script. How can I pass command line parameters to it? Example: script.pl "string1" "string2"
lamcro
  • 6,069
  • 18
  • 57
  • 70
137
votes
6 answers

Escaping a forward slash in a regular expression

My question is a simple one, and it is about regular expression escaping. Do you have to escape a forward slash / in a regular expression? And how would you go about doing it?
Zerobu
  • 2,561
  • 7
  • 25
  • 32
134
votes
3 answers

Check whether a string contains a substring

How can I check whether a given string contains a certain substring, using Perl? More specifically, I want to see whether s1.domain.example is present in the given string variable.
Belgin Fish
  • 19,187
  • 41
  • 102
  • 131
134
votes
2 answers

How do I enter a multi-line comment in Perl?

Possible Duplicate: What are the common workarounds for multi-line comments in Perl? How do I add a multi-line comment to Perl source code?
vrbilgi
  • 5,703
  • 12
  • 44
  • 60
132
votes
6 answers

How can I output UTF-8 from Perl?

I am trying to write a Perl script using the utf8 pragma, and I'm getting unexpected results. I'm using Mac OS X 10.5 (Leopard), and I'm editing with TextMate. All of my settings for both my editor and operating system are defaulted to writing…
Peter Conrey
131
votes
18 answers

In Perl, how can I read an entire file into a string?

I'm trying to open an .html file as one big long string. This is what I've got: open(FILE, 'index.html') or die "Can't read file 'filename' [$!]\n"; $document = ; close (FILE); print $document; which results in:
goddamnyouryan
  • 6,854
  • 15
  • 56
  • 105
131
votes
4 answers

Perl flags -pe, -pi, -p, -w, -d, -i, -t?

I have seen lots of ways of running Perl code or scripts, with different flags. However, when I try to google for what each flag means, I mainly get results to generic Perl sites and no specific information regarding the flags or their use is found…
Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
125
votes
8 answers

How can I check if a file exists in Perl?

I have a relative path $base_path = "input/myMock.TGZ"; myMock.TGZ is the file name located in input folder. The filename can change. But the path is always stored in $base_path. I need to check if the file exists in $base_path.
superstar
  • 1,832
  • 3
  • 17
  • 26
123
votes
10 answers

How do I tell CPAN to install all dependencies?

How do I tell CPAN to install all dependencies? I tried setting these in cpan: cpan> o conf prerequisites_policy follow cpan> o conf commit I still had to answer "y" a couple of times (but fewer than before it feels like). Is there a way to get it…
Nifle
  • 11,745
  • 10
  • 75
  • 100
123
votes
10 answers

How to match a substring in a string, ignoring case

I'm looking for ignore case string comparison in Python. I tried with: if line.find('mandy') >= 0: but no success for ignore case. I need to find a set of words in a given text file. I am reading the file line by line. The word on a line can be…
Mandar Pande
  • 12,250
  • 16
  • 45
  • 72
122
votes
9 answers

What's the safest way to iterate through the keys of a Perl hash?

If I have a Perl hash with a bunch of (key, value) pairs, what is the preferred method of iterating through all the keys? I have heard that using each may in some way have unintended side effects. So, is that true, and is one of the two following…
Rudd Zwolinski
  • 26,712
  • 17
  • 57
  • 60
122
votes
4 answers

Why are Perl 5's function prototypes bad?

In another Stack Overflow question Leon Timmermans asserted: I would advice you not to use prototypes. They have their uses, but not for most cases and definitely not in this one. Why might this be true (or otherwise)? I almost always supply…
Alnitak
  • 334,560
  • 70
  • 407
  • 495
121
votes
10 answers

Should I choose ActivePerl or Strawberry Perl for Windows?

I'm totally new to Perl, but I'd like to try it out. I read about two rival distributions available for Windows platform (I guess there's just Perl on other OSes :). Wikipedia says that Strawberry Perl comes with additional development tools to…
118
votes
8 answers

How to extract string following a pattern with grep, regex or perl

I have a file that looks something like this:
wrangler
  • 1,995
  • 2
  • 19
  • 22