[16967] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4379 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 19 21:05:28 2000

Date: Tue, 19 Sep 2000 18:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <969411914-v9-i4379@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 19 Sep 2000     Volume: 9 Number: 4379

Today's topics:
    Re: $0 not working under Solaris 2.7 (Greg Andrews)
    Re: 100 levels deep in subroutine calls! (Abigail)
    Re: 2 Questions (Martien Verbruggen)
    Re: 2 Questions <chimo@mailandnews.com>
    Re: Anonymous lists <ren.maddox@tivoli.com>
    Re: Anonymous lists (Richard J. Rauenzahn)
        Archive File Attribute on NT tanya_ellis@my-deja.com
    Re: Archive File Attribute on NT <elephant@squirrelgroup.com>
    Re: binmode(): How is OS related with "\n"? <ren.maddox@tivoli.com>
    Re: Can I dynamically create hashes? <ren.maddox@tivoli.com>
    Re: Can you store a condition in a variable? (Martien Verbruggen)
        Candidate for the top ten perl mistakes list (Adrian Pepper [MFCF])
    Re: Char to Octoal... ? <uri@sysarch.com>
    Re: Char to Octoal... ? (Abigail)
    Re: Char to Octoal... ? (Abigail)
    Re: Char to Octoal... ? <alian@alianwebserver.com>
    Re: File Parsing, Skipping lines <elephant@squirrelgroup.com>
    Re: FileMaker, DBI <jeff@vpservices.com>
        Finding element number of given element in array <g.soper@soundhouse.co.uk>
    Re: Finding element number of given element in array (Martien Verbruggen)
    Re: Finding element number of given element in array <ren.maddox@tivoli.com>
        Help with Mail:Folders and cgi mluebke@my-deja.com
    Re: How to make a child a parent ? <berube@odyssee.net>
    Re: How to make a child a parent ? <philipg@atl.mediaone.net>
        loop through file - how to loop back one line? <akelingos@petrosys-usa.com>
    Re: loop through file - how to loop back one line? <elephant@squirrelgroup.com>
    Re: Module for CGI Session Management? <philipg@atl.mediaone.net>
        NT File Attribute - archive tanya_ellis@hotmail.com
    Re: NT File Attribute - archive <elephant@squirrelgroup.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 19 Sep 2000 15:49:55 -0700
From: gerg@ncal.verio.com (Greg Andrews)
Subject: Re: $0 not working under Solaris 2.7
Message-Id: <8q8qij$h48$1@ncal.verio.com>

Stick <stickthestick@my-deja.com> writes:
>Does anyone know of a reason why setting $0 to a string would not work
>under solaris 2.7?
>
>The exact same script works fine under linux but under solaris the ps
>list shows the initial string not the changed string.
>

Correction:  the /usr/bin/ps list shows the initial command and
arguments rather than the string modified by the process.

Deep in the ps man page we find:

     args      The command with all its arguments  as  a  string.
               The  implementation may truncate this value to the
               field  width;   it   is   implementation-dependent
               whether  any  further  truncation  occurs.  It  is
               unspecified whether the string  represented  is  a
               version  of  the argument list as it was passed to
               the command when it started, or is  a  version  of
               the  arguments  as  they may have been modified by
               the application.

      -->                        Applications  cannot  depend  on
      -->      being  able to modify their argument list and hav-
      -->      ing that modification be reflected in  the  output
      -->      of  ps  .

                          The  Solaris  implementation limits the
               string to 80 bytes; the string is the  version  of
               the  argument list as it was passed to the command
               when it started.


The relevant portion of the paragraph was separated and highlighted
by me.

Try the /usr/ucb/ps command, which grovels through the memory blocks
of each process to read the process name, and therefore will see the
modified $0 in your perl scripts.


  -Greg


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

Date: 19 Sep 2000 23:19:28 GMT
From: abigail@foad.org (Abigail)
Subject: Re: 100 levels deep in subroutine calls!
Message-Id: <slrn8sft1r.5fq.abigail@alexandra.foad.org>

Ron D. Smith~ (rdsmith@sedona.ch.intel.com) wrote on MMDLXXVI September
MCMXCIII in <URL:news:8q8kj0$o5e@news.or.intel.com>:
$$ 
$$ 2) can I defeat this "warning"?  (Actually it is annoyingly fatal...) 
$$ preferably without touching the source code (which I do not control at my job

    no warnings 'recursion';

for modern versions of Perl.



Abigail
-- 
               split // => '"';
${"@_"} = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_)  {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};


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

Date: Tue, 19 Sep 2000 22:25:21 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: 2 Questions
Message-Id: <slrn8sfpu1.2cp.mgjv@verbruggen.comdyn.com.au>

On Tue, 19 Sep 2000 17:47:05 GMT,
	Uri Guttman <uri@sysarch.com> wrote:
> >>>>> "DF" == Daniel Frey <d.frey@aixigo.de> writes:
> 
>   DF> I think Perl is a write-only-language - you can't read Perl ;)
> 
> i see the smiley and that is still flame bait.

This whole thread is flame bait. Crossposting questions about what is
the 'best' language for almost anything [1] to several language groups is
flame bait. posting that question to one language group is flame bait.
The question itself is flame bait.

I killed it at home, and I'll kill it here as well now.

Martien

[1] and that includes the question 'what is the best first language?'.
-- 
Martien Verbruggen              | 
Interactive Media Division      | Failure is not an option. It comes
Commercial Dynamics Pty. Ltd.   | bundled with your Microsoft product.
NSW, Australia                  | 


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

Date: Tue, 19 Sep 2000 18:13:39 -0400
From: "William K Loppa" <chimo@mailandnews.com>
Subject: Re: 2 Questions
Message-Id: <8q8tcg$104$1@wanadoo.fr>

LOGO is an excellent choice for a beginners language.

It is important for beginners to learn certain concepts, like variables,
iteration, function calls, conditional statements, creating user made
functions.  These concepts can be learned from any language, and then later
applied to a different language (like C).

LOGO is an interpretted language, so it is easier to debug, and change, then
a compiled language, where you have to re-compile your program everytime.
Plus, it has an immediate mode, so you can test certain commands and
functions, without having to create a whole program to test them.

You can get some free implementations here. (With source code)

DOS/Linux

http://www.cs.berkeley.edu/~bh/

Windows 95/98/NT/2000

http://www.softronix.com/logo.html

Some Demo versions.

Microworlds Logo (really nice)

http://www.lcsi.ca

Machturtles Logo

http://www.machturtles.com/


Frankie <frankie@centurytel.net> wrote in message
news:39C5974E.AC51F612@centurytel.net...
> My apologies for the cross-post and the broad nature of this question.
> I just can't seem to find the info I want via traditional search
> engines, including Deja News.  And please, no flames.  I'm not a newbie
> and am aware I'm on thin ice with the cross and the questions.  Thanks.
>
> My question is what programming language would you recommend to a
> complete beginner in programming?  I've extensive background in various
> environments, so I'm not going to be terribly uneasy with the comp, I'm
> just looking for a good start.
>
> The second, and virtually hand in hand with the first, is where to go
> from there and in what sequence.  IOW, I'm thinking (just an example)
> qbasic to Visual Basic to C to C++ etc?  And yes, I'm going to throw in
> HTML, but I want to go beyond that.
>
> Again, my apologies if this is an inappropriate post.  Or, for that
> matter, too broad. Any help will be greatly appreciated.  E-mails are
> welcome (take the ** out per below) but since I'm posing the question, I
> can check all the Groups also.  TIA
>
> --
> "I do this really moronic thing that the government doesn't want me to
> do. It is called thinking" - George Carlin
>
>
> Remove * * to reply.
>
> -----------------------------------------------------------------------
> Pursuant to US Code, Title 47, Chapter 5, Subchapter II, ¢227,
> Any and all nonsolicited commercial E-mail sent to this address
> is subject to a download and archival fee in the amount of $500.00 US.
> E-Mailing denotes the acceptance of these terms
> -----------------------------------------------------------------------




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

