Hi I am looking for some help advice on a program I have been wrting for the past few days. What I would like to do is look through a list of filenames that I have already made up, I split the lines on a dot, and for the first part of the line that I call base if it is of the form rrv193 then 4 digits then cm then I rename that $base. Here is a piece of test code to show how I am attemting to do this, but the hash bit doesnt work. Is it because of the expression or becasue you cant do this in a hash? or have I got the wrong end of the stick
#!/usr/bin/perl #my hash which tries to "map" a regular expression to a a new name my %Ren2Dol = ( rrv193\d{4}cm => "RNF191", ); #pretend data line to teest my $line='rrv1931009cm.new090626'; #split the data line ($base,$rest)=split(/[\.\_]/,$line,2); #test print it to see that it split correxctly print "$base\n"; #try to see what new name would be my $newname=$Ren2Dol{$base}; print "$newname\n"; # a test print to make sure regular expression matches if ($line=~m/^rrv193\d{4}cm/) {print "line matched\n"}; if ($base=~m/^rrv193\d{4}cm/) {print "base matched\n"};

In reply to regular expression in a hash by lamasculo

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.