[9846] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3438 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 13 13:07:46 1998

Date: Thu, 13 Aug 98 10:00:28 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 13 Aug 1998     Volume: 8 Number: 3438

Today's topics:
    Re: A glob - Problem (or a map ??) <rootbeer@teleport.com>
    Re: A glob - Problem (or a map ??) (Tad McClellan)
    Re: A Regexp problem <upsetter@ziplink.net>
    Re: A Regexp problem <smolyn@cs.ubc.ca>
    Re: Access DB on same machine <murrayb@vansel.alcatel.com>
    Re: bug in rand()? <rootbeer@teleport.com>
    Re: Converting to lowecase (Larry Rosler)
    Re: Converting to lowecase (Craig Berry)
    Re: Converting to lowecase (Craig Berry)
    Re: File updating question <upsetter@ziplink.net>
    Re: floating point number precision? <rootbeer@teleport.com>
    Re: FREE Shopping Cart and Bulletin Board <webmanager.NOSPAM@municipalinfocentre.com>
        Have package use another symbol table? <arolfe@genome.wi.mit.edu>
        help: assign STDIN to variable for looping through file <christina.burnhamN*O*S*P*A*M@fmr.com>
    Re: help: assign STDIN to variable for looping through  <nguyend7@msu.edu>
    Re: Help: Installing Modules? <rootbeer@teleport.com>
        How to become a session leader? <anton@urc.ac.ru>
    Re: how to (Kevin Reid)
    Re: how to (Abigail)
        Index-Counter in foreach-Block!? <posern@informatik.uni-marburg.de>
    Re: Index-Counter in foreach-Block!? <nguyend7@msu.edu>
    Re: Index-Counter in foreach-Block!? (Mike Stok)
    Re: Index-Counter in foreach-Block!? (Larry Rosler)
    Re: INLINES.PL?WHEELS=PLASTIC <rootbeer@teleport.com>
    Re: INLINES.PL?WHEELS=PLASTIC <perlguy@inlink.com>
    Re: NT redirect to file <jdwyer@verio.com>
    Re: NT redirect to file <perlguy@inlink.com>
    Re: Opening a file as "+>>file" (Jeff Yoak)
        Perl for disk watcher <tonys@asic.sc.ti.com>
        PerlScript fails to access network resources jpeng@rocketmail.com
    Re: problem loading html page via perl location command derzayg@gsao.med.ge.com
    Re: Q: How to read a file piece by piece (Abigail)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 13 Aug 1998 15:24:13 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: A glob - Problem (or a map ??)
Message-Id: <Pine.GSO.4.02.9808130820410.10161-100000@user2.teleport.com>

On Thu, 13 Aug 1998, Frank Zimmermann wrote:

> The following solution I just found out (are there better ones?):
> 
> opendir CURRDIR, "." or die "Problem...: $!";
> @filelist =  grep /(.*.foo|.*.bar)/, readdir CURRDIR;
> closedir CURRDIR;

You probably want to use something like this pattern instead:

       /\.(?:foo|bar)$/

 ...if you want only files which end in .foo or .bar, rather than ones like
'junkfood' and 'rhubarb'. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 13 Aug 1998 11:22:40 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: A glob - Problem (or a map ??)
Message-Id: <gs3vq6.vk2.ln@localhost>

Frank Zimmermann (fz@hlsv.de) wrote:


: The following solution I just found out (are there better ones?):

: opendir CURRDIR, "." or die "Problem...: $!";
: @filelist =  grep /(.*.foo|.*.bar)/, readdir CURRDIR;
: closedir CURRDIR;


Yes, there are better ones.

The above will match these:

   stuff.barf
   thought.food.stuff
   disbarred


If you want it to end with foo|bar, then you need a regex that forces
it to end with foo|bar   ;-)


   @dirs = grep /\.(foo|bar)$/, readdir DIR;


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


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

Date: 13 Aug 1998 16:03:46 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: A Regexp problem
Message-Id: <6qv2p2$b3d@fridge.shore.net>

Tom Christiansen <tchrist@mox.perl.com> wrote:
:  [courtesy cc of this posting sent to cited author via email]

