Prev: piped open and shell metacharacters
Next: FAQ 8.27 What's wrong with using backticks in a void context?
From: Thomas Andersson on 31 Jul 2010 09:51 Tad McClellan wrote: >> a non failure signals 1? > > A non-failure stores the contents of the page in $page (a true value). > A failure stores an undef in $page (a false value). Prob is it will never fail, the server keeps feeding pages with no content in so a test needs to be added inside the loop. Would the following code help exiting the loop? if ( $page eq $endstring ) { exit( 0 ); }; ($endstring = "No more sorties" which is the string replacing data in emprty pages).
From: Tad McClellan on 31 Jul 2010 09:54 Thomas Andersson <thomas(a)tifozi.net> wrote: > Tad McClellan wrote: > >>> a non failure signals 1? >> >> A non-failure stores the contents of the page in $page (a true value). >> A failure stores an undef in $page (a false value). > > Prob is it will never fail, the server keeps feeding pages with no content > in so a test needs to be added inside the loop. > Would the following code help exiting the loop? > > if ( $page eq $endstring ) { > exit( 0 ); > }; > > ($endstring = "No more sorties" which is the string replacing data in emprty > pages). No that will never work unless this is the "web page" that is returned: No more sorties Most web pages will have tags and newlines and whatnot in them, so an equality test will not work. A pattern match would work though: last if $page =~ /No more sorties/; -- Tad McClellan email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/" The above message is a Usenet post. I don't recall having given anyone permission to use it on a Web site.
From: Thomas Andersson on 31 Jul 2010 10:02 Tad McClellan wrote: >> if ( $page eq $endstring ) { >> exit( 0 ); >> }; >> >> ($endstring = "No more sorties" which is the string replacing data >> in emprty pages). > > No that will never work unless this is the "web page" that is > returned: > > No more sorties Doh, stupid me, of course, thanks! > Most web pages will have tags and newlines and whatnot in them, > so an equality test will not work. A pattern match would work though: > > last if $page =~ /No more sorties/; That's clean and nice, if inserted before the page is saved I won't have to deal with useless pages! :) Thank you very much sir!
From: Sherm Pendley on 31 Jul 2010 10:03 "Thomas Andersson" <thomas(a)tifozi.net> writes: > Would the following code help exiting the loop? Exit() exits the *program*. In this case, since your loop is basically the whole program, it amounts to the same thing, but that won't always be the case! Better to use last - that's what it's for. > if ( $page eq $endstring ) { last; > }; > > ($endstring = "No more sorties" which is the string replacing data in emprty > pages). Is it sent as plain text, without even a newline character at the end? I doubt that - more likely, it's an HTML page that *contains* that string. That being the case, you could use the index() function to see if $endstring appears anywhere in $page: if ( index($page, $endstring) == -1 ) { last; } sherm-- -- Sherm Pendley <www.shermpendley.com> <www.camelbones.org> Cocoa Developer
From: Ben Morrow on 31 Jul 2010 10:13
Quoth "Thomas Andersson" <thomas(a)tifozi.net>: > > Also: get into the habit, now, of keeping you filehandles in proper > > variables. It will make life easier later. > > > > open my $FILE, ">", "..." or ...; > > Will definitely try to pick up good habbits on coding and formatting so > thanks for advice. > But if I createa variable of the filehandler like this, won't it contain the > filepath then, so when I do the print $FILE it will print the filepath > instead of the content of the file as I want? Or am I missunderstanding? > (quite likely). Yes, you are misunderstanding. If you create $FILE like that, it will contain a filehandle. If you then want to print to that filehandle, you do it like print $FILE "one two three\n"; (Note the lack of comma after $FILE: that's important). If you want to print $FILE itself, you can: print $FILE; # this is short for print STDOUT $FILE and you will get something like 'GLOB(0xDEADBEEF)'. Ben |