[7860] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1485 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 16 17:09:11 1997

Date: Tue, 16 Dec 97 14:00:21 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 16 Dec 1997     Volume: 8 Number: 1485

Today's topics:
     <INPUT TYPE="file" <cache@cyberhighway.net>
     closures and sort (Chad Lake)
     Re: CR/LF Text-File (brian d foy)
     Re: CR/LF Text-File (Chip Salzenberg)
     Re: Framework for building custom HTTP servers? (brian d foy)
     Re: ftp a file (Chip Salzenberg)
     Re: getting list of directories, returned as an array (Chip Salzenberg)
     Re: help decode a pattern <ldaffner@rsn.hp.com>
     Re: How to stop 'read' from waiting for ever in perl v5 (Chip Salzenberg)
     Re: localtime() _is_ year-2000 compliant, right? (Michael Budash)
     Re: localtime() _is_ year-2000 compliant, right? (brian d foy)
     Re: localtime() _is_ year-2000 compliant, right? <reibert@mystech.com>
     Re: Looking to work with Perl for Master's Thesis (Chip Salzenberg)
     Re: NEED:  Fast, Fast string trim() <ajh@rtk.com>
     Re: NEED:  Fast, Fast string trim() <ajh@rtk.com>
     Re: Newbie question. (Chip Salzenberg)
     Perl for Win32 and COM Ports (Repost because I got abso (Colin Foster)
     Re: post your dynamic IP address to a web page-cant be  (Brian Wheeler)
     Re: Really newbie question (brian d foy)
     Reset of the 'each' iterator with the assignment operat kboutin@magi.com
     Re: Return value after OPEN() (Juergen Heinzl)
     Re: Return value after OPEN() <rootbeer@teleport.com>
     Re: Return value after OPEN() <barnett@houston.Geco-Prakla.slb.com>
     where did the newline come from? <oberon@nospam.erols.com>
     Re: where did the newline come from? (brian d foy)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 16 Dec 1997 14:42:20 -0700
From: Keith Davis <cache@cyberhighway.net>
Subject: <INPUT TYPE="file"
Message-Id: <3496F5BA.E34@cyberhighway.net>

This may be a dumb question, but I'm really stumped. I don't even know
where to start!

How do you handle a file being uploaded from the browser's machine with
the html form element <INPUT TYPE="file">? The file NAME arrives as
input to the element(post) or query string(get). But, where is the file
and it's contents? And how do I direct where the file is saved and under
what name? I'd really appreciate some help on this as Netscape's
handbook offers no clues on what to do with this form element.

TIA

Keith Davis
cache@cyberhighway.net


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

Date: 16 Dec 1997 20:40:54 GMT
From: clake@belay.cs.utah.edu (Chad Lake)
Subject: closures and sort
Message-Id: <676p0m$feo@magus.cs.utah.edu>



Hey-ho all.

       I'm having a bit of trouble understanding the binding of the
variables $a and $b in sort routines.  I friend sent me a message
asking me about sorting hashes.  I responded, and to make a joke I
decided to try to do it ala SCHEME in perl (this friend of mine hates
SCHEME).  So, I decided to try and curry the sort of a hash (sorting
by the hash's values, that is).  So I came up with something like
this:



## Ok, let's set up some data to try things out
my %somehash;
foreach (0 .. 10) {
    $somehash{$_} = int(rand 100) + 1;
}

# your basic numeric sorting routine
sub by_value { $a <=> $b }

# Ah...create the subroutine
sub hash_by_value {
    my %hash = @_;
    sub { sort by_value $hash{$a},$hash{$b} };
}

## print stuff out
foreach $key (sort (eval hash_by_value(%totalTimes)) (keys $somehash)) {
    print "\t$key: $somehash{$key}\n";
}



Ok, so I was just joking, and out of curiosity decided to see how
close I got. Well, the above doesn't parse so I read the bit in the
Camel book about closures and modified it to look like this:

my $sort_func = hash_by_value(%somehash);
foreach $key (sort &$sort_func (keys $totalTimes)) {
     print "\t$key: $somehash{$key}\n";
}

But this still didn't work.  The problem seems to be that $a and $b
are not getting set when the anonymous subroutine defined in
hash_by_value is getting called.  


Sooooo, my question is, does the fact that $a abd $b get bound
specially screw me out of being able to do this horrendous act of perl
programming?   



				Thanks, 



							-c



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

Date: Tue, 16 Dec 1997 15:19:23 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: CR/LF Text-File
Message-Id: <comdog-ya02408000R1612971519230001@news.panix.com>

In article <675uqg$iuf$1@nz12.rz.uni-karlsruhe.de>, udta@rzstud1.rz.uni-karlsruhe.de (Tobias Poppe) wrote:

>I want to read a string from a Text-File.

>But every string in the TEXT-file ends width a
>CR/LF. (yes, it's a dos-text-file).
>But the perl/skript runs on a LinuX-System.
>How can i read strings from a text-file with cr/lf at the end of each
>line on a LinuX-Plattform ???

if you don't want to change the file, you can change the input 
record separator, $/, to "\r\n".  now perl thinks a "line" ends with
"\r\n" rather than the default "\n".

if you are making a similar file on the linux box, you might want to 
play with the output record separator so that "lines" end with "\r\n"
as well.

or you could just ftp everythign as ascii.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 16 Dec 1997 21:22:44 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: CR/LF Text-File
Message-Id: <676rdr$uvc$1@cyprus.atlantic.net>

According to tadmc@metronet.com (Tad McClellan):
>Remove xx (xxTony.Curtis@vcpc.univie.ac.at) wrote:
>: Re: CR/LF Text-File, Tobias
>: <udta@rzstud1.rz.uni-karlsruhe.de> said:
>
>: Tobias> But the perl/skript runs on a LinuX-System.  How can
>: Tobias> i read strings from a text-file with cr/lf at the
>: Tobias> end of each line on a LinuX-Plattform ???
>
>: Do this to the input line
>
>:     s/\r$//;
>
>: That will remove the CR (\r) if there's one at the end.
>
>
>Or, better yet, when transfering the files, use FTP in ASCII mode and
>it will convert the line endings for you.

Or just set   $/ = "\r\n"   when handling such files.
-- 
Chip Salzenberg             - a.k.a. -              <chip@pobox.com>
>> Stonehenge Consulting Services:  Perl training  (503) 777-0095 <<
       "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: Tue, 16 Dec 1997 16:04:10 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Framework for building custom HTTP servers?
Message-Id: <comdog-ya02408000R1612971604100001@news.panix.com>

In article <wx07m95vztf.fsf@sws5.ctd.ornl.gov>, Dave Sill <dsill@sws5.ctd.ornl.gov> wrote:

>Is there a module or recipe for creating small special-purpose HTTP
>servers in perl?

there are a number of ways you could go depending on how much
you like to play with the internals of the process.  you could play
with Socket or LWP for instance.  

if you have specific (perl) questions about implementation, post
again.  good luck :)

[snip description of special HTTP server]

>I know I could do something similar with Tk, but the beauty of HTTP is 
>that every schmoe in the world has a terminal that can access it.

i thought that's why it was scary.  do you want every schmoe poking
about your filesystem? :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 16 Dec 1997 21:17:08 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: ftp a file
Message-Id: <676r3c$utl$1@cyprus.atlantic.net>

According to PETER@yalevm.ycc.yale.edu:
>Hello.  Would anyone be so kind as to post an example of "ftp"ing a file
>from within Perl?  Thanks.

You should obtain and install the "libnet" package from CPAN, which
can be accessed from (among other places) www.perl.com/CPAN .
-- 
Chip Salzenberg             - a.k.a. -              <chip@pobox.com>
>> Stonehenge Consulting Services:  Perl training  (503) 777-0095 <<
       "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: Tue, 16 Dec 1997 21:00:51 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: getting list of directories, returned as an array
Message-Id: <676q4r$uq9$1@cyprus.atlantic.net>

According to rjk@coos.dartmouth.edu:
>Joshua J. Kugler wrote:
>> This doesn't work:
>>   find({push(@dirlist, $File::Find::name) if -d;}, '.');
>
>In this one, you're executing a block of code and passing the result
>to find.

Well, he's _trying_ to.  He's getting a syntax error because Perl thinks
it's a badly typed anonymous hash.  A leading "do" on the block would be
correct syntax for that buggy approach.  :-)
-- 
Chip Salzenberg             - a.k.a. -              <chip@pobox.com>
>> Stonehenge Consulting Services:  Perl training  (503) 777-0095 <<
       "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: 16 Dec 1997 13:05:23 -0600
From: Larry Daffner <ldaffner@rsn.hp.com>
Subject: Re: help decode a pattern
Message-Id: <f5ok9d5m7m4.fsf@rsn.hp.com>

>>>>> "t" == terminator  <milab@nortel.ca> writes:

  t> could someone interpret the expression below for me.
  t> $alines=~ /^\[([^\]]*)\]/

  t> i can make some sense of it, but i need to know what it does
  t> specifically. i think it will match a word starting with '[' and
  t> ending with ']', and save it in $1. but i don't know how the
  t> implementation [^\]]* is interpreted. could someone post the
  t> interpretation.

