in reply to Re: How do remove trailing data?
in thread How do remove trailing data?

The logic in the for loop is the same,is there a way I can do a better implementation,is there a way I can combine the forloops into one?pls advise
if((@changed_files || @newlyinsertedfiles || @branchedfiles)) { foreach my $file (@changed_files) { $file =~ s/#\d+$//; #print "FILE:$file\n"; push @changed_paths,"$file\n"; } foreach my $file (@newlyinsertedfiles) { $file =~ s/#\d+$//; #print "FILE:$file\n"; push @newlyinserted_paths,"$file\n"; } foreach my $file (@branchedfiles) { $file =~ s/#\d+$//; #print "FILE:$file\n"; push @branched_paths,"$file\n"; } }

Replies are listed 'Best First'.
Re^3: How do remove trailing data?
by samarzone (Pilgrim) on Dec 24, 2010 at 07:32 UTC

    If you can overwrite the existing array values you can use following for the complete if block. You need not write if as the loop will run only if arrays are not empty

    s/#\d+$// for (@changed_files, @newlyinsertedfiles, @branchedfiles);
    --
    Regards
    - Samar