: In comp.lang.perl.misc, "Matthew J. Forder" <mjforder@earthling.net> writes:
: :Oops! I apologise...I was working off the top of my head, and I couldn't
: :remember if the \q and \e needed to be capitilised. I guess that's what
: :I get for leaving all my books at work eh ;-)

: That wasn't my concern.  My concern was that you *cannot* use a regular
: expression to extract tags from arbitrary HTML.  See perlfaq9.

Why do you assume that that's what he's trying to do? His original post
said nothing about HTML.

--Art

--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: Thu, 13 Aug 1998 09:36:23 -0700
From: Greg Smolyn <smolyn@cs.ubc.ca>
Subject: Re: A Regexp problem
Message-Id: <35D31607.2476B551@cs.ubc.ca>

Abigail wrote:
> Any reason you can't be bothered to read the manual or the faq?
> 
> BTW, 'regex' is much easier to pronounce than 'regexp'.

Any reason why you can't be courteous to a fellow Perl user?

Oh, BTW, 'Perl' is pronounced 'Pearl'.



PS. For those of you who *did* offer advice, I appreciate it very much. 
Thanks! 

-- 
 -----------------------------------------------------------------
|Greg Smolyn (smolyn@cs.ubc.ca)                       \    /      |
|CSSS International Rep                            \   \  /   /   |
|University of British Columbia Computing Science   \   \/   /    |
|Vancouver, BC, Canada                               \  /\  /     |
|Proud owner of a 75 VW Super Beetle aka Helmut       \/  \/      |
|                                                 AirKooled Rulez |
 -----------------------------------------------------------------


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

Date: 13 Aug 1998 08:37:38 -0700
From: Brad Murray <murrayb@vansel.alcatel.com>
Subject: Re: Access DB on same machine
Message-Id: <ud8a4lwos.fsf@vansel.alcatel.com>

Brent Michalski <perlguy@inlink.com> writes:

> I do it all of the time with NT/IIS

NT/Apache 1.3.1 works also.  Apache has the advantage that it understands
the #! in your perl scripts, which can make your CGI work very portable.
It's also free.

-- 
 A picture is only worth a thousand words.  Language is worth
 all of the words. Hieroglyphics and pictograms are obsolete
                      for a reason.
      Brad Murray -*- Software Analyst -*- Alcatel Canada


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

Date: Thu, 13 Aug 1998 15:14:44 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: bug in rand()?
Message-Id: <Pine.GSO.4.02.9808130806140.10161-100000@user2.teleport.com>

On Thu, 13 Aug 1998, Alex Dong Li wrote:

> Is there is bug in random number generation function rand()?

No. :-)

That is, there's shouldn't be any bug in Perl's rand(), but there may be
one in the underlying system's, or in the way you're using it.

> For the following code, which is expected to generate random numbers
> between 0 and 8, different OS gave the different results:

> #!/usr/local/bin/perl -w
> $ran= int(rand(9));
> print $ran;

Looks good to me, except for the missing newline at the end of your
output. :-)  To be sure, though, if you'll be running this under very old
versions of perl, you may need to call srand first.

> On unix, it seems to be fine.

> On Win95, it generates a "second" number, a number which is closely
> related to the system time in seconds.

What version of perl are you using for this? Recent versions - anything
from the last year or so - should have a "good" random number. But, since
the random seed is coming from (among other things) the system time,
several runs in close succession may have some relation. 

> On WinNT, it gerneates a real constant.

I'm not sure what you mean by that. Do you mean that you get the same
integer each time? Again, recent versions should work fine.

If you're using 5.004 or later, and if the same problem happens with the
latest 5.005_0x release, file a bug report with perlbug. It may be
that perl isn't finding a good source of randomness for which to seed
the generator on those machines, in which case we should try harder to 
find some good randomness. Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 13 Aug 1998 08:24:53 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Converting to lowecase
Message-Id: <MPG.103ca5215937237b9897c8@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <6qudea$ovp$1@pheidippides.axion.bt.co.uk> on Thu, 13 Aug 1998 

09:54:22 GMT, Dermot McKay <MCKAYD@aplbt1.agw.bt.co.uk> says...
> In article <35D29F8B.504D181E@forumnett.no>, Hauk Langlo <hauk@forumnett.no> 
> wrote:
 ...
> >How do I convert all the word characters within $_[0] to lowercase?
 ...