The [^\]]* construct simply keeps the inside expression from matching
a ], in case there's another one on the line (Literally, match 0 or
more non-] characters). Thus, if you have something like [foo][bar],
it would match [foo], and not [foo][bar]. This could also be written
(and probably more correctly) as /^\[(.*?)\]/ (since the non-greedy
operator would stop at the first ]).

HTH
-Larry (speaking for myself, not HP)

-- 
| Larry Daffner - Software Engineer | email: ldaffner@rsn.hp.com        |
|      Hewlett Packard STO          |                                   |
Osborn's Law:
Variables won't; constants aren't.


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

Date: Tue, 16 Dec 1997 21:21:51 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: How to stop 'read' from waiting for ever in perl v5.004
Message-Id: <676rc6$uuq$1@cyprus.atlantic.net>

According to "Dafydd Richards" <dafydd@gwe.co.uk>:
>Is there anyway in perl 5.004 of breaking the wait on 'read' after a set
>time???

Not directly.  But you can avoid calling a blocking read() in the
first place.  The select() operator may serve your purpose, in
conjuction with the sysread() operator.  You can block in select()
until data are available, and then read them with sysread().
-- 
Chip Salzenberg             - a.k.a. -              <chip@pobox.com>
>> Stonehenge Consulting Services:  Perl training  (503) 777-0095 <<
       "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: Tue, 16 Dec 1997 11:58:24 -0700
