P
Perl Mon
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_LocalHTML_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>|°|\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
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_LocalHTML_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>|°|\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