#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    1
    Rep Power
    0

    Mr.BlindNewB question regarding spacing


    Hello,
    I have just started to learn Perl. I am not a programmer (yet).
    All of the examples I find have no spaces between lines and I am getting older so its harder for me to see and thus understand, so I’d like to add spaces (newlines, whitespace) in my programs—is this acceptable?
    I am including an example below of a program example I found and the way I have modified it to make it easier for me to understand and see.
    Can someone tell me if these two scripts will produce the EXACT same results?
    Or if my modifications change the functionality of it?


    Original:
    #!/usr/bin/perl
    @lines = `perldoc -u -f atan2;`;
    foreach (@lines) {
    s/\w<([^>]+)>/\U$1/g;
    print;
    }

    Modified:
    #!/usr/bin/perl

    @lines = `perldoc -u -f atan2;`;

    foreach (@lines)
    {
    s/\w<([^>]+)>/\U$1/g;
    print;
    }
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,593
    Rep Power
    4207
    It is perfectly acceptable to add spaces, newlines etc., as perl will not care about indentation. As long as you use a consistent style that you're comfortable with, that's all that really matters.

    The two scripts you've posted should work exactly the same.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,221
    Rep Power
    1809
    Perl doesn't care about whitespace for the most part, so you can add plenty of it. There is an option to allow regexes to span multiple lines as well.

    You'll need to put your code inside code tags on the forum though to preserve formatting. The little pound sign thing on the forum toolbar will wrap your code, or you can type them manually.

    [code]
    #!/usr/bin/perl
    etc
    [/code]
    Last edited by ishnid; October 1st, 2012 at 05:10 PM. Reason: Make [code] tag clearer by removing space.

IMN logo majestic logo threadwatch logo seochat tools logo