[19404] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1599 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 23 18:05:30 2001

Date: Thu, 23 Aug 2001 15:05:10 -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: <998604309-v10-i1599@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 23 Aug 2001     Volume: 10 Number: 1599

Today's topics:
        [OT] Re: Win32: how much disk space free? (Steven M. O'Neill)
    Re: annoying habit of perl 5 in freebsd (Abigail)
        Automating authentication (archer_boy)
    Re: Automating authentication <rsherman@ce.gatech.edu>
    Re: Can't get correct IP (Steve)
    Re: Can't get correct IP (Malcolm Ray)
    Re: Can't get correct IP <flavell@mail.cern.ch>
    Re: days since 1/1/1970 <cberry@cinenet.net>
        DBD::Pg install error (freebsd) (jake johnson)
        dynamic menu (efficiency) four12and8up@unspam-me.yahoo.com
    Re: dynamic menu (efficiency) (Logan Shaw)
    Re: help with searching for occurances of...... <samneric@tigerriverOMIT-THIS.com>
    Re: help with searching for occurances of...... (John J. Trammell)
        Help, MIME-Lite Error using send_by_smtp method! (KrazyKat)
    Re: local exec via cgi <wsegrave@mindspring.com>
    Re: Looking for Script <gareth.hinton@btinternet.com>
    Re: lwp-request warnings coming from Net::Domain (KrazyKat)
    Re: Openning a file (Abigail)
    Re: Openning a file <gmandesigns@hotmail.com>
    Re: Openning a file (Gary E. Ansok)
    Re: Openning a file <cpryce@pryce.net>
    Re: Openning a file <cpryce@pryce.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 23 Aug 2001 18:13:42 GMT
From: steveo@panix.com (Steven M. O'Neill)
Subject: [OT] Re: Win32: how much disk space free?
Message-Id: <9m3h4m$fci$1@news.panix.com>

Florian Haftmann  <florian.haftmann@stud.tum.de> wrote:
>Hi!

Hallo!

>I want to examine (Win32) how much disk space (drive A: or B:) is
>available?  How to do?

`dir`

HDDH
-- 
Steven O'Neill                                          steveo@panix.com
                                                       www.cars-suck.org


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

Date: 23 Aug 2001 20:19:14 GMT
From: abigail@foad.org (Abigail)
Subject: Re: annoying habit of perl 5 in freebsd
Message-Id: <slrn9oapad.6m2.abigail@alexandra.xs4all.nl>

Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote on MMCMXIV September
MCMXCIII in <URL:news:9m39lv$att$2@mamenchi.zrz.TU-Berlin.DE>:
][ According to Villy Kruse <vek@pharmnl.ohout.pharmapartners.nl>:
][ > 
][ > Actualy I would do $|=1; .  If you want to set it to one just say so.
][ > No need to fetch the preveious value (whatever that might be) and
][ > increment it.  
][ > 
][ > BTW, $| is magic and can only have the values 0 and 1 regardless what
][ > value you assign to it.
][ 
][ Quite, for that reason I dislike the popular $|++ idiom.  It looks like
][ you could later restore the state with $|--, but that works only on
][ one level, not nested.

$|-- is far worse than "not restoring the state". $|-- is a toggle that
switches buffering on and off.

][                         But as long as Randal uses it...

And this is how cargo cult coding is born. Just because Randal uses it
doesn't mean one cannot think for oneself. Even wizards from Arthurian
times aren't faultfree.

I bet the majority of the people using $|++ do it for no other reason
than having seen other people use it.


Abigail
-- 
perl -MLWP::UserAgent -MHTML::TreeBuilder -MHTML::FormatText -wle'print +(
HTML::FormatText -> new -> format (HTML::TreeBuilder -> new -> parse (
LWP::UserAgent -> new -> request (HTTP::Request -> new ("GET",
"http://work.ucsd.edu:5141/cgi-bin/http_webster?isindex=perl")) -> content))
=~ /(.*\))[-\s]+Addition/s) [0]'


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

Date: 23 Aug 2001 12:58:18 -0700
From: a_who_me@yahoo.com (archer_boy)
Subject: Automating authentication
Message-Id: <1147d2a.0108231158.7f17669a@posting.google.com>

Hello,

I am new to the Perl Expect.pm module. I would like to know how to go
about automating authentication with this module.



Thank U,

archer_boy


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

Date: Thu, 23 Aug 2001 16:24:32 +0500
From: Robert Sherman <rsherman@ce.gatech.edu>
Subject: Re: Automating authentication
Message-Id: <3B84E7F0.4D10E91E@ce.gatech.edu>

