[17571] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4991 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 29 18:15:55 2000

Date: Wed, 29 Nov 2000 15:15:24 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <975539724-v9-i4991@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 29 Nov 2000     Volume: 9 Number: 4991

Today's topics:
    Re: Recursively load all objects in an HTML page... <elijah@workspot.net>
    Re: Search & Replace (Tad McClellan)
    Re: Search & Replace <isterin@hotmail.com>
    Re: Search & Replace nobull@mail.com
    Re: Should { } always indicate a scope? nobull@mail.com
    Re: Skipping lines in a file <uri@sysarch.com>
    Re: splitting a string into an array and preserving the (Abigail)
    Re: splitting a string into an array and preserving the <xzrgpnys@yvtugubhfrovm.pbz>
        SQL to Perl Interface maintenance packages? <xeno@bigger.aa.net>
    Re: SQL to Perl Interface maintenance packages? <jeff@vpservices.com>
    Re: system() argument: multiple spaces collapsed into s <jeff.r.olson@westgroup.com>
        Tieing an object bdesany@my-deja.com
    Re: Why? (Tad McClellan)
    Re: Why? (Tom Christiansen)
    Re: Why? <johngros@Spam.bigpond.net.au>
    Re: Why? <johngros@Spam.bigpond.net.au>
    Re: Why? <johngros@Spam.bigpond.net.au>
    Re: Why? <ren.maddox@tivoli.com>
    Re: Why? (Tad McClellan)
    Re: Wrtiing on a Win32 system (Arek P)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 29 Nov 2000 21:43:34 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Recursively load all objects in an HTML page...
Message-Id: <eli$0011291603@qz.little-neck.ny.us>

In comp.lang.perl.misc, Eric Bohlman <ebohlman@omsdev.com> wrote:
> snakedjip@yahoo.com wrote:
> > A browser (like IE or Netscape) would then start downloading all of the
> > elements of that web page.  For example, if a web page contains "<IMG
> > SRC=...>" tags, or "<SCRIPT SRC=...>" tags, the browser would download
> > the contents of those files, and embed them in the final document.  Of
 ..
> > for "SRC=<document>", and load the contents of this <document> with
> > another LWP call, and do that recursively...
> That had better be the first solution that comes to mind, as it's the only
> solution that fits the problem description.

