Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl regular expression meaning.. 1

Status
Not open for further replies.

mskasu

Programmer
May 1, 2009
5
GB
Hi experts,

I have inherited this script, can someone explain what does
/\s+(\d+):\s+-\*\s+-/ do in this script:

open(NSR,"nsrjb|") || die "no nsrjb";
while(<NSR>) {
next unless /\s+(\d+):\s+-\*\s+-/;
$freeslot[$1]++;
}
close(NSR);

Grateful for any help.

Regards,
sami
 
Hi

Code:
[gray]# if $_ variable's value not matches the given regular expression start the next loop, also set the $1..$9 variables to the captured substrings[/gray]
  [b]next[/b] [b]unless[/b] [green][i]/\s+([highlight]\d+[/highlight]):\s+-\*\s+-/[/i][/green][teal];[/teal]

[gray]# increment the $freeslot array's item indicated by the previously captured $1[/gray]
  [navy]$freeslot[/navy][teal][[/teal][highlight][navy]$1[/navy][/highlight][teal]]++;[/teal]
[teal]}[/teal]
[tt]\s+([highlight]\d+[/highlight]):\s+-\*\s+-[/tt] will match for example :
[ul]
[li]"[tt] [highlight]3[/highlight]: -* -[/tt]"[/li]
[li]"[tt]foo bar [highlight]2009[/highlight]: -* -[/tt]"[/li]
[/ul]
Where I marked the captured substring with [highlight]yello[/highlight].

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top