archer_boy wrote:
> 
> Hello,
> 
> I am new to the Perl Expect.pm module. I would like to know how to go
> about automating authentication with this module.
> 
> Thank U,
> 
> archer_boy

authentication to what? from where? 

-- 
robert sherman
css, cee
georgia institute of technology
atlanta, ga, usa


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

Date: 23 Aug 2001 18:07:36 GMT
From: steve@zeropps.uklinux.net (Steve)
Subject: Re: Can't get correct IP
Message-Id: <slrn9oah8a.dc9.steve@zero-pps.localdomain>

On Thu, 23 Aug 2001 21:17:37 +0800, Peter Chan wrote:
>i try to get the user IP address with the environment variable.
>But it wasn't correct.
>
>I use this syntax:
>
>print "IP: $ENV{'REMOTE_ADDR'}\n";
>

I always use CGI.PM and do something like: 

my $Ip_Address = remote_host();

--
Cheers
Steve              email mailto:steve@zeropps.uklinux.net

%HAV-A-NICEDAY Error not enough coffee  0 pps. 

web http://www.zeropps.uklinux.net/

or  http://start.at/zero-pps

  6:57pm  up 40 days, 21:01,  2 users,  load average: 1.07, 1.07, 1.09


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

Date: 23 Aug 2001 19:48:21 GMT
From: M.Ray@ulcc.ac.uk (Malcolm Ray)
Subject: Re: Can't get correct IP
Message-Id: <slrn9oang5.p3p.M.Ray@carlova.ulcc.ac.uk>

On 23 Aug 2001 18:07:36 GMT, Steve <steve@zeropps.uklinux.net> wrote:
>On Thu, 23 Aug 2001 21:17:37 +0800, Peter Chan wrote:
>>i try to get the user IP address with the environment variable.
>>But it wasn't correct.
>>
>>I use this syntax:
>>
>>print "IP: $ENV{'REMOTE_ADDR'}\n";
>>
>
>I always use CGI.PM

CGI.pm

>and do something like: 
>
>my $Ip_Address = remote_host();

But that's not the same thing!  And your variable name is potentially
misleading.  remote_host() will return the remote hostname, if available,
falling back to the IP address if not.  Granted, most webservers these
days are not set up to resolve incoming IP addresses to names, but if
your CGI script happens to run on one which does, your statement won't
give the result you expect.

I'd be very surprised to find a webserver which supplied '127.0.0.1'
in $ENV{REMOTE_ADDR} and the client's hostname in $ENV{REMOTE_HOST}
(unless the client *is* localhost, of course).
-- 
Malcolm Ray                           University of London Computer Centre


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

Date: Thu, 23 Aug 2001 22:37:55 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Can't get correct IP
Message-Id: <Pine.LNX.4.30.0108232225230.28223-100000@lxplus023.cern.ch>

On Aug 23, Malcolm Ray inscribed on the eternal scroll:

> >my $Ip_Address = remote_host();
>
> But that's not the same thing!  And your variable name is potentially
> misleading.  remote_host() will return the remote hostname, if available,

well, in general it'll return information on whatever computer made
the direct request to the target web server, which might just be the
proxy server that was nearest to the web server.

> falling back to the IP address if not.

Hang on, the draft CGI RFC says

    6.1.10. REMOTE_HOST

   The fully qualified domain name of the agent sending the request to
   the server, if available, otherwise NULL.

Oh, sorry, you're right - this seems to be something which CGI.pm
massages, according to its documentation.

It's possible to configure Apache to resolve IP addresses to DNS names
only when URLs seem to be CGI calls.  For example the ones I manage
have a bracket that's effective whenever the URLpath contains "cgi".

> I'd be very surprised to find a webserver which supplied '127.0.0.1'
> in $ENV{REMOTE_ADDR} and the client's hostname in $ENV{REMOTE_HOST}
> (unless the client *is* localhost, of course).

Indeed.  remote_addr and remote_host always relate to the same
Internet host, but it often will not be the address/name of the actual
client.

cheers



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

Date: Thu, 23 Aug 2001 19:45:30 -0000
From: Craig Berry <cberry@cinenet.net>
Subject: Re: days since 1/1/1970
Message-Id: <Xns910681C9126E1cberrycinenetnet1@207.126.101.92>

abigail@foad.org (Abigail) wrote in
news:slrn9o8ess.6m2.abigail@alexandra.xs4all.nl: 

> And those seconds have been happily ignored by Unix time.

More accurately, most sysadmins set their clocks to reflect the current UTC 
time, which does incorporate leap seconds.  As a result, the time() value 
returned is for an epoch offset about half a minute from midnight Jan 1 
1970.

-- 
Craig Berry <http://www.cinenet.net/~cberry/>
"That which is now known, was once only imagined." - William Blake



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

Date: 23 Aug 2001 12:08:01 -0700
From: jake@omnimode.com (jake johnson)
Subject: DBD::Pg install error (freebsd)
Message-Id: <8897a0de.0108231108.6975f524@posting.google.com>

I'm trying to install (from source) DBD::Pg v1.01 after having
installed (from source) DBI v1.19 on FreeBSD 4.3 (Release) and I
encounter this error in the 'make test' step:

dell_box# make test
PERL_DL_NONLAZY=1 /usr/bin/perl -Iblib/arch -Iblib/lib
-I/usr/libdata/perl/5.00503/mach -I/usr/libdata/perl/5.00503 test.pl
OS: freebsd
install_driver(Pg) failed: Can't load 'blib/arch/auto/DBD/Pg/Pg.so'
for module DBD::Pg: Shared object "libpq.so.2" not found at
/usr/libdata/perl/5.00503/DynaLoader.pm line 169.

 at (eval 1) line 3
Perhaps a required shared library or dll isn't installed where
expected
 at test.pl line 53
*** Error code 255

Stop in /usr/home/jake6006/DBD-Pg-1.01.

