Rather than just blindly giving you an answer or accuse you of cheating on homework, I will try to explain what your code is doing. That way you can fix it yourself and maybe learn something in the process.
$path = hiec/by/mlor/kkss23/dndd@@mani/css.cpp/0
You are trying to assign a string to a variable. This won't work without quotes and a trailing semicolon. It is also a very good habit to add use strict; at the beginning of your program an use my on all of your variables. This is not required but it will save you a lot of headaches in the long run.
$path =~ (m/\d+$\/);
I think you have a typo. What you are doing is looking for digits followed by the value of the $\ special variable ($\ is the $OUTPUT_RECORD_SEPARATOR). I don't think this is what you want. I will take the liberty of changing the typo to what I think you want.
$path =~ (m/\d+$/);
Hmmmm. This line does essentially nothing. You are checking if there are numbers at the end of the string stored in $path. But you are not using the return value to see if the match succeeded and you are not capturing anything in the regexp. A simple match does not alter the string either. If you want to capture the digits you will have to add parentheses arround the \d+. If you want to change $path use a search/replace ( s/// ) operator. But be carefull. If you do something like a $path =~ s/.*?(\d+)$/$1/; and $path doe not end in digits $path will not be changed. Since you are doing a numeric compare below, the number that will be used will be the digits at the start of $path!

Here is the way I would do it.

use strict; my $path = 'hiec/by/mlor/kkss23/dndd@@mani/css.cpp/0'; if ($path =~ m/(\d+)$/ and $1 == 0) { # ends in zero } else{ # not zero or no digits }
What I do is check if $path ends in digits. If it does not, the compare on the right side of the and never is executed and the if statement fails so control goes to the else block. If $path ends in digits then the digits are captured into $1 due to the parentheses. $1 is compared to zero. If it is zero the first block is executed. If not then the else block is executed.

OK, so I gave you code. I hope you understand it. If you do and are getting help on homework then all the better. Understanding Perl is what the homework is all about.

--

flounder


In reply to Re: checking the end of line by flounder99
in thread checking the end of line by Sara

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.