Artimus has asked for the wisdom of the Perl Monks concerning the following question:

Hi , Wizards!

I have some troubles with authomatic opening of file descriptors. we have $adress(defined way like $adress="PATH1") which changes going threw the cycle(it changes to PATH2, PATH3, etc.) and here

open $adress, ">", "$adress.mailbox";

the Perl reports about error. if i can't use the string there in the 1st including of it in the code,- How can I create automatically opening for various amount of e-mails(this amount will depend on file I'm trying to process)? completely lost trying to solve it((

ahah,found out about no strict 'refs', - and IT WORKS!!!no more help needed=)

Replies are listed 'Best First'.
Re: Troubles with descriptors
by Old_Gray_Bear (Bishop) on May 12, 2013 at 21:46 UTC
    You said: "the Perl reports about error." What did 'the Perl' actually say? With out the error message, I am guessing in the dark here.

    If you are running out of file-descriptors (which is how I interpret your question), are you closing the @adress file handle after you are done with the mailbox? If not, I can easily see how you are running up against the file-descriptor limit. (This is one of the classical examples of a 'memory leak', acquiring a resource but not returning it.) But, with out the actual error message, this is just hypothesis in vacuuo

    Also, while I commend your use of the three argument open(), I have to fault your assumption that the open can't ever fail. Try this construct instead:

    open $adress, ">", "$adress.mailbox" or die("Can't open $adress.mailbo +x -- $!\n");

    ----
    I Go Back to Sleep, Now.

    OGB

      Can't use string as a symbol ref while "strict refs" in use

      thank you, kind man=), I've solved it with:

      no strict 'refs';

        Except that you solve it the wrong way. Don't do that. Or use the "no strict refs" pragma only if there is an excellent reason to do it, i.e. probably never until you reach the level of Perl super-guru doing pure black magics.

        Here, all you need to do is to declare your variable with the 'my' function:

        open my $adress, ">", "$adress.mailbox";

        I would just add that you should not open a file without testing if it worked. So this would most probably be better:

        open my $adress, ">", "$adress.mailbox" or die "could not open mailbox $!\n";