Map function in Perl

20 pts.
Tags:
Perl
Can someone explain me the meaning of this Perl function?
{ s/^(.+?logd{6}.txt:)//, s/ (save) / *$1* /, $pagestats .= "$_" } @rpagestats;

Answer Wiki

Thanks. We'll let you know when a new response is added.

It is basically a combination of the map function, and regular expressions.

The map function (map EXPR,LIST) evaluate EXPR for each element of LIST and returns the list value composed of the result of the evalutaion on each element of LIST. In this case, @rpagestats is the list.

The first parameter for the map function is { s/^(.+?log\d{6}\.txt:)//, s/ (save) / *$1* /, $pagestats .= “$_” }.

Here are some hints for you to understand these regular expressions:

s/ = means that a substitution will be made. (Example: s/STRING A/STRING B/ will replace STRING A with STRING B)
^ = means that the string that is to be matched must appear at the beginning of the text
. = match any character
+ = match 1 or more times
? = match 0 or more times
\d{n} = match exactly n digits
\. = match a “.” (dot)

Have a look at the following pages. they will help you a lot.

Good luck.

-Carlosdl

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following