# PERL question (right forum?)

**URL:** <https://boards.straightdope.com/t/perl-question-right-forum/102926>\
**Category:** Factual Questions\
**Created:** [April 10, 2002, 11:14pm UTC](https://boards.straightdope.com/t/perl-question-right-forum/102926 "2002-04-10T23:14:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shmigheghi](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@shmigheghi](https://boards.straightdope.com/u/shmigheghi)\
**Post date:** [April 10, 2002, 11:14pm UTC](https://boards.straightdope.com/t/perl-question-right-forum/102926/1 "2002-04-10T23:14:05Z")

</div>

This is for my web site where I’m trying to create a program that sends form input to a page where I can edit its contents if need be then send that to another page (HTML) that I choose to send it to.

I’ve got the admin thing set and ready, and I can get it to go to the page I want it to, but part of the “send to another page I choose” thing is editing the contents of the page (removing \</body\> and the like tags) before I write to it.

First I thought:

“Ok, I’ll put the page into an array, then search/replace the item in the array I want gone.”

Then I find that you can’t search/replace in an array. (Or so my book tells me, if I can, please tell me how)

So I try to figure out how to convert an array to a normal string variable. But I can’t. This is where you come in.

How do I switch an array to a normal string variable?  
If there’s a better way to do what I want done, I’d also like to know that.

Thank you very much.

---

<div class="post-metadata">

**Author:** ![Manduck](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/manduck/32/256_2.png) [@Manduck](https://boards.straightdope.com/u/Manduck)\
**Post date:** [April 11, 2002, 12:29am UTC](https://boards.straightdope.com/t/perl-question-right-forum/102926/2 "2002-04-11T00:29:38Z")

</div>

If you have the strings in array, you can just loop through the array:

```auto

for (@myarray) {
    s/<body>//gi;
    s/</body>//gi;
    # etc.
}

```

---

<div class="post-metadata">

**Author:** ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)\
**Post date:** [April 11, 2002, 12:33am UTC](https://boards.straightdope.com/t/perl-question-right-forum/102926/3 "2002-04-11T00:33:14Z")

</div>

Depends what you mean by “search/replace in an array.”

You can search/replace each element in an array by simply looping through it:

```auto

s/foo/bar/g for @array

```

To turn an array into a scalar you can use the concatination operator thusly:

```auto

my $stuff;
$stuff .= $_ for @array;

```

Or you can read the file into a scalar one line at a time:

```auto

my $stuff;
$stuff .= $_ while (<FILE>);

```

Or you can locally set the input record seperator to undef to slurp the file all at once:

```auto

local $/;
my $stuff = <FILE>;

```

See [perlopentut](http://www.perldoc.com/perl5.6.1/pod/perlopentut.html), [perlvar](http://www.perldoc.com/perl5.6.1/pod/perlvar.html) and [perlsyn](http://www.perldoc.com/perl5.6.1/pod/perlsyn.html) for more information.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [April 11, 2002, 12:39am UTC](https://boards.straightdope.com/t/perl-question-right-forum/102926/4 "2002-04-11T00:39:27Z")

</div>

Finally, a stylistic note that really irks me: It’s **Perl** , not PERL! Note the initial capitalization, and the lack of capitalization thereafter. Larry dreamed up the name first (it was originally Pearl, BTW) and then made up an expansion to fit it. Therefore, it isn’t a true acronym and should not be capitalized as such.

(If you want to avoid confusion in a context where confusion over such things might arise, Perl is the abstract language that is implemented by the program perl (which is usually launched in a \*nix-y environment by typing the command perl at a shell). Note the capitalization.)

---

<div class="post-metadata">

**Author:** ![shmigheghi](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@shmigheghi](https://boards.straightdope.com/u/shmigheghi)\
**Post date:** [April 11, 2002, 2:24am UTC](https://boards.straightdope.com/t/perl-question-right-forum/102926/5 "2002-04-11T02:24:10Z")

</div>

Thanks a bunch **Friedo**! The s/foo/bar/g was the thing I needed.

Note to **Derleth** :

Y’know, that was the first time I ever wrote it as PERL…thanks for the explaination though.
