Dear monks,

I've been using the code below to match some files in the path described in the code. However I'm getting a "Use of uninitialized value $_ in pattern match (m//)" error.

#!/usr/bin/perl/ use strict; use warnings; my $i; my $j; my $k; my $l; my $id = "AC"; my $moved; for ($i=2; $i<=3; $i++) { my $j = sprintf ("%04d", $i); for ($k=1; $k<=3; $k++) { my $l = sprintf ("%05d", $k); my $path; $path = "/home/results/initial/$id$j/F${l}"; chdir "$path"; /MV(\d{4})/; $moved = $1; print "$moved\n"; } }

I seem to be getting this error even though I have changed directory into the directory specified in the path - which is something I don't want to do, I want to give the absolute path each time, but I was just trying to see if it would solve my problem. I also ran the script using perl -wc to check syntax/warnings but it comes back as "syntax correct". Also, if I do print `ls $path/MV*`; it finds the files fine and prints them. What do you think could be the source of my problem?


In reply to Use of uninitialized value $_ in pattern match (m//)? by fasoli

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.