in reply to Re: using sub routines and solving an issue i have with passing variables
in thread using sub routines and solving an issue i have with passing variables

i just figured out something else i didnt know. you can name an array on the fly say for instance if you read a files name and want to make the filename the name of the array... take this into code consideration (which most of you probably already know this) i know this is off topic, but is there an easier method of labeling arrays?

my $string = "awesome_array"; my $other_string = "another_awesome_array"; push (@$string, 1, 2, 3, 4, 5 ); foreach my $element(@awesome_array){ print "$element\n"; push (@$other_string, $element) } print @another_awesome_array;
This rigth here is something that will help me alot on the script i am working on right now actually :) glad i figured this little tid bit out.
  • Comment on Re^2: using sub routines and solving an issue i have with passing variables
  • Download Code

Replies are listed 'Best First'.
Re^3: using sub routines and solving an issue i have with passing variables
by GrandFather (Saint) on Oct 01, 2014 at 00:45 UTC

    Try that code with strictures (which you should always use: use strict; use warnings; - see The strictures, according to Seuss). It works without strictures because of some magic. That magic can make it very hard to write correct code and find errors when things go wrong.

    You can achieve similar results by replacing the magic with a hash:

    use strict; use warnings; my %arrays; push @{$arrays{awesome_array}}, 1 .. 5; for my $element(@{$arrays{awesome_array}}){ print "$element\n"; push @{$arrays{another_awesome_array}}, $element; } for my $arrayName (keys %arrays) { print "$arrayName: @{$arrays{$arrayName}}\n" }

    Prints:

    1 2 3 4 5 awesome_array: 1 2 3 4 5 another_awesome_array: 1 2 3 4 5
    Perl is the programming world's equivalent of English
Re^3: using sub routines and solving an issue i have with passing variables
by Anonymous Monk on Oct 01, 2014 at 00:33 UTC