Sunday, 20 October 2019

how can we empty an elements of an array using perl?

Method 1:

@a=(1,7,9,4);
$#a = -1;
print @a;


Method 2:

@a=(1,7,9,4);
@a = ();
print @a;


Method 3:

@a=(1,7,9,4);
$_=(@a) = ();
print @a;


Method 4:

@a=(1,7,9,4);
$_=\@a;
@$_=();
print @a;


Method 5:

@a=(1,7,9,4);
$_=\@a;
@$_=[];
@$_=();
print @a;


Method 6:

@a=(1,7,9,4);
@a= map /![^.]+/,@a;
print @a;



Method 7:

@a=(1,7,9,4)
@a= grep /![^.]+/,@a;
print @a;


Method 8:

@a=(1,7,9,4)
@a= /![^.]+/ ~~ @a
print @a;


Method 9:

@a=(1,7,9,4);
map $_=~s/.+//, @a;
print @a;


Method 10:

@a=(1,7,9,4);
grep $_=~s/.+//, @a;
print @a;


Method 11:

@a=(1,7,9,4);
map {  $_=~s/.+//g; } @a ;
print @a;


Method 12:

@a=(1,7,9,4);
grep {  $_=~s/.+//g; } @a ;
print @a;


Method 13:

@a=(1,7,9,4);
$_=~s/.+// for @a;
print @a;


Method 14:

@a=(1,7,9,4);
my @b=();
@a=@b;
print @a;


Method 15:

@a=(1,7,9,4);
for(@a)
{pop @a;shift @a;}
print @a;


0 Comments:

Post a Comment

Note: only a member of this blog may post a comment.

<< Home