Date: 19 Sep 2000 18:00:36 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Anonymous lists
Message-Id: <m3itrsugvf.fsf@dhcp11-177.support.tivoli.com>

akhnaten88@my-deja.com writes:

> return [\@a, \@b, \@c];
> 
> First off.. is that the best way to return 3 lists worth of data? To

Well, returning an array reference doesn't really seem to buy you
anything.  Just use:

return \@a, \@b, \@c;

> make the problem more interesting, I had 2 functions that do this, and
> I had to take the return data from both and merge them into single
> lists. TO avoid writing out the second function, I'll just call then
> above function, func() twice and merge that data. Here is what I ended
> up doing:

[original code omitted]

Lots of ways to do this, but given the changed return value above,
here's one solution:

my @refs = func();
my $i;
push @{$refs[$i++]}, @$_ for func();

Note that this avoids copying the first set of values, but still must
copy the second set.  No need here for separate named arrays.  You can
access the values easily enough:

print "@$_\n" for @refs;

BTW, I don't like using $i there, but I couldn't think of a good way
to avoid it.  In other words, how do you iterate over two arrays at
the same time without using a counter?

-- 
Ren Maddox
ren@tivoli.com


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

Date: 19 Sep 2000 23:39:38 GMT
From: nospam@hairball.cup.hp.com (Richard J. Rauenzahn)
Subject: Re: Anonymous lists
Message-Id: <969406777.792977@hpvablab.cup.hp.com>

akhnaten88@my-deja.com writes:
[...]
>
>return [\@a, \@b, \@c];
>}
>
>First off.. is that the best way to return 3 lists worth of data? To

I think the extra level of indirection here is overkill.

>my $refs = func();
>(my ($l1ref, $l2ref, l3ref)) = @{$refs};
>my @list1 = @{$l1ref};
>my @list2 = @{$l2ref};
>my @list3 = @{$l3ref};
># now we call it again, and merge the data
>my $refs = func();
>(my ($l1ref, $l2ref, $l3ref)) = @{$refs};
>my @list1 = (@list1, @{$l1ref});
>my @list2 = (@list2, @{$l2ref});
>my @list3 = (@list3, @{$l3ref});

How about:

#!/opt/perl5/bin/perl -w

use strict;

sub func() {
   my @a = (1, 2, 3);
   my @b = (2, 3, 4);
   my @c = ('foo', 'bar', 'baz');
   return \@a, \@b, \@c;
}

my @a = func;
my @b = func;

my @lists;
$lists[$_] = [ @{$a[$_]}, @{$b[$_]} ] for (0..2);

print "@{$lists[$_]}\n" for (0..2);

---

I've changed your intent slightly here and have put the results into an
array of lists (@lists) rather than @list1, @list2, @list3.

Rich
-- 
Rich Rauenzahn ----------+xrrauenza@cup.hp.comx+ Hewlett-Packard Company
Technical Consultant     | I speak for me,     |   19055 Pruneridge Ave. 
Development Alliances Lab|            *not* HP |                MS 46TU2
ESPD / E-Serv. Partner Division +--------------+---- Cupertino, CA 95014


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

Date: Tue, 19 Sep 2000 23:07:54 GMT
From: tanya_ellis@my-deja.com
Subject: Archive File Attribute on NT
Message-Id: <8q8rjs$q04$1@nnrp1.deja.com>

I would like to delete a list of files on NT
which dont have the Archive File Attribute
checked.  (If the file is unchecked I know it has
been backed up to tape and can now be deleted.)
I have looked around for a file test operator to
check the archive attribute but far so
unsuccessful.

