< 1 2   Sort: Rank

What does `$result = f() .. g()' really return?
What does `$result = f() .. g()' really return? False so long as f() returns false, after which it returns true until g() returns true, and then starts the cycle again. This is scalar not list context, so we have the bistable flip-flop range operator famous in parsing of mail messages, as in `$in_bo...
2013-09-06, 1876👍, 0💬

Why is it hard to call this function: sub y { "because" }
Why is it hard to call this function: sub y { "because" } Because y is a kind of quoting operator. The y/// operator is the sed-savvy synonym for tr///. That means y(3) would be like tr(), which would be looking for a second string, as in tr/a-z/A-Z/, tr(a-z)(A-Z), or tr[a-z][A-Z].
2013-09-05, 1757👍, 0💬

How to read from a pipeline with Perl
How to read from a pipeline with Perl Example 1: To run the date command from a Perl program, and read the output of the command, all you need are a few lines of code like this: open(DATE, "date|"); $theDate = &lt;DATE&gt;; close(DATE); The open() function runs the external date command, the...
2013-09-05, 1840👍, 0💬

How do I send e-mail from a Perl/CGI program on a Unix system?
How do I send e-mail from a Perl/CGI program on a Unix system? Sending e-mail from a Perl/CGI program on a Unix computer system is usually pretty simple. Most Perl programs directly invoke the Unix sendmail program. We'll go through a quick example here. Assuming that you've already have e-mail info...
2013-09-04, 1815👍, 0💬

How do you print out the next line from a filehandle with all its bytes reversed?
How do you print out the next line from a filehandle with all its bytes reversed? print scalar reverse scalar &lt;FH&gt; Surprisingly enough, you have to put both the reverse and the &lt;FH&gt; into scalar context separately for this to work.
2013-09-04, 1956👍, 0💬

How do I sort a hash by the hash key?
How do I sort a hash by the hash key? Suppose we have a class of five students. Their names are kim, al, rocky, chrisy, and jane. Here's a test program that prints the contents of the grades hash, sorted by student name: #!/usr/bin/perl -w %grades = ( kim => 96, al => 63, rocky => 87, chrisy => 96, ...
2013-09-03, 1812👍, 0💬

How do I do &lt; fill-in-the-blank &gt; for each element in a hash?
How do I do &lt; fill-in-the-blank &gt; for each element in a hash? Here's a simple technique to process each element in a hash: #!/usr/bin/perl -w %days = ( 'Sun' =>'Sunday', 'Mon' => 'Monday', 'Tue' => 'Tuesday', 'Wed' => 'Wednesday', 'Thu' => 'Thursday', 'Fri' => 'Friday', 'Sat' => 'Satur...
2013-09-03, 1839👍, 0💬

What does Perl do if you try to exploit the execve(2) race involving setuid scripts?
What does Perl do if you try to exploit the execve(2) race involving setuid scripts? Sends mail to root and exits. It has been said that all programs advance to the point of being able to automatically read mail. While not quite at that point (well, without having a module loaded), Perl does at leas...
2013-09-02, 1846👍, 0💬

Why aren't Perl's patterns regular expressions?
Why aren't Perl's patterns regular expressions? Because Perl patterns have backreferences. A regular expression by definition must be able to determine the next state in the finite automaton without requiring any extra memory to keep around previous state. A pattern /([ab]+)c\1/ requires the state m...
2013-09-02, 1787👍, 0💬

What is the output of the following Perl program?
What is the output of the following Perl program? 1 $p1 = "prog1.java"; 2 $p1 =~ s/(.*)\.java/$1.cpp/; 3 print "$p1\n"; prog1.cpp
2013-08-30, 1835👍, 0💬

I want users send data by formmail but when they send nothing or call it from web site they will see error ....
I want users send data by formmail but when they send nothing or call it from web site they will see error. codes in PHP like this: if (isset($HTTP_POST_VARS)){ .......... } else{ echo ("error lalalalal") } How it will look in perl? In php it will be like if (isset($HTTP_POST_VARS)){ .... } In perl,...
2013-08-30, 1942👍, 0💬

