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
214
votes
3 answers

How is Perl's @INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?)

What are all the ways of affecting where Perl modules are searched for? or, How is Perl's @INC constructed? As we know, Perl uses @INC array containing directory names to determine where to search for Perl module files. There does not seem to be a…
DVK
  • 126,886
  • 32
  • 213
  • 327
209
votes
8 answers

How do I perform a Perl substitution on a string while keeping the original?

In Perl, what is a good way to perform a replacement on a string using a regular expression and store the value in a different variable, without changing the original? I usually just copy the string to a new variable then bind it to the s/// regex…
kaybenleroll
  • 16,794
  • 16
  • 54
  • 66
205
votes
7 answers

How do I compare two strings in Perl?

How do I compare two strings in Perl? I am learning Perl, I had this basic question looked it up here on StackOverflow and found no good answer so I thought I would ask.
PJT
  • 3,439
  • 5
  • 29
  • 40
204
votes
12 answers

What is the difference between 'my' and 'our' in Perl?

I know what my is in Perl. It defines a variable that exists only in the scope of the block in which it is defined. What does our do? How does our differ from my?
Nathan Fellman
  • 122,701
  • 101
  • 260
  • 319
194
votes
14 answers

How do you round a floating point number in Perl?

How can I round a decimal number (floating point) to the nearest integer? e.g. 1.2 = 1 1.7 = 2
Ranguard
  • 2,756
  • 3
  • 20
  • 15
189
votes
11 answers

How can I print the contents of a hash in Perl?

I keep printing my hash as # of buckets / # allocated. How do I print the contents of my hash? Without using a while loop would be most preferable (for example, a one-liner would be best).
Kys
  • 2,597
  • 5
  • 20
  • 16
184
votes
23 answers

How do I get the full path to a Perl script that is executing?

I have Perl script and need to determine the full path and filename of the script during execution. I discovered that depending on how you call the script $0 varies and sometimes contains the fullpath+filename and sometimes just filename. Because…
Chris Madden
  • 2,510
  • 2
  • 17
  • 11
181
votes
23 answers

How can I delete a newline if it is the last character in a file?

I have some files that I'd like to delete the last newline if it is the last character in a file. od -c shows me that the command I run does write the file with a trailing new line: 0013600 n t > \n I've tried a few tricks with sed but the…
Todd Partridge 'Gen2ly'
  • 2,258
  • 2
  • 19
  • 18
172
votes
20 answers

while (1) Vs. for (;;) Is there a speed difference?

Long version... A co-worker asserted today after seeing my use of while (1) in a Perl script that for (;;) is faster. I argued that they should be the same hoping that the interpreter would optimize out any differences. I set up a script that would…
Copas
  • 5,921
  • 5
  • 29
  • 43
172
votes
11 answers

How do I remove duplicate items from an array in Perl?

I have an array in Perl: my @my_array = ("one","two","three","two","three"); How do I remove the duplicates from the array?
David
  • 14,047
  • 24
  • 80
  • 101
163
votes
8 answers

Best way to give a variable a default value (simulate Perl ||, ||= )

I love doing this sort of thing in Perl: $foo = $bar || $baz to assign $baz to $foo if $bar is empty or undefined. You also have $foo ||= $bletch which will only assign $bletch to $foo if $foo is not defined or empty. The ternary operator in this…
Tom Auger
  • 19,421
  • 22
  • 81
  • 104
155
votes
6 answers

How to match any non white space character except a particular one?

In Perl \S matches any non-whitespace character. How can I match any non-whitespace character except a backslash \?
Lazer
  • 90,700
  • 113
  • 281
  • 364
154
votes
9 answers

What exactly does Perl's "bless" do?

I understand one uses the "bless" keyword in Perl inside a class's "new" method: sub new { my $self = bless { }; return $self; } But what exactly is "bless" doing to that hash reference ?
user47145
  • 1,775
  • 2
  • 13
  • 8
148
votes
5 answers

How do I update all my CPAN modules to their latest versions?

How do I update all my CPAN modules to their latest versions?
David B
  • 29,258
  • 50
  • 133
  • 186
145
votes
13 answers

grep -P no longer works. How can I rewrite my searches?

It looks like the new version of OS X no longer supports grep -P and as such has made some of my scripts stop working, for example: var1=`grep -o -P '(?<=).*(?=)' file.txt` I need to capture grep's result to a variable and I…
kugyousha
  • 2,472
  • 3
  • 21
  • 22