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:
Newlines - empty lines in code

 



Chris Charley
User

Jun 2, 2013, 9:08 AM

Post #1 of 6 (444 views)
Newlines - empty lines in code Can't Post

Why doesn't posted code preserve the empty lines anymore?


FishMonger
Veteran / Moderator

Jun 2, 2013, 9:20 AM

Post #2 of 6 (439 views)
Re: [Chris Charley] Newlines - empty lines in code [In reply to] Can't Post

Probably because you didn't use the code tags.

Please provide an example both as posted directly in the comment and the same code as a file attachment.


Chris Charley
User

Jun 2, 2013, 9:58 AM

Post #3 of 6 (436 views)
Re: [FishMonger] Newlines - empty lines in code [In reply to] Can't Post

I did use code tags and that's not the problem. However, I'll post this example and attach the file.

Code
#!/usr/bin/perl 
use strict;
use warnings;

my $filenameUNIX = "Unixlist";
my $filenameNON = "Nonprod";

open my $fh, "<", $filenameUNIX or die $!;
my $slurp; do {local $/; $slurp = <$fh>};
close $fh or die $!;

my $joined = join "|", sort {length $b <=> length $a} split /\n/, $slurp;
my $re = qr/\b(?:$joined)\b/;

open my $non, "<", $filenameNON or die $!;
open my $FOUND, ">", 'itemfound' or die $!;
while (<$non>) {
print $FOUND $_ if /$re/;
}
close $non or die $!;
close $FOUND or die $!;

Attachments: t33.pl (1.40 KB)


FishMonger
Veteran / Moderator

Jun 2, 2013, 10:14 AM

Post #4 of 6 (433 views)
Re: [Chris Charley] Newlines - empty lines in code [In reply to] Can't Post

Line spacing and indentation (which is only 1 of the lines) match.

What's the problem?


Laurent_R
Veteran / Moderator

Jun 2, 2013, 11:47 AM

Post #5 of 6 (430 views)
Re: [FishMonger] Newlines - empty lines in code [In reply to] Can't Post

Looks OK to me too.

Wink


FishMonger
Veteran / Moderator

Jun 2, 2013, 1:36 PM

Post #6 of 6 (422 views)
Re: [Chris Charley] Newlines - empty lines in code [In reply to] Can't Post

BTW, the hash lookup approach I showed in your other question is more efficient than that regex approach, especially if there are lots of entries in the "Unixlist" file.

The only valid reason I can see for using the regex approach would be if that was the requirement for a class homework assignment.

EDIT:
I just realized that the other thread was from mike3point0, which also leads me to believe that this is a class homework assignment.


(This post was edited by FishMonger on Jun 2, 2013, 1:46 PM)

 
 


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

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