From: mbudash@sonic.net (Michael Budash)
Subject: Re: localtime() _is_ year-2000 compliant, right?
Message-Id: <mbudash-1612971158240001@d39.pm.sonic.net>

In article <Pine.GSO.3.96.971216114018.23116K-100000@user2.teleport.com>,
Tom Phoenix <rootbeer@teleport.com> wrote:

>> On Tue, 16 Dec 1997, Michael Budash wrote:
>> 
>> > The camel book says the $year portion of the list returned by localtime()
>> > "has had 1900 subtracted from it". Do i dare make the assumption that in
>> > the year 2000, that value will be 100 and not 0? 
>> 
>> No, you don't dare. But if you evaluate localtime(time+1e8) you might find
>> out what you need to know.

Thanks, Tom. That was helpful. And not sarcastic (a rarity around here!)

As you probably know, the camel book mentions that localtime can take an
argument, but it only mentions what happens if you _don't_ pass it! You
and another kind soul prompted me to try passing it a number of seconds
since the "epoch". Which I did, and it is indeed yr-2000 compliant.

>> (Or, of course, you could look in the FAQ. :-)

Could you please tell me where the FAQ is? Now _that_ would be really helpful...

TIA
michael

-- 
                   _____________________________

                       Michael Budash, Owner
                     Michael Budash Consulting
                           707-255-5371
                        707-258-7800 x7736
                   http://www.sonic.net/~mbudash
                         mbudash@sonic.net
                   _____________________________


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

Date: Tue, 16 Dec 1997 15:46:18 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: localtime() _is_ year-2000 compliant, right?
Message-Id: <comdog-ya02408000R1612971546180001@news.panix.com>

