Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 9th, 2013, 06:27 AM
sid.verycool sid.verycool is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 sid.verycool User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 46 sec
Reputation Power: 0
Match at begin not ^ working for in my script

Hi all, i need to debug this script and make it work according to my requirement. This is an urgent requirement, i need to fix this asap.</p> The concept of the script was to replace "oldname" written after the word "module" with "newname" This worked well until the word module came in the comment.

CONTENT OF SCRIPT <code> #!/usr/bin/perl -w

BEGIN {undef $/;}


# I TRIED 1ST my $match = "^module.*?$ARGV[2].*?([\\(;])"; 2ND my $match = "\^module.*?$ARGV[2].*?([\\(;])"; 3RD my $match = "\\^module.*?$ARGV[2].*?([\\(;])"


my $match = "module.*?$ARGV[2].*?([\\(;])";
#print "$match";

my $filename = $ARGV[0];

open (INFILE, "<", $filename) or die "Failed to read file $filename : $! \n";

$string = <INFILE>;
close INFILE;



#I ALSO TRIED "$string =~ s/^$match/module $ARGV[1]$1/sg;";

$string =~ s/$match/module $ARGV[1]$1/sg;


open OUTFILE, ">$ARGV[0]" || die "Failed to create $ARGV[0]\n";
print OUTFILE ($string);
close OUTFILE;<\code>

what this script does to input file is : CONTENT OF BEFORE SCIPT IS RUN ON FILE <code>//Verilog HDL for "tt", "hh" "functional"
// if i write the word here the script goofs up
`timescale 1ps/10fs


module OLD(Y, A, B );
output Y;
input A;
input B;

endmodule
</code> NOW I RUN <code>script.pl FILE NEW OLD</code> now the CONTENT OF FILE BECOMES <code>//Verilog HDL for "tt", "hh" "functional"
// if i write the word here the script goofs up
`timescale 1ps/10fs


module NEW(Y, A, B );
output Y;
input A;
input B;

endmodule
</code> which is good but if i write the word "module" in the comment line i.e. CONTENT OF BEFORE SCrIPT IS RUN ON FILE which goofs up
<code>
//Verilog HDL for "tt", "hh" "functional"
// if i write the word module here the script goofs up
`timescale 1ps/10fs


module OLD(Y, A, B );
output Y;
input A;
input B;

endmodule </code>

Now the contents become <code>//Verilog HDL for "tt", "hh" "functional"
// if i write the word module NEW(Y, A, B );
output Y;
input A;
input B;

endmodule
</code> which is unacceptable to me. plz help guys,

Reply With Quote
  #2  
Old March 9th, 2013, 06:29 AM
sid.verycool sid.verycool is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 2 sid.verycool User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 46 sec
Reputation Power: 0
Thumbs down

The main problem is when module is given in // comment.
Therefore i want the script to only see module which has no preceding character in the line. hence i tried using ^module

Reply With Quote
  #3  
Old March 9th, 2013, 09:07 AM
FishMonger FishMonger is offline
Contributing User
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2009
Posts: 1,652 FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level)FishMonger User rank is General 3rd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 5 h 32 m 21 sec
Reputation Power: 1170
Loop over the file line-by-line instead of slurping it into a scalar and anchor the regex to the beginning of the string.

Also, you should ALWAYS include the strict and warnings pragmas in EVERY script.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Match at begin not ^ working for in my script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap