Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Useless use of substr in void context

by jweed (Chaplain)
on Feb 20, 2004 at 04:25 UTC ( [id://330455]=note: print w/replies, xml ) Need Help??


in reply to Useless use of substr in void context

Well, no one would get "trapped" in you if statements if you indented your code. That would help both you and the raving lunatic who will have to maintain your creation. ;)

Here, the warning is actually helpful. The thing to note here is that substr doesn't work like splice in that the position you higlight by LENGTH and OFFSET (see the docs) isn't removed it is just identified. So with this substr, you tell perl go to the beginning of the string $links and look at one character. But you neither store that character anywhere or change it, which makes it void context. You don't change the string, and you don't store what you've found. So perl thinks somethings fishy.

If you want to remove that first character try:
substr($links, 0, 1) = undef; or even substr($links, 0, 1, undef);


HTH.



Code is (almost) always untested.
http://www.justicepoetic.net/

Replies are listed 'Best First'.
Re: Re: Useless use of substr in void context
by mkurtis (Scribe) on Feb 20, 2004 at 04:56 UTC
    yep you got it jweed, thanks. However this code doesn't work, It doesn't print $content or append anything to urls.txt. My Perl is terrible, so I don't understand why. I just cross my fingers and run it. Thanks
      It doesn't print any content because the while at the top exits immediately.

      The while at the top exits immediately because you opened the file for appending (>>) instead of for reading (<).

      I think I see what you intend to do: you want to use the file as a queue, where you append new URLs to the end, and read unprocessed ones from the start (middle).

      A file is the wrong type of a datastructure for that.

      You could use an array, where you push new URLs in at one end, and shift them out at the other.

      Of course, in a real webcrawler, that array is going to get rather large.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://330455]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-04-19 12:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found