in reply to Re^5: Perl Errors
in thread Perl Errors

So if I want global variables I need to use MAIN::Variable_Name = whatever ok a few questions. Do I have to supply a value when I declare it? Do I have to refer to it as MAIN::Variable_Name or will Variable_Name work? Can I call it within other blocks? And in my full code is there any reason it would fail to open the directory?

Replies are listed 'Best First'.
Re^7: Perl Errors
by ww (Archbishop) on Mar 27, 2012 at 22:07 UTC

    Short answers:

    1. No.
    2. No
    3. (Usually) the latter
    4. You don't generally "call" a variable, but if you mean can you make use of it, yes
    5. Several

    This series of questions practically begs for a near-complete Perl tutorial. It seems that's what you need. So please read some documentation; a book; or examples of working code here in the Monastery, rather than jumping to unwarranted conclusions.

      I withdraw this post and replace with: You were right. Reading a basic tutorial and paying attention to chomp would help. Sorry I'm not used to /n being auto included. Usually I have to tell the program to start a new line.
        chomp() will remove the end of line character(s).
        On Windows these will be 0xOA, 0x0D.
        On Unix this just 0x0D.

        Perl is permissive about what it receives for a text line. chomp() will remove the end-of-line character(s) - might be 1 or might be 2 bytes.

        When Perl writes a line: print "something\n"; , that \n may be one or two characters depending upon the OS and the context (network communication uses 0xOA, 0x0D - no matter what the OS) - but Perl knows about this and does the "right thing".

        If I transfer a file from Windows to Unix, sometimes I need to do something like this to "convert" the file:

        while (<STDIN>) { chomp; #remove line endings print "$_\n"; #write this OS's line ending }
        "chomp()" is your friend as opposed to "chop()". chop() is seldom used.
        The 'C' functions that read lines do the "chomp" automatically for you.
        In Perl you have to do this yourself.