473,398 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Append the nested case statement content with outer case statement's content

1
Inputfile.txt is given file and output.txt is expected output in attachment.

In this situation we have to deal with nested case statements, which you can observe by seeing the input file and output given in attachment.
I got the output for one level nested case statement. first I saved the content between first "case" and last "esac" in a temp file and run the below given code.
Expand|Select|Wrap|Line Numbers
  1. open (data,"<input.txt");
  2. while (<data>) {
  3. $para1;  $para2;
  4.   unless (/case/../esac/){
  5.       if(/(.*)\)(.*)$/) {
  6.     $para1=$1;
  7.      $var=$2;       
  8.      }
  9.      else  {  $var=$_; }
  10. print $para1.$var."\n";
  11. }
  12.    if (/case/../esac/)  {
  13.         if(/(.*)\)(.*)$/) {
  14.        $para2=$1;
  15.        $var=$2;       
  16.        }
  17.       else  {  $var=$_; }        
  18. print $para1.$para2.$var."\n";
  19. }   }
  20. close data;
I need your help and suggestion to get output for multiple nested case statement.
Thank you.
Attached Files
File Type: txt inputfile.txt (678 Bytes, 312 views)
File Type: txt output.txt (232 Bytes, 285 views)
Oct 20 '16 #1
1 3574
RonB
589 Expert Mod 512MB
First, you're missing 2 very important pragmas/modules which should be in every perl script you write.
Expand|Select|Wrap|Line Numbers
  1. use strict;
  2. use warnings;
The strict pragma will require you to declare your vars, which is done with the my keyword.

When needing to extract data in nested blocks, you should be using a module designed for that purpose.

Text::Balanced - Extract delimited text sequences from strings.
Oct 20 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tom | last post by:
I would like to know if an .asp case statement can contain HTML elements. I am building an application that I would like to have dynamic choices. The dynamic part would be built in the a case...
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
10
by: Brett Romero | last post by:
If I want to use: switch (AppName) { case ApplicationName.App1: loadApp1Logo(); break; case ApplicationName.App2: loadApp2Logo(); break;
12
by: rAinDeEr | last post by:
Hi, I have a table with 2 columns ** CREATE TABLE test (emp_num DECIMAL(7) NOT NULL,emp_name CHAR(10) NOT NULL) and i have inserted a number of records. ** Now, I want to insert a new...
1
by: microsoft.public.dotnet.languages.vb | last post by:
Hi All, I wanted to know whether this is possible to use multiple variables to use in the select case statement such as follows: select case dWarrExpDateMonth, dRetailDateMonth case...
14
by: aa | last post by:
Code like this ======================= Select case q Case "a" Dim arr(5) Case "b" Dim arr(2) end select ===================== returns an error saying variable arr redefined.
2
by: Desitech | last post by:
I have a table entitled "Parts". In that table I have a field entitled "PartDoc" and four fields entitled "Product1", Product2", "Product3", and Product4". The datatype for these fields is Number...
5
by: RiddleMeThis | last post by:
Im trying to use 2 CASE statements together in a SELECT query without much luck. The second CASE uses the output from the first CASE as it’s expression (well it’s supposed to). When the 2nd CASE...
25
by: LBinGA | last post by:
Hello all: I'm having trouble with a nested If Statement working properly. I'm working in MS Access 2002 (OS Windows XP, ver 2002). The non-working code is going on the Form (a Single) as follows:...
2
by: kmssunil | last post by:
The case ist & else case is executing but not others Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim marks As Integer ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.