473,405 Members | 2,379 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,405 software developers and data experts.

pattern matching

I have tried the following code:

Expand|Select|Wrap|Line Numbers
  1. #! /usr/bin/perl
  2. use Switch;
  3. $i=0;
  4. open(FILE,"$ARGV[0]") || die "cannot open file";
  5. @lines = <FILE>;
  6. close(FILE);
  7. open(wfile,">$ARGV[1]");
  8. while ($lines[$i]) {
  9.     $line = $lines[$i];
  10.     if ( ($line =~ m/(^\w+)(\s+)(\()(\))/) 
  11.         || ($line =~ m/(^\w+)(\s+)(\()(\s+)(\))/)
  12.         || ($line =~ m/(^\s+)(\w+)(\s+)(\()(\s+)(\))/)
  13.         || ($line =~ m/(^\s+)(\w+)(\s+)(\()(\))/)
  14.         || ($line =~ m/(^\s+)(\w+)(\()(\s+)(\))/)
  15.         || ($line =~ m/(^\s+)(\w+)(\()(\))/)
  16.         || ($line =~ m/(^\w+)(\()(\))/)
  17.         || ($line =~ m/(^\w+)(\()(\s+)(\))/)
  18.     ) {
  19.         $b = $1; $a = $2;
  20.         if ($1 =~ m/(\s+)/) {
  21.             $b = $a;
  22.         }
  23.         $x = 1;
  24.         print wfile $line;
  25.         if ($line =~ m/\{/) {
  26.             $z = 1;
  27.             print wfile "echo \"calling func. $b\"\n";
  28.         }
  29.         $i++;
  30.         $line = $lines[$i];
  31.         if ($line =~ m/(^\{)/) {
  32.             $z = 1;
  33.             print wfile $line;
  34.             print wfile "echo  \"calling func. $b\"\n";
  35.         }
  36.         while ($z ==1 ) {
  37.             $d = $line;
  38.             $i++;
  39.             $line = $lines[$i];
  40.             switch($line) {
  41.                 case m/\{/ {
  42.                     $x++;
  43.                     print wfile $line
  44.                 }
  45.                 case m/\}/ {
  46.                     $x--;
  47.                     if ($x!=0) {
  48.                         print wfile $line
  49.                     }
  50.                 }
  51.                 else {
  52.                     print wfile $line
  53.                 }
  54.             }
  55.             if ($x == 0) {
  56.                 $z=0;
  57.                 print wfile "echo \"return from $b\"\n";
  58.                 print wfile $line
  59.             }
  60.         }
  61.  
  62.     } else {
  63.         print wfile $line;
  64.     }
  65.     $i++;
  66. }
  67. close(wfile);
  68.  
this code is for identifying a function in shell script & inserting echo statements when it is been called and returned.....
can u suggest someting to make it more efficient..
Sep 6 '07 #1
0 1061

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

Similar topics

8
by: gsv2com | last post by:
One of my weaknesses has always been pattern matching. Something I definitely need to study up on and maybe you guys can give me a pointer here. I'm looking to remove all of this code and just...
176
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
9
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
1
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001...
10
by: bpontius | last post by:
The GES Algorithm A Surprisingly Simple Algorithm for Parallel Pattern Matching "Partially because the best algorithms presented in the literature are difficult to understand and to implement,...
5
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
9
by: Jim Lewis | last post by:
Anyone have experience with string pattern matching? I need a fast way to match variables to strings. Example: string - variables ============ abcaaab - xyz abca - xy eeabcac - vxw x...
2
by: Ole Nielsby | last post by:
First, bear with my xpost. This goes to comp.lang.c++ comp.lang.functional with follow-up to comp.lang.c++ - I want to discuss an aspect of using C++ to implement a functional language, and...
1
by: VanKha | last post by:
I write this program for pattern-matching,but it gives wrong result: #include<iostream> #include<conio.h> #include<string.h> using namespace std; main() { char text,pat;...
5
by: pramodkh | last post by:
Hi All I am trying to match a pattern in a file and insert a line. If the pattern matches then insert a line before the matching pattern line. for example, I have the following content in a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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.