[11635] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5235 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 26 14:07:29 1999

Date: Fri, 26 Mar 99 11:00:21 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 26 Mar 1999     Volume: 8 Number: 5235

Today's topics:
        "push" and hash of lists? ran@netgate.net
    Re: "push" and hash of lists? <zenin@bawdycaste.org>
    Re: 'use'  or 'include' ? <cassell@mail.cor.epa.gov>
        Anonymous Hashes <carcudi@eli.net>
    Re: array question gwebb@reedtech.com
    Re: Calculating the current time in London or GMT+x <cassell@mail.cor.epa.gov>
    Re: Calculating the current time in London or GMT+x (John Stanley)
        check to see if directory exists <stephen@chiso.com>
    Re: check to see if directory exists (Steve Linberg)
    Re: comparing arrays <cassell@mail.cor.epa.gov>
        Counter Digits <cb2001@hotmail.com>
    Re: Currency Parsing <cassell@mail.cor.epa.gov>
    Re: Date/Time calculation: % through current month? <cassell@mail.cor.epa.gov>
    Re: dumping db header row before display <cassell@mail.cor.epa.gov>
        How do you use a variable in an array name? diane6683@my-dejanews.com
    Re: How do you use a variable in an array name? <jeromeo@atrieva.com>
        How secure is this eval statement? <jbeppu@softdc.com>
    Re: How to interpolate subroutines in here-documents? (M.J.T. Guy)
    Re: How to know that a pipe opened for writing is broke (Tad McClellan)
        my random doesn't return number!! <yannick@royaume.com>
    Re: my random doesn't return number!! (Steve Linberg)
    Re: newbie:need help stripping out comments <cassell@mail.cor.epa.gov>
        Passing parameters <olivier.maas@at-lci.com>
    Re: Problem about REGULAR EXPRESSION (Steve Linberg)
    Re: string substitution question <cassell@mail.cor.epa.gov>
    Re: Sys independent "Tue, 20 Aug 1996 14:25:27 GMT" ? <Allan@due.net>
    Re: system() redirecting output <ty@cnr.colostate.edu>
        Win NT, CGI and perl pfridlen@rec.unicen.edu.ar
    Re: Win NT, CGI and perl <eric.schwartz@acm.org>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 26 Mar 1999 17:56:07 GMT
From: ran@netgate.net
Subject: "push" and hash of lists?
Message-Id: <922470967.462.7@news.remarQ.com>

I want to do some categorization and cross-referencing of records.  Each
will have several keys,  only one of which is unique.  So I want to 
store each non-unique key in a hash that identifies all the records with
that key.  Example:  6 records with "author" fields of (Larry,  Moe, 
Moe, Curly, Larry, Shemp).  This would generate an array "@author" with 
values of:

  $author[0] == "Larry"
  $author[1] == "Moe"
  $author[2] == "Moe"
  $author[3] == "Curly"
  $author[4] == "Larry"
  $author[5] == "Shemp"]

and a hash "%author_ix" with values of:

  @{ $author_ix{"Larry"} } == (0, 4)
  @{ $author_ix{"Moe"} }  == (1, 2)
  @{ $author_ix{"Curly"} } == (3)
  @{ $author_ix{"Shemp"} } == (5)

The simplest way to do this seems to be to put this in the read loop:

   $author[$cnt] = $curr_author;
   push (@{ $author_ix{$curr_author} }, $cnt);
   $cnt++;

But it's not clear what happens the first time each author shows up, 
because the hash element is undefined.  Can I count on the use of "@" 
forcing the creation of the new element as a list?  Or should I do an 
"exists $author_ix{$curr_author}" first,  and use something like
"$author_ix{$curr_author} = [$cnt]" in the else block?

Thanks,

Ran





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

Date: 26 Mar 1999 18:44:47 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: "push" and hash of lists?
Message-Id: <922473928.960015@thrush.omix.com>

ran@netgate.net wrote:
	>snip<
:    $author[$cnt] = $curr_author;
:    push (@{ $author_ix{$curr_author} }, $cnt);
:    $cnt++;
:
: But it's not clear what happens the first time each author shows up,
: because the hash element is undefined.  Can I count on the use of "@"
: forcing the creation of the new element as a list?

	Yes, this will work fine. -So long as $author_id{$curr_author} is
	either undef or an ARRAY ref.  If it is any other type of ref you'll
	go boom.  If it is a string you'll go boom under strict, or cause
	random globals to be set if you're not under strict (hint: always
	'use strict;' to avoid this possibility).

