[22854] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5075 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 4 14:10:55 2003

Date: Wed, 4 Jun 2003 11:10:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 4 Jun 2003     Volume: 10 Number: 5075

Today's topics:
        reading a text file. <spikey-wan@bigfoot.com>
    Re: reading a text file. <usenet@expires082003.tinita.de>
    Re: Reference types ctcgag@hotmail.com
    Re: Reference types (Tad McClellan)
        Regex with numeric evaluation (Rick Ferrante)
    Re: regular expression problem (Tad McClellan)
    Re: Remove first character in a string? <cwilbur@mithril.chromatico.net>
    Re: Remove first character in a string? <dbo@xbn.nl>
    Re: Remove first character in a string? (Tad McClellan)
    Re: Replacing users password input with asterisks (Steven Danna)
    Re: Sorting hash (Tad McClellan)
    Re: Sorting hash <noreply@gunnar.cc>
    Re: strange perl behaviour with cgi <jurgenex@hotmail.com>
    Re: strange perl behaviour with cgi <tzz@lifelogs.com>
    Re: strange perl behaviour with cgi <tassilo.parseval@rwth-aachen.de>
        uploading a file with perl (Eric)
    Re: uploading a file with perl <nobull@mail.com>
        use()ing a module by pasting it in code (Alfonso)
    Re: use()ing a module by pasting it in code <nobull@mail.com>
    Re: use()ing a module by pasting it in code <nobull@mail.com>
    Re: Using "eval" with "my", works up to a point, then . (John van V.)
        while loop (Kevin Su)
    Re: while loop <ah76@httpsite.com>
    Re: while loop <g4rry_short@zw4llet.com>
    Re: while loop (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 4 Jun 2003 16:06:54 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: reading a text file.
Message-Id: <bbl20p$4vp$1@newshost.mot.com>

Hello World!

I'm on my first attempt at processing a text file. I've got the gist of
doing it a line at a time, but I'm wondering about the merits of reading the
whole thing in at once, or at least in blocks of lines.

Where should I start reading? (That is me reading to learn about what I want
to do, not reading the input file)

Thanks.

R.




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

Date: 4 Jun 2003 17:10:17 GMT
From: Tina Mueller <usenet@expires082003.tinita.de>
Subject: Re: reading a text file.
Message-Id: <bbl95p$ar4eo$1@ID-24002.news.dfncis.de>

Richard S Beckett wrote:

> I'm on my first attempt at processing a text file. I've got the gist of
> doing it a line at a time, but I'm wondering about the merits of reading the
> whole thing in at once, or at least in blocks of lines.

> Where should I start reading? (That is me reading to learn about what I want
> to do, not reading the input file)

perldoc perlopentut
perldoc -f open

hth, tina
-- 
http://www.tinita.de/     \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/   \     / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/   \    \ _,_\ __/\ __/_| /__/ perception
- my mail address expires end of august 2003 -


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

Date: 04 Jun 2003 14:40:31 GMT
From: ctcgag@hotmail.com
Subject: Re: Reference types
Message-Id: <20030604104031.084$Xr@newsreader.com>

david.pointon@tesco.net (Dave Pointon) wrote:
>
> I need

Why?

> a sub, which when passed a ref., takes a copy of either the
> ref. or the structure dependant on whether the ref. is to named or
> anonymous data e.g. assuming
>
> my %hash = (
>   field1 => \%someOtherHash,
>   field2 => {
>     field1 => undef,
>     field2 => undef,
>   },
> );
>
> Calling sub(\%hash) should result in field1 being copied as is i.e. an
> ARRAY ref.,

HASH ref?

> whereas field2 (the anonymous hash) is copied wholesale.

  field3 => $hashref

What about field3?


I can't any reason this would be necessary.  I can sort of see the desire
the other way around (deep copy things that others might have access to,
but shallow copy things that no one else has access to), but this is
rather mysterious.  But either way, I don't know how to do it.  I guess
you'd need to check the refcount, but even if I knew how to do that I
suspect that would be fraught with problems.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Wed, 4 Jun 2003 11:34:20 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Reference types
Message-Id: <slrnbds7sc.n66.tadmc@magna.augustmail.com>

Dave Pointon <david.pointon@tesco.net> wrote:
> tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnbdpuva.hue.tadmc@magna.augustmail.com>...
>> Dave Pointon <david.pointon@tesco.net> wrote:
>> 
>> > Can anyone help ...
>> 
>> If we knew what the _real_ problem was we might be able to help...
>> 
>> > I'm doing my nut trying to distinguish between references to anonymous
>> > and named data elements
>> 
>> Why do you think that you need to distinguish them?
> 
> I need a sub, 


Yes, but why is it that you think you need it?


> which when passed a ref., takes a copy of either the
> ref. or the structure dependant on whether the ref. is to named or
> anonymous data e.g. assuming


So, you either want to copy the reference itself, or you want to
copy the values contained in the referenced thingie.


> my %hash = (
>   field1 => \%someOtherHash,
>   field2 => {
>     field1 => undef,
>     field2 => undef,
>   },
> );
> 
> Calling sub(\%hash) should result in field1 being copied as is i.e. an
> ARRAY ref., whereas field2 (the anonymous hash) is copied wholesale.


As I suspected, we have an XY Problem here.

A reference is a reference, whether the referenced thingie has
a name or not.

So your design is flawed, since you cannot readily do what needs
to be done.

If we knew more about why you think you need to distiguish them
then perhaps we could offer a solution where the distinction
would not need to be made...


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


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

Date: 4 Jun 2003 11:03:46 -0700
From: rferrante@tnsi.com (Rick Ferrante)
Subject: Regex with numeric evaluation
Message-Id: <726cd874.0306041003.1b2ed1c1@posting.google.com>

Can anyone modify the regex below in line 2 to have it also check that
level is greater than threshold?

1: $msg="Level 86.3 (threshold 85)";
2: ($level,$threshold) = $msg=~/Level ([0-9.]+) \(threshold
([0-9.]+)\)/;
3: print "$level $threshold\n" if ($level >=$threshold);

Thanks,
Rick


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

Date: Wed, 4 Jun 2003 09:53:14 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: regular expression problem
Message-Id: <slrnbds1uq.n23.tadmc@magna.augustmail.com>

KT <kennedyel_5000@yahoo.com> wrote:

> if i have a variable that is as followed, 


There *is no* variable following.

Perhaps you meant a variable's _value_ instead?

Variables in Perl start with a "funny character", such as dollar-sign.


> how do i assign a new
> variable equal http:// and end with .hk   , but as the web page is
> vary every times, so i think it should stop be4 HTTP/1.0.
> 
> 
> GET http://www.orientaldaily.com.hk/ HTTP/1.0


   my $url = $1 if m#\bGET\s+(.*?)\s+HTTP/1\.0#;


Which will, of course, break for URLs that use a newer version
of the protocol...


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


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

Date: Wed, 04 Jun 2003 14:40:18 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: Remove first character in a string?
Message-Id: <87adcxhpz1.fsf@mithril.chromatico.net>

genericax@hotmail.com (Sara) writes:

> Astute observation- Perl DOES seem to have some "parity" issues like
> that. Consider the collary to:
> 
>    $x .= $y;
> 
> What if I want to PREPEND $y? Seems like
> 
>    $x =. $y;
> 
> would be nice too... 

Well, in this case there's a reason for the parity issue.  Suppose we
resolved the issue in all ways using the model you suggest.  Then we'd
run right into this problem:

$y=-$x; 

Should this be parsed as 

$y =- $x; 

or as 

$y = -$x; ?

I'm not sure it's an enormous problem to have 'shortcut' operators
that only work in one direction; in this case, when TMTOWTDI, it's
usually because one case is significantly common to make the
optimization in programmer brainspace worthwhile, as with chop
and chomp.  The += and .= operators seem to me to be more about not
surprising C programmers than they are about any real efficiency; in
C, it's possible that a brain-dead compiler could generate different
code for x = x + y; and x += y;, but I'd be really surprised if that
were the case in Perl, given the complex nature of scalars.

Charlton
 


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

Date: Wed, 04 Jun 2003 17:53:15 +0200
From: David Bouman <dbo@xbn.nl>
Subject: Re: Remove first character in a string?
Message-Id: <3EDE15EB.F88EEF1C@xbn.nl>

David Bouman wrote:

> Tad McClellan wrote:
>> David Bouman <dbo@xbn.nl> wrote:
>>> Koos Pol wrote:
>>>
>>>> chip() should make a fine opposite to chop() I find myself
>>>> removing a first char regularly.
>>>
>>> Nah, that would imply having an opposite to chomp() as well,
>>
>> sub pmohc {  # the anti-chomp
>>     $_[0] .= $/;
>> }
> 
> s{\$_\Q[0] .= \E\$/}'length($/) * map s`(?<!$/)\z`$/`||(), @_';

s/map(.*)\Q||()/grep$1/;

--
David.


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

Date: Wed, 4 Jun 2003 09:35:48 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Remove first character in a string?
Message-Id: <slrnbds0u4.n23.tadmc@magna.augustmail.com>

Sara <genericax@hotmail.com> wrote:

> there are
> actually 2 END-OF-LINE manipulators, chop() and chomp().


Only one of those is (sometimes) an end-of-line manipulator, 
the other one is an end-of-string manipulator.

:-)


