Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Open Source > Perl
|
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Perl section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 27th, 2007, 12:13 AM
Registered User
 
Join Date: Jun 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem in reading some part of a file

Hi all


I am trying to read a file which contains

rem ------------------------ book_tab variables ---------------------
.rem
.declare book_no a13
.declare l_code a10
.declare l_booking a12
.set page_no 1
.set first "N"
.set no_more_clauses "N"
#dt 1 1 80 #
#dt 2 1 6 9 48 50 61 63 76 80 80 #
.define loktabs
        loc_table book_tab, book_hazmat, custdata2, edit_table,
        book_rates, print_table in share update mode
..
.define get_input
        select key, key1, key2,
               passkey3, passkey4, print_name
          into input_booking_seq, fax_header, file_no,
               input_print_rates, myNoteId, print_name
          from ed_table
         where ed_table.tag = 'BOOK'
           and ed_table.key = 'PRINT'
           and ed_table.user_id = user
..
.define get_user_info
        select user_loc,user_name, user_company,
        into user_location, user_name, user_company,
        from sec_header
        where user_id = lower(substr(user,5,10))
..

.execute lok_tabs
.execute get_user_info


So you can see lot of .define lines and I need to extract the name and query from every .define lines like "get_input"
and its associated query....

I am posting my code also...


#!/usr/bin/perl


$ARGV[0] .= ".rpt";

open(FH,"<$ARGV[0]") or die "Cant open";
@arr = <FH>;

foreach $data(@arr){

if($data =~ /^\.def(.*)$/smx){


$data =~ s/(^\.\w+\s+)(\w+)(\s+)(.+)(^\. \.$)/$2,$4/smx;

print "This is Macro $data \n";

}

}
close(FH);


but its not working as the condition gets failed...

 
Old June 29th, 2007, 09:29 AM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Have a look at the flip flop operator (..), its googleable.


open(FH,"<$ARGV[0]") or die "Cant open";

while (<FH>) {
  print if (/\.define/ .. /\.\./);
}

--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with PHP file reading XML file for output rydog65 Beginning PHP 0 March 26th, 2008 05:13 PM
Run bat file as part of Setup project adorable.ashish General .NET 0 March 5th, 2008 07:42 AM
Problem with reading BAT file rhysduk VB How-To 0 January 12th, 2005 09:53 AM
reading HTML from file -> write to file mikeuk Beginning PHP 4 July 21st, 2004 05:40 AM
File System Watcher - Part 2 hugh@kmcnetwork.com VB.NET 1 December 29th, 2003 04:40 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.