: Or should I do an "exists $author_ix{$curr_author}" first, and use
: something like "$author_ix{$curr_author} = [$cnt]" in the else block?

	Nah, no need.

	This is Perl, not Java.

-- 
-Zenin (zenin@archive.rhps.org)

        Yah, Emacs is a good OS, but I prefer FreeBSD.


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

Date: Fri, 26 Mar 1999 09:35:57 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: 'use'  or 'include' ?
Message-Id: <36FBC57D.960EC6C2@mail.cor.epa.gov>

Tad McClellan wrote:
> Alexandre (alrope@zaz.com.br) wrote:
> :  Please, wich is the difference between 'use'  and 'include' comands.
> 
>    'use' is a Perl keyword, and 'include' is not.

But is he trying to ask a *valid* question?  I still don't know 
what that question is, but my guess is that it is one of the 
following:

[1] What is the difference between 'use' and 'require'?
or
[2] What is the difference between 'use' in Perl and 
    'include' in language XX ?  (where XX = 'C' or 'C++'
    or 'SAS' or ...)
I would guess the question is supposed to be some form of #2,
but without knowing which language/4GL is the target, I couldn't
answer it...

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 26 Mar 1999 18:27:12 GMT
From: Charles Arcudi <carcudi@eli.net>
Subject: Anonymous Hashes
Message-Id: <36FBD263.691DB2DE@eli.net>


--------------9259B9F635645DB50D18940F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

We all know about using foreach with a plain old hash:

                       foreach $k (keys %ENV) {
               print STDOUT "$ENV{$k}\n";
            }

Is there a similar construct for retrieving members of an anonymous has
(or attributes of a class, as the case may be), where the members are
referred to as $hash->{value}?

--------------9259B9F635645DB50D18940F
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<HTML>
We all know about using foreach with a plain old hash:

<P>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<TT>foreach $k (keys %ENV) {</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
print STDOUT "$ENV{$k}\n";</TT>
<BR><TT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}</TT><TT></TT>

<P>Is there a similar construct for retrieving members of an anonymous
has (or attributes of a class, as the case may be), where the members are
referred to as $hash->{value}?</HTML>

--------------9259B9F635645DB50D18940F--



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

Date: Fri, 26 Mar 1999 17:34:59 GMT
From: gwebb@reedtech.com
Subject: Re: array question
Message-Id: <7dggg2$3c8$1@nnrp1.dejanews.com>

In article <36fc5da9.2607784@news.skynet.be>,
  bart.lateur@skynet.be (Bart Lateur) wrote:
>
> I can't follow. Why do something so complicated (and possibly slow?)
>
> 	$file_extension =~ s/.*\.//;
>
> ONE substitution. Kill everything up to and including the last period.
>
> Note that this will fail (as will yours ;-) if there is NO extension,
> i.e. no period. The extension should be a null string in that case.

I agree that a regex seems like overkill, but here are some time tests I've
done after making all three versions work properly:

$ cat file.pl
#!perl -w

use Benchmark;
use strict;

my $count = 1000000;

timethese($count, {'char_class' => \&char_class,
                   'dot_mach' => \&dot_match,
                   'sub_str' => \&sub_str,
                  });

sub sub_str {
  my $filename = 'foo.bar.txt';
  substr($filename, 0, (rindex($filename, '.')+1 || length($filename))) ='';
}

sub char_class {
  my $filename = 'foo.bar.txt';
  $filename = '' unless $filename =~ s/^[^.]*\.//g;
}

sub dot_match {
  my $filename = 'foo.bar.txt';
  $filename = '' unless $filename =~ s/^.*\.//;
}
$ file.pl
Benchmark: timing 1000000 iterations of char_class, dot_mach, sub_str...
char_class:  9 wallclock secs ( 7.94 usr +  0.00 sys =  7.94 CPU)
  dot_mach:  7 wallclock secs ( 6.97 usr +  0.00 sys =  6.97 CPU)
   sub_str: 15 wallclock secs (14.20 usr +  0.00 sys = 14.20 CPU)




Can you find a better way to avoid using regexes than substr and [r]index?  I
was also surprised to see that the .* match was faster than the character
class. I even tried it with a really long extension so .* would have to read
the extension and then backtrack while the character class only read the
extension once to make sure there were no more '.'.  Still about the same
times.

Garth

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 26 Mar 1999 10:09:28 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Calculating the current time in London or GMT+x
Message-Id: <36FBCD58.3C87C44A@mail.cor.epa.gov>

Steffen Beyer wrote:
> [snip]
> AFAIK, DST begins and ends also in the middle of a week in the U.S.

Trust me on this.  The change is always made at 2 am Sunday.

I assume this is so that people can have a different excuse for 
missing church.  :-)

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 26 Mar 1999 18:57:01 GMT
From: stanley@skyking.OCE.ORST.EDU (John Stanley)
Subject: Re: Calculating the current time in London or GMT+x
Message-Id: <7dgl9t$c1l$1@news.NERO.NET>

In article <7d045j$73a$1@nnrp1.dejanews.com>,  <thst@my-dejanews.com> wrote:
>Assuming a server is located in California/USA. Now I want to find out the
>current time in London or some other places in europe.
>Well if I add constantly an amount of time (let's say 60*60*8=28800 for a time
>lag of 8 hours) like
>localtime(time + 28800)
>doesn't work, because summer time rules remain unconsidered.
>Is there something like a special parameter
>localtime(time,GMT+1) or something else ?

Why not just set your TZ environment variable to the time zone of
interest? 



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

Date: Fri, 26 Mar 1999 12:08:40 -0600
From: "Stephen M. Shelly" <stephen@chiso.com>
Subject: check to see if directory exists
Message-Id: <36FBCD28.723197C5@chiso.com>

I am trying to see if a directory exists on an NT machine, and am having
some troubles.

Here is my test statement:

if (!(-d "x:\\home\\$Name"))
    print ("Need to create homedir for $Name");

this is not working though.....
Any ideas?



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

Date: Fri, 26 Mar 1999 13:58:03 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: check to see if directory exists
Message-Id: <linberg-2603991358030001@ltl1.literacy.upenn.edu>

In article <36FBCD28.723197C5@chiso.com>, "Stephen M. Shelly"
<stephen@chiso.com> wrote:

> I am trying to see if a directory exists on an NT machine, and am having
> some troubles.
> 
> Here is my test statement:
> 
> if (!(-d "x:\\home\\$Name"))
>     print ("Need to create homedir for $Name");
> 
> this is not working though.....
> Any ideas?

How about telling us what happens and filling in some real data?  "It
doesn't work" ain't much to go on.

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
email: <linberg@literacy.upenn.edu>
WWW: <http://www.literacyonline.org>


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

Date: Fri, 26 Mar 1999 10:59:32 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: comparing arrays
Message-Id: <36FBD914.91C4F4D9@mail.cor.epa.gov>

Dave Waller wrote:
> 
> I have two arrays that are built from a db querry that I
> want to compare to several other arrays to find a closest
> fit match.
> 
> The data is all floats and in a 8 X 8 array.  The data is 0
> - 1 non-inclusive.

Let me see if I have this right.  You have 64 floats, all
between 0 and 1.  Is there any important structure to the
values in the array?
 
> I have thought about several schemes to find the closest
> match but they are all cumbersome.
> 
> Any sugestions??
> --
> Dave Waller
> Precision Drive and Control

One idea, which may not be useful.  If there is no inherent
structure which you must take into consideration, you could
squash each 8x8 matrix into an array of length 64.  Then
you could use a least-squares approach to consider which
of your arrays is closest to your test case.

my $sum = 0;
foreach $i (@testarray) {
    $sum += ($testarray[$i] - $otherarray[$i]) **2;
}

Then the array with the lowest value of $sum is the
'closest' - at least in a Euclidean sense.

David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 26 Mar 1999 19:25:32 +0100
From: "Christian" <cb2001@hotmail.com>
Subject: Counter Digits
Message-Id: <36fbd156.0@info.xpoint.at>

Hi

i programmed a counter in perl and now i want to show the hits on the page
so the user know, i'm visitor (eg. 00102) i made 10 gif files each
containing one digit.
so can anyone please tell me how to yoin the digits from a counter together
(on the fly).

fast help would be appreciated

many thanks in advance

chris




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

Date: Fri, 26 Mar 1999 10:49:01 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Currency Parsing
Message-Id: <36FBD69D.3B33C145@mail.cor.epa.gov>

Petet Yang wrote:
> Hi.
> I have just started to use Perl for a short time. I tried to parse a
> currency number, like $100. However, $ sign is a reserved word for Perl.
> How can I escape this sign to get the number?? Need help!

Okay, the first help I'll give you is that you should always use
the -w flag whenever you run a Perl program.  This will catch so
many errors and save you so much time you won't believe your eyes.
 
> Code:
> >$str = "$100";
> >print $str;
> 
> It displays nothing.

Right.  Now, if you had used the -w flag, it would have warned you
about this.  Double quotes interpolate values - meaning, your first
line thinks $100 ought to be another variable.  Either use '\' to
escape the dollar sign, like this:

$str = "\$100";

or use single quotes, which do *not* do the interpolation:

$str = '$100';

One other point.  If you're playing with currency amounts, you'll
want to look in the FAQ and find out how to (1) print out values
to two decimal places; and (2) get a warning about doing math
on dollar-cent quantities without sufficient care.
 
> Thanks,
> 
> Peter Yang
> 
> petery77@aol.com

HTH, 
David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 26 Mar 1999 09:56:00 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: Date/Time calculation: % through current month?
Message-Id: <36FBCA30.FFA40ADA@mail.cor.epa.gov>

Samuel Kilchenmann wrote:
> Bill Moseley schrieb in Nachricht ...
> >In article <7dg43m$qdc$1@news.swissonline.ch>, skilchen@swissonline.ch
> >says...
> >> my $time = time();
> >> sub var1 {
> >>   my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
> >>       localtime($time);
> >>   my @days_in_month = (31,28,31,30,31,30,31,31,30,31,30,31);
> >>   $days_in_month += 1 if ($year % 4 == 0);
> >                 ^^^
> >                 ^^^
> Yes i know, but since cancelling articles doesn't really work, i didn't
> even try that. I knew that somebody would see the mistake. It evidently
> should be
> $days_in_month[1] += 1 if ($year % 4 == 0);
> (yes the leapyear-check is too simplistic, but i don't care for this simple
> example)

But the leapyear check is *exact* for the defined range (1901 - 2099).
See my comment when I wrote this.  It's easy enough to add the rest of the
features in.  Just two more modulus checks.

> I don't think that my silly mistake influences the benchmark results and
> the difference in the calculated result to the version using timelocal.

Probably not.  But one thing I have learned from Benchmark is that my
intuition about 'fastest' code is not always right.

> but anyway: sorry about the mistake,

Hey, that's nothing.  Yesterday afternoon I couldn't tell the difference
between 0 and 1.  :-)

> Samuel Kilchenmann
> skilchen@swissonline.ch
 
David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 26 Mar 1999 09:46:18 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: dumping db header row before display
Message-Id: <36FBC7EA.9E317588@mail.cor.epa.gov>

tlcora wrote:
> 
> I have a flat text data file.  The first row is the header row and I want to
> remove it before displaying the entries.  Everything else works fine, but I
> can't figure out which perl function to use to remove only the header row
> prior to displaying.  I've looked through the faq several times and also
> searched dejanews using several parameters, yet still can't quite figure it
> out.  Most of the postings deal with deleting a line in a file (faq5), but I
> can't seem to adapt anything to get it to work. Faq4 deals with data, but I
> couldn't find a solution here either. I don't want to edit the file at this
> point, just display the entries without the header row. Could someone point
> me in the right direction?

You read through the FAQ first.  Excellent!  You deserve extra effort.
 
> commented to show my understanding (or lack there of) of each line.
> 
> open (DATABASE, "$datafile");    # will add error checking later

You really ought to throw in the error-checking as soon as you write it.
And it's so straightforward too!
  open DATABASE, "$datafile"    or die "Couldn't open $datafile: $!\n";

> while (<DATABASE>)
> {

Just a nitpick, but I like to indent inside blocks so they're easier to
read/debug/maintain.

> $row = $_;      # puts all of the database file into the scalar $row
> chop $row;        # gets rid of \n at the end of the file

I would have used chomp() here instead of chop().  But TIMTOWTDI.

> @fields = split (/\|/, $row);   # splits each of the fields delimited by |
> and places them in an array
> print "...<html for @fields snipped>  # outputs the contents of @fields to
> the browser

  print "html_chazerai" if $. > 1;
The $. variable tracks the record number for you.

> close (DATABASE);  # closes $datafile

And check the close() too:
  close DATABASE      or die "close() failure.  Ack!  $!\n";

> }
> 
> TIA!
> tlc-

HTH, 
David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 26 Mar 1999 16:45:12 GMT
From: diane6683@my-dejanews.com
Subject: How do you use a variable in an array name?
Message-Id: <7dgdil$ke$1@nnrp1.dejanews.com>

I've tried using the following bit of code in my parse_form subroutine, which
doesn't work (due to the @p_o_$ponum):

        elsif ($name =~ /^p_o_/) {
            if ($value ne '') {
                $ponum = (split(/_o_/,$name))[1];
                push ("@p_o_$ponum",$value);
            }
        }


I have 20 arrays, named @p_o_1 through @p_o_20, and I'm trying to avoid having
to repeat the above code for each array. I'm sure there's an easy way to do
this, but haven't been able to locate the solution in any of my perl books or
through the newsgroups. Any help is greatly appreciated.

Diane

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 26 Mar 1999 09:41:38 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: diane6683@my-dejanews.com
Subject: Re: How do you use a variable in an array name?
Message-Id: <36FBC6D2.E5B8A0C7@atrieva.com>

diane6683@my-dejanews.com wrote:

> I have 20 arrays, named @p_o_1 through @p_o_20, and I'm trying to avoid having
> to repeat the above code for each array. I'm sure there's an easy way to do
> this, but haven't been able to locate the solution in any of my perl books or
> through the newsgroups. Any help is greatly appreciated.

You need a hash of lists.

$arrays{$ponum} = \@array;

For all the exciting detail on perl data structures, see the perldsc
documentation.  You also might want to peruse the perlref document for
information on using perl references.

Good Luck! 

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: 26 Mar 1999 17:44:13 GMT
From: John BEPPU <jbeppu@softdc.com>
Subject: How secure is this eval statement?
Message-Id: <7dgh1d$oh8@news.service.uci.edu>


Assume that I cannot trust the contents of $plugin.

Am I in danger of being hax0red?


# ____________________________________________________________________________
sub create {
  my $self   = shift;
  my $plugin = shift;
  my @argv   = @_;

  return undef unless $plugin =~ /^[\w\d]+$/;

  # Is the above line good enough to prevent mischief in that eval
  # down there?

  if ($self->{available}{$plugin}) {
    my $obj;
    my $loader = sprintf 'require "%s/%s.pm"; $obj = %s->new(@argv);',
    $self->{directory}, $plugin, $plugin;
    eval "$loader" || print $@;
    return $obj;
  } else {
    return undef;
  }
}


I appreciate any advice regarding eval and security...



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

Date: 26 Mar 1999 17:28:42 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: How to interpolate subroutines in here-documents?
Message-Id: <7dgg4a$ghc$1@pegasus.csx.cam.ac.uk>

J. S. Jensen <jsjensen@Paramin.COM> wrote:
>How do I interpolate subroutine references within a here-document?

Other respondents have referred to the interpolation method suggested
in perlfaq4.    An alternative is to use s?printf() to insert arbitrary
expressions in a string:

use Cwd;
printf <<'EOF', cwd;
%s is the current directory.
EOF


Mike Guy


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

Date: Fri, 26 Mar 1999 06:01:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: How to know that a pipe opened for writing is broken? (perlfaq does not  give the answer)
Message-Id: <rdpfd7.dg1.ln@magna.metronet.com>

Sam Holden (sholden@pgrad.cs.usyd.edu.au) wrote:
: Patrice M.I. Parmentier <ppa@itmasters.com> wrote:

: >DO NOT EXPLAIN ME WHY IT DOES NOT WORK (perlfaq does).


   Yelling...


: Asking the same question twice with two different subjects is a bit excessive.


   ... breaking threads ...

   ... and blind-CC'ing too.



   Patrice,

      You will get the most from Usenet if you follow the
      conventions for its use. These are explained in the
      regular postings to the 

         news.announce.newusers

      newsgroup.


      Perhaps you didn't know that all 3 of those things are seen
      as rude on Usenet, but nearly all of your audience _perceived_
      it as (deliberate or accidental) rudeness.

      That can be expected to have a negative impact on the number
      and quality of the responses that you can expect  :-)


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


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

Date: Fri, 26 Mar 1999 17:37:26 GMT
From: "Yannick Girard" <yannick@royaume.com>
Subject: my random doesn't return number!!
Message-Id: <qBPK2.197$CW5.905@198.235.216.4>

Hi,

I'm giving you my code of random generation ...

CAn you tell me why it's doesn't return any number??
-------------------------------------------------------
srand();
@keys = keys %hash;
$rand_key = $keys[int rand @keys];
$numero = $hash{$rand_key};
--------------------------------------------------------

Thanks i need a Urgent REsponse!




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

Date: Fri, 26 Mar 1999 13:53:56 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: my random doesn't return number!!
Message-Id: <linberg-2603991353560001@ltl1.literacy.upenn.edu>

In article <qBPK2.197$CW5.905@198.235.216.4>, "Yannick Girard"
<yannick@royaume.com> wrote:

> Hi,
> 
> I'm giving you my code of random generation ...
> 
> CAn you tell me why it's doesn't return any number??
> -------------------------------------------------------
> srand();
> @keys = keys %hash;
> $rand_key = $keys[int rand @keys];
> $numero = $hash{$rand_key};
> --------------------------------------------------------
> 
> Thanks i need a Urgent REsponse!

#!/usr/bin/perl -w
use strict;

my %foo = ( "abc" => 123, "def" => 456, "ghi" => 789 );
my @foo_keys = keys %foo;

for (1..10) {
   my $rand_key = @foo_keys[rand scalar keys %foo];
   print qq($rand_key: "$foo{$rand_key}"\n);
}
__END__

def: "456"
ghi: "789"
abc: "123"
abc: "123"
abc: "123"
ghi: "789"
abc: "123"
abc: "123"
abc: "123"
def: "456"

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
email: <linberg@literacy.upenn.edu>
WWW: <http://www.literacyonline.org>


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

Date: Fri, 26 Mar 1999 10:21:49 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: newbie:need help stripping out comments
Message-Id: <36FBD03D.4B31F077@mail.cor.epa.gov>

coyote38 wrote:
> 
> I was converting a bunch of c to perl and wrote this bit of code to handle
> the comments.  You could easily modify it to strip out the comments.  The
> nit-picks won't like it, but the code works.

I'm not complaining too much.  Although I would recommend changing your
error-checking from '|| die' to 'or die'.  Different precedence on the
operators will make things work right if you ever have a failure on your 
open().

But...  Your code doesn't seem to handle things that look like comments
in quoted strings.  The best answer is in the FAQ.  Type 'perldoc perlfaq6'
or 'perldoc -q comments' to find it.  If all you want to do is what you
have written below, you could just say:

perl -i.conv -0777 -pe 's{/\*.*?\*/}{}gs' whatever.c
 
> #! /usr/bin/perl5 -w
> #
> # Eric Allen, PhD
> # 01-MAR-1999
> #
> # Converts c comment lines to perl comment lines in a given c file.
> #
> 
> if(! $ARGV[0])
> {
>     print "Convert c comments in what file?\n --> ";
>     $convertFile = <STDIN>;
>     if(! $convertFile)
>     {
>         die("Terminated.  No filename entered.\n");
>     }
> }
> else
> {
>     $convertFile = $ARGV[0];
> }
> chomp $convertFile;
> $commentOn = 0;
> open INFILE,"<$convertFile" || die("Terminated.  Could not open input file
> $convertFile\n");
> open OUTFILE,">$convertFile.conv" || die("Terminated.  Could not open output
> file $convertFile.conv\n");
> while($nextLine = <INFILE>)
> {
>     chomp $nextLine;
>     if($nextLine =~ /\/\*/)  # if $nextLine matches /*
>     {
>         $left = $`;
>         $right = $';
>         $right =~ s/\*\///g;  # substitute */ with nothing
>         $newLine = "$left"."# "."$right\n";
>         if($nextLine !~ /\*\//)  # if $nextLine does not also contain */
>         {
>             $commentOn = 1;  # turn comment flag on
>         }
>         print OUTFILE "$newLine";
>     }
>     elsif($commentOn)  # if comment flag is on
>     {
>         if($nextLine =~ /\*\//)  # if $nextLine matches */
>         {
>             $commentOn = 0;  # turn comment flag off
>             $nextLine =~ s/\*\///g;  # substitute */ with nothing
>         }
>         $newLine = "# "."$nextLine\n";
>         print OUTFILE "$newLine";
>     }
>     else
>     {
>         print OUTFILE "$nextLine\n";
>     }
> }
> close INFILE;
> close OUTFILE;
> print "All done.\n"
> 
> Martha Ferguson wrote in message <36FA97BD.522CE287@cca.rockwell.com>...
> >I have a file that I want to strip out comments.  Comments start with
> >/*  and end with */.  Some of these comments extend over several
> >lines.   If I do a regular expression:
> >
> >    s{/\*.*?\*/}[]gmx;  (global replace of comment line with blank line)
> >
> >
> >I get all the lines that start and end with /* */ but none of the lines
> >that span multiple lines ( neither the first nor last.in the
> >multi-line).  But if I do the range operator:
> >
> >    if (/\/\*/ .. /\*\//)
> >
> >all comments lines are found, but I don't know how to get those lines
> >replaced with a blank line.  I need to have the same number of lines in
> >the file after comments are replaced as there was with the comments.
> >
> >Any suggestions would be greatly appreciated.
> >
> >Thanks, Matha.
> >
 
David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 26 Mar 1999 17:43:03 +0100
From: Olivier Maas <olivier.maas@at-lci.com>
Subject: Passing parameters
Message-Id: <36FBB917.D453E555@at-lci.com>

Hi,
I cannot print the parameters I give to a perl prog via a form, any
idears why

my HTML page:
<html>
<BODY>

<FORM ACTION="c:/NewArbor/Olivier/Web/prems.pl" METHOD="POST">
                   URL : <INPUT NAME="Url" VALUE="http://www."
SIZE=30>   <P>
                   Titre de la page : <INPUT NAME="Titre" SIZE=40><P>
                   Auteur : <INPUT NAME="Nom" SIZE=25 VALUE="Me"><P>
                   E-mail : <INPUT NAME="Email" SIZE=25 VALUE="htt@"><P>

                   <INPUT TYPE="SUBMIT" VALUE=Inscription>
                   </FORM>
</body>
</html>

and prog .pl:
comments are due to the fact that I cannot get the html page directly
(pb with my Windows NT environement, still trying to figure out), I
therefore print a file on the disk to continue the tests.

#!/bin/perl
#push(@INC,'/Perl');
#Require("CGI.pm");
#use CGI ;
#$html= CGI->new ;
#print $html->header ;
      $Url='test';
#Les lignes qui suivent construisent un fichier HTML
open(TES,'>c:/NewArbor/Users/Olivier M/Web/tes2.html');
 print TES "<HTML>\n";
 print TES "<HEAD>\n";
 print TES "<TITLE>titre de la page renvoyie</TITLE>\n";
 print TES "</HEAD>\n";
 print TES "<BODY>\n";
 print TES "\n";
 print TES "<H1>Mon 3 exemple</H1>\n";
There is where I tried to get my arguments... I tried several syntaxes
but... nothing
 print TES "recuperation de Url: $Url\n";
 print TES "recuperation de nom: $input\n";
print TES "recuperation de Email: $input{'Email'}\n";
 print TES "\n";
 print TES "</BODY>\n";
 print TES "</HTML>\n";
close(TES)

Please mail back to maas@ensae.fr



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

Date: Fri, 26 Mar 1999 12:00:05 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Problem about REGULAR EXPRESSION
Message-Id: <linberg-2603991200050001@ltl1.literacy.upenn.edu>

In article <351a7eb3.20074681@news.inet.co.th>, ryanngi@hotmail.com (Ryan
Ngi) wrote:

> There is $sentence= "aaabbbcccaaakkkdddeeeaaa";
> 
> I want to pull "bbbccc"  out of the sentence.
> i use $sentence=~m/aaa(\S*)aaa/;
> 
> the command will pull bbbcccaaakkkdddeee out
> but i want only bbbccc
> 
> please suggest an easy simple way to do it.

Here's one, not the best, but should give you a pointer about what to look
at in the documentation:

$sentence = "aaabbbcccaaakkkdddeeeaaa";
$sentence =~ m/aaa(\S*?)aaa/;
print $1;

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
email: <linberg@literacy.upenn.edu>
WWW: <http://www.literacyonline.org>


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

Date: Fri, 26 Mar 1999 09:24:00 -0800
From: "David L. Cassell" <cassell@mail.cor.epa.gov>
Subject: Re: string substitution question
Message-Id: <36FBC2B0.E7830B64@mail.cor.epa.gov>

Brian Day wrote:
> Hi,
> I'm trying to substitute any whitespace in a string with a backslash followed by a whitespace character.
> 
> I need to pass the entire string as an argument and therefore need to have the whitespaces "escaped" before doing so.

Wow.  I'm having real trouble reading your message, since your
lines are a lot longer than the 72 or so that's normal.  Could
you fix that next time?  TIA.  Now let's see...

> The following won't work:
> 
> s/\s/\\s/g;

Right.  You'll want to read the perlop manpage ('perldoc perlop'
is a nice way to do it) do get more understanding.  But let's consider
what you want.  You need to capture the left-hand side and put a
backslash in front of it.  Now the right-hand side is a double-
quotish construct, so:

s/(\s)/\\$1/g;

where the parens capture the info and $1 (not \1 as in sed)
holds it.

HTH,
David
-- 
David L. Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Fri, 26 Mar 1999 12:41:09 -0500
From: "Allan M. Due" <Allan@due.net>
Subject: Re: Sys independent "Tue, 20 Aug 1996 14:25:27 GMT" ?
Message-Id: <7dggeg$aq8$1@camel18.mindspring.com>

Jari Aalto+mail.perl wrote in message ...
:jari.aalto@poboxes.com (Jari Aalto+mail.perl) writes:
:> I'm generating a meta tag to my webpages,and I'd like to
:> know what is the system independent way to generate standad
:> date string:
:> Tue, 20 Aug 1996 14:25:27 GMT
:> <META http-equiv="Expires" content="Tue, 20 Aug 1996 14:25:27 GMT">


:> I'd like to know a method that works in Win32 and all unix versions.
:> Is there a perl module for this?
:
:I forgot to mention, that I don't want current date, but a date
:that is, say 2 months away from current date. That requires a
:time manipulation package?
:
:Then it makes the Expires Tag useful :-)


How about;

$sec_in_day = 86400;
$num_days = 60;
($day,$mon,$date,$time,$year)= split(/
/,gmtime(time+($sec_in_day*$num_days)));
print "$day, $date $mon $year $time GMT\n";

HTH

AmD

--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
If a man does not keep pace with his companions, perhaps it is because he
hears a different drummer. Let him step to the music which he hears, however
measured or far away.
 - Thoreau




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

Date: Fri, 26 Mar 1999 11:01:41 -0700
From: "Ty! Boyack" <ty@cnr.colostate.edu>
Subject: Re: system() redirecting output
Message-Id: <36FBCB85.900CB14D@cnr.colostate.edu>

Rodighiero Stefano wrote:
> 
> Hi everybody!
> 
> I need a way to redirect output of a shell-command called with system().
> I tried with system( "diff >/dev/null", ...) but it doesn't seem to
> work.
> I can't use `` operator because I need errorlevel returned by the
> program.
> TIA
> 
> Stefano Rodighiero

The above command should be redirecting STDOUT to /dev/null,
but it does not do anything with STDERR.  You may be seeing
output from that.  You can send both STDOUT and STDERR to
/dev/null with the command
system("diff > /dev/null 2>&1");
or 
system("diff > [STDOUTFILE] 2> [STDERRFILE]");
if you want to capture anything.

Keep in mind that STDERR may contain warning messages, but
if you are examining the return code you will probably be 
fine.

-Ty!

-- 
|==========================||======================================|
| Ty! Boyack               || Colorado State University            |
| Unix Services Manager    || College of Natural Resources         |
| ty@cnr.colostate.edu     || A105B, Advanced Technology Lab, NESB |
| (970) 491-4966           ||                                      |
|==========================||======================================|


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

Date: Fri, 26 Mar 1999 16:48:23 GMT
From: pfridlen@rec.unicen.edu.ar
Subject: Win NT, CGI and perl
Message-Id: <7dgdoj$nd$1@nnrp1.dejanews.com>

Hi,

I have IIS4 on an NT 4.00 server. There I have created a directory
"perl-scripts" as a "scripts" subdirectory, where I4ve added a simple perl
script. Then in the IIS4 manager console I have set the directory to allow
SCRIPTS,and I have configured extension "pl" to call perl.exe as script
engine. When I try visiting the script with the web browser (accessing
http://localhost/scripts/perl-scripts/prueba.pl) I can see with the NT
taskbar process browser that PERL.EXE is launched, but it has 0 resources and
00:00 cpu time, and it never appears a response in the web browser, not even
an error message. I neither can terminate the process. So the script runs ok
using DOS console, but I can4t make the script run via web, even when it4s
clear that the perl.exe application is called by the IIS when accessing the
page.

Just in case it4s useful the script is:

#!c:\perl5\bin\perl.exe
# prueba.pl
#
print "Content-type: text/html\n\n";
print "<html>", "\n";
print "<head>", "\n";
print "<title>Hola</title>", "\n";
print "</head>", "\n";
print "<body>", "\n";
print "</body>", "\n";
print "</html>", "\n";
exit;
#end prueba.pl

Thanks for your help.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 26 Mar 1999 10:49:43 -0700
From: Eric The Read <eric.schwartz@acm.org>
Subject: Re: Win NT, CGI and perl
Message-Id: <xkfbthggmyw.fsf@valdemar.col.hp.com>

pfridlen@rec.unicen.edu.ar writes:
> I have IIS4 on an NT 4.00 server. There I have created a directory
> "perl-scripts" as a "scripts" subdirectory, where I=B4ve added a simple=
 perl
> script. Then in the IIS4 manager console I have set the directory to al=
low
> SCRIPTS,and I have configured extension "pl" to call perl.exe as script=

> engine. When I try visiting the script with the web browser (accessing
> http://localhost/scripts/perl-scripts/prueba.pl) I can see with the NT
> taskbar process browser that PERL.EXE is launched, but it has 0 resourc=
es and
> 00:00 cpu time, and it never appears a response in the web browser, not=
 even
> an error message. I neither can terminate the process. So the script ru=
ns ok
> using DOS console, but I can=B4t make the script run via web, even when=
 it=B4s
> clear that the perl.exe application is called by the IIS when accessing=
 the
> page.

Your script is fine.  This isn't a problem with Perl, but rather your
webserver installation.  You'd be better served asking this question on
an appropriate comp.infosystems.www.servers.* 'froup.

-=3DEric


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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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