> Perhaps Damian and company will make some improvements in P6.


Golly, I sure hope so!

:-)  :-)


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


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

Date: 4 Jun 2003 08:32:09 -0700
From: MissingWords@hotmail.com (Steven Danna)
Subject: Re: Replacing users password input with asterisks
Message-Id: <e78d8c5a.0306040732.2a3f918d@posting.google.com>

"Sisyphus" <kalinabears@hdc.com.au> wrote in message news:<3edd58a6$0$21274@echo-01.iinet.net.au>...

> Just some ideas on how you can approach this:
> 
> #!perl -w
> 
> use strict;
> use Term::ReadKey;
> 
> my $pwd = mask_pwd();
> print "\n", length($pwd), "\n", $pwd, "\n";
> 
> ##############################
> sub mask_pwd {
> 
> my $password = '';
> my $key;
> 
> print "Enter password\n";
> 
> while(1) {
> 
>       while(not defined($key = ReadKey(-1))) {};
> 
>       if(ord($key) != 13) { # ie not "Enter"
> 
>          if(ord($key) == 8) { # ie "Backspace"
> 
>             print "\r", "\0" x length($password);
>             chop($password);
>             print "\r", "*" x length($password);
>             }
> 
>          else {
>             $password .= $key;
>             print "*";
>             }
>          }
> 
>       else {last}
>       }
> 
> return $password;
> }
> 
> __END__
> 


Much Thanks for the code!!  

    This project is teaching me much about perl.  I had to make a few
adjustments to &mask_pwd(after I looked up the ord function and many
of the different escape characters).

   I only had to make two changes.  First I set $|=1 ,so the *'s would
come up right after the person typed the letter(then had to look up
what $| should be normaly so I could set it back), and I also changed
the way it handles backspace characters.

   In your example, the script first returns to the beginning of the
line, and then adds the "\0" characters; however, I need the "Enter
Password:" or equivalent string on the same line as the input. After
playing with your code and learning what everything was doing, I came
up with this:

-------------------------------------
sub mask_pwd {
$|=1;
my $password = '';
my $key;
while(1) {
      while(not defined($key = ReadKey(-1))) {};
      if(ord($key) != 13) { 
         if(ord($key) == 8) { 
            print "\b\0\b";
            chop($password);
            }
         else {
            $password .= $key;
            print "*";
            }
         }
      else {last;}
      }
$|=0;
return $password;
}
--------------------------------------------

   Thanks again for your help.  Not only did it help solve my problem
but I learned many new things.

Steven Danna
"The not-always-so-humble perl student"
^---not the best sig. but give me time.


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

Date: Wed, 4 Jun 2003 10:05:52 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Sorting hash
Message-Id: <slrnbds2mg.n23.tadmc@magna.augustmail.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:

> relying on the behaviour of
> perl shouldn't be equal to tempting fate, should it?


You are applying the wrong test.

Relying on the _documented_ behavior should not be tempting fate (much).

Relying on "how it does it with today's version" _is_ rolling the dice.



For example, print() is documented to "Returns true if successful",
so this is OK:

   my $printed = print "Hello World\n";
   if ( $printed )

but

   my $printed = print "Hello World\n";
   if ( $printed == 1 )

works today, but may break tomorrow.

print() is not documented to return 1, so the p5p can have it return
100 instead if they feel they have a good reason to.

I want my programs to keep working when I upgrade perl.  :-)


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


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

Date: Wed, 04 Jun 2003 19:32:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Sorting hash
Message-Id: <bblamt$b1cdj$1@ID-184292.news.dfncis.de>

Tad McClellan wrote:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> 
>> relying on the behaviour of perl shouldn't be equal to tempting
>> fate, should it?
> 
> You are applying the wrong test.
> 
> Relying on the _documented_ behavior should not be tempting fate
> (much).
> 
> Relying on "how it does it with today's version" _is_ rolling the
> dice.

<snip>

> I want my programs to keep working when I upgrade perl.  :-)

Hmm.. That's doubtlessly a valid point. Thanks, Tad. I'm convinced. :)

/ Gunnar

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Wed, 04 Jun 2003 13:24:15 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: strange perl behaviour with cgi
Message-Id: <3qmDa.42248$da1.1365@nwrddc03.gnilink.net>

Jes Naulen wrote:
> I am very puzzled by some Perl/CGI behaviour. I created a perl cgi
> script that's called from a browser. The perl variables are getting
> messed up. It seems the perl session is 'remembering' the values for
> the browsers perl session. I worked for hours trying to find out
> what's wrong, but in the end I ended with the bajsic script:
>
>   #!/usr/bin/perl
>   print "Content-type: text/html\n\n";
>   print $test;
>
> and it starts counting {1,2,3...). When I open another browser and
> call the script, that brouwser starts counting from 1 again. Here too,
> obviously the variable $test is being remembered between browser
> sessions.
>
> What is wrong (with perl, with apache?) and what can I do about it?

You never define any value for $test. That is very bad programming style.
Therefore perl is correct when it prints some random value.

If you would have used warnings then perl would have told you.

jue




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

Date: Wed, 04 Jun 2003 10:50:35 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: strange perl behaviour with cgi
Message-Id: <4nptltgamc.fsf@lockgroove.bwh.harvard.edu>

On Wed, 4 Jun 2003, tadmc@augustmail.com wrote:
> Jes Naulen <rinaul@hotmail.com> wrote:
>> 
>> I am very puzzled by some Perl/CGI behaviour. I created a perl cgi
>> script that's called from a browser.
> 
> That is impossible.
> 
> CGI programs, regardless of what programming language they are
> written in, are never called from a browser.
> 
> CGI programs are always called by a web _server_.

This is not true.  w3m does local CGI, which is in fact very useful
for CGI development.

http://w3m.sourceforge.net/MANUAL#LocalCGI

Besides, you're arguing semantics here.  "Called" can mean "indirectly
invoked," not only "run."

Ted


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

Date: 4 Jun 2003 17:28:10 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: strange perl behaviour with cgi
Message-Id: <bbla7a$cj1$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Jürgen Exner:

> Jes Naulen wrote:

>>   #!/usr/bin/perl
>>   print "Content-type: text/html\n\n";
>>   print $test;
>>
>> and it starts counting {1,2,3...). When I open another browser and
>> call the script, that brouwser starts counting from 1 again. Here too,
>> obviously the variable $test is being remembered between browser
>> sessions.
>>
>> What is wrong (with perl, with apache?) and what can I do about it?
> 
> You never define any value for $test. That is very bad programming style.
> Therefore perl is correct when it prints some random value.

