субота, 29 грудня 2012 р.

Matching Only Once regexp

Matching Only Once


http://www.tutorialspoint.com/perl/perl_regular_expression.htmThere is also a simpler version of the match operator - the ?PATTERN? operator. This is basically identical to the m// operator except that it only matches once within the string you are searching between each call to reset.

For example, you can use this to get the first and last elements within a list:

  #!/usr/bin/perl    @list = qw/food foosball subeo footnote terfoot canic footbrdige/;    foreach (@list)  {     $first = $1 if ?(foo.*)?;     $last = $1 if /(foo.*)/;  }  print "First: $first, Last: $last\n";    This will produce following result  First: food, Last: footbrdige

Немає коментарів:

Дописати коментар