in reply to Please help me

Hi

To expand a little on what jwkrahn said:

Your foreach loop probably is executing, but because  @INFFiles = `dir /b $filespec`; doesn't do what you think, it's only executing once. Backticks (`...`) return a string with the output of the command. If you wanted the filenames in a list, you'd have to split up the string yourself.Edit: wrong diagnosis. But I would still use a built-in way such as glob or readdir, rather than invoke an external command.

Perl already has ways to get a list of filenames. Perhaps the simplest replacement would be:

@INFFiles = glob($filespec);

If you use that, you won't need to chomp or prepend $path in the foreach loop.

Regarding $VersionNumber =~ s/^\d+\.\d+\.\d+\.\d+//g;, I'm not sure if this is a mistake or not, since it will remove everything except digits (0-9), '+' and '.':

$ perl -ple 's/[^\d+\.\d+\.\d+\.\d+]//g' This has no numbers, dot or plus This has 1 dot. 1. This has 1234567890 + . 1234567890+.

It can be simplified to:

$ perl -ple 's/[^.\d+]//g' This has no numbers, dot or plus This has 1 dot. 1. This has 1234567890 + . 1234567890+.

Since it is being used to clean up a version number, I think it is probably meant to be s/[^0-9.]//g - remove everything except digits and dot. Since you've already stripped everything out of version number, the next two lines (strip \x0d and chomp) seem unnecessary.

Finally, use strict; and use warnings; at the top of your script ( if you don't already ). And don't use function prototypes ( the $$$ in sub FileVersion($$$) ) - they don't do what you want.

FalseVinylShrub

Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.

Replies are listed 'Best First'.
Re^2: Please help me
by Jenda (Abbot) on Feb 12, 2010 at 10:15 UTC

    No he doesn't have to split the result of `command`. It gets split into lines in list context. The problem is that the newlines stay. So you do have to chomp() the elements.

    Jenda
    Enoch was right!
    Enjoy the last years of Rome.

      Hi

      Oops. Thank you.. Can't believe I didn't know that. Amended post.

      However, now confused as s/he does chomp() the elements, it seems to me. So I can't see what the problem is.

      FalseVinylShrub

      Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.

Re^2: Please help me
by mtrasp (Acolyte) on Feb 18, 2010 at 08:15 UTC

    Thank you very much for your Clear Explanation.First it gave me error Because Filespec path is wrong.but now $versionNumber is not coming correctly means it is taking another value. For example it is coming as 10.12.12.10 instead of 6.2.2.4.what may be the problem .$version Number is Taking another un related value. some times correct $versionNumber is coming Some times Not.so Initilization of $versionNUmber is Good idea?

      Hi

      No worries...

      Afraid I can't help with your new problem, because (a) I am ill and my brain isn't working (b) it's not clear enough. Try to post a cut-down sample that shows the problem, with sample input and output. See the "How to post a good question" link already posted. You may want to start a new thread, so more people see it.

      FalseVinylShrub

      Disclaimer: Please review and test code, and use at your own risk... If I answer a question, I would like to hear if and how you solved your problem.