For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > January 2006 > How to handle "\" indicating next line









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How to handle "\" indicating next line
Khairul Azmi

2006-01-10, 4:01 am

Hi all,
I am writing a code that would check line by line content of a line before
processing it. Problem occurs when there are lines that has character "\"
indicating a new line. For example

preprocessor http_inspect: global \
iis_unicode_map unicode.map 1252

When that happen, my code should be able to grab the whole phrase. My
current code would only capture up to "global \". Thanks in advance.

if (open (INFILE,"$snort_file")) {

while (<INFILE> ) {
my $line = $_;
if ($line !~ /^[[:space:]]*#.*$/) { # handle lines start with #
if (/\S/) { # handle empty lines
my @field = split;

} elsif ($field[0] eq "preprocessor") {
get_preprocessor ($line);
}

usenet@DavidFilmer.com

2006-01-10, 4:01 am

Khairul Azmi wrote:
> I am writing a code that would check line by line content of a line before
> Problem occurs when there are lines that has character "\"
> indicating a new line.


Would something like this help?

#!/usr/bin/perl

local $/; #slurp mode
local $_ = <DATA>;
s!/\n\s*!!g;
print;

__DATA__
this /
is /
some stuff
this is more stuff

### OUTPUT ################
this is some stuff
this is more stuff

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com