Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / July 2006



Tip: Looking for answers? Try searching our database.

LWP::Simple - Terminal won't but BBEdit will.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andrew Brosnan - 09 Jul 2006 22:03 GMT
Hi,

I came across something odd editing a script with BBEdit. The BBEdit #!
menu has a 'Run' command and a 'Run in Terminal' command. The script
below works fine when I use the Run command, but returns HTTP response
code 500 when I use Run in Terminal. I tried running it directly from
Terminal and I get the same result, HTTP response code 500.

I also noticed that getstore() returns 500 as a one-liner from Terminal
(but getprint() works fine). What gives?

Regards,
Andrew

   #!/usr/bin/perl
   
   use warnings;
   
   use strict;
   
   use LWP::Simple;
   
   my $url = 'http://www.google.com';
   
   my $file = 'Users/andrewbr/Desktop/google.html';
   
   my $res = getstore($url, $file)
   or die "Couldn't get/store $url";
   
   print $res;
Sherm Pendley - 09 Jul 2006 23:03 GMT
> Hi,
>
[quoted text clipped - 23 lines]
>
>     my $file = 'Users/andrewbr/Desktop/google.html';

$file is a relative path. When you use "Run", the current directory  
is '/' (inherited from BBEdit), so the relative path resolves  
correctly to "/Users/andrewbr/Desktop/google.html". When you choose  
"Run in Terminal", or run it manually, the current directory is the  
directory the script lives in, so getstore() tries to store the  
returned data in "(current directory)/Users/andrewbr/Desktop/
google.html" - probably not what you had in mind.

getprint() works because it's not trying to write to a non-existent  
directory.

Easy fix - add a / to the beginning of $file to make it a fully-
qualified path.

sherm--

Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
Andrew Brosnan - 09 Jul 2006 23:16 GMT
> > my $file = 'Users/andrewbr/Desktop/google.html';

> Easy fix - add a / to the beginning of $file to make it a fully-
> qualified path.

Ahh, that was a typo...thanks for proofreading me! :-) I thought I was
loosing it.

Andrew
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.