Perhaps from an educational standpoint correct. But it's not what
actually happens. Querying an uninitialized value will result in undef
which depending on the actual context (numerical or stringish) results
in 0 or "". Perl wont ever return a 'random' value, unlike C for
instance.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 4 Jun 2003 09:22:29 -0700
From: emedlin@clemson.edu (Eric)
Subject: uploading a file with perl
Message-Id: <9fdb9813.0306040822.7a7f03ca@posting.google.com>

I have wrote a small server and client (not finished, but runs).  The
client can send a command called sendfile to send the file it was
given as a command line argument.  Anyway I am losing the first few
bytes of data.  Well for some reason when I am getting the size it is
waiting for more data to come through and eating some of my data, why?
 To fix it I added a sleep(1) after I send it.  Can anyone tell me why
this happens when I get size and not the filename, and how I should
fix it, since I don't think sleep(1) is good a solution?  I have read
all I can find trying to fix this.  By the way just ignore the other
commands the serve excepts.  I was just playing.

SERVER CODE:
#!/usr/bin/perl
use IO::Socket;
use Net::hostent;

$server = IO::Socket::INET->new(
			Proto => "tcp",
			LocalPort => 9000,
			Listen => SOMAXCONN,
			Reuse => 1
			)
			or die "cannot setup server";
print "[Server $0 accepting clients]\n";

while($client = $server->accept()){
	$client->autoflush(1);
	print $client "Welcome to $0\n";
	printf "[Connect from %s]\n", $client->peerhost;
	while(<$client>){
		next unless /\S/;
		if(/quit|exit/i) {last;}
		elsif(/date|time/i) {printf $client "%s\n", scalar localtime;}
		elsif(/who/i) {printf $client `who`;}
		elsif(/sendfile/i) {
			print $client "recv file\n";
			$client->recv($file,256,0);
			$length = length($file);
			print "$length, $file\n";
			open($outfile, ">$file");
			$client->recv($size,8,0);
			$length = length($size);
			print "$length, $size\n";
			while($size > 0){
				$client->recv($buf,512,0);
				print $outfile $buf;
				$size -= length($buf);
			}
			close($outfile);i
		}
		else {print $client "Commands quit date who sendfile\n";}
	}
	close $client;
}

CLIENT CODE:
#!/usr/bin/perl
use IO::Socket;

$remote = IO::Socket::INET->new(
			Proto => "tcp",
			PeerAddr => "172.23.8.65",
			PeerPort => "9000"
			)
			or die "cannot connect to 172.23.8.65:9000\n";
$remote->autoflush(1);
print "[Connected to 172.23.8.65:9000]\n";

# spilt the program
die "can't fork: $!" unless defined($kidpid = fork());

if($kidpid){ # parent runs this
	while(defined($line=<$remote>)){
		print $line;
	}
	kill("TERM", $kidpid);
}else{ # child runs this
	while(defined($line=<STDIN>)){
		print $remote $line;
		if($line eq "sendfile\n"){
			$file = @ARGV[0];
			print "sending $ARGV[0]\n";
			$size = -s $file;
			print "$size\n";
			$remote->send($file,0);
			$remote->send($size,0);
			sleep(1);
			open($infile, $file);
			while(read($infile,$buf,512)){
				$remote->send($buf,0);
			}
			close($inflie);
		}
	}
}


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

Date: 04 Jun 2003 17:49:48 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: uploading a file with perl
Message-Id: <u94r35aitv.fsf@wcl-l.bham.ac.uk>

emedlin@clemson.edu (Eric) writes:

> I have wrote a small server and client (not finished, but runs).  The
> client can send a command called sendfile to send the file it was
> given as a command line argument.  Anyway I am losing the first few
> bytes of data.  Well for some reason when I am getting the size it is
> waiting for more data to come through and eating some of my data, why?

If you don't want to have to worry about short reads use read() not
recv() or sysread().

If you use recv() or sysread() you do need to worry about short
reads. (For details RTFM on the underlying C recvfrom() and read()).

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


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

