[18467] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 635 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 5 09:10:38 2001

Date: Thu, 5 Apr 2001 06:10:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <986476218-v10-i635@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 5 Apr 2001     Volume: 10 Number: 635

Today's topics:
        Please Help <Waarddebon@chello.nl>
    Re: Please Help (Bernard El-Hagin)
    Re: Please Help (Rafael Garcia-Suarez)
    Re: Please Help (Gwyn Judd)
    Re: Please Help <Waarddebon@chello.nl>
    Re: Please Help <joe+usenet@sunstarsys.com>
    Re: Please Help <bmb@ginger.libs.uga.edu>
    Re: Please Help (Bernard El-Hagin)
        WeatherNOAA suggestion <nospam@aol.com>
    Re: WeatherNOAA suggestion (Bernard El-Hagin)
    Re: XML request and response via HTTP - Intense Despera <gus@black.hole-in-the.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 05 Apr 2001 11:38:37 GMT
From: "Waarddebon" <Waarddebon@chello.nl>
Subject: Please Help
Message-Id: <1PYy6.234312$j_4.3099564@Flipper>

Why doesn't this work ?

$remote2="today";
open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
print THEFILE "hi";
close THEFILE;




------------------------------

Date: Thu, 5 Apr 2001 12:09:55 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Please Help
Message-Id: <slrn9coo3b.vpn.bernard.el-hagin@gdndev32.lido-tech>

On Thu, 05 Apr 2001 11:38:37 GMT, Waarddebon <Waarddebon@chello.nl> wrote:
>Why doesn't this work ?

Define "doesn't work".

>$remote2="today";
>open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");

You're not testing whether the open was successful or not.

open (THEFILE,"/data1/hm/makers/bezoekers/$remote2")
	or die "I ain't opening jack: $!\n";

>print THEFILE "hi";
>close THEFILE;

Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'


------------------------------

Date: Thu, 05 Apr 2001 12:11:15 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Please Help
Message-Id: <slrn9coo7r.l1s.rgarciasuarez@rafael.kazibao.net>

Waarddebon wrote in comp.lang.perl.misc:
> Why doesn't this work ?
> 
> $remote2="today";
> open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
> print THEFILE "hi";
> close THEFILE;

To find out why, use the Clueless::Open module below :

package Clueless::Open;

use strict;
use Exporter;
use vars qw/@ISA @EXPORT_OK/;
@ISA = qw/Exporter/;
@EXPORT_OK = qw/open/;

sub open (*;$@) {
  no strict 'refs';
  open caller()."::$_[0]", @_[1..$#_] or die "Can't open $_[1]: $!\n";
}

1;
__END__

Usage example :

#!/usr/local/bin/perl -w
use strict;
use Clueless::Open qw/open/;
open FOO, "quuux";
print while <FOO>;
close FOO;
__END__

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
perl -sleprint -- -_='Just another Perl hacker,'


------------------------------

Date: Thu, 05 Apr 2001 12:17:46 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Please Help
Message-Id: <slrn9cosf7.4m9.tjla@thislove.dyndns.org>

I was shocked! How could Waarddebon <Waarddebon@chello.nl>
say such a terrible thing:
>Why doesn't this work ?
>
>$remote2="today";
>open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
>print THEFILE "hi";
>close THEFILE;

You got me. How about posting the error message? It doesn't seem to have
any syntax errors. You might like to check the return value of open.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
The people must fight for their laws as for their walls.

		-- Heraclitus


------------------------------

Date: Thu, 05 Apr 2001 12:20:26 GMT
From: "Waarddebon" <Waarddebon@chello.nl>
Subject: Re: Please Help
Message-Id: <eqZy6.235215$j_4.3111092@Flipper>

It quits at the die statement... The idea of these lines is to write the
word hi in file $remote2. But for some reason the file isn't written.


Bernard El-Hagin <bernard.el-hagin@lido-tech.net> schreef in berichtnieuws
slrn9coo3b.vpn.bernard.el-hagin@gdndev32.lido-tech...
> On Thu, 05 Apr 2001 11:38:37 GMT, Waarddebon <Waarddebon@chello.nl> wrote:
> >Why doesn't this work ?
>
> Define "doesn't work".
>
> >$remote2="today";
> >open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
>
> You're not testing whether the open was successful or not.
>
> open (THEFILE,"/data1/hm/makers/bezoekers/$remote2")
> or die "I ain't opening jack: $!\n";
>
> >print THEFILE "hi";
> >close THEFILE;
>
> Cheers,
> Bernard
> --
> #requires 5.6.0
> perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$
?] }'




------------------------------

Date: 05 Apr 2001 08:22:41 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Please Help
Message-Id: <m3g0fntu26.fsf@mumonkan.sunstarsys.com>

"Waarddebon" <Waarddebon@chello.nl> writes:

> Why doesn't this work ?
> 
> $remote2="today";
> open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
> print THEFILE "hi";
> close THEFILE;
> 
> 
^
^
^   Beause your epidermis is showing.
^
^

-- 
Joe Schaefer       "The surest protection against temptation is cowardice."
                                               --Mark Twain


------------------------------

Date: Thu, 5 Apr 2001 08:56:13 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Please Help
Message-Id: <Pine.A41.4.21.0104050855540.16576-100000@ginger.libs.uga.edu>

On Thu, 5 Apr 2001, Waarddebon wrote:

> Why doesn't this work ?
> 
> $remote2="today";
> open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
> print THEFILE "hi";
> close THEFILE;


>

Brad



------------------------------

Date: Thu, 5 Apr 2001 13:01:09 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: Please Help
Message-Id: <slrn9cor37.vpn.bernard.el-hagin@gdndev32.lido-tech>

[don't post your reply above what you're replying to...it's silly and
annoying]

On Thu, 05 Apr 2001 12:20:26 GMT, Waarddebon <Waarddebon@chello.nl> wrote:
>
>
>Bernard El-Hagin <bernard.el-hagin@lido-tech.net> schreef in berichtnieuws
>slrn9coo3b.vpn.bernard.el-hagin@gdndev32.lido-tech...
>> On Thu, 05 Apr 2001 11:38:37 GMT, Waarddebon <Waarddebon@chello.nl> wrote:
>> >Why doesn't this work ?
>>
>> Define "doesn't work".
>>
>> >$remote2="today";
>> >open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
>>
>> You're not testing whether the open was successful or not.
>>
>> open (THEFILE,"/data1/hm/makers/bezoekers/$remote2")
>> or die "I ain't opening jack: $!\n";
>>
>> >print THEFILE "hi";
>> >close THEFILE;
>
>It quits at the die statement...

That's the point of the die statement.

>The idea of these lines is to write the word hi in file $remote2. But
>for some reason the file isn't written.

I realise what the point of "these lines" is. I just don't understand
what you mean by "doesn't work". Are you getting an error message? If so
quote it!

Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'


------------------------------

Date: Thu, 05 Apr 2001 11:00:31 GMT
From: "Arthur Gibbs" <nospam@aol.com>
Subject: WeatherNOAA suggestion
Message-Id: <jfYy6.13678$Ho5.4119037@typhoon.southeast.rr.com>

Thanks to Mark Solomon for your WeatherNOAA perl script.  I have used it and
also I have hacked it some to add an ability to read the state.html files to
give a graphical 5 day forcast.  If anyone wants to clean this code up and
include it in the next update of WeatherNOAA.  You are welcome to.

Click here to see an example:  http://www.abible.com/church/

Arthur :)

-------------
#!/usr/local/bin/perl -w

use LWP::Simple;
use LWP::UserAgent;
use vars '$proxy_from_env';
$proxy_from_env = 0;

print "Content-type: text/html\n\n";
print "Hello, World...\n";
&process_city_forecast('raleigh','nc');
print "$tout";
exit(1);


sub process_city_forecast {
 my ($city, $state) = @_;
 &get_city_forecast($city,$state);
 $weather = "\n\n<!-- Start: Weather for $city, $state -->\n";
 $weather .= "<table width=\"95\%\" border=\"0\" cellspacing=\"0\"
align=\"center\" cellpadding=\"1\" bgcolor=\"#000000\">\n";
 $weather .= "    <tr>\n";
 $weather .= "        <td>\n";
 $weather .= "            <table width=\"100\%\" border=\"0\"
cellspacing=\"0\" cellpadding=\"2\">\n";
 $weather .= "               <tr bgcolor=\"#000000\">\n";
 $weather .= "                   <td  width=\"0\%\" valign=\"top\"
colspan=\"5\">\n";
 $weather .= "      <font face=\"Arial, Helvetica, sans-serif\">\n";
 $weather .= "      <font color=\"#ffffff\"><B><center>Weather Forecast for
$city, $state</b></center></font></font>\n";
 $weather .= "     </td>\n";
 $weather .= "    </tr>\n";
 $weather .= "    <tr bgcolor=\"#ffffff\">\n";
 for($x = 1; $x < 6; $x++) {
 $weather .= "     <td align=\"middle\" width=\"20\%\">\n";
 $weather .= "      <font face=\"arial\" size=\"2\">$date[$x]</font><br>\n";
 $weather .= "      <font face=\"arial\" size=\"2\"><b>" .
ucfirst(lc($day[$x])) . "</b></font>\n";
 $weather .= "     </td>\n";
 }
 $weather .= "    </tr>\n";
 $weather .= "    <tr bgcolor=\"#eeeeee\">\n";
 for($x = 1; $x < 6; $x++) {
 $weather .= "     <td align=\"middle\" width=\"20\%\">\n";
 $weather .= "      <font face=\"arial\"
size=\"1\"><b>$forecast[$x]</b></font>\n";
 $weather .= "     </td>\n";
 }
 $weather .= "    </tr>\n";
 $weather .= "    <tr bgcolor=\"#ffffff\">\n";
 for($x = 1; $x < 6; $x++) {
 $weather .= "     <td align=\"middle\"><img
src=\"weather/icons01/$f[$x].gif\"></td>\n"
 }
 $weather .= "    </tr>\n";
 $weather .= "    <tr bgcolor=\"#ffffff\">\n";
 for($x = 1; $x < 6; $x++) {
 $weather .= "     <td align=\"middle\" valign=\"top\">\n";
 $weather .= "      <font face=\"arial\" size=\"1\"
color=\"990000\"><b>High: $high[$x]</b></font><br>\n";
 if ($low[$x]) {
 $weather .= "      <font face=\"arial\" size=\"1\" color=\"3333ff\"><b>Low:
$low[$x]</b></font>\n";
 }
 $weather .= "     </td>\n";
 }
 $weather .= "    </tr>\n";
 $weather .= "   </table>\n";
 $weather .= "  </td>\n";
 $weather .= " </tr>\n";
 $weather .= "</table>\n";
 $weather .= "<!-- End: Weather -->\n\n";
}


