l i n u x - u s e r s - g r o u p - o f - d a v i s
Next Meeting:
July 7: Social gathering
Next Installfest:
Latest News:
Jun. 14: June LUGOD meeting cancelled
Page last updated:
2002 Jan 12 21:10

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] dumb perl question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] dumb perl question

On Sat, 12 Jan 2002, Peter Jay Salzman wrote:

> i know i should know this by now...
> how does one get assignments out of a backreference from a regex match?

By evaluating the match in a list context.  See "man perlop" under "Regexp
Quote-Like Operators".


   print join( ":", "100.extra" =~ /(\d+)\.(.*)/), "\n";

What you do with the resulting list is up to you, and if you only put one
pair of parentheses in the match, your list will only include one item.
When you join the list into a scalar, it will "concatenate" all "one" 
of the list items together, so

  $_ = "100.extra";

  $num = join '', /(\d+)/;

pulls the first sequence of one or more digits out of the string and puts
it into $num.

As far as I know, creating a list context means the left hand side of the
assignment must be a list, or you have to call a function that expects a
list (such as join).


Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...2k

vox-tech mailing list

LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
EDGE Tech Corp.
For donating some give-aways for our meetings.