> You can do this two ways.
> $_[0] =~ s/$_[0]!\L$&!;

Wrong (doesn't parse -- delimiters don't match) and, if fixed, 
inefficient ($& slows the whole program).  And substituting a 
variable into a regex is always fraught with danger, because of possible 
metacharcters in the data.

$_[0] =~ s/(\Q$_[0]\E)/\L$1/;

if you insist on using a regex.

> or
> 
> $_[0]=(lc($_[0]);

Wrong (doesn't parse -- parentheses don't match).  At least this uses the 

better approach.

> OK Dermot

NG Dermot, I think. :-) 

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 13 Aug 1998 16:47:58 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Converting to lowecase
Message-Id: <6qv5bu$ijo$2@marina.cinenet.net>

Hauk Langlo (hauk@forumnett.no) wrote:
: Hi there, this should be an easy one. I only have to ask for help
: because I do not have my exellent book at hand right now.
:
: How do I convert all the word characters within $_[0] to lowercase.

If you're somewhere you can run perl, you have an excellent book at hand.
Behold:

  > perldoc perlfunc | grep lowercase         
       lc      Returns an lowercased version of EXPR.  This is the
               lowercased.  This is the internal function         

The *very first line matching the string 'lowercase' gives you your
answer!  Now, wouldn't that have been easier to do, rather than waiting
for an answer from Usenet, and bothering thousands of people?

: I guess it must be something like this:
: 
: $_[0] =~ s/\w/SOMETHING/g;

Were you to do it in the various hard ways...

  $_[0] =~ s/(\w)/\l$1/g;
  $_[0] =~ tr/A-Z/a-z/;    # Doesn't respect locale

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 13 Aug 1998 16:50:13 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Converting to lowecase
Message-Id: <6qv5g5$ijo$3@marina.cinenet.net>

Dermot McKay (MCKAYD@aplbt1.agw.bt.co.uk) wrote:
: In article <35D29F8B.504D181E@forumnett.no>, Hauk Langlo <hauk@forumnett.no> 
: wrote:
: >Hi there, this should be an easy one. I only have to ask for help
: >because I do not have my exellent book at hand right now.
: >
: >How do I convert all the word characters within $_[0] to lowercase. I
: >guess it must be something like this:
: >
: >$_[0] =~ s/\w/SOMETHING/g;
: 
: You can do this two ways.
: $_[0] =~ s/$_[0]!\L$&!;

 ...if you like weird redundancy and slowing down regexes throughout your
entire program...

: or
: 
: $_[0]=(lc($_[0]);

 ...if you prefer superfluous and unbalanced parentheses.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 13 Aug 1998 15:58:46 GMT
From: Scratchie <upsetter@ziplink.net>
Subject: Re: File updating question
Message-Id: <6qv2fm$b3d@fridge.shore.net>

Tom Phoenix <rootbeer@teleport.com> wrote:

:>     flock DATA, 2;

: You should really get this value from a module, rather than use a literal.

Why is that? I find it a lot easier to remember "2 = exclusive lock" than
what module to use and what the exact name of the variable that's equal to
2 is.

Just wondering what your rationale is .

--Art

--------------------------------------------------------------------------
                    National Ska & Reggae Calendar
                  http://www.agitators.com/calendar/
--------------------------------------------------------------------------


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

Date: Thu, 13 Aug 1998 15:17:03 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: floating point number precision?
Message-Id: <Pine.GSO.4.02.9808130816310.10161-100000@user2.teleport.com>

On 13 Aug 1998, GEMINI wrote:

> what I concern is not the matter of output precision,
> but the precision of internal arithmetical operations.
> I'd like to use more precise floating point number
> to reduce the truncation errors during arithmetic.

Use Math::BigFloat. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 13 Aug 1998 13:46:18 -0300
From: Angela Day <webmanager.NOSPAM@municipalinfocentre.com>
Subject: Re: FREE Shopping Cart and Bulletin Board
Message-Id: <35D3185A.E47E86CC@municipalinfocentre.com>

veronica@iminet.com wrote:

> I found an awesome web-based shopping cart for FREE at
> http://www.321website.com

Nice try; we saw your post before.





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

Date: Thu, 13 Aug 1998 12:30:47 -0400
From: Alex Rolfe <arolfe@genome.wi.mit.edu>
Subject: Have package use another symbol table?
Message-Id: <35D314B7.41C6@genome.wi.mit.edu>

I would like one package (call it A) to use another package's (call this
one B) symbol table.  The name of package B won't be known until
run-time.  I suppose that I could use eval's everywhere, but it seems
that there should be some easier solution.  

