in reply to How do remove trailing data?

$ perl -le" $_ = shift; print substr $_,0, rindex $_, q!#!" before#aft +er#last before#after $ perl -le" $_ = shift; print substr $_,0, index $_, q!#!" before#afte +r#last before
In honor of some guy with lots of experience

Replies are listed 'Best First'.
Re^2: How do remove trailing data?
by Anonymous Monk on Dec 24, 2010 at 03:12 UTC
    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"; } }

      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