Array / scalar conversions

S

starwars

Idiot perlbie questions...

If have on proceedure that requires input of a list of text, i.e., as an @
array.

The other procedure I have requires a simple scalar, i.e. $ .

I want BOTH procedures to operate on a block of text (mail message).

So, I use join on the @ and feed it to the $ only procedure.

And, vice-versa, using split.

It seems to work, but because of my ignorance, I wonder if I am doing it
"right"?

Question: is there an easy way to convert (or reference) array contents as
scalars without using the join function?
 
W

Walter Roberson

:If have on proceedure that requires input of a list of text, i.e., as an @
:array.

:The other procedure I have requires a simple scalar, i.e. $ .

:I want BOTH procedures to operate on a block of text (mail message).

:So, I use join on the @ and feed it to the $ only procedure.

:And, vice-versa, using split.

:It seems to work, but because of my ignorance, I wonder if I am doing it
:"right"?

:Question: is there an easy way to convert (or reference) array contents as
:scalars without using the join function?

If the manipulation processing of the array elements are independant of
each other, then use map. For example,

@new_lines = map { process_a_line $_ } @lines;

If the processing cannot be done independantly, then you could use
join -- or you could rewrite the scalar subroutine to allow arrays.
Many of the perl operators expect to work on scalars, though, so sometimes
using map is the easiest way.
 
M

MPBroida

starwars said:
Idiot perlbie questions...

If have on proceedure that requires input of a list of text, i.e., as an @
array.

The other procedure I have requires a simple scalar, i.e. $ .

I want BOTH procedures to operate on a block of text (mail message).

So, I use join on the @ and feed it to the $ only procedure.

And, vice-versa, using split.

It seems to work, but because of my ignorance, I wonder if I am doing it
"right"?

Question: is there an easy way to convert (or reference) array contents as
scalars without using the join function?


Question: You're not gonna screw up this newsgroup the
way you have comp.databases.ms-access, are you??
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top