Hi Deib,

Sorry for the delay in my response. I've been out of town since Jan. 5 and I just got back yesterday.

Are you creating the data file you're using? If so, it seems like you're creating extra work for yourself. It seems like the first line is the root of the site (or site folder) and the second line is the path to the page. Why don't you simply load the file with the lines that represent the paths to the pages and use these to parse out the site paths?

You could use the File::Basename module to parse the page paths. Consider this:

#!/usr/bin/perl use strict; use File::Basename; my @paths = ( 'www.google.com/folder/', 'www.google.com/folder/onething.htm', 'www.hotmail.com/folder/', 'www.hotmail.com/folder/anotherthing.htm', 'www.hotmail.com/folder' ); foreach my $path ( @paths ) { print "PATH: $path\n"; # This line does all the work. my ($base, $dir, $ext) = fileparse( $path, '\.[^.]*' ); printf "DIR: $dir\nBASE: $base\nEXT: $ext\n\n"; }

The commented line in the foreach loop is doing all the parsing work. It splits the path you give it into three pieces: The directory path to the file, the basename (the part of the file name before the extension), and the extension (the part of the file name after the final period.) Of course, if the file name does not contain an extension, the entire part after the final slash is returned as the basename.

This is certainly a more efficient way to process the input file since it reduces the number of lines you have to process by 50%. Of course, if you have to use the file the way it stands in the example you provided, this might not help as much. :)

Without knowing exactly what it is you're trying to do, I'm afraid I'll spend a lot of time guessing what your requirements are.

Let me know if you have other questions or if this is unclear.

HTH,

/Larry


In reply to Re^3: How to eliminate "/n" from text by larryp
in thread How to eliminate "/n" from text by Deib

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.