CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Perl script migration

 



abhisri
Novice

Jun 17, 2006, 6:48 AM

Post #1 of 6 (740 views)
Perl script migration Can't Post

Hello

I was given a perl script working on NT environment and asked to make changes to run the script on solaris environment. This script is moving files to folders. i.e backing up folders.

This script uses .ini file for rules. I changed the path to port to solaris environment and when I run the script its recognizing the path and then throws an error at the following condition... am new to perl and wonder why its going wrong

if (! ($dir_dst = ~ /^[\w\s\\\$\.\-:]+$/i && -e $dir_dst))

{

$err_code = "Error. Destination Directory \$DIR_DST=$dir_dst. Invalid name structure or does not exist.";

goto EXIT;

}

My folder in .ini file is /home/sridhar/To_Sridhar

the script is reading the folder and printing it and says when I checked the directory using script it says directory exists

Thanks for the help

Sridhar


davorg
Thaumaturge / Moderator

Jun 19, 2006, 5:27 AM

Post #2 of 6 (736 views)
Re: [abhisri] Perl script migration [In reply to] Can't Post

You are using a regex to check that the directory name is valid before checking for the existance of the directory. The regex is checking for word characters (\w), whitespace (\s), backslashes (\\), dollar signs (\$), dots (\.), dashes (\-) and colons (:). If your directory name contains anything other than those characters then the match fails and you'll get an error message.

Of course, your new directory name contains characters that aren't on that list. Therefore the regex will always fail and you'll always get the message.

You need to change the regex so that it checks for valid characters in a Unix directory name.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


abhisri
Novice

Jun 19, 2006, 5:38 AM

Post #3 of 6 (734 views)
Re: [davorg] Perl script migration [In reply to] Can't Post

Hello



Thanks for the reply. It would be a great help for me if you could show me what needs to be changed in the regexp to match it to unix environment.

This condition works fine on NT environment and fails in unix environment.

My folder structure is /home/sridhar/To_Sridhar

Thanks in advance

Sridhar


davorg
Thaumaturge / Moderator

Jun 19, 2006, 5:48 AM

Post #4 of 6 (731 views)
Re: [abhisri] Perl script migration [In reply to] Can't Post


In Reply To
It would be a great help for me if you could show me what needs to be changed in the regexp to match it to unix environment.


Well I think I was pretty explicit. Look at the list of characters that I said the old regex matches and compare that with the differences between Windows and Unix paths.

For more help you could try reading the documentation - perldoc perlretut is a tutorial on regular expressions and perldoc perlre is the definitive reference.

You might think that I'm being a bit obstructive by not just giving you the answer, but I think it's far more useful for you to work it out for yourself.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


abhisri
Novice

Jun 19, 2006, 6:01 AM

Post #5 of 6 (729 views)
Re: [davorg] Perl script migration [In reply to] Can't Post

Hello

You are 100% right.. and I will work it out hope its simple...if I read your first reply thoroughly i would get the answer there it self...

thanks again for the help



Sridhar


davorg
Thaumaturge / Moderator

Jun 19, 2006, 6:12 AM

Post #6 of 6 (728 views)
Re: [abhisri] Perl script migration [In reply to] Can't Post


In Reply To
if I read your first reply thoroughly i would get the answer there it self...


Remember there are two kinds of slashes...

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives