Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Loop will not save into the array

by Roger (Parson)
on Aug 17, 2005 at 11:21 UTC ( #484365=note: print w/replies, xml ) Need Help??

in reply to Loop will not save into the array

I fancy that converting your code from
$stripped_html[$x] = join(" ",split " ",$stripped_html[$x]);
$stripped_html[$x] = join(" ",split(/\s+/,$stripped_html[$x]));
will do the trick. The reason being that if you have more than one white spaces, say, n, the split will generate n-1 undef's in the array, thus the warning.

Well, I would probably rewrite this using regular expression:
$stripped_html[$x] =~ s/\s+/ /g;

Replies are listed 'Best First'.
Re^2: Loop will not save into the array
by graff (Chancellor) on Aug 18, 2005 at 05:05 UTC
    Roger: If you read far enough down in "perldoc -f split", you'll find that  split " ",$string and  split /\s+/,$string are in nearly equivalent (except in how they treat initial whitespace in $string).

    Using a single quoted space character as the split pattern is one of those nifty little bits of perl magic that is meant to save unnecessary typing, giving the same behavior as a bare "split" call with no regex pattern. (But  split / /,$string -- not using quotes -- really does split on every individual space character.)

    But I think you're right to suggest that the OP should add the extra parens, to make sure there's no confusion about which args are supposed to go to "split" as opposed to "join".

Re^2: Loop will not save into the array
by lampros21_7 (Scribe) on Aug 17, 2005 at 12:22 UTC
    Thanks for your suggestion Roger. Unfortunately, it hasn't done the trick, it will still print the contents of the initial URL and then start giving the uninitialized value warning message. You forgot a ) after the regex in the $stripped_html... var (am mentioning this just to make sure you didn't do it for a special reason). I believe the problem is that for some reason the data will not be written in my two arrays but i can't understand why that is.
      Use $website_links[0][0] instead of $website_links[0]. Why? Because $website_links[0] is an array reference.

      Hang on, better still, you just need to change one line of code to make it work...

      my @website_links = $webcrawler->links;
      my @website_links = map { $_->[0] } $webcrawler->links;


        Hi Roger, it still doesn't work. I have changed it to

         my @website_links = map { $_-> [0] } $webcrawler->links; and then in the while loop

        @links = map { $_-> [0] } $webcrawler->links($new_uri[0]); but it still gives the same error. Sorry about this! I havent mentioned that am using ActivePerl 5.8.7 Build 813 if this is going to get rid of some headaches. Thanks for the help.Lambros

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2022-12-03 20:05 GMT
Find Nodes?
    Voting Booth?

    No recent polls found