James G. Sack (jim) wrote:

RBW wrote:
James G. Sack (jim) wrote:

RBW wrote:


I'm a complete noob at Perl so please bear with me... I basically
cobbled this together.

I'm getting this effect in the output file:

|| shExpMatch(url, "      ad.be.doubleclick.net
")|| shExpMatch(url, "      ad.harmony-central.com
")|| shExpMatch(url, "      ad.img.yahoo.co.kr
")|| shExpMatch(url, "      ad.sales.olympics.com
")

...

")|| shExpMatch(url, "adopt.specificclick.net
")|| shExpMatch(url, "adpick.switchboard.com
")|| shExpMatch(url, "adpulse.ads.targetnet.com
")|| shExpMatch(url, "adq.nextag.com

From this perl code:
#!/usr/bin/perl
#######################################################
open(MYINPUTFILE, "<AdBlockList-Hosts-4May06.test");             # open
for input
my(@lines) = <MYINPUTFILE>;                                      # read
file into list
@lines = sort(@lines);                                           # sort
the list
my($line);

move the next line



chomp($line);                                               # I thought
this was to eliminate the newline in the inputfile...

$appendString = '")';

foreach $line (@lines)                                           # loop
thru list
{
to here
(and see what happens)



print
"$line"."$appendString"; # print in sort order
}

close(MYINPUTFILE);

exit;



Which is fine but I need each line to look something like this where the
string   '")';   is at the end of the line and there is a newline after
that, like this:
|| shExpMatch(url, "      ad.be.doubleclick.net")
|| shExpMatch(url, "      ad.harmony-central.com")
...


When I am done and everything is cleaned up format wise I am going to
pipe this long list to a file like so:
[EMAIL PROTECTED] applications]$./testAppend.pl > outputTestAppend.txt

I think this is just a formatting problem but I'm not sure.

TIA,
RBW




Bing-GO!!

Thanks Jim that worked just fine.
I also put a newline like so:

print "$line"."$appendString\n";

And it worked...

Now I have a few lines that have a quote mark followed by one space in
some cases and six spaces in other cases which need to get replaced by
just a quote mark... I'll let you know how it goes...




You will probably end up with something like

 $line =~ s/"\s+/"/;


You may also wish to ask yourself whether the de-space should be
performed before the sort?

..j

I stuck it right in the loop and it rendered perfectly in the output. Are there any efficiency plusses or minuses with this aproach so far (elegance vs. brute force)? Like I said it is working fine but I know the minute you go past a few lines you should keep your eyes out for unnecessarly taxing or sucking up resources...

I'm fixing up a proxy.pac file for someone BTW...

Can you point me in the right direction for inserting this list as is in the output file into the proxy.pac file (just the clues and hints for now so I can track it down myself ;^). I will just be cutting and pasting for now but I am interested in making this list and another get inserted at a given place in the proxy.pac file via code.

Thanks!
RBW

--
[email protected]
http://www.kernel-panic.org/cgi-bin/mailman/listinfo/kplug-lpsg

Reply via email to