Hence i am not getting the things.

What does this mean? I already explained it to you: If you ask good questions, like you've done a few times so far, we can give good answers. If you ask questions that can't be answered because you haven't provided enough information, not only will you not get good answers, you will lose support from more and more monks as you go on. I gave you three links to read, please do so, and always follow that advice!

Your code looks ok to me (Update: however, you should take stevieb's advice, as well as hippo's advice to Use strict and warnings) and when I set $output_dir to an input file name, it seems to work. However, only you know what all of your specifications are, and what all of your input looks like, so I can't tell you if your code will always work, at the moment only you can confirm that your code fully works. Testing is an important skill, and what I can do is show you how you might go about this. For example, you can test whether your code, properly modularized into a subroutine, works for various test inputs. Here, I'm using in-memory files (open) and Test::More. Note how I've left your logic entirely unchanged.

#!/usr/bin/env perl use warnings; use strict; sub scan_handle_for_rev { my $filehandle = shift; my $first_line = 1; my $max_id; while (<$filehandle>) { if (/rev(\d+)/) { if ($first_line) { $first_line = 0; $max_id = $1; } else { $max_id = $1 if ($1 > $max_id); } } } return $max_id; } use Test::More; { open my $fh, '<', \<<'END_TEST_INPUT' or die $!; | |-- action.txt | `-- rev2 | `-- rev1.html `-- add.html END_TEST_INPUT is scan_handle_for_rev($fh), 2; close $fh; } { open my $fh, '<', \<<'END_TEST_INPUT' or die $!; |--action | |-- action.txt | `-- rev1 | | `-- rev1.html | `-- rev2 | `-- rev1.html `-- add.html END_TEST_INPUT is scan_handle_for_rev($fh), 2; close $fh; } { open my $fh, '<', \<<'END_TEST_INPUT' or die $!; |--action | |-- action.txt | `-- rev1 | | `-- rev1.html | `-- rev13 | | `-- rev1.html | `-- rev2 | `-- rev1.html `-- add.html END_TEST_INPUT is scan_handle_for_rev($fh), 13; close $fh; } done_testing;

In reply to Re^3: How to take only maximum directory name by using its digits using perl? by haukex
in thread How to take only maximum directory name by using its digits using perl? by finddata

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.