can anyone help?


Tanya


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


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

Date: Wed, 20 Sep 2000 11:49:59 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: Archive File Attribute on NT
Message-Id: <MPG.1432a6b1b495b8e59897be@localhost>

tanya_ellis@my-deja.com <tanya_ellis@my-deja.com> wrote ..
>I would like to delete a list of files on NT
>which dont have the Archive File Attribute
>checked.  (If the file is unchecked I know it has
>been backed up to tape and can now be deleted.)
>I have looked around for a file test operator to
>check the archive attribute but far so
>unsuccessful.
>
>can anyone help?

  (assuming you're using the standard Perl port for Win32)

go to your pretty HTML documentation provided by ActiveState .. scroll 
down the table of contents to the section containing the Win32 modules 
 .. then take a guess which one of the Win32 modules might help you find 
out about file attributes

click on it and read the information on the right

repeat process for any other questions before asking them here

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 19 Sep 2000 17:03:22 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: binmode(): How is OS related with "\n"?
Message-Id: <m3og1kujit.fsf@dhcp11-177.support.tivoli.com>

Larry Rosler <lr@hpl.hp.com> writes:

> In article <jvn5ss4f1jprj7uvjbgsvnotltre0ooonr@4ax.com> on Sat, 16 Sep 
> 2000 02:51:13 GMT, Bart Lateur <bart.lateur@skynet.be> says...
> > Alan J. Flavell wrote:
> > 
> > >> To sum up: if it's a binary file, a common guideline is to binmode it,
> > >
> > >But how does a newbie know what a "binary file" is?
> > 
> > If you plan to read and use it one a byte by byte basis, without any
> > conversion, then it's best to treat it as a binary file.
> 
> It is perhaps clearer to say that a 'text file' is a file structured 
> into 'lines'.  A 'binary file' is anything else.

In the particular case of DOS/WINDOWS, I would use the following
definition:

A binary file is any file that might contain an embedded \C-z, \C-j or
\C-m, other than the specific \C-m\C-j combination at line endings and
the \C-z at the end of the file.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 19 Sep 2000 16:17:20 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Can I dynamically create hashes?
Message-Id: <m3r96gulnj.fsf@dhcp11-177.support.tivoli.com>

hbpursle@duke-energy.com (Bryce Pursley) writes:

> I have run the following code successfully.  Is this doing what was
> suggested?  Is this saving processing by referencing the @tmp array
> instead of copying it again?
> 
> while (defined ($filename = glob ($yesthistfilelist)) ) { # Begin
> Block 1
>  open (HISTFILE, $filename) || die "can't open $filename: $!";
>  while (defined <HISTFILE>) { # Begin Block 1A
>   foreach (<HISTFILE>) { # Begin Block 1B
>    my @tmp = split (/,/);
>    if (($tmp[5] =~ (/^SIMCST/)) && ($tmp[7] =~ (/^ALARM|^Alarm/))) {
>     $tid = ($tmp[2]);
>     $timestamp = ($tmp[0]);
>     $tidhash{$tid}{$timestamp} = \@tmp;
>    }
>   } # end Block 1B        <----------------------\
>  } # end Block 1A                                |
> } # end Block 1                                  |
                                                   |
                                                   |
Yes, this is fine.  @tmp goes out of scope here ---/, so there is no
danger of it being modified after the reference is saved.  This is
exactly what was being recommended -- glad you got it figured out.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 19 Sep 2000 22:19:20 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Can you store a condition in a variable?
Message-Id: <slrn8sfpin.2cp.mgjv@verbruggen.comdyn.com.au>

On Tue, 19 Sep 2000 12:21:04 -0700,
	Larry Rosler <lr@hpl.hp.com> wrote:
> In article <slrn8sf5vb.5fq.abigail@alexandra.foad.org> on 19 Sep 2000 
> 16:45:37 GMT, Abigail <abigail@foad.org> says...
> > 
> > (Yellow and green? *shudder*)
> 
> Check out the Australiam team's colors.

The Australian team is not a web page :)

