Link to home
Start Free TrialLog in
Avatar of Tolgar
Tolgar

asked on

How to do substitution without a loop in an array in Perl

The following line are in @myAray as two elements of the array.

<br><br> 2: %SCHEMA  Class constructor function 
<br>3: 
<br>4: %   Copyright 1974-2012
<br>5: <font color="red">%   $Revision: 1.1.4 $  $Date: 2012/03/09 01:24:38 $
</font><br>6: 
<br>7: %%%% Get handles classes
<br>8: CreatePackage   = find(xxx);

Open in new window


The array has two elements as below

print $myArray[0]
<br><br>

Open in new window


print $myArray[1]
 2: %SCHEMA  Class constructor function 
<br>3: 
<br>4: %   Copyright 1974-2012
<br>5: <font color="red">%   $Revision: 1.1.4 $  $Date: 2012/03/09 01:24:38 $
</font><br>6: 
<br>7: %%%% Get handles classes
<br>8: CreatePackage   = find(xxx);

Open in new window


What I would like to do is to remove HTML formatting from these two elements all at once without using a loop to loop in the array.

The expected output is:
2: %SCHEMA  Class constructor function 
3: 
4: %   Copyright 1974-2012
5: %   $Revision: 1.1.4 $  $Date: 2012/03/09 01:24:38 $
6: 
7: %%%% Get handles classes
8: CreatePackage   = find(xxx);

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Wow! we think so similarly.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tolgar
Tolgar

ASKER

I have one short follow up question:

Each element has two space characters in the beginning. I would like to remove these two spaces with one newline character (\n) for each element of the array.

How can I do it?


Current output:
  2: %SCHEMA  Class constructor function 
3: 
4: %   Copyright 1974-2012
5: %   $Revision: 1.1.4 $  $Date: 2012/03/09 01:24:38 $
6: 
7: %%%% Get handles classes
8: CreatePackage   = find(xxx);
  12: %SCHEMA  Class constructor function 
13: 
14: %   Copyright 1974-2012
15: %   $Revision: 1.1.4 $  $Date: 2012/03/09 01:24:38 $
16: 
17: %%%% Get handles classes
18: CreatePackage   = find(xxx);

Open in new window


Expected output:
  
2: %SCHEMA  Class constructor function 
3: 
4: %   Copyright 1974-2012
5: %   $Revision: 1.1.4 $  $Date: 2012/03/09 01:24:38 $
6: 
7: %%%% Get handles classes
8: CreatePackage   = find(xxx);
  
12: %SCHEMA  Class constructor function 
13: 
14: %   Copyright 1974-2012
15: %   $Revision: 1.1.4 $  $Date: 2012/03/09 01:24:38 $
16: 
17: %%%% Get handles classes
18: CreatePackage   = find(xxx);

Open in new window

If I'm understanding what you want, this should do it...
@myArray = map { s{^\s+}{}; s{<[^>]+>}{}g; $_ } @myArray;

Open in new window