I have POSTGRES_LIB and POSTGRES_INCLUDE properly defined (else 'make'
wouldn't have worked). In fact, for additional reference I've provided
the output from 'make'. I'm running these things as root instead of
postgres... does it matter?

I'd appreciate any help offerred.  Thanks.



dell_box# make
cc -c -I/usr/local/pgsql/include/
-I/usr/local/lib/perl5/site_perl/5.005/i386-freebsd/auto/DBI      
-DVERSION=\"1.01\"  -DXS_VERSION=\"1.01\" -DPIC -fpic
-I/usr/libdata/perl/5.00503/mach/CORE  Pg.c
cc -c -I/usr/local/pgsql/include/
-I/usr/local/lib/perl5/site_perl/5.005/i386-freebsd/auto/DBI      
-DVERSION=\"1.01\"  -DXS_VERSION=\"1.01\" -DPIC -fpic
-I/usr/libdata/perl/5.00503/mach/CORE  dbdimp.c
mkdir blib/arch
mkdir blib/arch/auto
mkdir blib/arch/auto/DBD
mkdir blib/arch/auto/DBD/Pg
Running Mkbootstrap for DBD::Pg ()
chmod 644 Pg.bs
cc -o blib/arch/auto/DBD/Pg/Pg.so  -Wl,-E -shared -lperl -lm Pg.o
dbdimp.o    -L/usr/local/pgsql/lib/ -lpq
chmod 755 blib/arch/auto/DBD/Pg/Pg.so
cp Pg.bs blib/arch/auto/DBD/Pg/Pg.bs
chmod 644 blib/arch/auto/DBD/Pg/Pg.bs
mkdir blib/lib/auto/DBD
mkdir blib/lib/auto/DBD/Pg
mkdir blib/man3
Manifying blib/man3/DBD::Pg.3
Manifying blib/man3/DBD::dbd-pg.3


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

Date: Thu, 23 Aug 2001 20:42:26 -0000
From: four12and8up@unspam-me.yahoo.com
Subject: dynamic menu (efficiency)
Message-Id: <toaqli9e61ti1c@corp.supernews.com>

I'm fooling around with keyboard input and wanted to create dynamic menu
choices similar to what Internet Explorer does on the address line.

For example, if I have a list of the 50 US states, and I type 'M'
on the input line, I would want to parse the list of states and find only
those beginning with 'M'. If the next letter I type is 'i', the
list should be narrowed down to the four states beginning with 'Mi'.

And so on, with the same thing happening in reverse (delete the 'i' and the
list goes back to all states beginning with 'M').

My question is about efficiency. I thought I'd iterate through an array of
all 50 states when the first character is entered, and put all matches into
a hash or arrays that corresponds with the number of characters entered.

Say $match{0} contains an array of the 50 states.

When the first letter is entered, iterate through @{$match{0}} and get:
$match{1} = ['Maine' .. 'Montana',];

Then the next letter 'i' is entered. Iterate @{$match{1}} and get:
$match{2} = ['Michigan', 'Minnesota', 'Mississippi', 'Missouri',];

Then if I delete the 'i' I could simply delete $match{2}.

If the foreach doesn't match anything, then nothing is added to %match. I'm
using ReadKey.pm and ANSIScreen.pm for entry/positioning. This brings in other
considerations but I can deal with them. I'm just concerned about finding the
most efficient (read: fastest) way to do this, for my own knowledge.


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

Date: 23 Aug 2001 16:38:00 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: dynamic menu (efficiency)
Message-Id: <9m3t3o$jtl$1@charity.cs.utexas.edu>

In article <toaqli9e61ti1c@corp.supernews.com>,
 <four12and8up@unspam-me.yahoo.com> wrote:
>I'm fooling around with keyboard input and wanted to create dynamic menu
>choices similar to what Internet Explorer does on the address line.
  :
  :
>My question is about efficiency. I thought I'd iterate through an array of
>all 50 states when the first character is entered, and put all matches into
>a hash or arrays that corresponds with the number of characters entered.
>
>Say $match{0} contains an array of the 50 states.
>
>When the first letter is entered, iterate through @{$match{0}} and get:
>$match{1} = ['Maine' .. 'Montana',];

Well yeah, except that since what you're describing is a stack, you
want to use an array instead of a hash.  Then you can do something like
this:

	push (@match,
	    [
		grep ( $character eq substr($_, $#match, 1),
		    @{ $match[$#match] } )
	    ] );

Or if you want to do it the long, slow way:

	my $newmatches = [];

	foreach my $m (@{ $match[$#match] })
	{
	    push (@$newmatches, $m)
		if $character eq substr ($m, $#match, 1);
	}

	push (@match, $newmatches);

>Then the next letter 'i' is entered. Iterate @{$match{1}} and get:
>$match{2} = ['Michigan', 'Minnesota', 'Mississippi', 'Missouri',];
>
>Then if I delete the 'i' I could simply delete $match{2}.

Which is really easy:

	pop @match;

I think the way you've described is just about the most efficient way
to do it, unless the menus never change.  If they never change, then
you can compute all possible sublists ahead of time and store a sort of
a tree data structure where at each node, you have a list of keystrokes
and which child nodes they take you to.  For this list:

	@choices = qw{ foo bar fun };

the data structure might look like this:

	{
	    choices => [ 'bar', 'foo', 'fun' ],
	    chars =>
	    {
		'f' =>
		{
		    choices => [ 'foo', 'fun' ],
		    chars =>
		    {
			'o' =>
			{
			    choices => [ 'foo' ],
			    chars => 
			    {
				'o' =>
				{
				    choices => [ 'foo' ],
				    chars => {}
				}
			    }
			},
			'u' =>
			{
			    choices => [ 'fun' ],
			    chars =>
			    {
				'n' =>
				{
				    choices => [ 'fun' ],
				    chars => {}
				}
			    }
			}
		    }
		},
		'b' =>
		{
		    choices => [ 'bar' ],
		    chars =>
		    {
			'a' =>
			{
			    choices => [ 'bar' ],
			    chars =>
			    {
				'r' =>
				{
				    choices => [ 'bar' ],
				    chars => {}
				}
			    }
			}
		    }
		}
	    }
	}

As you can see, the data structure would get pretty large pretty
quickly.  Obviously, you are going to be wasting time if you build this
big data structure on the fly.  But if you do have the data structure,
then wherever you are in the data structure, you can simply print out
$foo->{choices}, read a character, and then look it up in
$foo->{chars}.  If $foo->{chars} doesn't exist, then it wasn't a valid
character.  If it was, then you advance to that position in the tree.
(You probably want to keep a stack of previous positions in the data
structure in case the user hits backspace and you want to back up.)

There's also one completely different way to do it.  That is to put all
the choices into an ordered array, and then use a binary search to take
the string that the user has already typed and find the indices of the
first and last items in the array that match the string.

So, if your array looks like this:

	Maine
	Maryland
	Massachusetts
	Michigan
	Minnesota
	Mississipi
	Missouri
	Montana

and if the user has typed "Mi", you'd do a binary search for the first
"Mi" thing in the array and then another for the last "Mi" thing in the
array.  This would give you the indices 3 and 6, respectively, and if
you wanted to print the list out, you could simply print a range of the
array ("@choices[3..6]").

When the user types another character, you can start the binary search
using the indices you already had, because if they type more characters
this is only going to narrow the selection.

Again, if you want the ability to back up, you probably want to push
the indices onto a stack.  (It's not absolutely necessary, though, and
you might decide to assume that backspacing is rare in practice and
doesn't need to be optimized.)

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: Thu, 23 Aug 2001 14:14:01 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: help with searching for occurances of......
Message-Id: <MPG.15ef11dc9776ccef989694@news.onemain.com>

John J. Trammell wrote:
> On 23 Aug 2001 09:19:34 -0700, Paul wrote:
> > I have a large data file that on each line contains a 6 digit ID
> > number. I would like to run a script to find, for each ID number (0 to
> > 999999) how many times each one occurs in the file.

You want 1,000,000 pieces of information ???
 
> my %count;
> 
> while (<>) { chomp; $count{$_}++; }
> 
> for (sort keys %count) { print "$_=$count{$_}\n" }

This will work, but you have to read really, Really, REALLY fast :)


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

Date: 23 Aug 2001 18:38:17 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: help with searching for occurances of......
Message-Id: <slrn9ob2ik.ifs.trammell@haqq.hypersloth.net>

On Thu, 23 Aug 2001 14:14:01 -0400, Samneric wrote:
> This will work, but you have to read really, Really, REALLY fast :)

Unless he's running on a teletype.  Then he just needs to scare
up a pallet or two of paper.

-- 
Steve Balmer, CEO of Microsoft, recently referred to LINUX as a cancer.
Unsurprisingly, that's incorrect; LINUX was released on August 25th, 1991
and is therefore a virgo.


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

Date: 23 Aug 2001 11:16:59 -0700
From: stuartlemmen@hotmail.com (KrazyKat)
Subject: Help, MIME-Lite Error using send_by_smtp method!
Message-Id: <95e8c608.0108231016.770fefa8@posting.google.com>

I'm trying to use the MIME-Lite package to send emails with
attachments from a Win NT 4 workstation. I have the latest version
installed using ActiveState ppm. The attachments seem to work now that
I am using the "send_by_smtp()" method and the mail goes to the person
in the 'To' field but it does *not* also go to the person in the 'Cc'
field *and* I am forever getting this error message:

"The system cannot find the path specified."

When I tried to debug the code(below) to find what was generating this
error, I realized it was showing up "randomly" while debugging. Then I
realized it was an error apparently generated by another process(?),
in other words, the error always appeared after a certain amount of
time while debugging which makes it very hard to track down. Does
anyone have any ideas?? Here is my code:

#!perl -w
use strict;
use MIME::Lite;
my $msg;
$msg = MIME::Lite->new(
                From    => 'me@myhost.com',
                To      => 'me@anotherhost.com',
                Cc      => 'me@yetanotherhost.com',
                Subject => 'Testing MIME-Lite with attachments',
                Type    => 'TEXT',
                Data    => "Here is a little image for you!"
                );
$msg->attach(
             Type     => 'image/gif',
             Path     => 'd:/Images/TestImage.jpg',
             Filename => 'AlternateName.jpg'
            );
$msg->send_by_smtp('mysmtp.host.com', Timeout => 60);
exit 1;

THANKS!!

-Krazy Richard


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

Date: Thu, 23 Aug 2001 14:45:43 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: local exec via cgi
Message-Id: <9m3n1b$sv0$1@slb5.atl.mindspring.net>

"gnari" <gnarinn@hotmail.com> wrote in message
news:998073498.838356931228191.gnarinn@hotmail.com...
> In article <129rntscc67ecs5cm8hehf82cpet5618fi@4ax.com>,
> GunneR  <ds@ss.com> wrote:
> >I know this is very insecure, and im not sure if its even perl
> >related, but...
> >
> >Im trying to write a cgi script that executes local code (via system,
> >exec, etc) on the system that visits the page.
>
> do you mean that you want to use a browser on your PC to run cgi script
> on a server that will somehow start local code on your PC ?
>
> then i have 2 questions:
***snipped***

TinyWeb (free) or MicroWeb (shareware) can be used to provide a "local"
server on MS Windows.

Bill Segraves
Auburn, AL




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

Date: Thu, 23 Aug 2001 22:03:52 +0100
From: "Gareth Hinton" <gareth.hinton@btinternet.com>
Subject: Re: Looking for Script
Message-Id: <9m3s94$279$1@neptunium.btinternet.com>

If there is no other way around it:

You can get hold of various freeware/shareware, or at least very cheap
applications which will monitor devices and run a command if the device
ceases to respond. I'm sure you could run a batch file/perl script to do
what you want.
Servers alive is a very cheap (free I believe for a limited amount of
devices) utility which will do the job.
One advantage with Servers Alive that I found was that it could perform
another command when the device comes back up, so you could even re-instate
the routers. Do a search for it.
No doubt there are many others.

Gaz


"T Mesbah" <tmesbah@hotmail.com> wrote in message
news:6e9d9699.0108170605.2eddec74@posting.google.com...
> The reason of using a static route is that we use encryptor on front
> of the router and these encryptor block all routing protocols and the
> only way to make it working is to use static route. I am looking for
> script to remove the static route and use an another path without
> caming in at the office and remove them manually.
>
> Thanks
>
>
> "Ian M" <ian.mulvihill.no.spam@computer.org> wrote in message
news:<3b7bc173$0$227$cc9e4d1f@news.dial.pipex.com>...
> > "Dennis H" <dennis@noreplies.com> wrote in message
> > news:KGOe7.42984$rV6.2110903@e420r-atl2.usenetserver.com...
> > >
> > >
> > > Uhhhh... why?
> > >
> > >
> > > "T Mesbah" <tmesbah@hotmail.com> wrote in message
> > > news:6e9d9699.0108151340.4493cafd@posting.google.com...
> > > > Hi,
> > > >
> > > > 1) I have two Cisco router routerA and routerB.
> > > > 2) In routerA I have static route "ip route X.X.X.X Y.Y.Y.Y Z.Z.Z.Z"
> > > > to access routerB.
> > > >
> > > > I am looking for script that ping routerB each 5 minutes and if
> > > > routerB is down then the script need to telnet to routerA and remove
> > > > these static route.
> > > >
> > > > Many Thanks
> > >
> > >
> >
> > That's what routing protocols are for.  Is this too easy and efficient?
> >
> > Either you have a more complicated and unsual reason to do it this way,
or
> > misunderstand the (preferable) options.  Do you want clarify what you're
> > trying to solve, and we could make some suggestions?
> >
> >
> > Cheers,
> > Ian




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

Date: 23 Aug 2001 13:02:38 -0700
From: stuartlemmen@hotmail.com (KrazyKat)
Subject: Re: lwp-request warnings coming from Net::Domain
Message-Id: <95e8c608.0108231202.403d97f5@posting.google.com>

"kenneth" <japh_klch@programmer.net> wrote in message news:<9lh2kr$r3k4@imsp212.netvigator.com>...
> When I run:
> 
> D:\temp>lwp-request
> The system cannot find the path specified.
> Use of uninitialized value in scalar assignment at
> D:/Perl/site/lib/Net/Domain.pm line 202.
> Use of uninitialized value in scalar assignment at
> D:/Perl/site/lib/Net/Domain.pm line 202.
> Use of uninitialized value in pattern match (m//) at
> D:/Perl/site/lib/Net/Domain.pm line 226.
> Use of uninitialized value in split at D:/Perl/site/lib/Net/Domain.pm line
> 233.
> ...
> 
> Why this still haven't been fixed in the latest version? I've already
> updated to libwww-5.53 and libnet-1.0703. I see that in Net::Domain it tries
> to run "domainname" to get the domain name, but this Unix command is not
> available on Windows.
> 
> Any idea?
> 
> Kenneth


Ken, I just ran into this brick wall myself(grumble). Do you know for
a fact that a bug report was issued? If not I'll gladly do the
paperwork unless you'd rather :o) Also, have you found a workaround
that I could use in the meantime? Thanks.

For everyone's edification here is the detrimental Windoze un-friendly
line:

chop($dom = `domainname 2>/dev/null`) unless(defined $dom);
(L: 157 in package Net::Domain)


-Krazy Richard


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

Date: 23 Aug 2001 20:08:01 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Openning a file
Message-Id: <slrn9oaolc.6m2.abigail@alexandra.xs4all.nl>

Tassilo von Parseval (Tassilo.Parseval@post.rwth-aachen.de) wrote on
MMCMXIII September MCMXCIII in <URL:news:3B842C47.2000408@post.rwth-aachen.de>:
@@ SpeedCancer wrote:
@@ 
@@ > Is it possible to open and close a file in a sub routine?
@@ > Im using this code but it does'nt seem to work
@@ > 
@@ > &openfile (ARGUMENTLIST)
@@ > 
@@ > sub openfile
@@ >     use strict;
@@ 
@@ Using strict is a good idea, but why only inside a subroutine? However, 
@@ you forgot to wrap your sub into curly brackets.
@@ 
@@ >     my $filename = ("file.txt");
@@ 
@@ This is dangerous. On the left, you have scalar context and on the right 
@@ a one-element list.

You are making a classical newbie mistake - assuming that () means list.

Please write down 500 times (in blood):

        THERE ARE NO LISTS IN SCALAR CONTEXT.

What you have on the right side of the assignment is an expression.
An expression with parenthesis, often used to indicate precedence.

Would you expect:

        (4) + (5)

to return 2? After all, `+' forces scalar context on its arguments,
and that would be one element lists according to your reasoning....

@@ Interestingly enough, Perl does in fact store the string in the 
@@ variable. I would have expected that it assigned 1 to $filename. Perhaps 
@@ one of DWIMings.

No DWIM. There's no array in scalar context here.


Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
#    A Bishop sits near
#    the forest. A trout leaping out
#    of the pool. Or Wunt.


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

Date: Thu, 23 Aug 2001 20:37:03 GMT
From: "SpeedCancer" <gmandesigns@hotmail.com>
Subject: Re: Openning a file
Message-Id: <PPdh7.57462$gj1.5280792@bgtnsc05-news.ops.worldnet.att.net>


Abigail <abigail@foad.org> wrote in message
news:slrn9oaolc.6m2.abigail@alexandra.xs4all.nl...
> Tassilo von Parseval (Tassilo.Parseval@post.rwth-aachen.de) wrote on
> MMCMXIII September MCMXCIII in
<URL:news:3B842C47.2000408@post.rwth-aachen.de>:
> @@ SpeedCancer wrote:
> @@
> @@ > Is it possible to open and close a file in a sub routine?
> @@ > Im using this code but it does'nt seem to work
> @@ >
> @@ > &openfile (ARGUMENTLIST)
> @@ >
> @@ > sub openfile
> @@ >     use strict;
> @@
> @@ Using strict is a good idea, but why only inside a subroutine? However,
> @@ you forgot to wrap your sub into curly brackets.
> @@
> @@ >     my $filename = ("file.txt");
> @@
> @@ This is dangerous. On the left, you have scalar context and on the
right
> @@ a one-element list.
>
> You are making a classical newbie mistake - assuming that () means list.
>
> Please write down 500 times (in blood):
>
>         THERE ARE NO LISTS IN SCALAR CONTEXT.
>
> What you have on the right side of the assignment is an expression.
> An expression with parenthesis, often used to indicate precedence.
>
> Would you expect:
>
>         (4) + (5)
>
> to return 2? After all, `+' forces scalar context on its arguments,
> and that would be one element lists according to your reasoning....
>
> @@ Interestingly enough, Perl does in fact store the string in the
> @@ variable. I would have expected that it assigned 1 to $filename.
Perhaps
> @@ one of DWIMings.
>
> No DWIM. There's no array in scalar context here.
>
>
> Abigail
> --
> perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'
> #    A Bishop sits near
> #    the forest. A trout leaping out
> #    of the pool. Or Wunt.

my $filename = ("file.txt"); #does'nt load the file into the Scalar context.
it simply tells the FH to open file.txt into the @text array. And if you
will try my code without the sub routine it works. Try putting this into
your interpreter
You will of course actually have to have file.txt just create one.

#!/usr/bin/perl -w
use strict;
my $filename = ("file.txt"); #Tells FH the name of the file to open.
open FH, "<$filename" or die "Could not open file: $!\n";
my @text = <FH>; #creates an array out of the opened file
print @text; #prints the file

Ureka It works! now that we all know it works. maybe someone can tell me how
to put it in a sub.  And no offense to anyone but you should work on reading
your code. Especially Tad McClellan from Texas




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

Date: 23 Aug 2001 21:53:39 GMT
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: Openning a file
Message-Id: <9m3u13$9d7@gap.cco.caltech.edu>

In article <slrn9oaolc.6m2.abigail@alexandra.xs4all.nl>,
Abigail <abigail@foad.org> wrote:
>Please write down 500 times (in blood):
>
>        THERE ARE NO LISTS IN SCALAR CONTEXT.

How would you describe this?

    my $x = qw/a b c/;

According to perlop, qw// generates "a real list".

I know, you'll probably tell me it's an implied comma-operator.
But that's not how the documentation describes it.  ;-)

-- Gary Ansok


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

Date: Thu, 23 Aug 2001 16:57:22 -0500
From: "cp" <cpryce@pryce.net>
Subject: Re: Openning a file
Message-Id: <DYeh7.10389$x84.2994155@ruti.visi.com>


"SpeedCancer" <gmandesigns@hotmail.com> wrote in message
news:PPdh7.57462$gj1.5280792@bgtnsc05-news.ops.worldnet.att.net...
<snip

> > @@ SpeedCancer wrote:
> > @@
> > @@ > Is it possible to open and close a file in a sub routine?
> > @@ > Im using this code but it does'nt seem to work
> > @@ >
> > @@ > &openfile (ARGUMENTLIST)
> > @@ >
> > @@ > sub openfile
> > @@ >     use strict;
> > @@
> > @@ Using strict is a good idea, but why only inside a subroutine?
However,
> > @@ you forgot to wrap your sub into curly brackets.
> > @@
> > @@ >     my $filename = ("file.txt");
> > @@
> > @@ This is dangerous. On the left, you have scalar context and on the
> right
> > @@ a one-element list.
> >
> > You are making a classical newbie mistake - assuming that () means list.
> >
> > Please write down 500 times (in blood):
> >
> >         THERE ARE NO LISTS IN SCALAR CONTEXT.
> >
> > What you have on the right side of the assignment is an expression.
> > An expression with parenthesis, often used to indicate precedence.
> >
> > Would you expect:
> >
> >         (4) + (5)
> >
> > to return 2? After all, `+' forces scalar context on its arguments,
> > and that would be one element lists according to your reasoning....
> >

<snip>

>
> my $filename = ("file.txt"); #does'nt load the file into the Scalar
context.
> it simply tells the FH to open file.txt into the @text array. And if you
> will try my code without the sub routine it works. Try putting this into
> your interpreter
> You will of course actually have to have file.txt just create one.
>
> #!/usr/bin/perl -w
> use strict;
> my $filename = ("file.txt"); #Tells FH the name of the file to open.
> open FH, "<$filename" or die "Could not open file: $!\n";
> my @text = <FH>; #creates an array out of the opened file
> print @text; #prints the file
>
> Ureka It works! now that we all know it works. maybe someone can tell me
how
> to put it in a sub.  And no offense to anyone but you should work on
reading
> your code. Especially Tad McClellan from Texas

First, you should go to your computer, log onto the machine where Perl is
installed, go to a command line (DOS prompt? I hate Wintel) and type:

perldoc perlsub
perldoc -q list
and
perldoc -f open

these will give perl documentation on several topics that you have questions
about.

You code works, yes. It's also wrong, and you were told why in several
posts, including the above referenced quotes. In fact, the very people you
have just pissed-off told you the answer to your questions. Several times.
To sum up:

1) my $filename = 'file.txt'; # use single quotes, as you don't need
interpolation, loose the parantheseis.
2) You _can_ open a file in a sub routine, if you learn how to declare a sub
routine.

my $filename = 'file.txt'; # make sure to provide the full path if needed.
openfile($filename);
# Alternatively, as Tad pointed out, you could say openfile("file.txt");
Note the quotes.

sub openfile {
    # Note the braces to wrap the sub's code. This is one thing that you
missed, and
    # And it was pointed out.

     my $input = shift; # gets the argument that was passed in.
     open (FH, $filemame) or die "$!"; # Always always check system calls.
     # $! is a magic variable, it holds the error message from failed system
calls.

     while (<FH>) { # read the file line by line until EOF
        # do whatever you want with each line
     }
    close FH or die "$!"; # Again, check that the file closes!
    # or my @text = <FH>; yada yada yada...
} # end sub

cp




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

Date: Thu, 23 Aug 2001 17:04:15 -0500
From: "cp" <cpryce@pryce.net>
Subject: Re: Openning a file
Message-Id: <43fh7.10644$x84.2995156@ruti.visi.com>


"Gary E. Ansok" <ansok@alumni.caltech.edu> wrote in message
news:9m3u13$9d7@gap.cco.caltech.edu...
> In article <slrn9oaolc.6m2.abigail@alexandra.xs4all.nl>,
> Abigail <abigail@foad.org> wrote:
> >Please write down 500 times (in blood):
> >
> >        THERE ARE NO LISTS IN SCALAR CONTEXT.
>
> How would you describe this?
>
>     my $x = qw/a b c/;
>
> According to perlop, qw// generates "a real list".
>
> I know, you'll probably tell me it's an implied comma-operator.
> But that's not how the documentation describes it.  ;-)
>

no. It's an implied split. $x gets the value of three, the number of
elements in the list.





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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

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 1599
***************************************


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