Martien
-- 
Martien Verbruggen              | My friend has a baby. I'm writing
Interactive Media Division      | down all the noises the baby makes so
Commercial Dynamics Pty. Ltd.   | later I can ask him what he meant -
NSW, Australia                  | Steven Wright


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

Date: 19 Sep 2000 22:55:29 GMT
From: arpepper@math.uwaterloo.ca (Adrian Pepper [MFCF])
Subject: Candidate for the top ten perl mistakes list
Message-Id: <8q8qt1$134$1@watserv3.uwaterloo.ca>

My candidate for the top ten perl mistakes list

Using close instead of closedir to close a handle opened using opendir.


Adrian Pepper, MFCF


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

Date: Tue, 19 Sep 2000 22:22:35 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Char to Octoal... ?
Message-Id: <x7zol4c996.fsf@home.sysarch.com>

>>>>> "A" == Adam  <adamf@box43.gnet.pl> writes:

  A> D Borland wrote:
  >> 
  >> Can anyone here, inform me of how you can return the octal value of a char,
  >> from a $... ?
  >> 
  >> Did i explain this right... ?
  >> 
  >> Thanks for your time...
  >> 
  >> ';'

  A> this is as simply as:
  A> 	printf( "%o", $var );
  A> 	or
  A> 	$var = sprintf( "%o", $var );

bzzt! thanx for playing. better luck next time.

that will convert the whole value of the var to octal. he asked for the
octal value of a char. you need to get the char as an integer first with ord.

  A> ;)

misspelled. :)

uri

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


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

Date: 19 Sep 2000 23:14:05 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Char to Octoal... ?
Message-Id: <slrn8sfsnn.5fq.abigail@alexandra.foad.org>

Alain BARBET (alian@alianwebserver.com) wrote on MMDLXXVI September
MCMXCIII in <URL:news:39C7BE53.7D91B942@alianwebserver.com>:
:} Hi,
:} 
:} > Can anyone here, inform me of how you can return the octal value of a char,
:} > from a $... ?
:} 
:} perldoc -f oct


Nope.

See perldoc -f oct.



Abigail
-- 
$"=$,;*{;qq{@{[(A..Z)[qq[0020191411140003]=~m[..]g]]}}}=*_=sub{print/::(.*)/};
$\=$/;q<Just another Perl Hacker>->();


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

Date: 19 Sep 2000 23:15:19 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Char to Octoal... ?
Message-Id: <slrn8sfsq1.5fq.abigail@alexandra.foad.org>

Adam (adamf@box43.gnet.pl) wrote on MMDLXXVI September MCMXCIII in
<URL:news:39C7C407.62A7@box43.gnet.pl>:
?? D Borland wrote:
?? > 
?? > Can anyone here, inform me of how you can return the octal value of a char,
?? > from a $... ?
?? > 
?? > Did i explain this right... ?
?? > 
?? > Thanks for your time...
?? > 
?? > ';'
?? 
?? this is as simply as:
?? 	printf( "%o", $var );
?? 	or
?? 	$var = sprintf( "%o", $var );
?? if you want it back in some variable instead of STDOUT.


Unlikely. That interprets $var as a *number* and gives the octal
representation of that.

Try again.



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: Wed, 20 Sep 2000 02:30:32 +0200
From: Alain BARBET <alian@alianwebserver.com>
Subject: Re: Char to Octoal... ?
Message-Id: <39C80528.9D019393@alianwebserver.com>

> Nope.
> See perldoc -f oct.

I see. And there is something i think understand i don't really
understand.
oct may be use for
oct -> val and not val -> oct ?
--
Alain & Estelle BARBET


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

Date: Wed, 20 Sep 2000 11:01:01 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: File Parsing, Skipping lines
Message-Id: <MPG.14329b354dbf86cb9897ba@localhost>

J. Stone <jstone211@my-deja.com> wrote ..
>If I know I need to move ahead a certain number of lines once I've
>found an item in my file, what is the best way to do this?

check out the 'next' function

  perldoc -f next

>Also, I need to find a particular header in a file, once I find that I
>need to find another header ( the first header is not always followed
>by the 2nd header, so I must verify)... then I can read lines and parse
>using unpack.  Any tips?

without a better explanation of your input any tips will be very hit-
and-miss .. you might do well to have a look at the built-in input 
record separator variable $/ .. this can be used to change perl's idea 
of a 'line' when you're reading lines in

you might be able to set $/ to the first header (which means that each 
'first header' would signify a new line) and then check to see whether 
the second header is in that line before processing

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 19 Sep 2000 15:53:58 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: FileMaker, DBI
Message-Id: <39C7EE86.7CB4AF82@vpservices.com>

kevin metcalf wrote:
> 
> ... way to use perl to make changes to my filemaker database ....
> it's on a Macintosh G4 server.

If you don't find a direct ODBC solution that works on the MAC, you
might try exporting the filemaker db to a delimited or fixed file and
use DBD::RAM or DBD::CSV on it, or even possibly to a dbase II format
and use DBD::XBase on it.  I think all three of those DBDs should work
on the MAC though I haven't tried myself.

-- 
Jeff


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

Date: Tue, 19 Sep 2000 23:34:32 +0100
From: Geoff Soper <g.soper@soundhouse.co.uk>
Subject: Finding element number of given element in array
Message-Id: <4a00b0ced9g.soper@soundhouse.co.uk>

If I know a string exists once in a array how can I set a variable to the
number of the element of the given string?

Many thanks

-- 
Geoff Soper
g.soper@soundhouse.co.uk
Take a look at the Soundhouse page http://www.soundhouse.co.uk/


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

Date: Tue, 19 Sep 2000 23:15:07 GMT
From: mgjv@verbruggen.comdyn.com.au (Martien Verbruggen)
Subject: Re: Finding element number of given element in array
Message-Id: <slrn8sfsra.hc9.mgjv@verbruggen.comdyn.com.au>

On Tue, 19 Sep 2000 23:34:32 +0100,
	Geoff Soper <g.soper@soundhouse.co.uk> wrote:
> If I know a string exists once in a array how can I set a variable to the
> number of the element of the given string?

*parse*parse*parse*grok*

First: read this:

# perldoc perlfaq4
[snip]
       How can I tell whether a list or array contains a certain
       element?
[snip]

In other words: Please read the Perl documentation, in particular FAQ
section 4.

Because you want to get the index of your element as well, your
question is slightly different. If you do it once, simply use the loop
at the end of that section, and keep track of the index while going.

If you need to do it more than once, you should reverse the array into
a hash, and use that. Note that if you have duplicate elements, that
this technique will only give you the match with the highest index. if
all your elements are unique, you have no problems.

my @foo = qw(foo bar baz banana foo);
my %foo_index;
@foo_index{@foo} = 0 .. $#foo;
print "$foo_index{bar} $foo_index{banana} $foo_index{foo}\n";

gives

1 3 4

See the perl documentation on hash slices

# perldoc perldata


Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | +++ Out of Cheese Error +++ Reinstall
Commercial Dynamics Pty. Ltd.   | Universe and Reboot +++
NSW, Australia                  | 


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

Date: 19 Sep 2000 17:46:21 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Finding element number of given element in array
Message-Id: <m3lmwouhj6.fsf@dhcp11-177.support.tivoli.com>

Geoff Soper <g.soper@soundhouse.co.uk> writes:

> If I know a string exists once in a array how can I set a variable to the
> number of the element of the given string?

