Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Assigning value to the array elements

by ioannis (Abbot)
on Oct 28, 2005 at 14:31 UTC ( #503662=note: print w/replies, xml ) Need Help??


in reply to Assigning value to the array elements

You can assign into elements of an array if they are variables. All work is in one line -- within the print statement.
use List::MoreUtils qw(pairwise); my ($first, $second, $third, $fourth, $fifth, $sixth); my @vars = \($first, $second, $third, $fourth, $fifth, $sixth); my @aarr = ('<chap', '<book', '<isb'); print {$,=' '; \*STDOUT} pairwise { ${$a} = $b} @vars, @aarr;

Replies are listed 'Best First'.
Re^2: Assigning value to the array elements
by anniyan (Monk) on Oct 28, 2005 at 14:55 UTC

    Thanks that works perfectly for my use. Also thanks for Fletch, wfsp and no_slogan.

    The reason i am using this is, i dont know exactly how many values will be in @aarr. But i want to assign those values to some scalar variables which i will use in my program later for another use. If there is any alternative please suggest

    Regards,
    Anniyan
    (CREATED in HELL by DEVIL to s|EVILS|GOODS|g in WORLD)

      But i want to assign those values to some scalar variables which i will use in my program later for another use. If there is any alternative please suggest
      Change the rest of the program so it doesn't expect the values to appear in scalar variables. Really. Your code will be much easier to understand if it says this:
      my $first = $config_values{first}; open my $file, $first;
      rather than just blithely saying the second line and leaving the poor reader to figure out how $first got its value.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://503662]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-11-28 18:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?