App-Jawk

 view release on metacpan or  search on metacpan

bin/jawk  view on Meta::CPAN

        my @parts;
        if ($delimiter eq ' ' ) {
            @parts = split( ' ', $line );	    # ' ' is a special case with split, which acts special. look it up!
        } else { 
            @parts = split(/$quote_meta_delimiter/, $line);	    # so you can split on chars like "("
            #shift(@parts) while (@parts && $parts[0] =~ /^\s*$/);  # should we strip leading blank fields?
        }

        if ($exe) { # if we have an exe from the command line, run it for each input line
            # if they passed a line to execute, then run it for each line we read 
            my $exe_expanded = replace_exe_vars( $exe, \@parts );   # expand to perl script
            eval "$exe_expanded";      # string eval.
            warn "$prog: Error running: $exe_expanded: $@\n" if $@;
        } else {    # otherwise, pull out fields via numbered args.

            # convert the args (things from @ARGV that don't look like command-line options)
            # into fields. Must be done for each line, because we need the
            # number of elements.
            print STDERR "args are @args, parts are @parts\n" if $debug;
            my @fields = convert_args_to_fields( \@args, scalar(@parts) );
            
            # if we're in -x mode, invert the fields to
            # figure out which are left after exclusions.

bin/jawk  view on Meta::CPAN

                @fields = invert_fields( \@fields, scalar(@parts) );
            }

            print (join($joiner, @parts[@fields]) . "\n");
        }
    }
    exit(0);    # done
}

############################################
# my $exe_expanded = replace_exe_vars( $exe, \@fields )
sub replace_exe_vars {
    my ($exe, $fieldsref) = @_;
    my @fields = @$fieldsref;

    # AWK MODE IS DISABLED ABOVE
    if ($awky) { 
        # awky style, to be deprecated. Replace $1 $2 $3 etc.
        #   since we can't actually assign to $1, $2, $3, etc easily,
        #   we manually parse out $\d+ and ${\d+} sequences from the exe string they pass
        #   and pass back a string to be eval'ed :)



( run in 0.313 second using v1.01-cache-2.11-cpan-5623c5533a1 )