This is a FAQ:

               How do I find the first array element for which a
               condition is true?

               You can use this if you care about the index:

                   for ($i= 0; $i < @array; $i++) {
                       if ($array[$i] eq "Waldo") {
                           $found_index = $i;
                           last;
                       }
                   }

               Now `$found_index' has what you want.

perldoc -q element

-- 
Ren Maddox
ren@tivoli.com


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

Date: Tue, 19 Sep 2000 23:19:58 GMT
From: mluebke@my-deja.com
Subject: Help with Mail:Folders and cgi
Message-Id: <8q8sac$qnq$1@nnrp1.deja.com>

I'm writting a small script that is supposed to open a mailbox file,
and display a list of subject lines on the web. Sounds easy right? Here
is my code so far:

*** code starts here ***

#!/usr/bin/perl -w
use Mail::Folder::Mbox;
$| = 1;
print "Content-type: text/html\n\n";
print "TEST1";
$folder = new Mail::Folder('mbox', "/path/to/mailbox");
print "TEST2\n";
$mref = $folder->get_header(1);
print "TEST3\n";
$subj = $mref->get('Subject'); chomp($subj);
print "TEST4\n";
print "$subj";
$folder->close;

*** end code ***

If you run the program on the command line, all four test messages AND
the subject line of the first message is displayed. Here's the kicker,
if it's run via CGI, only TEST1TEST2 is displayed. Even if I explisitly
state to print to STDOUT, nothing.

Anyboy have any thoughts on whats happening?

--
Matt Luebke
mluebke@resourcenetworks.com


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


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

Date: Tue, 19 Sep 2000 19:16:20 -0400
From: "Neb" <berube@odyssee.net>
Subject: Re: How to make a child a parent ?
Message-Id: <LqSx5.149$hs2.7049@news.globetrotter.net>

well i'm coding on Windows, but the actual Perl code will run on Unix.

amonotod <amonotod@netscape.net> a écrit dans le message :
8q8ln8$it7$1@nnrp1.deja.com...
> In article <veQx5.140$hs2.6831@news.globetrotter.net>,
>   "Neb" <berube@odyssee.net> wrote:
> <snip>
> > is there a way to make that child INDEPENDANT from the parent?
> <snip>
> >     system('notepad');
> <snip>
>
> notepad, huh?  Must be win32... see Win32::Spawn().
>
> amonotod
>
> --
>     `\|||/                     amonotod@
>       (@@)                     netscape.net
>   ooO_(_)_Ooo________________________________
>   _____|_____|_____|_____|_____|_____|_____|_____|
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.




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

Date: Wed, 20 Sep 2000 01:02:29 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: How to make a child a parent ?
Message-Id: <F0Ux5.106$PW4.189034@typhoon.southeast.rr.com>

Neb <berube@odyssee.net> wrote in message
news:veQx5.140$hs2.6831@news.globetrotter.net...
> Hi,
>
> Suppose I got a process that fork a child.  The problem is that the child
> will run for a long period of time, way longer than the calling parent.
So,
> is there a way to make that child INDEPENDANT from the parent?

You want a new session ID (setsid) or process group (setpgrp), depending
upon what flavor of Unix you'll be dealing with.

[snip]
> It's not what I want.  I want to really make sure the parent can die, and
> that the forked "child" process can continue to live without the parent.

This very simple example runs on my Linux machine:

use POSIX;

if (fork == 0) {
        if (POSIX::setsid == -1) {
                die "can't setsid";
        }
        exec "/bin/sleep 20";
}

hth,
p




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

Date: Tue, 19 Sep 2000 18:11:05 -0500
From: "Alec Kelingos" <akelingos@petrosys-usa.com>
Subject: loop through file - how to loop back one line?
Message-Id: <ssfsfondqa8h2d@corp.supernews.com>

While looping through a file, how can I 'move back' one line.  eg.

Open(fh,"myfile.dat");
While (<fh>) {
    If ( bla bla bla) {  # I need to start the next read from the previous
line }
}

