I have a log file that lists several things each line, which conist of things like IP, time, URL, and Title.. I have a ForEach command that lists every URL, and I want it to list every title too. Like if in the log file it says: (By the way...I use |+| as a sperator..) 127.0.0.1|+|1004565225|+|http://www.blahblah.com/whatever.html|+|Whatever HTML's Title It will list it, for example, like this in the ForEach: ...stuff...http://www.blahblah.com/whatever.html...more stuff.. I want it to also show the title... so it'd be like: ...stuff...http://www.blahblah.com/whatever.html...Whatever HTML's Title...more stuff... Here's the entire code I'm working with...and I know some of you Monks out there will say I code sloppy, and I do, and try and recode the entire thing. Please don't. I just need to know how to do this, because nothing I try works.. and I have tried everything I know..
use CGI qw(param); require "config.txt"; $refresh="60"; $ip=$ENV{'REMOTE_ADDR'}; $time=time; open(FILE,$log); flock (FILE,3); @users=<FILE>; close(FILE); foreach $lines (@users){ chop($lines); ($ips,$times,$locationold,$titles)=split('×',$lines); $timeoff=$time-$times; push @titlez,$titles if (!$exists{$titles}); push @locations,$locationold if (!$exists{$locationold}); $exists{$locationold}=1; $exists{$titles}=1; ${$locationold}{online}++; } $line="$ip×$time×$place×$title"; ${$location}{online}++; foreach $loc (@locations){ if(${$loc}{online} < "2") { ${$loc}{users} = "user"; } else { ${$loc}{users} = "users"; } }
... And here comes the last and final method I tried...
foreach $ttl (@titlez){ #chop($ttl); ($titlea)=split('þ',$ttl); push @titleb,$titlea if (!$exists{$titlea}); $exists{$titlea}=1; } foreach $loctitle (@titleb){ $online++; }
...The part above I know I don't need, because it doesn't work..
if($online < "2") { $users = "user"; $userz = "User"; } else { $users = "users"; $userz = "Users"; } $nocache = "<meta http-equiv='PRAGMA' content='nocache'>\n"; $nocache .= "</head>"; print "Content-type: text/html\n\n"; open (FILE,"<$header"); while( $tmplh = <FILE> ) { $tmplh =~ s/<<UO\:\:Number>>/$online/g; $tmplh =~ s/<<UO\:\:Users>>/$userz/g; $tmplh =~ s/<\/head>/$nocache/g; print $tmplh; } close(FILE); foreach my $loc (sort {${$b}{online} <=> ${$a}{online}} @locations) { if ($loc eq "" || $loc eq "Unknown" ) { $area = "Unknown"; } else { if ($loc =~ /http:/i && $loc ne "") { $area = "<a href=\"javascript:opener.location.href='$loc';location.hre +f='$where';\"><acronym title=\"$loctitle\">$loc</acronym></a><\!-- Ti +tlez: @titlez --><!-- TitleB: @titleb --><!-- Locations: @locations - +->"; } else { $area = "$loc"; } } open (FILE,"<$middle"); while( $tmplm = <FILE> ) { $tmplm =~ s/<<UO\:\:Number>>/${$loc}{online}/g; $tmplm =~ s/<<UO\:\:Users>>/${$loc}{users}/g; $tmplm =~ s/<<UO\:\:Page>>/$area/g; print $tmplm; print "\n"; } close(FILE); } $showon = "$online $users"; # If you even dare try to edit ANYTHING between here... $cr = "<font face='Arial' size='1' color='#CCCCCC'><i>Powered By <a hr +ef=\"javascript:alert('Don\\'t laugh, but currently, Kage is siteless +.');\"><acronym title=\"Powered By UzerzOnlyne v$version\">UzerzOnlyn +e v$version</acronym></a></i></font></center>\n"; # and here, that will make this script against the Copyright that was +placed upon it. Don't even # try it. That is your only warning. $cr .= "</body>"; open (FILE,"<$footer"); while( $tmplf = <FILE> ) { $tmplf =~ s/<<UO\:\:ShowOnline>>/$showon/g; $tmplf =~ s/<\/body>/$cr/g; print $tmplf; } close(FILE);

In reply to ForEach Command struggle.. by Kage

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.