Array / scalar conversions

Discussion in 'Perl Misc' started by starwars, Feb 3, 2004.

  1. starwars

    starwars Guest

    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?
    starwars, Feb 3, 2004
    #1
    1. Advertising

  2. In article <>,
    starwars <> 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)
    Walter Roberson, Feb 3, 2004
    #2
    1. Advertising

  3. starwars

    MPBroida Guest

    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??
    MPBroida, Feb 3, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dmitri Zakharov
    Replies:
    2
    Views:
    6,513
    Dmitry Roslyakov
    Jun 11, 2004
  2. Replies:
    10
    Views:
    703
    Jasen Betts
    Aug 5, 2005
  3. John E

    letters in a scalar to array

    John E, Jul 1, 2003, in forum: Perl Misc
    Replies:
    4
    Views:
    91
    Carlton Brown
    Jul 1, 2003
  4. Clint Olsen
    Replies:
    6
    Views:
    351
    Jeff 'japhy' Pinyan
    Nov 13, 2003
  5. Mark

    Replace scalar in another scalar

    Mark, Jan 27, 2005, in forum: Perl Misc
    Replies:
    4
    Views:
    161
    Arndt Jonasson
    Jan 27, 2005
Loading...

Share This Page