Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Beginner confused with string matching

by mavericknik (Sexton)
on Apr 09, 2015 at 14:55 UTC ( #1122950=perlquestion: print w/replies, xml ) Need Help??

mavericknik has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I recently started learning perl because I need to write some code to modify some netlists. For now, I'm trying to figure out a script written by someone else. I mostly understand the logic, I'm stuck at a point where he uses a comparison.
if ($val =~ /^[ ]+Pin:[ ]*([^\.]*)\.([^ ]*)[ ]*out/) { $cellname = $mod->find_cell($1); $pin_connected = $2; }
How would I go about deciphering the thing after $val? Also, the verilog-perl module is used here. I'm struggling to figure out what the "$1" does in $mod->find_cell($1) Is it something related to perl? I could not find anything in the verilog perl module documentation. Thanks.

Replies are listed 'Best First'.
Re: Beginner confused with string matching
by hippo (Bishop) on Apr 09, 2015 at 15:08 UTC

    Welcome to the wonderful world of Perl.

    The thing after the $val is called a "Regular Expression" and is, arguably, one of Perl's finest features. You can read all about it at perlre and the tutorial at perlretut

    The $1 (and $2) fall out from the use of the regular expression and specifically the capture groups within it which are delimited by the parentheses, eg. whatever is matched by ([^\.]*) is stored in $1, etc. They are not related to anything specific in the verilog module.

    The documentation for Perl is also a strong point and I encourage you to become familiar with it and how to use it at the earliest opportunity. You can read it online or from your local machine with the handy perldoc command.

    If you are still stuck parsing the regular expression (regex) after this, then by all means ask further.

Re: Beginner confused with string matching
by Anonymous Monk on Apr 09, 2015 at 15:03 UTC

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1122950]
Approved by marto
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2022-12-08 19:55 GMT
Find Nodes?
    Voting Booth?

    No recent polls found