Re: Remove first letter of each string in array
From: Tore Aursand (tore_at_aursand.no)
Date: 05/27/04
- Next message: Yash: "Listing files sorted by creation time"
- Previous message: Tore Aursand: "Re: Templating system needs help"
- In reply to: Julia deSilva: "Remove first letter of each string in array"
- Next in thread: Jim Cochrane: "Re: Remove first letter of each string in array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 27 May 2004 16:46:43 +0200
On Thu, 27 May 2004 15:07:20 +0100, Julia deSilva wrote:
> my @array = qw(1this 2is 3a 4new 5message);
>
> for (my $x=0;$x<@array;$x++){
> $array[$x] = substr($array[$x],1,length($array[$x]))
> }
>
> foreach (@array){print"$_\n";};
>
> This does indeed remove the first letter of each string in this array, but
> is there a better way ! ?
Use Perl's 'for' or 'foreach';
for ( @array ) {
$_ = substr( $_, 1 );
}
-- Tore Aursand <tore@aursand.no> "War is too serious a matter to entrust to military men." (Georges Clemenceau)
- Next message: Yash: "Listing files sorted by creation time"
- Previous message: Tore Aursand: "Re: Templating system needs help"
- In reply to: Julia deSilva: "Remove first letter of each string in array"
- Next in thread: Jim Cochrane: "Re: Remove first letter of each string in array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|