top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Difference between list and data in Perl ?

+2 votes
297 views
Difference between list and data in Perl ?
posted Nov 15, 2014 by Ganesh

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button

Similar Questions
0 votes
sub myfunc {
 my @x=(1,2,3);
 return @x;
}

or

sub myfunc {
 my @x=(1,2,3);
 return [@x];
}

which one is the better way to return the list content? And if the method is an instance method?

0 votes

I routinely generate rows of tab-separated data like this;

my @array = ( "boris", "natasha", "rocky", "bullwinkle"); print join "t", @array, "n";

However this code inserts an extra tab between bullwinkle and the newline character. So when it is important I do this instead:print join "t", @array;print "n";
I suppose you could put both statements on a single line. Is there a simpler/faster way to generate this output: boristnatashatrockytbullwinklen?

+1 vote

I would retrieve my hash table when i pass it in argument at a function. In my case, function1 return my hash table, then i pass my hash table in argument to my function2 and in my function2 i would retrieve my hash table for browse it.

sub function1{
    my code;
    return %hash;
}

sub function2{
    my %hash=$_[0];
    my code browse my hash;
}

my %hash = function1();
function2(%hash);

I have the following error : Odd number of elements in hash assignment at

0 votes

I am using constant mainly to enable printing of debugging messages (e.g. use constant DEBUGGING_L1 => 0;)

Normally, the value is '0' and when I need to see debug messages, I make this 1 and run the script. Is there a way to allocate value to constants at run time so that I can avoid editing the script again and again?

Also, is there a better way to handle debugging?

...