Date: 4 Jun 2003 06:51:15 -0700
From: piz_dek@yahoo.com.au (Alfonso)
Subject: use()ing a module by pasting it in code
Message-Id: <b79fd483.0306040551.78ac509a@posting.google.com>

Hello,

Is it possible to paste in the code of A.pm instead
of doing:

use A;

?

I heard that use A is the same as pasting in the code
of the module, but I can't get that to work.

Thank you.


Alfonso


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

Date: 04 Jun 2003 17:36:45 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: use()ing a module by pasting it in code
Message-Id: <u98yshajfm.fsf@wcl-l.bham.ac.uk>

piz_dek@yahoo.com.au (Alfonso) writes:

> Is it possible to paste in the code of A.pm instead
> of doing:
> 
> use A;

Usually, yes.

BEGIN {
  # Paste source of A.pm here
}

BEGIN {
  import A;
}

Occasionally you would need to make some changes.  Depends on exactly
what smaet 

Of course, this only works at all for modules written in Perl.

> I heard that use A is the same as pasting in the code
> of the module,

No, an explaination of what use does see:

perldo -f use;

>  but I can't get that to work.

What happens when you try?  Do your hands drop off at the wrist?
Never say "I can't get it to work".  Always show a mimimal but
complete attempt.

Anyhow, even if you could get it to work you probably shouldn't do it.

Why do you think you want to do this?

Have you seen the FAQ: "How do I keep my own module/library directory?"

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


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

Date: 04 Jun 2003 17:51:53 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: use()ing a module by pasting it in code
Message-Id: <u9znkx945y.fsf@wcl-l.bham.ac.uk>

Brian McCauley <nobull@mail.com> writes:

> Occasionally you would need to make some changes.  Depends on exactly
> what smaet 
       ^^^^^

That should have read "smart(-arsed) things the module gets up to".

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


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

Date: 4 Jun 2003 07:08:30 -0700
From: john@thinman.com (John van V.)
Subject: Re: Using "eval" with "my", works up to a point, then ...
Message-Id: <e154927f.0306040608.2e466da3@posting.google.com>

Ilya wrote:
>       The solution to the particular problem is to stop using Perl
>       parser internal tables as a hash.  Declare a lexical hash
>       *beforehands*, 

Sure, I understand that and thats what I do.  I orginally wrote my
Gopts package to support KShell which isnt so picky.  Then I started
using it in perl because admins are used to shell and need pretty
quick access to the logic in the code.

Getop::Std is too limited and the Getopt::Long is cumbersome.

So the question becomes, it is useful and apparently not harmful, or
is it ??  So is strict.pm too strict ??  If so, doesnt it discourage
its use in small scripts ??

From Getop::Std:

       Note that, if your code is running under the recommended "use
strict
       'vars'" pragma, you will need to declare these package
variables with
       "our":

           our($opt_x, $opt_y);

 Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote in message news:<bbivk6$17lb$1@agate.berkeley.edu>...
> [A complimentary Cc of this posting was sent to
> Tassilo v. Parseval
> <tassilo.parseval@post.rwth-aachen.de>], who wrote in article <bbeof6$6nc$1@nets3.rz.RWTH-Aachen.DE>:
> > > my $eval_me = ' my $a '              ;
> > > 
> > > print $eval_me, "<-- in evalme\n"    ;
> > > 
> > > eval $eval_me                        ;
> > 
> > Now you have a lexical variable $a lying around.
> 
> Nope, wrong tense.  The variable had been lying around during the "time"
> that eval was running the code.  Not any more.
> 
> I put time in quotes because lexicality is not time-related, but
> space-related.  The scope starts at some *place* in the script, and
> ends likewise; NOT at some moment of time.
> 
> Ilya
> 
> P.S.  The solution to the particular problem is to stop using Perl
>       parser internal tables as a hash.  Declare a lexical hash
>       *beforehands*, then work explicitly with the elements of this
>       hash - instead of using named variables.


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

