in reply to Re: File manipulation only works when I split it into two files.
in thread File manipulation only works when I split it into two files.

Ah, nice, that does it. I vaguely remember trying to do it in one loop over but I don't remember how I did that. It didn't work, anyway.

Thank you.

  • Comment on Re^2: File manipulation only works when I split it into two files.

Replies are listed 'Best First'.
Re^3: File manipulation only works when I split it into two files.
by oko1 (Deacon) on Dec 03, 2008 at 02:31 UTC

    Doing it in one loop:

    #!/usr/bin/perl -w use strict; die "Usage: ", $0 =~ /([^\/]+)$/, " <filename>\n" unless @ARGV; $^I = ''; # We're really brave - no backup file! + while (<>){ next unless /./; # Skip empty lines tr/A-Z/a-z/; # Lowercase the lot s#^(?!http://)#http://#; # Prefix 'http://' if one is missing print; }

    If 'petpages' contains the following:

    foobar.com http://foo.int fOoBaR.nEt FoObAr.OrG

    then running the above script with 'petpages' as an argument results in the content being changed to this:

    http://foobar.com http://foo.int http://foobar.net http://foobar.org

    Update: Clarified phrasing a bit.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf