[16922] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4334 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 15 14:06:43 2000

Date: Fri, 15 Sep 2000 11:05:23 -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: <969041123-v9-i4334@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 15 Sep 2000     Volume: 9 Number: 4334

Today's topics:
        a pesky regex -- any ideas? <rdice@pobox.com>
    Re: a pesky regex -- any ideas? <jeffp@crusoe.net>
    Re: a pesky regex -- any ideas? <rdice@pobox.com>
    Re: a pesky regex -- any ideas? <stephenk@cc.gatech.edu>
    Re: a pesky regex -- any ideas? <jluongonospam@draper.com>
    Re: a pesky regex -- any ideas? <monty@primenet.com>
    Re: binmode(): How is OS related with "\n"? (Tim Hammerquist)
    Re: binmode(): How is OS related with "\n"? <lr@hpl.hp.com>
        Calling a Unix function from a Perl program c315633@my-deja.com
    Re: Calling a Unix function from a Perl program <tony_curtis32@yahoo.com>
    Re: Calling a Unix function from a Perl program <ren.maddox@tivoli.com>
    Re: Can anyone help with weird error? (Andrew J. Perrin)
    Re: Can anyone help with weird error? lishy1950@my-deja.com
    Re: Changing the filename for reporting compile errors (Mark-Jason Dominus)
    Re: format @<<< rathmore@tierceron.com
    Re: format @<<< rathmore@tierceron.com
    Re: format @<<< <lr@hpl.hp.com>
    Re: hashes: how to pass ref into subroutine? nobull@mail.com
    Re: How do I sort a list of list by a certain column <ubl@schaffhausen.de>
        how to install perl in windows95? <catman77@ar51.net>
    Re: how to install perl in windows95? <eric.kort@vai.org>
        Lost libraries when upgrading from 5.005 to 5.6 bluearchtop@my-deja.com
    Re: Module for CGI Session Management? <philipg@atl.mediaone.net>
    Re: Module for CGI Session Management? <ubl@schaffhausen.de>
    Re: Module for CGI Session Management? <mkruse@netexpress.net>
        Module subroutine not recognized? <dmgreer@airmail.net>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 15 Sep 2000 15:19:27 GMT
From: Richard Dice <rdice@pobox.com>
Subject: a pesky regex -- any ideas?
Message-Id: <39C23D8D.ABA70051@pobox.com>

Hello all...

I've got a regex here that's bugging me.  If anyone sees an easy answer,
please let me (the list, etc.) know.

Consider the following piece of text, all stored in 1 scalar, $header:
-------- text starts below  -----------------
Sender: someguy
Message-ID: <396F25A3.B9E48F3E@quux.com>
Date: Fri, 14 Jul 2000 10:37:23 -0400
From: fizz@bin.com
X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.12-20 i686)
X-Accept-Language: en
MIME-Version: 1.0
To: email_1@foo.com, email2@foo.com,
    email_3@foo.com,
  email_4@foo.com
Cc: email_a@bar.com, email_b@bar.com,
    email_c@bar.com
Subject: Re: Feedback request, topic: Collaboration
References: <Pine.LNX.4.10.10007141020240.2204-100000@localhost.localdomain>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
-------- text ended above  ------------------

Obviously, this is taken from an email header.

I want to get all the "to" addresses, then the "cc" addresses, in the format
as if this created my $to:

$to = <<"EOT";
email_1@foo.com, email2@foo.com,
    email_3@foo.com,
  email_4@foo.com
EOT

I've tried a bunch of variation on:

    $header =~ /\nTo: (.+)\n\S/s && do { $to = $1; };

but apparently I haven't tried the right one yet.

Note that, to my eye, the distinctive feature that I'm trying to pick out in
here is that the 1st line following the chunk of lines I'm interested in 
does _not_ start with whitespace, thus the "\n\S" in the regex above.

I must simply be not re-expressing myself properly. :-)

Suggestions are very welcome.

Cheers,
Richard


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

Date: Fri, 15 Sep 2000 11:40:05 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: a pesky regex -- any ideas?
Message-Id: <Pine.GSO.4.21.0009151127170.12100-100000@crusoe.crusoe.net>

[posted & mailed]

On Sep 15, Richard Dice said:

>Sender: someguy
>Message-ID: <396F25A3.B9E48F3E@quux.com>
>Date: Fri, 14 Jul 2000 10:37:23 -0400
>From: fizz@bin.com
>X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.12-20 i686)
>X-Accept-Language: en
>MIME-Version: 1.0
>To: email_1@foo.com, email2@foo.com,
>    email_3@foo.com,
>  email_4@foo.com
>Cc: email_a@bar.com, email_b@bar.com,
>    email_c@bar.com
>Subject: Re: Feedback request, topic: Collaboration
>References: <Pine.LNX.4.10.10007141020240.2204-100000@localhost.localdomain>
>Content-Type: text/plain; charset=us-ascii
>Content-Transfer-Encoding: 7bit

>I want to get all the "to" addresses, then the "cc" addresses, in the format
>as if this created my $to:

>    $header =~ /\nTo: (.+)\n\S/s && do { $to = $1; };

It's easiest if you first modify the $header string as such:

  $header =~ s/\n[ \t]+/ /g;

That will change it from

To: me@me.com, you@you.com,
  him@him.com,
  her@her.com

to

To: me@me.com, you@you.com, him@him.com, her@her.com

And then you need only extract THAT line:

  ($addr) = $header =~ /^To: (.+)/m;

The /m modifier (as documented in perlre) lets ^ match at the beginning of
a "line" within the string.

If you don't want to make this modification to $header before-hand, then
your regex needs to match from 'To: ' to the end of the line, and then the
NEXT line, as long as the next line starts with whitespace.

  ($addr) = $header =~ /^To: (.+(?:\n[ \t].+)*)/m;

Let me break this apart for you:

  m{
    ^To:        # match 'To:' at the beginning of a 'line'
    (           # save to $1 (to be stored to $addr)
      .+          # 1 or more NON-\n characters
      (?:         # followed by (grouping, but not saving to $2)
        \n          # a newline
        [\ \t]      # a space or tab
        .+          # 1 or more NON-\n characters
      )*          # 0 or more times
    )
  }xm;          # /x for these comments, /m for the ^ trick

The reason for that (?: ... ) section is to match continuation lines,
which there may be 0 or more of.

I hope this clears up your problem, and helps you understand regexes
slightly better.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Fri, 15 Sep 2000 15:48:50 GMT
From: Richard Dice <rdice@pobox.com>
Subject: Re: a pesky regex -- any ideas?
Message-Id: <39C24473.437714DD@pobox.com>

Jeff:

Thanks, that was awesome.

> On Sep 15, Richard Dice said:
 .
 .
 .
> It's easiest if you first modify the $header string as such:
> 
>   $header =~ s/\n[ \t]+/ /g;
 .
 .
 .
> Let me break this apart for you:
> 
>   m{
>     ^To:        # match 'To:' at the beginning of a 'line'
>     (           # save to $1 (to be stored to $addr)
>       .+          # 1 or more NON-\n characters
>       (?:         # followed by (grouping, but not saving to $2)
>         \n          # a newline
>         [\ \t]      # a space or tab
>         .+          # 1 or more NON-\n characters
>       )*          # 0 or more times
>     )
>   }xm;          # /x for these comments, /m for the ^ trick
 .
 .
 .
> I hope this clears up your problem, and helps you understand regexes
> slightly better.

Learning more about regexs (admittedly, not one of my stronger suits)
was part of the motivation for coming out and "admitting my problem."
Yeah, of course I could hack that string apart procedurally, but that
wasn't what I wanted to do.  Your reply is totally helpful along
these lines.

Cheers,
Richard


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

Date: Fri, 15 Sep 2000 11:53:46 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: a pesky regex -- any ideas?
Message-Id: <39C24609.721BF543@cc.gatech.edu>

Richard Dice wrote:

> Hello all...
>
> I've got a regex here that's bugging me.  If anyone sees an easy answer,
> please let me (the list, etc.) know.
>
> Consider the following piece of text, all stored in 1 scalar, $header:
>

> To: email_1@foo.com, email2@foo.com,
>     email_3@foo.com,
>   email_4@foo.com
> Cc: email_a@bar.com, email_b@bar.com,
>     email_c@bar.com
> Subject: Re: Feedback request, topic: Collaboration
> References: <Pine.LNX.4.10.10007141020240.2204-100000@localhost.localdomain>
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
>

> I want to get all the "to" addresses, then the "cc" addresses, in the format
> as if this created my $to:
>
> $to = <<"EOT";
> email_1@foo.com, email2@foo.com,
>     email_3@foo.com,
>   email_4@foo.com
> EOT
>
> I've tried a bunch of variation on:
>
>     $header =~ /\nTo: (.+)\n\S/s && do { $to = $1; };
>
> but apparently I haven't tried the right one yet.
>
>
> I must simply be not re-expressing myself properly. :-)
>

Close, but use a lazy match instead of a greedy one:
$header =~ /\nTo: (.+?)\n\S/s && do { $to = $1; };
perldoc perlre

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Fri, 15 Sep 2000 11:44:08 -0400
From: "James M. Luongo" <jluongonospam@draper.com>
Subject: Re: a pesky regex -- any ideas?
Message-Id: <39C243C8.F5E49FD6@draper.com>

First, you should set  $*=1 for multi-line matching
Then why don't you just do this

$header =~ /\nTo: (*)\nCc/

This was off the top of my head.  If anyone can suggest a better method,
go ahead.


Richard Dice wrote:
> 
> Hello all...
> 
> I've got a regex here that's bugging me.  If anyone sees an easy answer,
> please let me (the list, etc.) know.
> 
> Consider the following piece of text, all stored in 1 scalar, $header:
> -------- text starts below  -----------------
> Sender: someguy
> Message-ID: <396F25A3.B9E48F3E@quux.com>
> Date: Fri, 14 Jul 2000 10:37:23 -0400
> From: fizz@bin.com
> X-Mailer: Mozilla 4.72 [en] (X11; U; Linux 2.2.12-20 i686)
> X-Accept-Language: en
> MIME-Version: 1.0
> To: email_1@foo.com, email2@foo.com,
>     email_3@foo.com,
>   email_4@foo.com
> Cc: email_a@bar.com, email_b@bar.com,
>     email_c@bar.com
> Subject: Re: Feedback request, topic: Collaboration
> References: <Pine.LNX.4.10.10007141020240.2204-100000@localhost.localdomain>
> Content-Type: text/plain; charset=us-ascii
> Content-Transfer-Encoding: 7bit
> -------- text ended above  ------------------
> 
> Obviously, this is taken from an email header.


> 
> I want to get all the "to" addresses, then the "cc" addresses, in the format
> as if this created my $to:
> 
> $to = <<"EOT";
> email_1@foo.com, email2@foo.com,
>     email_3@foo.com,
>   email_4@foo.com
> EOT
> 
> I've tried a bunch of variation on:
> 
>     $header =~ /\nTo: (.+)\n\S/s && do { $to = $1; };
> 
> but apparently I haven't tried the right one yet.
> 
> Note that, to my eye, the distinctive feature that I'm trying to pick out in
> here is that the 1st line following the chunk of lines I'm interested in
> does _not_ start with whitespace, thus the "\n\S" in the regex above.
> 
> I must simply be not re-expressing myself properly. :-)
> 
> Suggestions are very welcome.
> 
> Cheers,
> Richard

-- 
------------------------
James M. Luongo  x1427
Draper Laboratory Room 4207
------------------------


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

Date: 15 Sep 2000 16:16:17 GMT
From: Jim Monty <monty@primenet.com>
Subject: Re: a pesky regex -- any ideas?
Message-Id: <8pti0h$cv3$1@nnrp1.phx.gblx.net>

James M. Luongo <jluongonospam@draper.com> wrote:
> First, you should set $*=1 for multi-line matching

The 2nd Camel (p. 129) says:

    Use of $* is now deprecated, and is allowed only for maintaining
    backwards compatibility with older versions of Perl. Use /m (and
    maybe /s) in the regular expression match instead.

-- 
Jim Monty
monty@primenet.com
Tempe, Arizona USA


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

Date: Fri, 15 Sep 2000 17:37:30 GMT
From: tim@degree.ath.cx (Tim Hammerquist)
Subject: Re: binmode(): How is OS related with "\n"?
Message-Id: <slrn8s4ob3.jp.tim@degree.ath.cx>

multiplexor <abuse@localhost.com> wrote:
> I read from perlfunc that binmode is used in OS that distinguish between
> binary and text files. Also, the systems which delimit lines with a single
> character do not need binmode(). However, I am curious about how the two
> points are related. For example, MS-DOS doesn't delimit lines with single
> character "\n", as I know. Does it mean that MS-DOS distinguishes between
> binary and text files? How about Unix?

Yes, MS-DOS and Win32 both distinguish between binary and text files.
Unix does not (though there may be exceptions).

One of the reasons to binmode a DOS binary file is that DOS used to
(and may still) use ASCII code 26 (^Z) as an EOF char for _text_ files.
If you don't binmode a binary file, the OS will consider the first ASCII
26 char as the end of the file, even though it may be in the middle of
the file.

In OSs that don't distinguish between text and binary, it doesn't matter
at all if you binmode them anyway.  Therefore, some consider it a
precaution to routinely binmode all open files.

HTH,
-- 
-Tim Hammerquist <timmy@cpan.org>
The optimist thinks this is the best of all possible worlds.
The pessimist fears it is true.
	-- Robert Oppenheimer


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

Date: Fri, 15 Sep 2000 10:35:59 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: binmode(): How is OS related with "\n"?
Message-Id: <MPG.142bfdd99605ae5898ad71@nntp.hpl.hp.com>

In article <8pstrq$915$1@horn.hk.diyixian.com> on Fri, 15 Sep 2000 
18:33:30 +0800, multiplexor <abuse@localhost.com> says...
> I read from perlfunc that binmode is used in OS that distinguish between
> binary and text files. Also, the systems which delimit lines with a single
> character do not need binmode(). However, I am curious about how the two
> points are related. For example, MS-DOS doesn't delimit lines with single
> character "\n", as I know. Does it mean that MS-DOS distinguishes between
> binary and text files? How about Unix?

The first subject heading in 'perlport' is 'Newlines'.  Go and learn...

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


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

Date: Fri, 15 Sep 2000 15:34:00 GMT
From: c315633@my-deja.com
Subject: Calling a Unix function from a Perl program
Message-Id: <8ptfh6$6u$1@nnrp1.deja.com>

We have a unix function that checks for errors and returns an error number.

function chk_errors {

  while read -r line_o_data
   do
      error_number=`echo $line_o_data | cut  -c 1-3`;
      error_text=`echo $line_o_data | cut -c 5-`;
      ERR_1=`cat $JOBLOG/$JOBNAME.log | grep $error_text`

      if [ $? -eq 0 ]
      then
         # found error
         print $error_number
         exit
      else
         return_value=0
      fi
  done < /usr/testlib/doc/error_messages.txt

}

I want to call this unix function from a Perl program.

MAIN:
{

    $TESTIT=`$TESTLIB/functions/chk_errors $JOBNAME`;
    print $TESTIT
}

The way I have it above, does not return the error message.  I don't even
know the perl program is really executing the unix function.

Does anyone know how to do this?

Thanks.


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


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

Date: 15 Sep 2000 11:02:37 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Calling a Unix function from a Perl program
Message-Id: <87og1pr6ci.fsf@limey.hpcc.uh.edu>

>> On Fri, 15 Sep 2000 15:34:00 GMT,
>> c315633@my-deja.com said:

> We have a unix function that checks for errors and
> returns an error number.  function chk_errors {

Hmmm.  There's no such thing as a "unix function".  What
you show below is a function from a shell scripting
language, apparently sh based.

>     $TESTIT=`$TESTLIB/functions/chk_errors $JOBNAME`;
> print $TESTIT }

You need to put the shell function into a shell script
that will actually invoke it and pass the command-line
parameters to it (remember: it's only the shell that
understands functions written in its syntax) and then you
call that from perl.

hth
t
-- 
We're rich!  Richer than astronauts!
                                         -- Homer Simpson


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

Date: 15 Sep 2000 11:16:12 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Calling a Unix function from a Perl program
Message-Id: <m366nxzl4j.fsf@dhcp11-177.support.tivoli.com>

c315633@my-deja.com writes:

> We have a unix function that checks for errors and returns an error number.

Here is the first problem.  This is implemented as a function rather
than as a script.  The easiest solution to this entire dilemma might
be to write a short shell script that calls this function, and then
call that shell script from Perl.

> function chk_errors {
> 
>   while read -r line_o_data
>    do
>       error_number=`echo $line_o_data | cut  -c 1-3`;
>       error_text=`echo $line_o_data | cut -c 5-`;
>       ERR_1=`cat $JOBLOG/$JOBNAME.log | grep $error_text`
> 
>       if [ $? -eq 0 ]
>       then
>          # found error
>          print $error_number
>          exit
>       else
>          return_value=0
>       fi
>   done < /usr/testlib/doc/error_messages.txt
> 
> }

You might consider simply implementing this in Perl directly.
Shouldn't be too difficult.  Here's a start...

sub chk_errors {
  my $error_file = "/usr/testlib/doc/error_messages.txt";
  open ERRFILE, $error_file or die "Could not read $error_file, $!\n";
  while(<ERRFILE>) {
    my($error_number, $error_text) = /(.{3}).(.*)/;
    # though I bet "split / /, $_, 2" might work", but that depends on
    # the actual format of the data
 .
 .
 .
}

Though now that I've parsed the function a few times I have realized
that it is probably appropriate to load error_messages.txt into an
array and then compare each line of the job file with each element of
the array.  This should be significantly more efficient than grepping
the job file for each error.  Unless the error_messages.txt file is
actually larger than the job file....

> I want to call this unix function from a Perl program.
> 
> MAIN:
> {
> 
>     $TESTIT=`$TESTLIB/functions/chk_errors $JOBNAME`;
>     print $TESTIT
> }

What exactly is $JOBNAME?  And why are you passing it as an argument
to the chk_errors function?  As far as I can tell, that function does
not take any arguments, but rather assumes that JOBNAME (and JOBLOG)
are set in the environment.

> The way I have it above, does not return the error message.  I don't even
> know the perl program is really executing the unix function.

You probably need to check the value of $? in the Perl script to see
if an error occurred in the backticks.  I expect that the shell
function is simply not loaded into the shell that Perl creates for the
backticks.

-- 
Ren Maddox
ren@tivoli.com


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

Date: 15 Sep 2000 11:39:54 -0400
From: aperrin@demog.berkeley.edu (Andrew J. Perrin)
Subject: Re: Can anyone help with weird error?
Message-Id: <uwvgdhdf9.fsf@demog.berkeley.edu>

lishy1950@my-deja.com writes:

> Hello
> I'm getting the following error when running a script:
> 
> Can't modify concatenation in scalar assignment at isconfig.pl line 272,
> near ");"
> 
> Here is the part of the code in question:
> 
>   271    %api.ssprefix=       ("int","sckt://url:port/blah/blah",
>   272             "prod","sckt://url:port/blah/blah");
>   273
>   274    %api.webcomm.svr.addresses=    ("int","url:port",
>   275             "prod","url:port");
> 

 . is not a legal character for a variable name; it's the concatenation
operator which is why you're getting that message.

%api_webcomm_svr_addresses = {int  => 'url:port',
                              prod => 'url:port'};

would be one solution; if you're looking for multi-level data
structures, look at perldoc perldsc.

-- 
----------------------------------------------------------------------
Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
       aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
----------------------------------------------------------------------


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

Date: Fri, 15 Sep 2000 17:25:44 GMT
From: lishy1950@my-deja.com
Subject: Re: Can anyone help with weird error?
Message-Id: <8ptm1r$8mv$1@nnrp1.deja.com>

You're right.  When I changed it from %api.ssprefix to %apissprefix, I
didnt' get the error.  I also have hashes with underscores in them.

Thanks!

In article <uwvgdhdf9.fsf@demog.berkeley.edu>,
  aperrin@demog.berkeley.edu (Andrew J. Perrin) wrote:
> lishy1950@my-deja.com writes:
>
> > Hello
> > I'm getting the following error when running a script:
> >
> > Can't modify concatenation in scalar assignment at isconfig.pl line
272,
> > near ");"
> >
> > Here is the part of the code in question:
> >
> >   271    %api.ssprefix=       ("int","sckt://url:port/blah/blah",
> >   272             "prod","sckt://url:port/blah/blah");
> >   273
> >   274    %api.webcomm.svr.addresses=    ("int","url:port",
> >   275             "prod","url:port");
> >
>
> . is not a legal character for a variable name; it's the concatenation
> operator which is why you're getting that message.
>
> %api_webcomm_svr_addresses = {int  => 'url:port',
>                               prod => 'url:port'};
>
> would be one solution; if you're looking for multi-level data
> structures, look at perldoc perldsc.
>
> --
> ----------------------------------------------------------------------
> Andrew Perrin - Solaris-Linux-NT-Samba-Perl-Access-Postgres Consulting
>        aperrin@igc.apc.org - http://demog.berkeley.edu/~aperrin
> ----------------------------------------------------------------------
>


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


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

Date: Fri, 15 Sep 2000 16:48:50 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Changing the filename for reporting compile errors
Message-Id: <39c252f1.72f3$348@news.op.net>

In article <39C222FA.5D8E256D@flash.net>,
Thom Harp  <thomharp@flash.net> wrote:
>Good point. Is setting the umask so only the current user can access it good
>enough?  Or is the problem bigger than that?

On many systems, /tmp is world-writable.  This means that anyone can
delete any file in /tmp, even if they don't own the file or have
permission to read or to write it.

There's a certain amount of time between when your program writes
/tmp/foo.pl and the time you use 'do' to read it back.  If the
attacker can delete /tmp/foo.pl during this interval and replace it
with their own /tmp/foo.pl, then when your program comes to do the
'do', it gets someone else's code, instad of the code it was
expecting.

It's usually a better idea to make a new, private directory owned
by you and to install the code there.




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

Date: Fri, 15 Sep 2000 17:03:39 GMT
From: rathmore@tierceron.com
Subject: Re: format @<<<
Message-Id: <8ptkoq$73p$1@nnrp1.deja.com>


> But probably you'd just be better off just using printf:
>
>     printf "%-4s%-4s" => $x, $y;

Anyway to left justify with printf? All my data is right justified now,
and that isn't what I want. It did print the spaces at the end that I
need though. :)


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


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

Date: Fri, 15 Sep 2000 17:08:17 GMT
From: rathmore@tierceron.com
Subject: Re: format @<<<
Message-Id: <8ptl1d$787$1@nnrp1.deja.com>

Ok, I'm an idiot. Please ignore. The '-' in there makes it left
justified. After reading your post, I looked up 'printf'
in "Programming Perl" and couldn't find much of anything. And no
reference at all to the '-' so I removed it. Then on a hunch, I put it
back, and bam! worked like magic.

Sorry, again.

**Also, deja.com hick-upped and posted my question twice. Can't wait to
get trn**


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


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

Date: Fri, 15 Sep 2000 10:32:34 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: format @<<<
Message-Id: <MPG.142bfd0db60e8b4e98ad70@nntp.hpl.hp.com>

In article <8ptkoq$73p$1@nnrp1.deja.com> on Fri, 15 Sep 2000 17:03:39 
GMT, rathmore@tierceron.com <rathmore@tierceron.com> says...
> 
> > But probably you'd just be better off just using printf:
> >
> >     printf "%-4s%-4s" => $x, $y;
> 
> Anyway to left justify with printf? All my data is right justified now,
> and that isn't what I want. It did print the spaces at the end that I
> need though. :)

That is called left-alignment, as specified by the '-' in the format 
specifier.  You can specify minimum and maximum field width and whether 
the text is padded with spaces on the right (left-aligned) or on the 
left (right-aligned).

perldoc -f sprintf

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


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

Date: 15 Sep 2000 17:08:24 +0100
From: nobull@mail.com
Subject: Re: hashes: how to pass ref into subroutine?
Message-Id: <u9zol9r62v.fsf@wcl-l.bham.ac.uk>

mickey <michael@GeekTimes.com> writes:

> # I'm trying to understand how I can pass a reference to a hash so that
> # (1) I don't copy the entire hash and (2) I can add elements to that
> # hash from a subroutine.
> #
> # I've checked both the Perl FAQ and perlfaq.com without satisfaction.

FAQs are not the only manuals.

> # PLEASE email my personal account as well; this newsgroup is too busy!
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^

It would be less so if people would read the manuals rather than post
here and expect us to read the manuals to them.

perldoc perlref
perldoc perlreftut

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


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

Date: Fri, 15 Sep 2000 17:03:01 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: How do I sort a list of list by a certain column
Message-Id: <39C23A26.A188B62@schaffhausen.de>

Thanks,

I figured this code should do the work, but it does nothing:

sub sort {
 my $self   = shift;
 my $column = shift; # the column's index

 @{$self->{DB}} = CORE::sort {
  $a->[$column] cmp  $b->[$column]
 } @{$self->{DB}};
}

Hope somebody can get it right!

Thanx,

malte

Koos Pol schrieb:

> On Thu, 14 Sep 2000 12:14:26 +0200, Malte Ubl <ubl@schaffhausen.de> wrote:
> | Hi,
> |
> | I want to sort a list of lits by a certain column. An example would be
> | to sort
> | a list of the names of all the members of a family by the third member
> | of
> | the family.
>
> Look in perlfaq4 for how to sort a hash on it's key values. It it easy to
> extrapolate this approach to lists of lists.
>
> Koos Pol
> ----------------------------------------------------------------------
> S.C. Pol - Systems Administrator - Compuware Europe B.V. - Amsterdam
> T:+31 20 3116122   F:+31 20 3116200   E:koos_pol@nl.compuware.com
>
> Check my email address when you hit "Reply".



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

Date: Fri, 15 Sep 2000 17:28:33 GMT
From: tim <catman77@ar51.net>
Subject: how to install perl in windows95?
Message-Id: <ss4n21psdc6125@corp.supernews.com>

Downed active perl "617, and 5xx". They do not come with a install for 
windows. The install faq on windows is crap. Does anyone really know how 
to install perl into windows95?Tim.

--
Posted via CNET Help.com
http://www.help.com/


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

Date: Fri, 15 Sep 2000 13:45:03 -0400
From: "Eric" <eric.kort@vai.org>
Subject: Re: how to install perl in windows95?
Message-Id: <8ptn3h$i5l$1@msunews.cl.msu.edu>

"tim" <catman77@ar51.net> wrote in message
news:ss4n21psdc6125@corp.supernews.com...
> Downed active perl "617, and 5xx". They do not come with a install for
> windows. <<snip>>

if you download the intel package from activestate.com it comes as a .msi
(windows installer) file...just double click it and it installs itself like
a charm.

hth
Eric




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

Date: Fri, 15 Sep 2000 16:40:10 GMT
From: bluearchtop@my-deja.com
Subject: Lost libraries when upgrading from 5.005 to 5.6
Message-Id: <8ptjd5$5a4$1@nnrp1.deja.com>

I just upgrade from 5.005 to 5.6 and I can no longer access all my
modules installed under 5.005. Did I miss something in the Configure
script? Or is the only way to re-install all modules from CPAN?  Thanks.


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


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

Date: Fri, 15 Sep 2000 15:43:02 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: Module for CGI Session Management?
Message-Id: <asrw5.5126$g35.516386@typhoon.southeast.rr.com>

Matt Kruse <mkruse@netexpress.net> wrote in message
news:mMiw5.43285$Qx4.1470559@news1.rdc1.il.home.com...
> Is there a perl module available whose purpose is just to maintain a
> "session" in CGI programming?
>
> I haven't found one, and there doesn't seem to be a definitive answer in
> past newsgroup postings.
>
> What I'd be looking for is a completely portable solution - that is, not
> reliant on web server or OS.
> In a couple of minutes, I wrote down these thoughts:

Apache::Session does what you want.

>   - Sessions stored as files in a configurable directory
>   - Session ID's generated randomly (best way to do this?)
>   - Files hold name/value pairs of session data
>   - Check session file dates to see if session has expired (last modified
> date).
>   - When a session expires, do full cleanup of old expired sessions (won't
> scale well, depends on app)

It meets the first three for sure, not sure about the last two.  Even if it
doesn't, extending Apache::Session is easy.  It wouldn't take very long at
all to implement those things.

> So, I could see it working like this:
>
> $Session = new CGI::Session($id);  # Reads in existing session or creates
> new
> unless ($Session->isExpired()) {
>     $Session->setValue("requests",$Session->getValue("requests")++);
>     }
> if ($Session->getValue("requests") > 50) {
>     $Session->End();
>     }
> else {
>     $Session->Save();
>     }

tie %session, 'Apache::Session::File';
$sess{requests}++;

> Makes logical sense to me. This wouldn't be too difficult, really. Just
> takes time. If anyone has already written it, please let me know. Also, I
> know that CGI.pm does some sort of session management, but it doesn't
really
> do what I would like, or in a way I would like to do it.

hth,
p




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

Date: Fri, 15 Sep 2000 17:14:08 +0200
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Module for CGI Session Management?
Message-Id: <39C23CC1.10F4F14@schaffhausen.de>

Hi,

if you dont have too much data, why not use cookies?

malte

Matt Kruse schrieb:

> Is there a perl module available whose purpose is just to maintain a
> "session" in CGI programming?
>
> I haven't found one, and there doesn't seem to be a definitive answer in
> past newsgroup postings.
>
> What I'd be looking for is a completely portable solution - that is, not
> reliant on web server or OS.
> In a couple of minutes, I wrote down these thoughts:
>
>   - Sessions stored as files in a configurable directory
>   - Session ID's generated randomly (best way to do this?)
>   - Files hold name/value pairs of session data
>   - Check session file dates to see if session has expired (last modified
> date).
>   - When a session expires, do full cleanup of old expired sessions (won't
> scale well, depends on app)
>
> So, I could see it working like this:
>
> $Session = new CGI::Session($id);  # Reads in existing session or creates
> new
> unless ($Session->isExpired()) {
>     $Session->setValue("requests",$Session->getValue("requests")++);
>     }
> if ($Session->getValue("requests") > 50) {
>     $Session->End();
>     }
> else {
>     $Session->Save();
>     }
>
> Makes logical sense to me. This wouldn't be too difficult, really. Just
> takes time. If anyone has already written it, please let me know. Also, I
> know that CGI.pm does some sort of session management, but it doesn't really
> do what I would like, or in a way I would like to do it.
>
> Thanks!
>
> Matt Kruse
> mkruse@netexpress.net
> http://www.mattkruse.com/



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

Date: Fri, 15 Sep 2000 11:05:41 -0500
From: "Matt Kruse" <mkruse@netexpress.net>
Subject: Re: Module for CGI Session Management?
Message-Id: <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
;)

> 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.

--
Matt Kruse
http://www.mattkruse.com/






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

Date: Fri, 15 Sep 2000 12:49:50 -0500
From: "Dale Greer" <dmgreer@airmail.net>
Subject: Module subroutine not recognized?
Message-Id: <BAA0D86DA1575C66.A1FCAB191BE7E677.4257BB6109769A8E@lp.airnews.net>

I'm a Perl newbie working on someone else's Perl code, using ActiveState
Perl 5.6 on Windows 2000 with Apache 1.3.

I get this in the Apache error.log (names have been changed to protect the
innocent),
Undefined subroutine &Module::Function called at myApp/WAP/Session.pm line
97, <DATA> line 161.

Basically, myApp looks like this,
use Module;
sub connection {
 my $variable= undef;
 unless (something_is_true) {
 $variable= &Module::Function();
 }
}

Module basically looks like this,
package Module;
sub Function()
{
 ...
}

This all looks fine to me, and it works on the other person's setup. Why
won't it work on mine?

Dale Greer
dmgreer@airmail.net





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

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


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