in reply to Problem with storing values

I don't think this is the right way to do what you want. According to Verilog::Netlist::Net, dump_drivers is for debugging purposes. Since it doesn't give many more details about what it does, you should not rely on it to provide output in a consistent manner. It could change any any time in the future.

Looking at the source code, dump_drivers prints to STDOUT. So, to capture its output into a variable, you'd probably have to use select. But, I don't think that's worth it.

The reason you see 0 but true is because that is the return value of the last statement executed by sub dump_drivers:

flush STDOUT;

You should gather all the info you need for each pin as you descend through the Verilog module hierarchy.

UPDATE: Again, I don't recommend it, but to capture the STDOUT, you could do something like:

my $fh; my $out; my $old_stdout; open $fh, '>', \$out; $old_stdout = select $fh; my $x = $pin->net->dump_drivers(); select $old_stdout; close $fh; print $out; # This has the output you want

Replies are listed 'Best First'.
Re^2: Problem with storing values (Verilog::Netlist::Net)
by mavericknik (Sexton) on Apr 16, 2015 at 19:58 UTC
    Thank you very much for your reply. Well, the reason I was trying to do this is I'm trying to reuse bits of code that one of my seniors wrote for something similar. It appears that the source code of "dump_drivers" has changed since he used it(a few years back). I tried your method using select, it does seem to work for now. Could you explain what exactly did you do there? The thing is, this is much easier for me to write code for the pins like this as I am cycling through all the pins in the design like so:
    foreach my $cell ($mod->cells) { foreach my $pin ($cell->pins) { $netdrivers = ($pin->net)->dump_drivers; } }
    Then I'm using the drivers to check some conditions. Maybe I could store all the pin drivers for the design beforehand and look them up when required, but this is just so convenient. Is the only reason you would now recomment obtaining the values from STDOUT be that the functionality of "dump_drivers" could change again at anytime? Or is there some other reason? Thanks!
      You're welcome.

      Yes, as I stated, I don't think you should use the dump_drivers output. The primary reason is that it can change in future versions of Verilog-Perl without notice.

      The module author provides some support at http://www.veripool.org/projects/verilog-perl/boards