English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories
2

What does this mean in PERL?
s/[\r\n]+//g;
my @fields = split /\|/;

I have a basic understanding that when this program reads in this file, it is creating an array and parsing each line based on a | symbol. But I don't know what the characters mean (/ \ \r \n... etc) Can someone please help?

Thanks!

2007-12-05 08:22:45 · 3 answers · asked by Licursi 2 in Computers & Internet Programming & Design

3 answers

The important concept that you need to learn hear is what a Regular Expression is. This is basically what the first line means in simple terms. Substitute (thats what the 's' means) return (\r) or newline (\n) characters with nothing. If you are going to continue programming in pearl or any language for that matter, you should learn about regular expressions. Check out the site below, it will help you out a lot.

2007-12-05 08:48:49 · answer #1 · answered by Dr Cog 3 · 1 0

PERL can consult from different issues: a million. The language itself 2. The interpreter (this is this methodology that takes perl scripts and 'interprets' them to run them on your gadget. the perl compiler is a factor of the perl interpreter. even however perl you could run a perl script without compiling such as you may in C or Java, the script nevertheless gets compiled into binary executable code earlier being run. The PERL compiler produces this binary executable as a report that could be complete, without the over head of doing the 'merely in time' collect each and every time you run the script.

2016-09-30 22:50:19 · answer #2 · answered by ? 4 · 0 0

The \n and \r means to match any "new line" or "returns" that may appear in the line PERL is reading. The + means one or more characters. The // means blank. the "g" at the end means go all the way to the end. Finally, the s/ means to substitute.

To sum it up, you are telling PERL that PERL should substitute all "new line" or "returns" with blank.

To make it look easier, here, I substitute the letter A with the letter B.

$var=AAACCDDDEE;
$var=~s/A/B/g;
print "$var\n";

This is how it looks like when I run it....
perl sub.pl
BBBCCDDDEE

Hope that helps!!

2007-12-05 18:18:49 · answer #3 · answered by thepinky 3 · 1 0

fedest.com, questions and answers