473,322 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Perl Won't Display URL Strings From A Text File

23
I'm having a small problem with a perl script. It's probably something very small that I'm overlooking, but I haven't been able to find anything that has helped.

I have a plain text file that contains some information from a few web pages. For instance:

Path-Name: http://blahblahblah.blahblah.htm
Content-Length: 2732
Last-Mtime: 1145848708
Document-Type: html*

<html>
<head>
<title>Blah Blah</title>
<style type="text/css">
::
::
</html>

At the top of all the html code is the url that the information is pulled from. What I'm trying to do is display the urls that are found in this text file. So I'm using the conditional statement:

if($line =~ /Path-Name:/i)
{
print $line;
}

What it returns is:

Path-Name:

However, there is no url printed. I know it can find it and the string is there, so why isn't it printing it.

Thank you again.
May 2 '07 #1
6 1566
miller
1,089 Expert 1GB
Your premise and data appear fine. So that leaves not enough information. Show us more of the script maybe we'll be able to help.

- Miller
May 2 '07 #2
try print out $line before the 'if' statement.
If $line print out the whole line, inside the 'if' statement should print out the whole line too.
May 3 '07 #3
alnoir
23
try print out $line before the 'if' statement.
If $line print out the whole line, inside the 'if' statement should print out the whole line too.
OK. That's interesting. It seems when I did that it prints out every line as expected. However, it is only printing the string up until the first space. After that, nothing else from the scalar '$line' is printed.

Why wouldn't it print out the entire content of the string?

Thank you.
May 4 '07 #4
alnoir
23
Your premise and data appear fine. So that leaves not enough information. Show us more of the script maybe we'll be able to help.

- Miller
I think this might explain more about how the code works.

The conditional statement is within a for-loop:

foreach $line (@weblist)
{
:
:
}

As described in the original post, you can see that this is where the $line scalar is coming from.

@weblist is an array of strings from the text file that contains the information from the web-pages. The code building it is:

#first it creates an array of lines from the web content to be searched
open (CONTENT, "spider.content.txt");
@weblist;
$k = 0;
for $weblist (<CONTENT>)
{
#file is being read and the array is being built
($weblist[$k]) = $weblist=~ /(\S+)/;
$k++;
}
close CONTENT;

spider.content.txt is the file that contains the web-page information, like the example in the original post.

I'm thinking that the problem is coming from how the array is being built from this file.

I hope this helps. Thank you for your help.
May 4 '07 #5
KevinADC
4,059 Expert 2GB
it looks like the regexp:

Expand|Select|Wrap|Line Numbers
  1. ($weblist[$k]) = $weblist=~ /(\S+)/; 
this gets the first occurance of one or more non-space characters and stores it in $weblist[$k]. This can only be one word (or whatever) up to the first space character in the string $weblist.
May 4 '07 #6
alnoir
23
Ah! You're right. I needed to do this for another part of the program and didn't need it there. So I did away with that and now it works fine. Thanks again.
May 5 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Xah Lee | last post by:
suppose you want to do find & replace of string of all files in a directory. here's the code: ©# -*- coding: utf-8 -*- ©# Python © ©import os,sys © ©mydir= '/Users/t/web'
4
by: Piotr Turkowski | last post by:
Hi! I've got some code in Perl and I have to have it in C, but my knowlege of Perl is < 0 :-(, so I need your help. here's the code. Thanks in advance. decrypt.pl #!/usr/local/bin/perl...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
1
by: josh.kuo | last post by:
First of all, I know this is a PHP news group, so my question may not be completely appropriate here since it involves some perl. I have read this post that dealt with a similar problem that I am...
1
by: andipfaff | last post by:
Hi there, I am fighting with my MysQL database in order to get french and cyrillic characters properly displayed on my website. I've created tables with latin1 charset. My Perl script on the...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
5
by: Davo1977 | last post by:
Analysing text files to obtain statistics on their content You are to write a Perl program that analyses text files to obtain statistics on their content. The program should operate as follows: ...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.