Assuming $_ contains HTML, which of the following substitutions will remove all tags in it?
Assuming $_ contains HTML, which of the following substitutions will remove all tags in it? 1.s/&lt;.*&gt;//g; 2.s/&lt;.*?&gt;//gs; 3.s/&lt;\/?[A-Z]\w*(?:\s+[ A-Z]\w*(?:\s*=\s*(?:(["']).*?\ 1|[\w-.]+))?)*\s*&gt;//gsi x;You can't do that. If it weren't for HTML comments, imprope...
2013-08-29, 1803👍, 0💬

Why should I use the -w argument with my Perl programs?
Why should I use the -w argument with my Perl programs? Many Perl developers use the -w option of the interpreter, especially during the development stages of an application. This warning option turns on many warning messages that can help you understand and debug your applications. To use this opti...
2013-08-28, 1727👍, 0💬

What are scalar data and scalar variables?
What are scalar data and scalar variables? Perl has a flexible concept of data types. Scalar means a single thing, like a number or string. So the Java concept of int, float, double and string equals to Perl's scalar in concept and the numbers and strings are exchangeable. Scalar variable is a Perl ...
2013-08-28, 1807👍, 0💬

How to turn on Perl warnings? Why is that important?
How to turn on Perl warnings? Why is that important? Perl is very forgiving of strange and sometimes wrong code, which can mean hours spent searching for bugs and weird results. Turning on warnings helps uncover common mistakes and strange places and save a lot of debugging time in the long run. The...
2013-08-27, 1877👍, 0💬

What happens when you return a reference to a private variable?
What happens when you return a reference to a private variable? Perl keeps track of your variables, whether dynamic or otherwise, and doesn't free things before you're done using them.
2013-08-27, 1761👍, 0💬

Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}?
Assuming both a local($var) and a my($var) exist, what's the difference between ${var} and ${"var"}? ${var} is the lexical variable $var, and ${"var"} is the dynamic variable $var. Note that because the second is a symbol table lookup, it is disallowed under `use strict "refs"'. The words global, lo...
2013-08-26, 1867👍, 0💬

What is Perl one-liner?
What is Perl one-liner? There are two ways a Perl script can be run: --from a command line, called one-liner, that means you type and execute immediately on the command line. You'll need the -e option to start like "C:\ %gt perl -e "print "Hello";". One-liner doesn't mean one Perl statement. One-lin...
2013-08-26, 1921👍, 0💬

How to open and read data files with Perl
How to open and read data files with Perl Data files are opened in Perl using the open() function. When you open a data file, all you have to do is specify (a) a file handle and (b) the name of the file you want to read from. As an example, suppose you need to read some data from a file named "check...
2013-08-22, 1813👍, 0💬

Which of these is a difference between C++ and Perl?
Which of these is a difference between C++ and Perl? Perl can have objects whose data cannot be accessed outside its class, but C++ cannot. Perl can use closures with unreachable private data as objects, and C++ doesn't support closures. Furthermore, C++ does support pointer arithmetic via `int *ip ...
2013-08-22, 1948👍, 0💬

How do I set environment variables in Perl programs?
How do I set environment variables in Perl programs? you can just do something like this: $ENV{'PATH'} = '...'; As you may remember, "%ENV" is a special hash in Perl that contains the value of all your environment variables. Because %ENV is a hash, you can set environment variables just as you'd set...
2013-08-21, 1879👍, 0💬

Why do you use Perl?
Why do you use Perl? Perl is a powerful free interpreter. Perl is portable, flexible and easy to learn.
2013-08-21, 1925👍, 0💬

What is Shell scripting
What is Shell scripting A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language. Typical operations performed by shell scripts include file manipulation, program execution, and printin...
2008-05-30, 7908👍, 0💬

What are scalar data and scalar variables
What are scalar data and scalar variables? Perl has a flexible concept of data types. Scalar means a single thing, like a number or string. So the Java concept of int, float, double and string equals to Perl\'s scalar in concept and the numbers and strings are exchangeable. Scalar variable is a Perl...
2007-11-20, 4893👍, 0💬

< 1 2   Sort: Rank