in reply to Re^2: Help with exercise
in thread Help with exercise

Yes, agreed ++. Here, I wanted to keep it simple in the context of an exercise.

Although, to tell the full truth, I am not sure I would really check the chdir return status after I have checked that $dir contains a valid directory entry in the current directory (I know it might still fail for various reasons, such as missing privileges, but this is quite unlikely in my context and, sometimes, there is a trade-off between code complexity and coding efficiency). Or I might probably use the autodie module in such a context with a lot of system calls.

Update: or, as suggested by Random_Walk, we might go the other way around and let chdir do the checks.

Replies are listed 'Best First'.
Re^4: Help with exercise
by karlgoethebier (Abbot) on Sep 24, 2017 at 16:11 UTC

    BTW, mkpath from Path::Tiny does it all, less or more:

    "...Errors will be trapped and an exception thrown. Returns the list of directories created or an empty list if the directories already exist, just like make_path."
    karls-mac-mini:monks karl$ perl -MPath::Tiny -E 'say path (q(/foo/bla) +)->mkpath' /Users/karl/Desktop/bla karls-mac-mini:monks karl$ perl -MPath::Tiny -E 'say path (q(/foo/bla) +)->mkpath' karl-mac-mini:monks karl$

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help