In article <mbudash-1612971158240001@d39.pm.sonic.net>, mbudash@sonic.net (Michael Budash) wrote:

>In article <Pine.GSO.3.96.971216114018.23116K-100000@user2.teleport.com>,
>Tom Phoenix <rootbeer@teleport.com> wrote:

>>> (Or, of course, you could look in the FAQ. :-)
>
>Could you please tell me where the FAQ is? Now _that_ would be really helpful...


* the FAQ is included with perl.  you could try `man perlfaq`.  if it
isn't there, it's time to upgrade :)

* or you could go to <URL:http://www.perl.com>, and investigate from
there.  almost everything Perl can be found from there. 

* searching for "Perl FAQ" in Yahoo leads to many perl FAQs, including
the official one.  other search engines might be as easy.

* or several other strategies for finding information.

though you might think this sort of message is sarcastic, is it 
designed to help you find information on your own (since it is such
a simple task).

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 16 Dec 1997 14:12:26 -0700
From: "Mark S. Reibert" <reibert@mystech.com>
Subject: Re: localtime() _is_ year-2000 compliant, right?
Message-Id: <3496EEB9.2A01E8DA@mystech.com>

Michael Budash wrote:

> The camel book says the $year portion of the list returned by localtime()
> "has had 1900 subtracted from it". Do i dare make the assumption that in
> the year 2000, that value will be 100 and not 0? I guess the more direct
> question is: is $year limited to some set number of decimal places? I
> think not, but a fellow programmer disagrees.

Hmmm, a small world indeed! I have pondered the same question but still don't
have an answer.

Mark Reibert
-----------------------------
   Mark S. Reibert, Ph.D.

  Mystech Associates, Inc.
  3233 East Brookwood Court
   Phoenix, Arizona 85044

    Tel: (602) 732-3752
    Fax: (602) 706-5120
 E-mail: reibert@mystech.com
-----------------------------




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

Date: Tue, 16 Dec 1997 21:15:19 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Looking to work with Perl for Master's Thesis
Message-Id: <676qvv$ut3$1@cyprus.atlantic.net>

According to bmk@agnostic.ebb.org (Bradley M. Kuhn):
>I am currently looking for Master's Thesis topic in a computer science
>graduate program.  I have a strong dedication to free (and in particular,
>GPL'ed) software, and I also like to find ways to "bridge the gap" between
>computer science theory and implementation.  Plus, I love Perl.
>
>Consequently, I hope to find a Master's Thesis topic that will result in the
>implementation of something useful for the free software community.  I enjoy
>Perl, so I was thinking I might be able to do something with Perl.

The Perl project and other free software projects could use a good
workflow automation tool that encourages its use instead of being an
additional burden.  Development is the easy part to coordinate; but
bug tracking and fixing is harder.

The hardest part seems to be marking old bugs as "old" so that they
won't necessarily be believed unless/until someone verifies that they
still exist in the newer versions of the product.

It goes without saying that distributed processing with authentication
is a necessary part of any such product.

Let me know when you're done.  :-)
-- 
Chip Salzenberg             - a.k.a. -              <chip@pobox.com>
>> Stonehenge Consulting Services:  Perl training  (503) 777-0095 <<
       "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: Tue, 16 Dec 1997 11:58:04 -0800
From: "Aaron Harsh" <ajh@rtk.com>
Subject: Re: NEED:  Fast, Fast string trim()
Message-Id: <676mfm$hl3$1@brokaw.wa.com>


Andrew Johnson wrote in message <3496BE6C.567B1254@gpu.srv.ualberta.ca>...
>Tony Bowden wrote:
>> Now, what's the fastest way of removing all unwanted whitespace, which
>> means triming all leading and trailing spaces, _and_ trimming multiple
>> whitespace down to single spaces? Can this be done easily in one pass?
>
>here's a quickie one pass version (quickie in terms of thinking it up, not
>running time) ---should be easy to improve upon:
>
>$_='   blah   blah blah   blah   ';
>s/(^\s+|\s+$)|(\s+)/$1?'':' '/eg;
>print;