Is this possible or will I have to make a temporary copy of the previous
line?

I know I could easily do it by loading the file into an array, but I'm
trying to avoid this as the files can be over 100 megs.

Thanks in advance
Alec





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

Date: Wed, 20 Sep 2000 11:53:09 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: loop through file - how to loop back one line?
Message-Id: <MPG.1432a76c994028e79897bf@localhost>

Alec Kelingos <akelingos@petrosys-usa.com> wrote ..
>While looping through a file, how can I 'move back' one line.  eg.
>
>Open(fh,"myfile.dat");
>While (<fh>) {
>    If ( bla bla bla) {  # I need to start the next read from the previous
>line }
>}
>
>Is this possible or will I have to make a temporary copy of the previous
>line?

you can do this with the 'seek' function (although you will need to keep 
a pointer to the previous line by using 'tell' and saving the position)

or .. just save the last line .. it's a pretty trivial operation (and 
almost certainly cheaper than a 'tell' and then a 'seek')

  perldoc -f seek
  perldoc -f tell

>I know I could easily do it by loading the file into an array, but I'm
>trying to avoid this as the files can be over 100 megs.

the only real problem with saving the previous line is if the lines are 
extremely long .. but - as I'm sure you know - this is almost never a 
significant problem with a text file

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Wed, 20 Sep 2000 00:44:48 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Module for CGI Session Management?
Message-Id: <4MTx5.99$PW4.175021@typhoon.southeast.rr.com>


Matt Kruse <mkruse@netexpress.net> wrote in message
news:39c24855$0$20713@wodc7nh0.news.uu.net...
> Philip Garrett <philipg@atl.mediaone.net> wrote
> > Apache::Session does what you want.
>
> Is that specific to Apache server, though? I assumed it was, given the
name
> ;)

It isn't Apache-specific, despite the name.  The documentation states that
it will run under standalone CGI.

> > tie %session, 'Apache::Session::File';
> > $sess{requests}++;
>
> I'll have to look at the module, but if all it is is a simple tie to a
file,
> then it would need a bunch of changes to make it work how I would want it
> to. I started doing some coding on it this morning and found that it's
> really not that complicated at all. I may just stick with my own module
and
> possibly make it available if anyone wants it.

You're right, but although coding it yourself might not be difficult,
Apache::Session provides a standard interface that lots of other people
already know, and that you don't have to code and maintain.

hth,
p




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

Date: Tue, 19 Sep 2000 23:17:26 GMT
From: tanya_ellis@hotmail.com
Subject: NT File Attribute - archive
Message-Id: <8q8s5k$qmm$1@nnrp1.deja.com>

What I would like to do is get a directory list and delete all those
files which the archive attribute is not checked (as this means the file
has been backed up to tape)

I am wondering how to query a NT file to find out whether the archive
attribute is checked or not.

Is this even possible using perl?  Everything I have looked at makes no
mention to this file attribute.


Thanks

Tanya


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


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

Date: Wed, 20 Sep 2000 11:57:41 +1100
From: jason <elephant@squirrelgroup.com>
Subject: Re: NT File Attribute - archive
Message-Id: <MPG.1432a87bf201a35c9897c0@localhost>

  [ posted to comp.lang.perl.misc and CCed to tanya_ellis@hotmail.com ]

tanya_ellis@hotmail.com <tanya_ellis@hotmail.com> wrote ..
>What I would like to do is get a directory list and delete all those
>files which the archive attribute is not checked (as this means the file
>has been backed up to tape)
>
>I am wondering how to query a NT file to find out whether the archive
>attribute is checked or not.
>
>Is this even possible using perl?  Everything I have looked at makes no
>mention to this file attribute.

please try not to ask the same question twice .. I've already answered 
this in the other thread that you started entitled "Archive File 
Attribute on NT"

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4379
**************************************


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