Perhaps he wanted some tool that abstracted that from him. (Besides
the solution need not be recursive, so it is not the "only solution
that fits".)

> > Is there an easier way ?
> No.

Use a proxy that saves eveything, then have an intern/trained-monkey
view the pages through a browser using that proxy?

> > What packages do you suggest I use ?
> HTML::LinkExtor.  It will take care of the parsing for you and give you a
> list of the URLs that you need to deal with.

It doesn't make it easy to know that ILAYERs would not be loaded by
IE or that <LINK REL=stylesheet HREF=foo> would be followed by a "4.x"
browser but not a <LINK REL=home HREF=foo> would not. Or that Netscape
loads images specified as background to a <TR> but most other
browsers don't.

Plus if you get text/html page (eg a 404) <IMG>, a typical browser
won't recurse into that, but a text/html page (even a 404) loaded
in a <FRAME> would be.

And then you don't even want to consider the mess if you have a
link like <IMG SRC="magic"> where the server looks at the
Accept: headers to decide what kind of image to return for "magic".
In that case your User-Agent tool needs to duplicate request headers
for the browser(s) in question. 

This sort of thing requires a specialized type of robot. I've written
a crude tool to do this, but I have not released it. I don't want
to get maintaince questions about it: I know it is far from perfect.

Here's a section of code from it, illustrating what I've done for
solving this problem. $bv has the 'browser version'.

	if ($bv =~ /lynx/i) {
	  $getframes     = 1;	# <FRAME>
	  $getiframes    = 0;	# <IFRAME>
	  $getlayers     = 0;	# <LAYER>
	  $getembed      = 0;	# <EMBED>
	  $getimages     = 0;	# <IMG>
	  $gettrimages   = 0;	# background= in <TR>
	  $gettableimages= 0;	# background= in <TABLE>, <TH>, <TD>
	  $getjavascript = 0;	# <SCRIPT src=>, not just JS, actually
	  $getjava       = 0;	# <APPLET>
	  $getcss        = 1;	# <STYLE src=> / <LINK REL=stylesheet HREF=>
	  $getmetaequiv  = 1;	# <META HTTP-EQUIV=refresh"content=>
	} elsif ($bv =~ /lwp/i) {
	  $getframes     = 0;
	  $getiframes    = 0;
	  $getlayers     = 0;
	  $getembed      = 0;
	  $getimages     = 0;
	  $gettrimages   = 0;
	  $gettableimages= 0;
	  $getjavascript = 0;
	  $getjava       = 0;
	  $getcss        = 0;
	  $getmetaequiv  = 0;
	} elsif ($bv =~ /links/i) {
	  $getframes     = 1;
	  $getiframes    = 0;
	  $getlayers     = 0;
	  $getembed      = 0;
	  $getimages     = 0;
	  $gettrimages   = 0;
	  $gettableimages= 0;
	  $getjavascript = 0;
	  $getjava       = 0;
	  $getcss        = 0;
	  $getmetaequiv  = 0;
	} elsif ($bv =~ /w3w/i) {
	  $getframes     = 1;
	  $getiframes    = 0;
	  $getlayers     = 0;
	  $getembed      = 0;
	  $getimages     = 0;
	  $getembed      = 0;
	  $getimages     = 0;
	  $gettrimages   = 0;
	  $gettableimages= 0;
	  $getjavascript = 0;
	  $getjava       = 0;
	  $getcss        = 0;
	  $getmetaequiv  = 0;
	} elsif ($bv =~ /netscape/i) {
	  $getframes     = 1;
	  $getiframes    = 0;
	  $getlayers     = 1;
	  $getembed      = 1;
	  $getimages     = 1;
	  $getjavascript = 1;
	  $getjava       = 1;
	  $getcss        = 1;
	  $getmetaequiv  = 1;

	  $gettableimages=
	  $gettrimages   = ($bv =~ /[456789]\./);
	} elsif ($bv =~ /explorer/i) {
	  $getframes     = 1;
	  $getiframes    = 1;
	  $getlayers     = 0;
	  $getembed      = 1;
	  $getimages     = 1;
	  $getjavascript = 1;
	  $getjava       = 1;
	  $getcss        = 1;
	  $getmetaequiv  = 1;

	  $gettableimages= ($bv =~ /[456789]\./);
	  $gettrimages   = 0;
	} elsif ($bv =~ /opera/i) {
	  # Just a guess for opera, really. I didn't test it carefully.
	  $getframes     = 1;
	  $getiframes    = 0;
	  $getlayers     = 0;
	  $getembed      = 0;
	  $getimages     = 1;
	  $getjavascript = 0;
	  $getjava       = 1;
	  $getcss        = 1;
	  $getmetaequiv  = 1;
	  $gettableimages= 0;
	  $gettrimages   = 0;
	} elsif ($bv =~ /icab/i) {
	  $getframes     = 1;
	  $getiframes    = 0;
	  $getlayers     = 0;
	  $getembed      = 0;
	  $getimages     = 1;
	  $getjavascript = 0;
	  $getjava       = 1;
	  $getcss        = 1;
	  $getmetaequiv  = 1;
	  $gettableimages= 1;
	  $gettrimages   = 0;
	}

Elijah
------
also has a library of request headers used by different browsers


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

Date: Wed, 29 Nov 2000 12:25:12 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Search & Replace
Message-Id: <slrn92aevo.3r4.tadmc@magna.metronet.com>

Kris Steinwender <kst3inw3@usvisi0n.c0m> wrote:

>    I've been thrown into writing a little Perl.  


Then you will need to learn a little Perl.

There are lots of docs that are already on your hard disk
that will help you learn the parts you need.


>What I need to do is read
>in a text file,  


   perldoc -f open


>and get the value of line 1.  I then
>have to cross reference a dictionary file that contains mappings for that
         ^^^^^^^^^^^^^^^
>number to another number.

That is one of the "key phrases" that should make you think
that a hash data structure would be helpful.

   perldoc perldata


>    After this,  I have to truncate the IDN field to the right 5 characters.


   perldoc -f substr


>    When all this finishes, I have to rewrite the file,  with the change
>within the file.


   perldoc -f open   # again
   perldoc -f print

   perldoc -q change

      "How do I change one line in a file/
       delete a line in a file/
       insert a line in the middle of a file/
       append to the beginning of a file?"


>    The dictionary file looks like this (the format is:  characters 1->3 are
>the lookups,  4-8 are the replacement number).


   perldoc -f unpack


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 29 Nov 2000 19:13:08 GMT
From: ISTERIN <isterin@hotmail.com>
Subject: Re: Search & Replace
Message-Id: <903kft$cs0$1@nnrp1.deja.com>

Reading files preatty simple

open(FILE, "file.txt");

$match = 25511037;

Then

while($line = <FILE>) {
chomp($line);
#here match
my $first_3 = substr($match, 0, 3);
my $subst = substr($match, 3);
if ($line =~ m/$first_3/)
{
$line =~ s/$first_3/$subst/g;
} else {
next;
}
}

Something like this above, use regular expressions to match and
substitute.  I just did some easy matching but you might need a
reference on reg exp to do a better job, since I am not positive about
your data.

Ilya Sterin

In article <3a25322b$1_2@goliath2.newsfeeds.com>,
  "Kris Steinwender" <k s t 3 i n w 3 @ u s v i s i 0 n . c 0 m> wrote:
> Hi all,
>
>     I've been thrown into writing a little Perl.  What I need to do is
read
> in a text file,  and get the value of line 1.  I then
> have to cross reference a dictionary file that contains mappings for
that
> number to another number.
>
>     After this,  I have to truncate the IDN field to the right 5
characters.
>
>     When all this finishes, I have to rewrite the file,  with the
change
> within the file.
>
>     The incoming file looks like this:
>
> ACT 250
> JCD 00
> RXN 000838-1
> IDN 00002228
>
>     And should go out like this:
>
> ACT 11037
> JCD 00
> RXN 000838-1
> IDN 02228
>
>     The dictionary file looks like this (the format is:  characters
1->3 are
> the lookups,  4-8 are the replacement number).
>
> 25511037 StoreA
> 33445102 Store B
> 47235026 StoreC
>
>     Thank you all in advance, any help or insight would be greatly
> appreciated.
>
> -Kris Steinwender,  U.S. Vision
> kst3inw3@usvis0n.c0m
> (Replace numbers with letters to reply via e-mail)
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----==  Over 80,000 Newsgroups - 16 Different Servers! =-----
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 29 Nov 2000 20:18:12 +0000
From: nobull@mail.com
Subject: Re: Search & Replace
Message-Id: <u9n1eio7ln.fsf@wcl-l.bham.ac.uk>

"Kris Steinwender" <k s t 3 i n w 3 @ u s v i s i 0 n . c 0 m> writes:
>     I've been thrown into writing a little Perl.

May I suggest therefore that you learn a little Perl?

>  What I need to do is read
> in a text file,  and get the value of line 1.  I then
> have to cross reference a dictionary file that contains mappings for that
> number to another number.
> 
>     After this,  I have to truncate the IDN field to the right 5 characters.
> 
>     When all this finishes, I have to rewrite the file,  with the change
> within the file.

So where do you perceive a problem?

>     The incoming file looks like this:
> 
> ACT 250
> JCD 00
> RXN 000838-1
> IDN 00002228
> 
>     And should go out like this:
> 
> ACT 11037
> JCD 00
> RXN 000838-1
> IDN 02228
> 
>     The dictionary file looks like this (the format is:  characters 1->3 are
> the lookups,  4-8 are the replacement number).
> 
> 25511037 StoreA
> 33445102 Store B
> 47235026 StoreC

OK just this once have a fish:

#!/usr/bin/perl -w
# Untested!
use strict;

my %rep;

open(DICT,'<dictfile') or die $!;
while (<DICT>) {
  /^(\d{3})(\d{5})/
    or die 'Bad entry in dictionary';
  $rep{$1} = $2;
}
close DICT or die $!;

open(FILE,'+<datafile') or die $!;
my @data = <FILE> or die 'Empty file';
$data[0] =~ s/(\d+)/$rep{$1} or die "No translation for $1"/e
  or die 'No number in first line';
s/^IDN .*(.....)/IDN $1/ for @data;
truncate FILE, 0 or die $!;
print FILE @data or die $!;
close FILE or die $!;
__END__

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 29 Nov 2000 17:50:58 +0000
From: nobull@mail.com
Subject: Re: Should { } always indicate a scope?
Message-Id: <u9snoaoef1.fsf@wcl-l.bham.ac.uk>

Jeff Pinyan <jeffp@crusoe.net> writes:

> The {...} used for dereferencing a reference (as in @{$aref}) are a right
> block, if they don't contain a simple expression.  

Can you explain that last bit "if they don't contain a simple
expression"?

I know that if the the {...} contain a word then they are handled
differently - it's almost as though the {} wern't there at all. @{foo}
is the same as @foo and can even refer to a lexically scoped variable.
The only difference is that @{foo} iterpolates into a string properly
even if followed by a word-character.

Are there any other situations where @{...} can be made to display
non-BLOCK semantics?  Note, I say "display".  If the compiler
optomises out the BLOCK where there's no observable difference
resulting from doing so then this is not worthy of mention when
discussing langauge semantics.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 29 Nov 2000 18:15:23 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Skipping lines in a file
Message-Id: <x77l5mbq6c.fsf@home.sysarch.com>

>>>>> "FS" == Flint Slacker <flint@flintslacker.com> writes:

  FS> $count = 0;
  FS> $process = 0;
  FS> while(<>) {
  FS> 	chomp;
  FS> 	if(/pattern/) { $process = 1; }
  FS> 	if($process) {
  FS> 		# do something with it
  FS> 		$count++;
  FS> 		if($count > $goodlines) { $process = 0; $count = 0; }
  FS> 	}
	
  FS> }

perl has many tricks to eliminate state variables. lookup scalar
 .. (range) and it will simplify your code (untested):

	while( <> ) {

		if ( /pattern/ .. $count++ > $goodlines ) {

			# crunch the line

			next ;
		}

		$count = 0 ;
	}

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: 29 Nov 2000 17:46:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <slrn92ag6t.mnq.abigail@tsathoggua.rlyeh.net>

On 29 Nov 2000 10:14:43 -0700, Tom Christiansen (tchrist@perl.com) wrote in comp.lang.perl.misc <URL: news:<3a253983$1@cs.colorado.edu>>:
++ In article <upba2t8l2ka3dhjr6iq2cu4p76c2bro9vj@news.supernews.net>,
++ Bernie Cosell  <bernie@fantasyfarm.com> wrote:
++ >and lots of us have accounts at "America Online", 
++ 
++ I rest my case.


Actually, the "old" and the "new" meaning don't differ that much.
After all, for many people, their shiny Pentium VI with 16 Gb of
RAM and a dozen Tb of disk storage is nothing more than a terminal
to an almighty thing - the Internet.

The only difference is that now people get impressed by animated
GIFs, and then by running code.



Abigail


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

Date: 29 Nov 2000 19:10:07 GMT
From: kevin metcalf <xzrgpnys@yvtugubhfrovm.pbz>
Subject: Re: splitting a string into an array and preserving the "\n"
Message-Id: <3A25551B.FAD07DE@yvtugubhfrovm.pbz>

Bernie Cosell wrote:
> 
> tchrist@perl.com (Tom Christiansen) wrote:
> 
> } ...  There's
> } no reason to kowtow to confusion by the uninformed masses.  Instead,
> } inform them.  Just blindly putting up with glaring inaccuracies
> } is what gets us bacteerias and noocyular missives.  All the world
> } is not Texas, you know.
> }
> } "Online" hardly means "Internet".   Bah.  Teach the kiddies.
> 
> Bah, yourself.  I guess that for folks who are inflexible and rooted in the
> past, English in general and computer-terminology in particular, must cause
> a lot of problems because it evolves and adapts so much.  For some time
> now, the *common* usage of 'online' has meant "connected to the internet"
> with more restrictive meanings [connected to a local net, or connected to a
> particular server] as being context-dependent subsets --- the general
> unqualified [by context or otherwise] meaning of the term has grown to
> embrace the Internet [as I pointed out: look at IE, with "delete all
> offline content" and other online/offline discriminations; Agent has
> online/offline defaults; you can go visit "The Atlantic (magazine) Online".
> And most of us dial into "Online Service Providers" and lots of us have
> accounts at "America Online", ICQ finds friends who are "online", etc, etc,
> etc.  But then, I guess all the folk that work at those companies all are
> just "kiddies" and don't know whereof they speak...  But wait...

So your saying that because people use America Online, we have to start
dumming down our vocabulary to greet them?  When I read his post I see
the 'kiddies' as being the uninformed that you are conversing with.  Why
you have to rant and rave about how you misunderstood what he said is
beyond the scope of this group.  Do you also think that the phrase
'hacker' should now only mean malevolent, misguided miscreants who find
it amusing to mame mainfraims?  Congratulations!  You just won a million
dollars and a goat.  (If one doesn't get it, one should ask one's
'kiddies' who play video games!)  Anyway, I think Tom is right.  Nyah! 
;)

