Home: Perl Programming Help: Beginner:
Mr.BlindNewB regarding spacing



mhinkle
New User

Oct 1, 2012, 10:37 AM


Views: 2026
Mr.BlindNewB 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;
}


Laurent_R
Veteran / Moderator

Oct 1, 2012, 1:19 PM


Views: 2020
Re: [mhinkle] Mr.BlindNewB regarding spacing

Yes, both versions will produce the same result.


BillKSmith
Veteran

Oct 1, 2012, 1:30 PM


Views: 2020
Re: [mhinkle] Mr.BlindNewB regarding spacing

Your modified code should work fine.

A good project for you would be to write a perl program to make your modifications for you. The following one-liner is a good start.

Code
perl -pe "$_ .= qq( \n )" myscript.pl


This works on windows. You may have to change the double quotes to single quotes on other systems.

For now, you can redirect the output to a file to save it.
Add that feature to your own program.
Good Luck,
Bill