Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > LWP::Simple getstore not working inside of hash :(

Reply
Thread Tools

LWP::Simple getstore not working inside of hash :(

 
 
Perl Mon
Guest
Posts: n/a
 
      01-04-2005
I have a question. I am a perl newbie, but I like it a lot so far. I
can get this little Perl file to work as a stand alone perl program:

#!/usr/bin/perl
use strict;
use warnings;
use LWP::Simple;

my $TINI_IP = 'http://192.168.1.6';

my $TiniWeather_LocalHTML_location = 'C:/Program
Files/SlimServer/server/TiniWeatherLocalHTML.txt';

LWP::Simple::getstore($TINI_IP,$TiniWeather_LocalH TML_location) or die
"Copy failed: $!";

But, if I try and insert that code under the my functions hash below in
another program, I can't get it to work. I have worked about 8 hours
on this (incuding reading tons off of the Internet). I was wondering
if anyone had any ideas. Any help would be greatly appreciated.

I have the same use statment in the program that this snippet comes
from as above.

************ start code snippet here *********************

my %functions = (
'left' => sub {
Slim::Buttons::Common:opModeRight(shift);
},
'up' => sub {
my $client = shift;

$context{$client} = Slim::Buttons::Common::scroll(
$client,
-1,
$#weather_list + 1,
$context{$client} || 0,
);
$client->update();
},
'down' => sub {
my $client = shift;

$context{$client} = Slim::Buttons::Common::scroll(
$client,
1,
$#weather_list + 1,
$context{$client} || 0,
);
$client->update();
},
'numberScroll' => sub {
my ($client,undef,$digit) = @_;

$context{$client} = Slim::Buttons::Common::numberScroll(
$client,
$digit,
\@weather_list,
1,
sub { $weather_list[shift]->[0] },
);
$client->update();
},
'add' => sub {
#
# refresh the weather data list from the text file
#
# note that the [add] key is labeled as [rec] on the Sony remotes
#
my @field;
my $client = shift;

Slim:isplay::Animation::showBriefly(
$client,
getDisplayName() . ' ' . string('PLUGIN_WEATHER_DATA_UPDATING'),
);


my $TINI_IP = 'http://192.168.1.6';
my $TiniWeather_LocalHTML_location = 'C:/Program
Files/SlimServer/server/TiniWeatherLocalHTML.txt';

getstore($TINI_IP,$TiniWeather_LocalHTML_location) or die "Copy
failed: $!";

open (INPUT, "$TiniWeather_LocalHTML_location") || die "cannot open
file";
# opens the file to read, with the filehandle "INPUT"
# Whenever we write "INPUT" in the program it will look at the file
we're pointing to here.

open (OUTPUT, ">$weather_data_location") || die "cannot open file";
# opens the file to write with the filehandle "OUTPUT"
# The single ">" character before the filename means it's open for
writing

while (<INPUT>) {
# executes what's in the curly brackets on each line of "INPUT"
# until it reaches the end of the file

s/<br>/ /g;
s/ <font size="4"><center>Current Weather Conditions |<html>//g;
s/<TD>|<\/TD>|<td>|<\/td>|<\/tr>|<tr>|<th>|<\/th>|&#176|\t|\n//g;
unshift @field, $_;
# breaks up the file into lines
# assigns the lines to the array "field"
# strips out some of the HTML formatting stuff
}

@field = reverse @field;

select OUTPUT;

print "Local Temperature Today's High Today's Low | $field[29]
$field[30] $field[31]\n";
print "Wind Speed & Direction Today's High Today's Peak | $field[46]
$field[47] $field[48]\n";
print "Humididy Dewpoint | $field[63]
$field[80]\n";
print "Barometric Pressure Trend | $field[97]
$field[100]\n";
print "Rainfall YTD | $field[114]\n";
print "Data is updated every 10 minutes. Last updated: | $field[10]";

select STDOUT;

close INPUT;
close OUTPUT;
# close the two files that were used

read_textfile();
},
);

********************* End code snippet here ********************
Thanks

 
Reply With Quote
 
 
 
 
Jim Keenan
Guest
Posts: n/a
 
      01-04-2005
Perl Mon wrote:
> I have a question. I am a perl newbie, but I like it a lot so far. I
> can get this little Perl file to work as a stand alone perl program:
>
> #!/usr/bin/perl
> use strict;
> use warnings;


Good so far!

> use LWP::Simple;
>
> my $TINI_IP = 'http://192.168.1.6';
>
> my $TiniWeather_LocalHTML_location = 'C:/Program
> Files/SlimServer/server/TiniWeatherLocalHTML.txt';
>


errr ... Couldn't you shorten the name of that variable? Such a long
name courts typing errors.

> LWP::Simple::getstore($TINI_IP,$TiniWeather_LocalH TML_location) or die
> "Copy failed: $!";
>
> But, if I try and insert that code under the my functions hash below in
> another program, I can't get it to work. I have worked about 8 hours
> on this (incuding reading tons off of the Internet). I was wondering
> if anyone had any ideas. Any help would be greatly appreciated.
>
> I have the same use statment in the program that this snippet comes
> from as above.
>
> ************ start code snippet here *********************
>
> my %functions = (
> 'left' => sub {
> Slim::Buttons::Common:opModeRight(shift);
> },
> 'up' => sub {


Are we supposed to know what this Slim::Buttons ... module is? It's
clearly not on CPAN.

Jim Keenan
 
Reply With Quote
 
 
 
 
Perl Mon
Guest
Posts: n/a
 
      01-08-2005
I finally got this to work by using this code:

sub UpdateWeather {
my $LocalCopy = 'C:\\Program
Files\\SlimServer\\server\\TiniWeatherLocalHTML.tx t';
my $TINI_IP = get('http://192.168.1.6');
open (OUTPUT, ">$LocalCopy");
select OUTPUT;
print "$TINI_IP";
select STDOUT;
close OUTPUT;
}

It looks as if something may be wrong with the code that SlimServer
(www.slimdevices.com) has in it (it is written in Perl and installs a
lot of modules so users don't have to install Perl separately. I have
notified them of the situation. Thanks for your help.

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      01-09-2005
Perl Mon <(E-Mail Removed)> wrote:


> my $LocalCopy = 'C:\\Program
> Files\\SlimServer\\server\\TiniWeatherLocalHTML.tx t';



This will work fine too you know:

my $LocalCopy = 'C:/Program
Files/SlimServer/server/TiniWeatherLocalHTML.txt';

No need for silly slashes.


> open (OUTPUT, ">$LocalCopy");



You should always, yes *always*, check the return value from open():

open (OUTPUT, ">$LocalCopy") or die "could not open '$LocalCopy' $!";


> select OUTPUT;
> print "$TINI_IP";



Why bother with the select()?

Why bother with the useless use of quotes?


print OUTPUT $TINI_IP;

will do exactly the same thing as those 2 lines,
with 8 less characters to type and read.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Perl Mon
Guest
Posts: n/a
 
      01-11-2005
Thanks for the tips. I still have tons to learn, as if that isn't
obvious. I will revise my code. I really appreciate you taking the
time to help

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
LWP::Simple getstore with absolute path not working emrefan Perl Misc 6 06-16-2008 02:42 PM
not declared error- control inside a control inside a webform DC Gringo ASP .Net 4 12-17-2007 02:22 AM
not declared error- control inside a control inside a webform DC Gringo ASP .Net Web Controls 3 09-14-2004 09:29 PM



Advertisments