in reply to simple (in theory) regexp question
e.g.
or reading into arraymode and then building scalar (might be faster, but haven't tested it).sub ReadFile { my ($filename) = @_; local $/; # undef $/ for slurping in whole file open (FILE, $filename) or die "Error in reading from $filename: $!\n"; my $content = <FILE>; close (FILE); $content =~ s/^(?!--|\n).*\n//mg; # => see japhy's answer return ($content); } # ReadFile
sub ReadFile { my ($filename) = @_; open (FILE, $filename) or die "Error in reading from $filename: $!\n"; my $content = ""; while (<FILE>){ if ($_ eq "\n" # if empty line or /^\-\-/){ # or -- at the beginning $content .= $_; # then append } # if } # while close (FILE); return ($content); } # ReadFile
Best regards,
perl -le "s==*F=e=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"
|
|---|