Date: 4 Jun 2003 07:07:50 -0700
From: ksu@amaranthllc.com (Kevin Su)
Subject: while loop
Message-Id: <5dd555c5.0306040607.55a409d7@posting.google.com>

Hi, I am trying to do a while loop.  The idea is that the while loop
looks through a body of information, and each time it iterates though,
it cuts a line off that body.  So say the body were:
abc
def
ghi
Then the while loop would look through that body, do something to abc
(I got that part) and then change the body to:
def
ghi
And basically continue until the body is null.  Here is what I have so
far.

while ($body=~/(.+||\s+)\n/mig) { #while the body has anything in it 
     print $1; #print that first line   
     $body=~s/$1//; #substitute the first line with nothing and back
to while.
}


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

Date: Wed, 04 Jun 2003 10:36:33 -0400
From: Andy <ah76@httpsite.com>
Subject: Re: while loop
Message-Id: <oprp8yu7xz1lzrqp@news.gwi.net>

On 4 Jun 2003 07:07:50 -0700, Kevin Su <ksu@amaranthllc.com> wrote:

> Hi, I am trying to do a while loop.  The idea is that the while loop
> looks through a body of information, and each time it iterates though,
> it cuts a line off that body.  So say the body were:
> abc
> def
> ghi
> Then the while loop would look through that body, do something to abc
> (I got that part) and then change the body to:
> def
> ghi
> And basically continue until the body is null.  Here is what I have so
> far.
>
> while ($body=~/(.+||\s+)\n/mig) { #while the body has anything in it 
> print $1; #print that first line   $body=~s/$1//; #substitute the first 
> line with nothing and back
> to while.
> }
>

More info needed.  Are you getting your "body" from a file?  Or is it a 
scalar, array, hash, what?

-- 
Andy


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

Date: Wed, 04 Jun 2003 15:40:52 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: while loop
Message-Id: <bbl0he$oh0$1$8300dec7@news.demon.co.uk>

Kevin Su wrote:

> Hi, I am trying to do a while loop.  The idea is that the while loop
> looks through a body of information, and each time it iterates though,
> it cuts a line off that body.  So say the body were:
> abc
> def
> ghi
> Then the while loop would look through that body, do something to abc
> (I got that part) and then change the body to:
> def
> ghi
> And basically continue until the body is null.  Here is what I have so
> far.
> 
> while ($body=~/(.+||\s+)\n/mig) { #while the body has anything in it
>      print $1; #print that first line
>      $body=~s/$1//; #substitute the first line with nothing and back
> to while.
> }

Kevin,

there are different ways to do this, depending on where you're getting your
information from. Assuming you've already got a string with all the data
in, and that the data is separated with newlines, I could do:

@stuff = split /\n/, $body;
while (@stuff) {
  $line = shift(@stuff);
  print "$line\n";
}

This:
1. Splits the data into an array, with each element ending on a newline.
2. Reapeats while the array is not empty (or while it's defined)
3. Takes the next line out of the array, and puts it in $line,
4. Then prints it.

You could also do:

@stuff = split /\n/, $body;
foreach $line (@stuff) {
  print "$line\n";
}

Or, if you're not worried about readability,

@stuff = split /\n/, $body;
foreach (@stuff) { print; }


HTH,

Garry




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

Date: Wed, 4 Jun 2003 11:45:00 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: while loop
Message-Id: <slrnbds8gc.n7n.tadmc@magna.augustmail.com>

Kevin Su <ksu@amaranthllc.com> wrote:

> each time it iterates though,
> it cuts a line off that body.


> Here is what I have so
> far.
> 
> while ($body=~/(.+||\s+)\n/mig) { #while the body has anything in it 


That pattern will match every possible string!

The || will match the empty string.

If the string _is_ all whitespaces, it may match the .+ part rather than
the \s+ part.


You should not throw modifiers on willy-nilly without considering
their effect.

m//i is useless when there are no letters in your pattern.

m//m is useless when there are no anchors in your pattern.


   while ( $body =~ s/(.*\n)//g ) {  # untested


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


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

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


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