CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



mhinkle
New User

Oct 1, 2012, 10:37 AM

Post #1 of 3 (1030 views)
Mr.BlindNewB regarding spacing Can't Post

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

Post #2 of 3 (1024 views)
Re: [mhinkle] Mr.BlindNewB regarding spacing [In reply to] Can't Post

Yes, both versions will produce the same result.


BillKSmith
Veteran

Oct 1, 2012, 1:30 PM

Post #3 of 3 (1024 views)
Re: [mhinkle] Mr.BlindNewB regarding spacing [In reply to] Can't Post

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

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives