On 03/21/2021, at 03:39, samar <[email protected] 
<mailto:[email protected]>> wrote:
> The reason you cannot reproduce the error with your file may be that the 
> second column is limited to three different texts (B1, B2, and B3) whereas in 
> mine there are more (up to B7 here, but the script should also work with more 
> than seven):


Hey Samar,

Nyet.  The logic of JD's script is quite clear if you know how to read Perl, 
and that shouldn't happen.

My best guess is your test file is different in structure than what you've 
given us as an example, and that's throwing off JD's script – but I can't tell 
without being able to reproduce the problem.

I created a 10,000 line test file with 1000 A-groups, and JD's script works 
perfectly in about 1/4 of a second on my old Mid-2010 17" 2.66 GHz Intel Core 
i7 MacBook Pro.

When asking for text processing it's best to give real-world data if at all 
possible, because the devil is in the details – and small anomalies can cause 
big problems.

I've rewritten JD's script to hopefully reduce any chance of error.  It's a bit 
terse, but hopefully the commenting overcomes that.

Why wait 8 seconds when instantaneous is available?

--
Best Regards,
Chris


#!/usr/bin/env perl -sw
# 
-----------------------------------------------------------------------------------------
# Auth: Christopher Stone <[email protected] 
<mailto:[email protected]>>
# dCre: 2012/11/27 08:12
# dMod: 2021/03/21 21:13 
# Task: Create Indented Structure from a 2 Column tab-delimited table.
# Tags: @ccstone, @Shell, @Script, @Indented, @Column, @Table
# 
-----------------------------------------------------------------------------------------
use v5.010;

my $column1StartStr = "";        # Initialize variable

while (<>) {                     # Process Lines one at a time.

   m!(^[^\t]+)(\t.+)!m;          # Matches Column 1 & [\t]Column 2 in the 
current line to $1 & $2.

   if ($1 eq $column1StartStr) { # Equality test – start-state of Col A & Col A 
of current line:

      say "$2";                  # If equal; print only Col B with \t delim.

   } else {

      say "$1$2";                # If NOT equal; print both columns.
      $column1StartStr = $1;     # If NOT equal; reset Col A start string.

   }

}

# 
-----------------------------------------------------------------------------------------


-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/EF00E382-AECA-426B-99FD-A49353D18137%40gmail.com.

Reply via email to