Is it cheating to do some of it outside a regex?  Here's my entry, which is
about four times faster than Andrew's (to run, not to type :-):

$_ = join(" ", /\S+/g);




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

Date: Tue, 16 Dec 1997 12:29:14 -0800
From: "Aaron Harsh" <ajh@rtk.com>
Subject: Re: NEED:  Fast, Fast string trim()
Message-Id: <676o9v$grc$1@brokaw.wa.com>

Aaron Harsh wrote in message <676mfm$hl3$1@brokaw.wa.com>...
>Is it cheating to do some of it outside a regex?  Here's my entry, which is
>about four times faster than Andrew's (to run, not to type :-):
>
>$_ = join(" ", /\S+/g);


Hmm..  This can be optimized for the likely case of lots of words with
single-spaces between them, which doubles the speed on the original test:

  $_ = join(" ", /\S+(?: \S+)*/g);

and has the side effect of making the line a little less legible (I'm not
going to make a judgement about whether this is a good thing or a bad thing
:-)  Probably about as good as responding to your own posts).

Aaron Harsh
ajh@rtk.com




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

Date: Tue, 16 Dec 1997 21:26:00 GMT
From: chip@mail.atlantic.net (Chip Salzenberg)
Subject: Re: Newbie question.
Message-Id: <676rk0$v00$1@cyprus.atlantic.net>

According to mjtg@cus.cam.ac.uk (M.J.T. Guy):
>Roger Hansson  <qpkrogh@epk.ericsson.se> wrote:
>>Can I use include files in Perl , like I use include files in C?
>>I have a couple of scripts that use the same subroutines/functions, and
>>I want to have only one version of each subrutine/function.
>
>The "require" function will include a file for you.
>See 'perldoc -f require'.

You can also   do $filename   which is more like a C #include, in that
lexical variables are visible across the file boundary.
-- 
Chip Salzenberg             - a.k.a. -              <chip@pobox.com>
>> Stonehenge Consulting Services:  Perl training  (503) 777-0095 <<
       "Aarrrr!  Sixteen men on a dead Dodge Dart!"  // MST3K


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

Date: Tue, 16 Dec 1997 21:18:13 GMT
From: cfoster@cfoster.demon.co.uk (Colin Foster)
Subject: Perl for Win32 and COM Ports (Repost because I got absolutely no replies to the original)
Message-Id: <3498efb7.8881573@news.demon.co.uk>

I am trying to chat to a device connected to COM2:. I have tried
various scripts, starting with

  open MODEM,"+>com2:";
  print MODEM "AT\n";
  $input = <MODEM>;
  print $input;
  close MODEM;

then later .. 

  use IO::Handle;

  open MODEM,"+>com2:";
  binmode MODEM;
  MODEM->autoflush(1);

  print MODEM "AT\n";
  $input = <MODEM>;
  print $input;

  close MODEM;

Neither recieve anyting, though flashing lights on the modem would
indicate that the print to MODEM is sending something.

I can talk directly to the modem using Hyperterminal without any
problems, so I must be doing something wrong.

Any help would be appreciated.

Using Perl for Win32 build 313 on Windows 95 OSR2 if that is relevant,
but the scripts run no better on other machines with (subtly)
different versions of Perl and W95.

Colin F


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

Date: 16 Dec 1997 20:58:52 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: Re: post your dynamic IP address to a web page-cant be done, right?
Message-Id: <676q2c$4b8$1@dismay.ucs.indiana.edu>

In article <Pine.GSO.3.96.971216110147.23116G-100000@user2.teleport.com>,
	Tom Phoenix <rootbeer@teleport.com> writes:
> On 15 Dec 1997, Brian Wheeler wrote:
> 
>> open(OUT,">/tmp/$$");
> 
> Even when your script is "just an example" (and perhaps especially in that
> case!) you should _always_ check the return value after opening a file.
> Thanks.

	I usually do, but my fingers were hurting.... :)  and I _did_ leave
a disclaimer at the bottom...




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

Date: Tue, 16 Dec 1997 15:25:06 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Really newbie question
Message-Id: <comdog-ya02408000R1612971525060001@news.panix.com>