sub get_city_forecast {
 #RALEIGH-DURHAM, NC  MOCLDY   PTCLDY   MOCLDY   PTCLDY   FAIR
 #                    46/63    43/65    48/69    50/72    55/78
 #                    POP 10   POP 0    POP 0    POP 0    POP 10

 my $URL_BASE = 'http://iwin.nws.noaa.gov/iwin/';

 my ($city, $state, $filename, $fileopt, $UA) = @_;

 my $URL = $URL_BASE . lc $state . '/state.html';


 # City and States must be capital
 #
 $state = uc($state);
 $city  = uc($city);

 # Declare some working vars
 #
 my ($rawData);

 # Get data from filehandle object
 #
 $rawData = get_data($URL,$filename,$fileopt,$UA);

 # Return error if there's an error
 if ($rawData =~ /Error/) {
  return $rawData;
 }

 my %sky = (
    'N/A'           => 'N/A',    #-
    'TSTRMS'  => 'T-Storms',   #4
    'RN/SNW'  => 'Rain and Snow',  #5
    ''    => 'Wintry Mix',  #7
    'SHWRS'   => 'Showers',   #11
    'RAIN'   => 'Rain',    #12
    'SNOSHWR'  => 'Snow Showers',  #14
                'SNOW'          => 'Snow',    #16
                'DUST'          => 'Dust',    #19
    'FOG'   => 'Fog',    #20
    'HAZE'   => 'Haze',    #21
    'SMOKE'   => 'Smoke',    #22
    'WINDY'   => 'Windy',    #24
          'CLOUDY'        => 'Cloudy',   #26
    ''    => 'Mostly Cloudy',  #27 Night
                'MOCLDY'        => 'Mostly Cloudy',  #28
                'MOSUNNY'       => 'Mostly Sunny',  #28
    ''    => 'Partly Cloudy',  #29 Night
    'PTCLDY'        => 'Partly Cloudy',  #30
    'PTSUNNY'       => 'Partly Sunny',  #30
    'CLEAR'   => 'Clear',    #31
    'SUNNY'         => 'Sunny',    #32
    ''       => 'Fair',    #33 Night
    'FAIR'          => 'Fair',    #34
    ''         => 'Isolated T-Storms',  #37
    ''         => 'Scattered T-Storms',  #38
    ''         => 'Scattered Showers',  #39
    ''         => 'Scattered Snow Showers', #41

               'DRIZZLE'        => 'a Drizzle',
               'LGT RAIN'       => 'Light Rain',
      'FRZ DRZL'  => 'Freezing Drizzle',
               'FLURRIES'       => 'Snow Flurries',
               'LGT SNOW'       => 'Light Snow',
               'NOT AVBL'       => '*not available*',
      'MISG'   => '---',
      'VRYHOT'   => '---'
 );

 # Get line for our city from Data
 #
 foreach (split /\015\012\015\012/, $rawData) {
#  print "<hr>$_";

  if ($_ =~ /^\s+FCST\s+FCST/) {
   my $section = $_;
   $section =~ s/FCST//g;
   $section =~ s/^\s+//g;
   local($l1, $l2) = split(/\015\012/, $section);
   ($day[1], $day[2], $day[3], $day[4], $day[5]) = split(/\s+/, $l1);
   $l2 =~ s/^\s+//g;
   ($date[1], $date[2], $date[3], $date[4], $date[5]) = split(/\s{3}/, $l2);
  }

  if ($_ =~ /^$city/) {
   local($l1, $l2, $l3) = split(/\015\012/, $_);
   $l1 =~ s/[A-Za-z'-]*, \w+\s+//g;
   ($f[1], $f[2], $f[3], $f[4], $f[5]) = split(/\s+/, $l1);
   for($x = 1; $x < 6; $x++) {
    $forecast[$x] = $sky{$f[$x]};
   }
   $l2 =~ s/^\s+//g;
   ($t[1], $t[2], $t[3], $t[4], $t[5]) = split(/\s+/, $l2);
   for($x = 1; $x < 6; $x++) {
    ($high[$x], $low[$x]) = split(/\//, $t[$x]);
    if ($low[$x] > $high[$x]) {
     my $switch = $low[$x];
     $low[$x] = $high[$x];
     $high[$x] = $switch;
    }
   }
   $l3 =~ s/^\s+POP\s+//g;
   ($pop[1], $pop[2], $pop[3], $pop[4], $pop[5]) = split(/\s+POP\s+/, $l3);
   last;
  }
 }

}


sub get_url {
    my ($URL, $UA) = @_;

 $URL or die "No URL to get!";

    # Create the useragent and get the data
    #
    if (! $UA) {
 $UA = new LWP::UserAgent;
        $UA->env_proxy if $proxy_from_env;
    }
    $UA->agent("Weather");

    # Create a request
    my $req = new HTTP::Request GET => $URL;
    my $res = $UA->request($req);
    if ($res->is_success) {
  return $res->content;
    }
    else {
  return;
    }
} # getURL()

sub get_data {
 my ($URL,$filename,$fileopt,$UA) = @_;

 $fileopt ||= 'get';

 my $data; # Data

 if ( ($fileopt eq 'get') || ($fileopt eq 'save') ) {
  print STDERR "Retrieving $URL\n" if $main::opt_v;
  $data = get_url($URL,$UA) ||
   return "Error getting data from $URL";
  if ( $fileopt eq 'save' ) {
   print STDERR "Writing $URL to $filename\n" if $main::opt_v;
   open(OUT,">$filename") or die "Cannot create $filename";
   print OUT $data;
   close OUT;
   $fileopt = 'usefile';
  }
 }
 if ( $fileopt eq 'usefile' ) {
  print STDERR "Reading data from $filename\n" if $main::opt_v;
  open(FILE,$filename) or die "Cannot read $filename";
  while (<FILE>) { $data .= $_; }
 }
 return $data;
}




------------------------------

Date: Thu, 5 Apr 2001 11:20:45 +0000 (UTC)
From: bernard.el-hagin@lido-tech.net (Bernard El-Hagin)
Subject: Re: WeatherNOAA suggestion
Message-Id: <slrn9col72.vpn.bernard.el-hagin@gdndev32.lido-tech>

On Thu, 05 Apr 2001 11:00:31 GMT, Arthur Gibbs <nospam@aol.com> wrote:
>Thanks to Mark Solomon for your WeatherNOAA perl script.  I have used it and
>also I have hacked it some to add an ability to read the state.html files to
>give a graphical 5 day forcast.  If anyone wants to clean this code up and
>include it in the next update of WeatherNOAA.  You are welcome to.

[snipped code]

You should learn about here documents and get all of those
$weather .= "stuff" thingies cleaned up.

Cheers,
Bernard
--
#requires 5.6.0
perl -le'* = =[[`JAPH`]=>[q[Just another Perl hacker,]]];print @ { @ = [$ ?] }'


------------------------------

Date: Thu, 05 Apr 2001 11:51:18 GMT
From: Gus <gus@black.hole-in-the.net>
Subject: Re: XML request and response via HTTP - Intense Desperation
Message-Id: <986471478.17804.1.nnrp-14.c29f015a@news.demon.co.uk>

Klaus Wright <Klaus_member@newsranger.com> wrote:

> I have no clue how to go about sending the http post while specifying a
> URI and
> host (SOAP does it, but unfortunately SOAP needs to run on both the 
> server and
> client and XML::Stream hints at it, but does not let you seperate the 
> URI and
> host.)  5 consecutive days of Googling this dilema has brought migraines 
> and
> hostility into my life.  

Sounds like a job for LWP. Make an HTTP::Request object up with the POST
method and your XML content and pass it to LWP::UserAgent to actually
do the HTTP side of things, then read the servers XML response from the 
LWP::UserAgent response.

(untested code follows, you get the idea I hope)

#!/usr/bin/perl -w

use LWP::UserAgent;
use HTTP::Request;

$ua = new LWP::UserAgent;
$ua->timeout(10);

$headers = 'X-Foobar: Test';
$content = some_sub_which_makes_xml();

$request = new HTTP::Request('POST','http://foo.bar:1234/stuff',
                             $headers,$content);

$response = $ua->request($request);
if ($response->is_success) {
    print "I got back", $response->content;
}else{
    print "Error: HTTP response code ",$response->code,"\n";
}









-- 
gus@black.hole-in-the.net
0x58E18C6D
82 AA 4D 7F D8 45 58 05  6D 1B 1A 72 1E DB 31 B5
http://black.hole-in-the.net/gus/


------------------------------

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 635
**************************************


home help back first fref pref prev next nref lref last post