The goal here is that functions in A will work like they've been
declared in B, even though they aren't.   They should use the symbol
table (and therefore variables) from B.  A is going to be a generic
package.  B will allow for customizations to A and will be used by
another program.  

Thanks,
	Alex Rolfe	
	arolfe@genome.wi.mit.edu


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

Date: Thu, 13 Aug 1998 11:16:07 -0400
From: PeanutGallery <christina.burnhamN*O*S*P*A*M@fmr.com>
Subject: help: assign STDIN to variable for looping through file
Message-Id: <35D30337.50E00BA7@fmr.com>

(UNIX AIX platform)
I want to read a file and loop through the lines, either using a command
line argument or standard in using the same while loop.

command line: open argv[1] and while( <FILE_NAME>)
standard input: just while(<STDIN>)
I tried assigning STDIN to $filename and opening it the same way I would
ARGV[0] but it doesn't work. I tried just settting FILE_NAME to <STDIN>
or STDIN, doesn't work.   Can somebody help me out?
thanks. Please unmunge my email address if you reply directly to me.

--
=====================================================
- When replying to me remember to unmunge my anti-spam address -
The border between life and death is poorly guarded
-- from Due South




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

Date: 13 Aug 1998 15:21:18 GMT
From: Dan Nguyen <nguyend7@msu.edu>
Subject: Re: help: assign STDIN to variable for looping through file
Message-Id: <6qv09e$b6i$2@msunews.cl.msu.edu>

PeanutGallery <christina.burnhamN*O*S*P*A*M@fmr.com> wrote:
You can try using while(<>) it'll read open each @ARGV, if @ARGV is
empty it'll read from STDIN

-- 
           Dan Nguyen            | There is only one happiness in
        nguyend7@msu.edu         |   life, to love and be loved.
http://www.cse.msu.edu/~nguyend7 |                   -George Sand



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

Date: Thu, 13 Aug 1998 15:45:46 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Help: Installing Modules?
Message-Id: <Pine.GSO.4.02.9808130842540.10161-100000@user2.teleport.com>

On 13 Aug 1998, Mike wrote:

> Everything runs smoothly until 'make install' which give me the following
> error message:
> /bin/sh:
> /var/tmp/perl-root/usr/lib/perl5/i386-linux/5.00401/perllocal.pod: No such
> file or directory

perllocal.pod (which is not to be confused with perllocale.pod) should
have been built when perl was installed. Unfortunately, someone built your
perl with that file in the /var/tmp directory, and it's probably not there
anymore. You should probably (have your sysadmin) re-build perl with the
proper location for that file. (Information on how to do that comes with
the perl source.) Good luck!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 13 Aug 1998 20:15:52 +0600
From: Anton Voronin <anton@urc.ac.ru>
Subject: How to become a session leader?
Message-Id: <35D2F518.D4FF373D@urc.ac.ru>

Perl does not have setsid() function. Is there any other way to become a
session leader? I tried to setpgrp(), but setting pgid equal to pid does not
make process the session leader (may be because session pointer is not changed
and there is another session leader in the session with this pointer).

Thanks in advance,
Anton

-- 
Anton Voronin                | Ural Regional Center of FREEnet,
<anton@urc.ac.ru>            | Southern Ural University, Chelyabinsk, Russia
http://www.urc.ac.ru/~anton  | Programmer & System Administrator


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

Date: Thu, 13 Aug 1998 11:23:11 -0400
From: kpreid@ibm.net (Kevin Reid)
Subject: Re: how to
Message-Id: <1ddp4sm.19u7zwo18o01wlN@slip166-72-108-11.ny.us.ibm.net>

Nicholas Ritter <ritter@lfc.edu> wrote:

> I am have an array element that contians a 12 digit, alphanumeric,
> case-insentive string (to be more specific, it is an ethernet address,
> but without the colons). 
> 
> I am new to perl, and I can't seem to figure out a way to get perl to
> take the array element, and insert a colon every two characters.
> 
> Here is an example of what I have, and what I want perl to do with it:
> 
> someArray[1] = 008894fg7t44
> 
> I want perl to change it to:
> 
> someArray[1] = 00:88:94:fg:7t:44
> 
> 
> Is Perl capable of doing this? And if so, can somebody demonstrate it to
> me? I have approx. 1500 Ethernet addresses that must be converted. If I
> can't get it done with Perl, I will have to rewrite everything in Java
> ('cause I know Java can do it).

#!perl -w

$val = '008894fg7t44';

print "Orig: $val\n";

$val =~ s/(..)(?=.)/$1:/g;

print "Colons: $val\n\n";

$val = '12.34.56';

__END__

> Also, how can I take an array element and flip it arround. For instance:
> 
> someArray[1] = 2.1
> 
> And convert it to:
> 
> someArray[1] = 1.2

#!perl -w

print "Orig: $val\n";

$val1 = join '', reverse split //, $val;

print "Reversed characters: $val1\n";

$val2 = join '.', reverse split /\./, $val;

print "Reversed elements: $val2\n";

__END__

-- 
  Kevin Reid.      |         Macintosh.
   "I'm me."       |      Think different.


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

Date: 13 Aug 1998 16:06:09 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: how to
Message-Id: <6qv2th$bu7$2@client3.news.psi.net>

Nicholas Ritter (ritter@lfc.edu) wrote on MDCCCVIII September MCMXCIII in
<URL: news:35D23831.EB869767@lfc.edu>:
++ 
++ Here is an example of what I have, and what I want perl to do with it:
++ 
++ someArray[1] = 008894fg7t44
++ 
++ I want perl to change it to:
++ 
++ someArray[1] = 00:88:94:fg:7t:44

$someArray [1] =~ s/(..)(?=.)/$1:/g;

++ Is Perl capable of doing this? And if so, can somebody demonstrate it to
++ me? I have approx. 1500 Ethernet addresses that must be converted. If I
++ can't get it done with Perl, I will have to rewrite everything in Java
++ ('cause I know Java can do it).

Everything Java can do, Perl can do. But you can do it in C or in Pascal
as well. Nothing magical about Java.

++ Also, how can I take an array element and flip it arround. For instance:
++ 
++ someArray[1] = 2.1
++ 
++ And convert it to:
++ 
++ someArray[1] = 1.2


Depending on what you exactly want:

   $someArray [1] = reverse $someArray [1];
   $someArray [1] = join '.', reverse split /\./, $someArray [1];


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


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

Date: 13 Aug 1998 15:06:33 GMT
From: "K.Posern" <posern@informatik.uni-marburg.de>
Subject: Index-Counter in foreach-Block!?
Message-Id: <35D300C3.5F8F9BBE@informatik.uni-marburg.de>

Hi.
I KNOW the Index-Counter-Skalar-Variable for a Filehandle: $.
But I DON'T know the Skalar-Varialbe which holds the current
Index-value of a list in a foreach-Block. So this for example:

foreach (@foo) {
    print $_;
    ##how do I know here at WHICH position in @foo I am?!
}

I know, I COULD use an extra Counter-Variable, but it would be SOOOO
GREAT if I don't need it.... ?!

And if there isn't such a Special-variable in Perl - who could tell me
why?! - because I would think such a variable would be needed for a
foreach-Loop - or how does Perl count the loops?!

I hope my english is not too bad ... I am from germany and a bit in
hurry at the moment...

THANKS for answering (just right now)!!

Bye.





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

Date: 13 Aug 1998 15:18:43 GMT
From: Dan Nguyen <nguyend7@msu.edu>
Subject: Re: Index-Counter in foreach-Block!?
Message-Id: <6qv04j$b6i$1@msunews.cl.msu.edu>

K.Posern <posern@informatik.uni-marburg.de> wrote:
: foreach (@foo) {
:     print $_;
:     ##how do I know here at WHICH position in @foo I am?!
Why would you want to know?
If you did you should probably use a C-style for loop instead.



-- 
           Dan Nguyen            | There is only one happiness in
        nguyend7@msu.edu         |   life, to love and be loved.
http://www.cse.msu.edu/~nguyend7 |                   -George Sand



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

Date: 13 Aug 1998 15:24:10 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Index-Counter in foreach-Block!?
Message-Id: <6qv0eq$439@news-central.tiac.net>

In article <35D300C3.5F8F9BBE@informatik.uni-marburg.de>,
K.Posern <posern@informatik.uni-marburg.de> wrote:
>Hi.
>I KNOW the Index-Counter-Skalar-Variable for a Filehandle: $.
>But I DON'T know the Skalar-Varialbe which holds the current
>Index-value of a list in a foreach-Block. So this for example:
>
>foreach (@foo) {
>    print $_;
>    ##how do I know here at WHICH position in @foo I am?!
>}
>
>I know, I COULD use an extra Counter-Variable, but it would be SOOOO
>GREAT if I don't need it.... ?!
>
>And if there isn't such a Special-variable in Perl - who could tell me
>why?! - because I would think such a variable would be needed for a
>foreach-Loop - or how does Perl count the loops?!

There isn't a special counter for this.  If you want to heep a track of
where you are then you can use a C style for loop:

  for ($i = $[; $i <= $#foo; $i++) {
    ...
  }

or you can do something like:

  $i = $[;
  foreach (@foo) {
    ...
  }
  continue {
    $i++;
  }

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@colltech.com                  |            Collective Technologies (work)


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

Date: Thu, 13 Aug 1998 08:31:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Index-Counter in foreach-Block!?
Message-Id: <MPG.103ca692cbd060f39897c9@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <35D300C3.5F8F9BBE@informatik.uni-marburg.de> on 13 Aug 1998 
15:06:33 GMT, K.Posern <posern@informatik.uni-marburg.de> says...
 ...
> But I DON'T know the Skalar-Varialbe which holds the current
> Index-value of a list in a foreach-Block. So this for example:
> 
> foreach (@foo) {
>     print $_;
>     ##how do I know here at WHICH position in @foo I am?!
> }
> 
> I know, I COULD use an extra Counter-Variable, but it would be SOOOO
> GREAT if I don't need it.... ?!

There is none.  You have to do it yourself.

> And if there isn't such a Special-variable in Perl - who could tell me
> why?! - because I would think such a variable would be needed for a
> foreach-Loop - or how does Perl count the loops?!

Perl doesn't count the loops.  The 'foreach' statement iterates over the 
specified list.
 
-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 13 Aug 1998 15:49:12 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: INLINES.PL?WHEELS=PLASTIC
Message-Id: <Pine.GSO.4.02.9808130848210.10161-100000@user2.teleport.com>

On Thu, 13 Aug 1998, Crist=F3bal Hormaz=E1bal wrote:

> When I put a link like this:
> <A HREF=3D"INLINES.PL?wheels=3Dplastic ">Plastic wheels</A>
>=20
> How do I read the line with my Perls script?=20

Use the CGI.pm module. Hope this helps!

--=20
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 13 Aug 1998 16:04:49 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: INLINES.PL?WHEELS=PLASTIC
Message-Id: <35D30EA1.7A75AF7C@inlink.com>

$wheels=$ENV{QUERY_STRING};

HTH,
Brent


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

Date: 13 Aug 1998 16:01:00 GMT
From: John Dwyer <jdwyer@verio.com>
Subject: Re: NT redirect to file
Message-Id: <6qv2js$qsd$1@news.ncal.verio.com>


Sorry. I found the problem. I needed to specify the directory of the perl
executable on the command line, i.e.

c:\perl\bin\perl processor.pl detail.txt > summary.txt

I had associated file type ".pl" with perl, but apparently that won't work
when the data is redirected...

thanks anyway,
john

> Hi,

> I'm using PerlWin32 on NT workstation 4.0 and am having a bit of a
> problem redirecting output to a file.

> I've got a perl script (processor.pl) that basically processes a detail
> file and spits out summary stats. At the command line, I run:

> processor.pl detail.txt > summary.txt

> I know the Perl piece appears to be working correctly, because when I just
> run the program without redirection, the data scrolls across the screen.

> Under Win95, all the output ends up in "summary.txt", which is what I
> want. On WinNT, I end up with an empty file.



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

Date: Thu, 13 Aug 1998 16:05:51 GMT
From: Brent Michalski <perlguy@inlink.com>
Subject: Re: NT redirect to file
Message-Id: <35D30EDF.C54DB743@inlink.com>

Do you have rights to create a new file in the directory you are trying
to create it in?

Brent


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

Date: Thu, 13 Aug 1998 15:54:04 GMT
From: jeff@yoak.com (Jeff Yoak)
Subject: Re: Opening a file as "+>>file"
Message-Id: <ZSDA1.1288$vq2.1678496@newse2.tampabay.rr.com>

Tom Christiansen <tchrist@mox.perl.com> wrote:

>Nobody understands I/O.  Grr...

Here's the most recent thing I don't understand about I/O.  :)

Can you open a file to write and get an exclusive lock safely?  Here's
what I'm worried about:

open(OUT,">whatever") or die "could not open $!";
#someone reads my zero-length file here.
flock(OUT,2);

The best I figured out as a work-around was this:

open(OUT,"+<whatever") or die "Could not open $!";
flock(OUT,2) or die "Couldn't flock $!";
seek(OUT,0,0);
truncate(OUT,0);

This requires that file be there first which wasn't a problem in this
case and it doesn't change the file until I get the lock.  Is there a
better way?

Cheers,
Jeff

-- 
Jeff Yoak         jeff@yoak.com



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

Date: Wed, 12 Aug 1998 17:29:57 -0500
From: Tony Shi <tonys@asic.sc.ti.com>
Subject: Perl for disk watcher
Message-Id: <35D21765.A3E94332@asic.sc.ti.com>

I heard someone wrote a perl program to check the disk space with a
threshold. Did anyone see it before?


Thanks.


Tony


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

Date: Thu, 13 Aug 1998 15:17:02 GMT
From: jpeng@rocketmail.com
Subject: PerlScript fails to access network resources
Message-Id: <6qv01d$vdc$1@nnrp1.dejanews.com>

I am using IIS 3.0 and PerlScript 316 on a NT 4.0 SP3 box. The script tries to
execute "dir \\remote_server\c$" and receives "access is denied". In the same
script, I can use VBscript to create a file in \\remote_server\c$. Does anyone
know how I can get around it? BTW, cgi version of the same script is working
fine though.

Jack

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Thu, 13 Aug 1998 15:09:13 GMT
From: derzayg@gsao.med.ge.com
Subject: Re: problem loading html page via perl location command
Message-Id: <6quviq$unv$1@nnrp1.dejanews.com>

The statement below is absolutely incorrect.  When you redirect as follows:

print "Location:  /someplace\n\n";

the URL can certainly be a relative URL.  However, the leading slash indicates
the document root of the server which the CGI is running on.  My guess is that
the $file referred possibly to an absolute directory on the system, as
opposed to one that was relative to the document root.

Greg


>
> The browser appends that to the current directory, so obviously if you
> call this script located in
> http://www.server.com/cgi-bin/redirect/blah.pl, the resulting
> Location: header after appending is
> http://www.server.com/cgi-bin/redirect/directory/index.html
>
> This is a "relative URL" you are handing to the web browser, as
> opposed to a "fully qualified URL".  Your solution should be something
> like this:
>
> print "Location: http://www.blah.com/$file/index.html\n\n";
>

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 13 Aug 1998 15:55:52 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Q: How to read a file piece by piece
Message-Id: <6qv2a8$bu7$1@client3.news.psi.net>

Mark-Jason Dominus (mjd@op.net) wrote on MDCCCVIII September MCMXCIII in
<URL: news:6qtjfa$b0h$1@monet.op.net>:
++ 
++ 
++ Because of standard I/O buffering, you have probably written the tar
++ data before the HTTP header here.  You really need to have
++ 
++ 
++ >sub Send_As_tgz {
++     my $old_bar = $|;
++     $| = 1;
++ >   print "Content-Type: application/zip\n";
++ >   print "Content-Disposition: attachment;  filename=\"$file_name.tgz\"\n\n"
++ >   system $TAR, '-C', $Rwhere, 'czf', '-', $who;
++     $|=$old_bar;
++ >}


Yes, or use 'local':

sub Send_As_tgz {
   local $| = 1;
   print "Content-Type: application/zip\n";
   print "Content-Disposition: attachment;  filename=\"$file_name.tgz\"\n\n";
   system $TAR, '-C', $Rwhere, 'czf', '-', $who;
}



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


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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