In article <6762hd$nu3$1@news.capgemini.se>, peter.edlund@capgemini.se wrote:

>>    I just started fooling around with CGIs in perl and I wanteed to
>>know how do I call a script from my HTML file ?
>
>This question eventually belongs to comp.www.authoring.cgi.

i think you meant comp.infosystems.www.authoring.cgi

>but shortly: you need to turn on server side includes (SSI) on [bad wrap] 
>your web server and then put something like [bad wrap] 
><!--#exec cgi="/my/cgi/dir/myscript.pl"--> in your HTML page. [bad wrap] 

perhaps people should be more careful with the concepts of sufficiency
and necessity.  in this case, the given solution will work, but it not
the only one, so "you need" is wrong.  let's remember that if someone is
asking such a question, he doesn't know about the possible solutions, so
telling him that he "needs" a particular solution (especially without
knowledge of the set of solutions available to him) is misleading.

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Tue, 16 Dec 1997 21:39:15 GMT
From: kboutin@magi.com
Subject: Reset of the 'each' iterator with the assignment operator '=' ?
Message-Id: <3496f551.1675862162@news.istar.ca>

I am getting confused about the behaviour of the 'each' function
combined
with the assignment '=' operator.  The "each iterator" of a hash seem
to
get reset if this hash is assigned subsequently to something in a list
context (e.g.: to an @array or to a %hash).  I thought that only a
call to
the "keys" function could reset this iterator (that and a complete
sequence through the elements of the hash with each)!  Is there a
description of this "behavior" in the standard documentation (Camel
book,
Panther Book, ...)?  Anyone has an explanation?

Examples follow:

EXAMPLE 1

WORKS FINE! Walks through the items of hash %a and successively hash
%b.
Note how two separate 'each iterator' are maintained for %a and %b

#!/opt/bin/perl -w

%a = ('a','1','b','2','c','3');
# Assignment removed from here

while ( ($key,$value) = each %a) {

  %b = %a;  # and placed in the loop AFTER the call to 'each'

  print "KEY=$key :: VALUE=$value\n";

  while (($key2,$value2) = each %b ) {
    print "K=$key2 , V=$value2    ";
    last if $value2 == 2;
  }
  print "\n";
}

EXAMPLE 2

DOES NOT WORK!  Loops infinitely in the first while loop since the
'each
iterator' of %a is reset every time the assignment "%b = %a" is done.
Note also the the iterator for %b seem seem to get reset too.

##!/opt/bin/perl -w

#%a = ('a','1','b','2','c','3');
#%b = %a;   # Assignment before the call to 'each'

#while ( ($key,$value) = each %a) {

#  print "KEY=$key :: VALUE=$value\n";

#  while (($key2,$value2) = each %b ) {
#    print "K=$key2 , V=$value2    ";
#    last if $value2 == 2;
#  }
#  print "\n";
#}





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

Date: 16 Dec 1997 19:47:01 GMT
From: juergen@unicorn.noris.de (Juergen Heinzl)
Subject: Re: Return value after OPEN()
Message-Id: <slrn69dn0h.di.juergen@unicorn.noris.de>

In article <3496D492.283988F8@cks.ssd.k12.wa.us>, Jerome O'Neil wrote:
>I have noticed recently that the "regulars" have been promoting the
>value of checking the return value of open() after opening a file.  Very
>well and good.
>
>Is it good form to check the value after opening a pipe to another
>process?

Checking the return value is *always* good style.

Happy hacking,
Juergen

-- 
\ Real name     : Juergen Heinzl     \       no flames      /
 \ EMail Private : unicorn@noris.de   \ send money instead /
  \ Phone Private : +49 911-4501186    \                  /


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

Date: Tue, 16 Dec 1997 12:11:44 -0800
From: Tom Phoenix <rootbeer@teleport.com>
To: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
Subject: Re: Return value after OPEN()
Message-Id: <Pine.GSO.3.96.971216120758.23116Q-100000@user2.teleport.com>

On Tue, 16 Dec 1997, Jerome O'Neil wrote:

> Is it good form to check the value after opening a pipe to another
> process?