Kevin
--
email: xzrgpnys@yvtugubhfrovm.pbz
Huh?  http://www.flactem.com/utils/rot13.html


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

Date: 29 Nov 2000 12:40:59 -0800
From: Xeno Campanoli <xeno@bigger.aa.net>
Subject: SQL to Perl Interface maintenance packages?
Message-Id: <3a2569db_1@huge.aa.net>

If I've got some perl classes, each corresponding to a row in an SQL database,
are there any packages out there for maintaining both the Perldefinitions from SQLside
changes and the SQL definitions from the Perl side changes?

Thanks for any feedback.

-- 
Xeno Campanoli (erstwhile Xeno Whitenack, and Rick Burgess)
Email:	xeno@aa.net	(Web pages:  http://www.aa.net/~xeno)


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

Date: Wed, 29 Nov 2000 13:00:31 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: SQL to Perl Interface maintenance packages?
Message-Id: <3A256E6F.1F49C2A6@vpservices.com>

Xeno Campanoli wrote:
> 
> If I've got some perl classes, each corresponding to a row in an SQL database,
> are there any packages out there for maintaining both the Perldefinitions from SQLside
> changes and the SQL definitions from the Perl side changes?

It's a bit difficult for me to tell what you are asking, but one
possible interpretation would lend itself to DBD::RAM, a driver for DBI
that allows you to treat perl data structures as a SQL accessible
database with or without storing them to disk.  If you can get more
specific, perhaps there are other answers.

-- 
Jeff


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

Date: Wed, 29 Nov 2000 12:05:35 -0600
From: "Jeffrey R. Olson" <jeff.r.olson@westgroup.com>
Subject: Re: system() argument: multiple spaces collapsed into single space
Message-Id: <3a254537$1@woodstock.int.westgroup.com>

"Jeffrey R. Olson" <jeff.r.olson@westgroup.com> wrote in message
news:3a243940$1@woodstock.int.westgroup.com...
> I'm running ActivePerl 522 on Windows NT 4.0, and am having the following
> problem with the system() function:
>
> I've created a simple example of the problem I'm having.  Say I have a
> script test1.pl:
>
> #---------
> my $infile = "hello  world";
> print "\$infile in test1.pl: $infile\n";
> system qq(perl "test2.pl" "$infile");
> #---------
>
> And say test2.pl looks like this:
>
> #---------
> my $infile = shift;
> print "\$infile in test2.pl: $infile\n";
> #---------
>
> Upon running test1.pl, the output is this:
>
> $infile in test1.pl: hello  world
> $infile in test2.pl: hello world
>
> Note how the two spaces between "hello" and "world" are collapsed into a
> single space.  In fact, it seems that any number of consecutive spaces is
> collapsed into a single space.
>

Thanks to Larry Rubinow (larry.rubinow@westgroup.com) for helping me figure
out a way to get this to work.  Here is the solution:

Change the third line in test1.pl to

system "perl", "test2.pl", qq("$infile");

and the output now becomes:

$infile in test1.pl: hello  world
$infile in test2.pl: hello  world

just as one would hope.  The reason?  Here are Larry's comments:

"See the documentation for exec(), which is referenced in the docs for
system():

"If there is more than one argument in LIST, or if LIST is an array with
more than one value, calls execvp(3) with the arguments in LIST. If there is
only one scalar argument or an array with one element in it, the argument is
checked for shell metacharacters, and if there are any, the entire argument
is passed to the system's command shell for parsing (this is `/bin/sh -c' on
Unix platforms, but varies on other platforms). If there are no shell
metacharacters in the argument, it is split into words and passed directly
to `execvp()', which is more efficient."

"Perl is splitting your single-string parameter into words and
reconstituting it later -- thereby losing the double space."

I had tried the multiple-argument form of system() earlier, but could never
get it to work because of the spaces in $infile.  The qq("") construct is
something I'll definitely keep in my bag o' tricks!

Thanks for the help, Larry.

Jeff

____________________________
Jeff Olson
Portal & E-Solutions Development Group, West Group
651.687.4858
jeff.r.olson@westgroup.com







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

Date: Wed, 29 Nov 2000 22:32:28 GMT
From: bdesany@my-deja.com
Subject: Tieing an object
Message-Id: <90405s$nfv$1@nnrp1.deja.com>

I have a Graph::Undirected object ($G), which is rather large and I'd
like to tie it so memory usage isn't so much of an issue. Being the
newcomer to perl (and programming in general) that I am, it is not
immediately obvious to me how to tie this object. MLDBM seems like it
might be the thing, but the docs tell me it works on hashes (%o),
whereas even though my object references a multilevel hash, it is
outwardly a scalar ($G). Does anyone have an approach to this problem I
can explore? Or maybe even a canned recipe to actually accomplish
this? :) Thanks-
-Brian.



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 29 Nov 2000 11:51:31 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Why?
Message-Id: <slrn92ad0j.3o7.tadmc@magna.metronet.com>

Roman Stawski <roman.stawski@fr.adp.com> wrote:
>John Boy Walton wrote:

>> while ( defined( $line = <BOGUS> ) )

>    while (<BOGUS>)
>    { 
>        print $_;
>    }
>
>or even
>
>    print while <BOGUS>;
>
>work just as well. 


Yes, but what if $_ was already being used for something else?

   while ( $line = <BOGUS> )

also works just as well.


>Your test defined is superfluous 


Yes, but not for the reason that you give below.

It is superfluous because perl will put in a defined() test 
for you if you do not do it explicitly. But there is nothing 
wrong with being explicit.


>since $line will
>always be true 


Nope, not "always".


>for all lines read (including 'empty' ones) 
         ^^^^^


Right. But it is possible to read and not get something that
ends with newline (and is therefore not a "line")...


>and be
>false at the end of the file.


Yes, but there is a case where you are not at the end of file,
and have not read a "line" (where "\n0" are the last 2 characters
in the file, or where a one-byte file contains "0").

In that case, you read a "0". Uh oh! That is a false value.
You drop out of the loop without processing it.

So you _do_ need to test definedness rather than truth
(but perl will do it even if you forget).


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 29 Nov 2000 11:38:42 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Why?
Message-Id: <3a254d32@cs.colorado.edu>

In article <slrn92ad0j.3o7.tadmc@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:
>>    while (<BOGUS>)
>>    { 
>>        print $_;
>>    }
>>or even
>>    print while <BOGUS>;
>>work just as well. 
>
>Yes, but what if $_ was already being used for something else?
>   while ( $line = <BOGUS> )
>also works just as well.

But what if $line was already being used for something else?

    while (<BOGUS>) { ... }
    while ($line = <BOGUS>) { ... }

Are both prone to a similar thing, although $_ is "more global"
than $line would be.

    while (local $_    	   = <BOGUS>) { ... }
    while (my    $line 	   = <BOGUS>) { ... }
    while (local $line 	   = <BOGUS>) { ... }
    while (local our $line = <BOGUS>) { ... }

But not this:

    while (our $line 	   = <BOGUS>) { ... }

If you want a lexically protected variable, use my().
If you want a temporally protected variable, use local().
If you want neither, use neither.

Oh--and you can't lexically protect a non-lexical variable, like $_.

(But Tad knew this already.  I'm only pretending to talk to him
that others might listen . :-)

--tom


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

Date: Wed, 29 Nov 2000 20:20:07 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Why?
Message-Id: <XxdV5.11050$GW5.71238@news-server.bigpond.net.au>

Well I can't think what.
I did write a script to unlink "Users.ini.Bak.<time stamp here>".
But it deleted those files briliantly and left Users.ini alone.
I was trying to load up Users.ini into an array so I could process
individual users deleting some and then rewriting Users.ini with the valid
users. I only used print $line to check if I was reading the values
correctly. Nothing printed out so I checked Users.ini and all values were
gone.
"Ren Maddox" <ren.maddox@tivoli.com> wrote in message
news:m3hf4q4xhd.fsf@dhcp11-177.support.tivoli.com...
> "John Boy Walton" <johngros@Spam.bigpond.net.au> writes:
>
> > The following script wiped the contents of the file.
> > I don't know why, as I understand it the print statement should go to
> > <STDOUT> not <BOGUS>.
> >
> > #!E:/Millenium Programs/perl/bin/Perl -w
> > $path = "C:/Program Files/G6FTP/";
> > $file = $path."Users.ini";
> > open BOGUS,"$file";
> > while ( defined( $line = <BOGUS> ) )
> > {
> >  print $line;
> > }
>
> I see nothing there that would modify the file.  I suspect something
> else happened.
>
> --
> Ren Maddox
> ren@tivoli.com




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

Date: Wed, 29 Nov 2000 20:22:58 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Why?
Message-Id: <CAdV5.11053$GW5.71259@news-server.bigpond.net.au>

I forgot about strict because I was testing this before cutting and pasting
into a larger script. The larger script uses a mailing module that I can't
get to run with strict. I can't declare its variables properly. (Just a
newbie).
"Roman Stawski" <roman.stawski@fr.adp.com> wrote in message
news:3A251AAA.CF1539B3@fr.adp.com...
> John Boy Walton wrote:
> >
> > The following script wiped the contents of the file.
> > I don't know why, as I understand it the print statement should go to
> > <STDOUT> not <BOGUS>.
> >
> > #!E:/Millenium Programs/perl/bin/Perl -w
>
> If you're on a DOS box, then this is a waste of time...
>
>     #!perl -w
>
> works just fine, and is quicker to type. Since you used -w, how come
> you forgot about use strict?
>
> > $path = "C:/Program Files/G6FTP/";
> > $file = $path."Users.ini";
> > open BOGUS,"$file";
>
> You don't need to quote $file! And aren't you missing a
>
>     or die "Can't open $file: $!"
>
> clause at the end of that line?
>
> > while ( defined( $line = <BOGUS> ) )
> > {
> >  print $line;
> > }
>
>     while (<BOGUS>)
>     {
>         print $_;
>     }
>
> or even
>
>     print while <BOGUS>;
>
> work just as well. Your test defined is superfluous since $line will
> always be true for all lines read (including 'empty' ones) and be
> false at the end of the file.
>
> Pontificating apart, the script works fine for me. I have had similar
> problems though in the past when I tried to read from a file that I
> opened using something like
>
>     open BOGUS, ">$file" or die "Can't open $file: $!";
>
> by mistake. Are you sure you don't have something like that?
>
> --
> Roman Stawski - ADPgsi




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

Date: Wed, 29 Nov 2000 20:30:24 GMT
From: "John Boy Walton" <johngros@Spam.bigpond.net.au>
Subject: Re: Why?
Message-Id: <AHdV5.11059$GW5.71294@news-server.bigpond.net.au>

I just remembered when I first wrote the script I opened the file using open
BOGUS,">$file";
When I ran the script it gave me an error -> BOGUS only opened for output.
Would this have wiped the contents?
I already have the feeling yes, but would like confirmation.

"John Boy Walton" <johngros@Spam.bigpond.net.au> wrote in message
news:XxdV5.11050$GW5.71238@news-server.bigpond.net.au...
> Well I can't think what.
> I did write a script to unlink "Users.ini.Bak.<time stamp here>".
> But it deleted those files briliantly and left Users.ini alone.
> I was trying to load up Users.ini into an array so I could process
> individual users deleting some and then rewriting Users.ini with the valid
> users. I only used print $line to check if I was reading the values
> correctly. Nothing printed out so I checked Users.ini and all values were
> gone.
> "Ren Maddox" <ren.maddox@tivoli.com> wrote in message
> news:m3hf4q4xhd.fsf@dhcp11-177.support.tivoli.com...
> > "John Boy Walton" <johngros@Spam.bigpond.net.au> writes:
> >
> > > The following script wiped the contents of the file.
> > > I don't know why, as I understand it the print statement should go to
> > > <STDOUT> not <BOGUS>.
> > >
> > > #!E:/Millenium Programs/perl/bin/Perl -w
> > > $path = "C:/Program Files/G6FTP/";
> > > $file = $path."Users.ini";
> > > open BOGUS,"$file";
> > > while ( defined( $line = <BOGUS> ) )
> > > {
> > >  print $line;
> > > }
> >
> > I see nothing there that would modify the file.  I suspect something
> > else happened.
> >
> > --
> > Ren Maddox
> > ren@tivoli.com
>
>




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

Date: 29 Nov 2000 15:15:50 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Why?
Message-Id: <m3d7fe4gzd.fsf@dhcp11-177.support.tivoli.com>

"John Boy Walton" <johngros@Spam.bigpond.net.au> writes:

> I just remembered when I first wrote the script I opened the file using open
> BOGUS,">$file";
> When I ran the script it gave me an error -> BOGUS only opened for output.
> Would this have wiped the contents?
> I already have the feeling yes, but would like confirmation.

Consider it confirmed.  It *will* do that.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 29 Nov 2000 14:49:18 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Why?
Message-Id: <slrn92andu.4di.tadmc@magna.metronet.com>

John Boy Walton <johngros@Spam.bigpond.net.au> wrote:

>I just remembered when I first wrote the script I opened the file using open
>BOGUS,">$file";
>When I ran the script it gave me an error -> BOGUS only opened for output.
>Would this have wiped the contents?
>I already have the feeling yes, but would like confirmation.


If you seek confirmation of what open() will do, then read
the docs for open(), don't come here expecting others to
read it for you.

   "If MODE is '>', the file is truncated and opened for output"

Look up "truncated" in a dictionary.


-- 
    Tad McClellan                          SGML consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Wed, 29 Nov 2000 14:36:33 EST
From: Arek@nospam._pietruszewski_.com (Arek P)
Subject: Re: Wrtiing on a Win32 system
Message-Id: <903ls1$11cm$1@earth.superlink.net>

On Thu, 23 Nov 2000 09:30:03 +0800, "Roland Tek" <rtek84@email.com>
wrote:

>Lately, I have downloaded the Active Perl for Win32 system. After installing
>it, I have no idea where I should start. I read the readme, they taught me
>how to make the "hello world", I just don't know where I should write that.
>There is no console or anything for me to type on Windows 98. Can anyone
>show me how?
>
>
>
I think most of the peops here would not reply to Your posting...but
everyone is new at some point;
use notepad or wordpad to save Your files with .pl extention
and run Your perl scripts (for example first.pl ) in dos shell like
this
perl first.pl 
or 
first.pl 
If You have proper associations in registry You should be able to do
the scriptname.pl by itself or even double click on  the .pl file from
explorer.   Stick to dos shell for now.  

HTH
				ArekP



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

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 V9 Issue 4991
**************************************


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