Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Need help with the Perl script

Posted on 2014-09-09
1
155 Views
Last Modified: 2014-09-09
Below is the compare script which compares strings in two text files.  The two attached files are workspace.txt and invalids.txt. This script checks if the string in workspace.txt is present in invalids.txt. If a match is found then corresponding line in invalids.txt is printed or else the string from workspace.txt is printed.

For example:

The above check in invalids.txt is to look for string between the dot(.)and colon(') at the end.
       
For instance in the file invalids.txt consider the line
'PACKAGE BODY: TRON2000.ts_k_jrp_300901sfsfs0_mma'      

For comparison only consider the string

ts_k_jrp_300901sfsfs0_mma

======If a match is found then print the complete corresponding line in invalids.txt  like


     'PACKAGE BODY: TRON2000.ts_k_jrp_300901sfsfs0_mma' is invalid

      or else just print the text from workspace.txt is valid ....in this case print

      ts_k_jrp_300901sfsfs0_mma is valid


Below is the script .


use strict;
use warnings;
use Fatal qw(open close);
my $finv = shift or die "Usage: $0 <invalids_file> <workspace_file>\n";
my $fwrk = shift or die "Usage: $0 <invalids_file> <workspace_file>\n";
open IN, $finv or die "could not open $finv: $!";
my %chk;
while (<IN>) {
    chomp;
    next if m{^\d+\s+rows?\s*$};
    if (m{\.(.*)'\s*$}) {
        $chk{$1} = $_;
    }
}
close IN;
open IN, $fwrk or die "could not open $fwrk: $!";
while (<IN>) {
    chomp;
    if (exists $chk{$_}) {
        print "$chk{$_} is invalid\n";
    } else {
        print "$_ is valid\n";
    }
}
close IN;
                           

Open in new window


##########Need a modification in the above script to handle uppercase strings in invalids.txt like


'PACKAGE BODY: TRON2000.TS_K_JRP_300901SFSF0_MMA'

The call to the script is  test_compare.pl path/to/invalids.txt path/to/workspace.txt
workspace.txt
invalids.txt
0
Comment
Question by:gaurav sharma
1 Comment
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40312265
#!/usr/bin/perl
use strict;
use warnings;
die "Usage: $0 <invalids_file> <workspace_file>\n" unless @ARGV==2;
use Fatal qw(open close);
my %chk;
while( <> ){
    s/\s+$//;
    @ARGV &&  m{\.(.*)'$} and $chk{lc $1} = $_;
    @ARGV || print $chk{lc $_}?"$chk{lc $_} is invalid\n":"$_ is valid\n";
}

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question