Only if you care whether Perl did what you wanted. :-)

That is to say, in nearly all cases, yes, you should check. But if you use
-w (as you almost certainly should) failure to start the other process
should, at least, provide a diagnostic message. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: Tue, 16 Dec 1997 14:26:06 -0600
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Return value after OPEN()
Message-Id: <3496E3DD.2107ECD5@houston.Geco-Prakla.slb.com>

Jerome O'Neil wrote:

> I have noticed recently that the "regulars" have been promoting the
> value of checking the return value of open() after opening a file.  Very
> well and good.
>
> Is it good form to check the value after opening a pipe to another
> process?
>
> Jerome "Put *WHAT* in my Pipe and Smoke It?" O'Neil

In my humble opinion, I should think you would always, always, always want
to check such a thing.  Otherwise, how do you know that you're not just
shoveling data uselessly, or sending it off into the WOM
(Write-Only-Memory) device (a.k.a. /dev/null)?

I personally feel better about it because it cuts down on stupid typos,
flaws in logic, and other random idiocy that sometimes creep into the
corners of my mind, out my fingers, and into my programs....

;-)

Dave

--
"Security through obscurity is no security at all."
                -comp.lang.perl.misc newsgroup posting

------------------------------------------------------------------------
* Dave Barnett               U.S.: barnett@houston.Geco-Prakla.slb.com *
* DAPD Software Support Eng  U.K.: barnett@gatwick.Geco-Prakla.slb.com *
------------------------------------------------------------------------





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

Date: Tue, 16 Dec 1997 16:10:58 -0500
From: oberon <oberon@nospam.erols.com>
Subject: where did the newline come from?
Message-Id: <3496EE62.3D9CCCDA@nospam.erols.com>

I've got a script, with the following code fragment in it:

$num_date = <STDIN>;
($num_month = $num_date) =~ s/^(\d+) \d{4}/$1/;

$num_date is set to "4 1997\n" via STDIN, and after my substitution,
$num_month was "4\n".  I may be missing something very basic here, but I
have no idea how the newline got added to $num_month.  As I see it, it
should have value "4", and nothing else.

A few persons I've showed it to have said that my syntax is painful, but
it works, and they were not able to determine how the newline got
appended to $num_month.  Well, the painful syntax is due to my
inexperience with perl; and, yeah, this whole problem goes away if I
chomp $num_month.  But I like to know exactly why something is
happening, rather than simply change the way it is done to avoid an
nuexpected behavior.

Can any of you good people help me?

--Ken Taborek
--oberon at erols dot com


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

Date: Tue, 16 Dec 1997 15:56:47 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: where did the newline come from?
Message-Id: <comdog-ya02408000R1612971556470001@news.panix.com>

In article <3496EE62.3D9CCCDA@nospam.erols.com>, oberon <oberon@nospam.erols.com> wrote:

[ sorry - no email for you :( ]

>I've got a script, with the following code fragment in it:
>
>$num_date = <STDIN>;
>($num_month = $num_date) =~ s/^(\d+) \d{4}/$1/;
>
>$num_date is set to "4 1997\n" via STDIN, and after my substitution,
>$num_month was "4\n".  I may be missing something very basic here, but I
>have no idea how the newline got added to $num_month.  As I see it, it
>should have value "4", and nothing else.

a line of <STDIN> comes with the trailing input record separator (what
that is might depend on your system).  to remove a trailing
input record separator, you can use the chomp() function:

   $num_date = <STDIN>;
   chomp($num_date);

in your case, you replaced everything up to 1997 (which you matched with
\d{4} ), which left everything after that, including the \n, untouched.
thus, $num_month was "4\n".  you could have done:

   ($num_month = $num_date) =~ s/^(\d+) \d{4}.*/$1/;

but i would have done something like:

      $num_date  = m/^(\d+)/;
   my $num_month = $1;

so that the original input is unchanged, and the program flow is a bit
more clear.

good luck :)

-- 
brian d foy                                  <comdog@computerdog.com>
NY.pm - New York Perl M((o|u)ngers|aniacs)*  <URL:http://ny.pm.org/>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 1485
**************************************

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