Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Array / scalar conversions

Reply
Thread Tools

Array / scalar conversions

 
 
starwars
Guest
Posts: n/a
 
      02-03-2004
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?

 
Reply With Quote
 
 
 
 
Walter Roberson
Guest
Posts: n/a
 
      02-03-2004
In article <(E-Mail Removed) ux.net>,
starwars <(E-Mail Removed)> wrote:
: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.
--
*We* are now the times. -- Wim Wenders (WoD)
 
Reply With Quote
 
 
 
 
MPBroida
Guest
Posts: n/a
 
      02-03-2004
starwars wrote:
>
> 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??
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer conversions and Data types conversions vb@gmail.com C Programming 10 08-05-2005 09:51 AM
Replace scalar in another scalar Mark Perl Misc 4 01-27-2005 02:48 PM
Expanding scalar hash element in array ref. Dmitri Zakharov Perl 2 06-11-2004 11:11 AM
Shorthand for($scalar) loops and resetting pos($scalar) Clint Olsen Perl Misc 6 11-13-2003 12:50 AM
letters in a scalar to array John E Perl Misc 4 07-01-2003 03:35 PM



Advertisments