Hello

I'll try explaining what this code does. But first: about regular expressions.

Without getting too technical, Regular Expressions are one way of describing a set of words. So, when we say

if ($str =~ /some_re/){ do something ... }
what we're really doing is asking if the string belongs to the set described by the regular expression.

I don't (and can't) explain the whole of perl's regular expressions but I'll explain enough to make you understand the code segment.

foreach (qw/one one.five two two.one two.ten two.ten.12 three three.nine four five/){ print "$_\n"; if($_ =~ /\./){ # if the word has a dot ".". # Keep everything after the last "." in the string my ($label) = /\.([^\.]*)$/; # a dot, followed by zero # or more letters that are # not dots, attached to the # end of the string. # return those letters # since they're between # brackets. $tree->add($_, -text => $label , # add the label to $tree -image => $mw->Getimage(folder)); } }
Hope this helped

Aziz,,,

Update: Thanks blakem for pointing out the need for escapes for \] in <pre> tags.


In reply to Re: About regular expression by abstracts
in thread About regular expression by benlaw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.