944,147 Members | Top Members by Rank

Ad:
  • Perl Discussion Thread
  • Unsolved
  • Views: 2098
  • Perl RSS
Dec 8th, 2005
0

Trouble Expanding a bus in PERL

Expand Post »
Hi all,

I am trying to list out a bus as individual names.

For instance - When I come across a section in a file that lists a bus like this:

<busname>[0:2]

I would like to print out this:

<busname>[0]
<busname>[1]
<busname>[2]

Here is what I have - It goes into an endless loop and I can't seem to solve it.
#! /usr/intel/bin/perl -w
my $block = $ARGV[0];
my $RTL_pin = "$block.test.v";
open (RTL, "$RTL_pin") or die "could not open file $RTL_pin\n";
system ("touch newtest2");
open( NEWFILE2, "> newtest2" ) or die "Can't open file: newtest2 $!";

system (" grep -E '[input]|[ouput]|[inout]' $RTL_pin > $RTL_pin.hold");
system (" cp -p $RTL_pin.hold $RTL_pin");

while (<RTL>)
{
chomp;
s/;/ /g;
if ($_ =~ /(.*\s+)\[(\d+)\d+)\]/)
{
$bn = $1; #busname
$h = $2; #high number
$l = $3; #low number
$i = 0;
# print NEWFILE2 "\n$l\n$h\n$bn\n";
for ($i = $l; $h; $i++)
{
print "$bn[$i]";
}
}
}



Thanks for any help.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mforeman is offline Offline
11 posts
since Sep 2005
Dec 9th, 2005
2

Re: Trouble Expanding a bus in PERL

Please put your code in [CODE] and [CODE] tags in the future, on any forum.

Quote originally posted by mforeman ...
Perl Syntax (Toggle Plain Text)
  1. for ($i = $l; $h; $i++)
This loop will terminate when the middle expression evaluates to a false value. You seem to want $i <= $h, not $h. ($h will just return something like 2 or 3 (whatever its value is), every time, and those are true values, causing the loop to run infinitely.)
Team Colleague
Reputation Points: 1135
Solved Threads: 173
Super Senior Demiposter
Rashakil Fol is offline Offline
2,480 posts
since Jun 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Perl Forum Timeline: A simple perl script
Next Thread in Perl Forum Timeline: Fields in HTML Form





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC