# Basic perl code

**URL:** <https://community.unix.com/t/basic-perl-code/291115>\
**Category:** Programming\
**Created:** [July 7, 2011, 6:46am UTC](https://community.unix.com/t/basic-perl-code/291115 "2011-07-07T06:46:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pspriyanka](https://community.unix.com/letter_avatar/pspriyanka/32/5_5575768a8748004e209b776fc1b2916d.png) [@pspriyanka](https://community.unix.com/u/pspriyanka)\
**Post date:** [July 7, 2011, 6:46am UTC](https://community.unix.com/t/basic-perl-code/291115/1 "2011-07-07T06:46:41Z")

</div>

hi,

can anybody explain me the below code. i am new to perl

==========================================

```nohighlight
$o_dups{$1} = 1 if /^\w+\t.{19}\t([^,]+),/;

```

==========================================

regards,  
priyanka

---

<div class="post-metadata">

**Author:** ![bartus11](https://community.unix.com/user_avatar/community.unix.com/bartus11/32/1418_2.png) [@bartus11](https://community.unix.com/u/bartus11)\
**Post date:** [July 7, 2011, 6:52am UTC](https://community.unix.com/t/basic-perl-code/291115/2 "2011-07-07T06:52:16Z")

</div>

It creates hash element in %o\_dups, with the key being extracted from 3rd field in TAB delimited line present in $\_. The extracted part is from the start of that field to the first comma.

---

<div class="post-metadata">

**Author:** ![Skrynesaver](https://community.unix.com/user_avatar/community.unix.com/skrynesaver/32/14143_2.png) [@Skrynesaver](https://community.unix.com/u/Skrynesaver)\
**Post date:** [July 7, 2011, 6:59am UTC](https://community.unix.com/t/basic-perl-code/291115/3 "2011-07-07T06:59:11Z")

</div>

```nohighlight
$o_dups{$1} = 1 if /^\w+\t.{19}\t([^,]+),/; 

```

man perlre for more info on regexes but a quick breakdown follows

```nohighlight
$o_dups{$1}=1 # set the value in the o_dups hash for the match capture ($1) to true 
 if /^\w+\t.{19}\t([^,]+),/;#if the regex matches

```

The regex itself breaks down as:

```nohighlight
/^ # beinning of line
\w+# one or more "word" characters, (ie. alphanumeric + "_")
 \t # a litteral tab
.{19} # any 19 characters
\t # a literal tab again
([^,]+) # A series of non "," chars in brackets so capture this as the first capture ($1 above)
,#followed by a comma
/ #End match

```
