473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

1 New Member
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, 316 views)
File Type: txt output.txt (232 Bytes, 291 views)
Oct 20 '16 #1
1 3583
RonB
589 Recognized Expert Moderator Contributor
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
2358
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 statment that will output based upon the value of the option evaluated. This example only shows one case statement but there are eight case statements. Thanks for any insight! Tom If Not objRs.EOF Then
13
11233
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 statement? The break keyword will only come out of the switch, not the for-next loop.
10
18039
by: Brett Romero | last post by:
If I want to use: switch (AppName) { case ApplicationName.App1: loadApp1Logo(); break; case ApplicationName.App2: loadApp2Logo(); break;
12
21067
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 record (3232,'Raindeer') based on the condition that the
1
21662
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 "01" : dWarrExpDateMonth="Jan" : dRetailDateMonth="Jan" case "02" : dWarrExpDateMonth="Feb" : dRetailDateMonth="Feb" End Select
14
2236
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
1314
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 (look-up). (the number represents a product) So each record in the table could look like this. PartID PartDoc Product1 Product2 Product3 Product4 12 P-7824 1 5 ...
5
7260
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 statement is removed it works, but when it is included i get this error: SELECT accountNum ,balanceCalculation = CASE WHEN Balance > 5000 THEN Balance *2 ELSE Balance /2 END
25
7364
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: Dim Effective_Date As Date If Me.Effective_Date >= 1/1/10 And Me.Effective_Date <= 12/31/10 Then = ( * 0.09) = * ElseIf Me.Effective_Date >= 1/1/11 And Me.Effective_Date <= 12/31/11 Then = ( * 0.22) = *
2
1245
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 marks = CInt(TextBox1.Text) Select Case marks Case Is > 35 MsgBox("number is greater than 35") Case Is > 50
0
8498
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8152
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8341
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6817
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5476
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1598
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.