[10156] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3749 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 18 10:07:20 1998

Date: Fri, 18 Sep 98 07:03:35 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 18 Sep 1998     Volume: 8 Number: 3749

Today's topics:
    Re: assigning file contents to a string (Steve Linberg)
    Re: Can I run Perl program regularly? <dejah@DejahsPrivateIce.com>
    Re: Cookies? (Plamen Petkov)
    Re: Cookies? (brian d foy)
    Re: doing a compare with a variable <garry@america.net>
    Re: doing a compare with a variable (Tad McClellan)
    Re: doing a compare with a variable (Mark-Jason Dominus)
    Re: finding out last Sunday (Steffen Beyer)
        How large is a scalar? and related declaration question <dejah@DejahsPrivateIce.com>
    Re: how safe is xor encryption ? (Michael J Gebis)
    Re: how safe is xor encryption ? <jim.michael@gecm.com>
    Re: I need a script writen, can someone help me please <a.g.macinnes@rl.ac.uk>
    Re: Is there any FAQ? <a.g.macinnes@rl.ac.uk>
    Re: Javascript or Perl or Java? (Jay Flaherty)
        Need help with a simple program (newbie). <vmp12@csufresno.edu>
    Re: newbie - time difference <garry@america.net>
    Re: newbie - time difference <barnett@houston.Geco-Prakla.slb.com>
        Newbie needs CGI help c960901@student.dtu.dk
    Re: Newbie needs help <weinstem@bms.com>
    Re: passing argument !!!! <garry@america.net>
    Re: Perl & Java - differences and uses <zenin@bawdycaste.org>
    Re: Perl & Java - differences and uses <zenin@bawdycaste.org>
    Re: Perl & Java - differences and uses (Andrew M. Kuchling)
        Perl for Win32 dilemma <ppype@connect.ab.ca>
    Re: Perl implementation question <dejah@DejahsPrivateIce.com>
    Re: Perl one-liners <barnett@houston.Geco-Prakla.slb.com>
    Re: Perl one-liners (Mark-Jason Dominus)
    Re: print statement. Please help (David A. Black)
    Re: print statement. Please help (Tad McClellan)
        Process checking <Ian_Lowe@fanniemae.com>
    Re: Q:Non-blocking system read - how to cancel block bu <garry@america.net>
    Re: regular expression puzzle <J.D.Gilbey@qmw.ac.uk>
    Re: Regular Expressions for Reading Data (David A. Black)
    Re: Regular Expressions for Reading Data jzobel@my-dejanews.com
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Fri, 18 Sep 1998 09:43:05 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: assigning file contents to a string
Message-Id: <linberg-1809980943050001@ltl1.literacy.upenn.edu>

In article <x3yr9xbhi59.fsf@tigre.matrox.com>, Ala Qumsieh
<aqumsieh@tigre.matrox.com> wrote:

> linberg@literacy.upenn.edu (Steve Linberg) writes:
> 
> > 
> > In article <6tlp2m$rn8$1@nnrp1.dejanews.com>, avern@hotmail.com wrote:
> > 
> > > I know this is a very newbie-ish question, but I've already checked
the FAQ. 
> > > Does any know a very concise way (say, 1 line) to assign the contents of a
> > > file to a string variable? I've seen instructions on processing a file
> > > line-by-line or paragraph-by-paragraph, but I don't want to manipulate the
> > > file contents in any way.  I just want to store the entire file in a
> > > variable, so that I can later refer to the variable in a print statement. 
> > > Can this be done without creating a sub-procedure?
> > 
> > $bigstring = join ('', <FILE>);
> 
> This is very slow and very non-Perlish.

Well, you're right about the slow part; it is slow on large files, but
faster than many other common solutions because it allocates $bigstring in
one chunk rather than incrementally, right?  (Non-Perlish!  Oop, ego
poke.  :P  )

> { undef $/; $string = <FILE> }

That said, your solution above is indeed faster and better; I had never
seen it before.  I don't know if there are any consequences to be had of
undef'ing $/, and since I'm unsure about how many of the system variables
are used, I'm usually hesitant about messing with them - or if I do, I set
them right back after I'm done with them.  I'm assuming changing $/ would
mess up any code below yours that wasn't expecting it... although I
suppose this could be an argument for explicitly setting it before
accessing files, just in case someone above you has changed it.

However, if I had studied perlvar more closely, I would have found your
code below.  Very cool.  Another neat side effect of changing $/ is that
if you set it to an integer value, it limits the record length.  So you
could set it to 80 to get the first 80 characters of every line in a file,
for instance.

A side question: are there faster ways than mine up there to slurp a whole
file into a string without changing $/?

> Hope this helps,

Heck, it helped me!  And it wasn't even my question.  :)
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: Fri, 18 Sep 1998 08:26:01 -0500
From: Mary E Tyler <dejah@DejahsPrivateIce.com>
Subject: Re: Can I run Perl program regularly?
Message-Id: <36025F67.551E@DejahsPrivateIce.com>

Sergei S. Laskavy wrote:
> 
> "Paul Marsh" <pjm@hplb.hpl.hp.com> writes:
> 
> > If your using windows nt use the AT command,
> 
> > D wrote in message <358ecba4.0@rapeme.kirov.ru>...
> 
> > >How can I make a program that can run my Perl program regularly
> > >(daily)?
> 
> UNIX: man crontab
> 
> --
> FreeBSD Project: http://FreeBSD.org/docproj/    Vim: http://www.vim.org/
> $_='$6C86:P$^P|2D<2GJPl=2D<2GJp82>3:E^>D<^DFn';tr#P-~\x20-O#\x20-~#;print


Okay, my web host (ie i don't run the server) won't let me run cron...
is there any *other* way.

dejah
-- 
i trust i make myself obscure, i have need of obscurity now- robert bolt

a heated exchange of unread mail would be welcomed by all- christensen

Skating Fiction. Featuring the  highly acclaimed serial On The Edge!
http://www.DejahsPrivateIce.com


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

Date: Fri, 18 Sep 1998 13:30:18 +0300
From: plamendp@NOSPAM.techno-link.com (Plamen Petkov)
Subject: Re: Cookies?
Message-Id: <MPG.106c62b0b219144498969c@news.techno-link.com>

In article <6trjuc$f3s$1@nnrp1.dejanews.com> 
Date: Thu, 17 Sep 1998 18:21:00 GMT 
wyndo@cxo.com wrote:

Not a cookie related, though... however:

>  
>  Call your CGI program like this:
>  
>  whatever.cgi?somevar=15&someothervar=18&whatever=6
>  
>  This will AUTOMATICALLY be viewed by perl as a "GET" operation. Just read all
>  those variables in like normal. You should be able to completely maintain
>  state among multiple CGI programs by simply generating all your links via CGI
>  with the right parameters after the URL. I'm writing a full sized RPG (web
>  game) in Perl, and I'm maintaining state this way, only using a cookie as a
>  "checksum" to make sure nobody cheats.

I always try to use hidden form fields when and if possible. The way you 
suggest may result in too long URL. Hidden form fields provide another 
"secure" like behavior - the user can't see the parameters you are 
passing to your CGI script and, apart from this, can handle virtualy 
unlimited number of (state) parameters passed. 

The only disadvanages is the design and look&feel shortage - you always 
have to use these poor submit buttons... The workaround is to use 

<input type=image...> 

TAG istead.


IMHO.



-- 
== REMOVE NOSPAM. ===
Plamen Petkov
mailto:plamendp@NOSPAM.techno-link.com
http://www.bgstore.com


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

Date: Fri, 18 Sep 1998 09:35:51 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Cookies?
Message-Id: <comdog-ya02408000R1809980935510001@news.panix.com>
Keywords: from just another new york perl hacker

In article <MPG.106c62b0b219144498969c@news.techno-link.com>, plamendp@NOSPAM.techno-link.com (Plamen Petkov) posted:


>I always try to use hidden form fields when and if possible. The way you 
>suggest may result in too long URL. Hidden form fields provide another 
>"secure" like behavior - the user can't see the parameters you are 
>passing to your CGI script and, apart from this, can handle virtualy 
>unlimited number of (state) parameters passed. 

hidden form fields simply mean that they are not to be displayed
(by a compliant browser).  they are in no way a security feature
and any reliance on them as a security feature is doomed to failure.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers needs volunteers! <URL:http://www.pm.org/to-do.html>


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

Date: Fri, 18 Sep 1998 12:33:59 GMT
From: Garry Williams <garry@america.net>
Subject: Re: doing a compare with a variable
Message-Id: <36025382.1041F134@america.net>

Steve . wrote:
> 
> I have a variable equal to:
> 
> $var=dog7

$var = "dog7";

You forgot the quotes and semicolon.  

-Garry Williams

> I then have a section:
> 
> if ($dot =~ /$var/)
>   {
>     bla bla bla
>   }
> 
> Even though I know the value $dot contains the value of var, it
> doesn't seem to realize it.  Can you do the above comparisons with
> variables or do they have to be static items?  If not, how do you word
> the above.
> 
> Also, can you do the same as above, but have $dot be an array and see
> if the value is in the array?  Thanks.
> 
> Steve


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

Date: Fri, 18 Sep 1998 07:40:35 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: doing a compare with a variable
Message-Id: <3cktt6.jdd.ln@metronet.com>

Steve . (syarbrou@ais.net) wrote:
: I have a variable equal to:

: $var=dog7

   Please don't post pseudo code without pointing out its pseudoness.

   Especially when it is Oh So Easy to make it into real Perl code.

      $var='dog7';

   You will get better answers if you use real code (and cut/paste it
   rather than trying to retype it all correctly)



: I then have a section:

: if ($dot =~ /$var/)
:   {
:     bla bla bla
:   }

: Even though I know the value $dot contains the value of var, it
              ^^^^^^

   But we don't.

   Actually I expect that it does NOT contain 'dog7'. Or, there is
   something else you are not telling us.



: doesn't seem to realize it.  Can you do the above comparisons with
: variables 


   Yes.


: or do they have to be static items?  


   No.


: If not, how do you word
: the above.


   Here is a _complete program_ that should illustrate your problem.

   But it works fine.

   Does it work for you?

------------------------------------
#!/usr/bin/perl -w

$var='dog7';

$dot = 'this has a dog7 in it';

if ($dot =~ /$var/) {
   print "bla bla bla\n";
}
------------------------------------


: Also, can you do the same as above, but have $dot be an array and see
: if the value is in the array?  


   if (grep /$var/, @some_array) {
      print "found it in the array\n";
   }


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


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

Date: 18 Sep 1998 09:38:24 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: doing a compare with a variable
Message-Id: <6ttnog$ita$1@monet.op.net>

In article <36018b43.2618328@news.ais.net>, Steve . <syarbrou@ais.net> wrote:
>Even though I know the value $dot contains the value of var, it
>doesn't seem to realize it. 

I suspect that you simplfied the example, and in doing so, you broke
it.  Can you show a real, complete example that demonstrates the
problem?

>Can you do the above comparisons with variables or do they have to be
>static items?

Yes.  Perl interpolates the value of the variable into the regex just
as if it were a "..." string.  If the value contains characters that
are special in regexes, like "*", they will be treated specially.

If this isn't what you want, often the simplest solution is to use the
`index' function instead.  It searches for one string inside another.

>Also, can you have $dot be an array and see if the value is in the
>array?

That is a FAQ.

# perlfaq4: How can I tell whether an array contains a certain element?



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

Date: 18 Sep 1998 10:15:55 GMT
From: sb@engelschall.com (Steffen Beyer)
Subject: Re: finding out last Sunday
Message-Id: <6ttbsr$jkl$1@en1.engelschall.com>

Steve . <syarbrou@ais.net> wrote:

> I have a program that basically states:

> Stats for the current week through xx/xx/xx

> What I would like to do is say something like:

> Stats for the week starting on xx/xx/xx
> where the xx/xx/xx above is the Sunday for the current week.  In other
> words if this is Monday, I want yesterday's date.  I could store the
> info in a file when the logs are cleared, but figured there was a
> cleaner way of doing it.  Thanks.


  use Date::Calc qw( Today Day_of_Week Add_Delta_Days );

  $searching_dow = 7; # 7 = Sunday

  @today = Today();

  $current_dow = Day_of_Week(@today);

  $diff = $searching_dow - $current_dow;

  @date = Add_Delta_Days(@today, $diff - 7) if ($diff);

(A correction is being made for the fact that you want the week to
start with Sunday, although the ISO standard says that the week begins
with Monday.)

Hope this helps.

Yours,
-- 
    Steffen Beyer <sb@engelschall.com>
    Free Perl and C Software for Download: www.engelschall.com/u/sb/download/


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

Date: Fri, 18 Sep 1998 08:40:46 -0500
From: Mary E Tyler <dejah@DejahsPrivateIce.com>
Subject: How large is a scalar? and related declaration question.
Message-Id: <360262DA.772F@DejahsPrivateIce.com>

how large is a scalar? (ie how big a number will it store?)

okay, *yes* i have been reading the FAQs and I am currently reading the
HTML man stuff (i think) and I am wading through the camel book, but i
have not come upon this yet.

second, i have seen much *stuff* (the technical terms stuff) about
declarations. i can understand in C how you can declare 

myvariable int;

and that is a declaration... but there are just scalars and lists in
PERL and so i am confused as to how to declare anything...

speaking of which, when i *do* declare a sub routine, the interpreter
balks and complains at me. then i realized, the camel says that i can
prototype a subroutine, but it doesn't show *how*. here is a C function
prototype

int FooInt (IntIn int, Format char);

what would be the corresponding prototype in PERL?

what's more... how do you *call* it?

thanks in advance,
dejah
-- 
i trust i make myself obscure, i have need of obscurity now- robert bolt

a heated exchange of unread mail would be welcomed by all- christensen

Skating Fiction. Featuring the  highly acclaimed serial On The Edge!
http://www.DejahsPrivateIce.com


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

Date: 18 Sep 1998 04:18:38 GMT
From: gebis@fee.ecn.purdue.edu (Michael J Gebis)
Subject: Re: how safe is xor encryption ?
Message-Id: <6tsmuu$75q@mozo.cc.purdue.edu>

genepool@netcom.com (Jim Michael) writes:

}beyret@my-dejanews.com wrote:
}: any advice ? for commercial usage? I checked out PGP 5.0 for unix but its
}: licencing is rather expensive for us. (at least for a few months)

}I think there are no commercial restrictions on Blowfish.

It also appears there is not a perl module for Blowfish.

This may need to be fixed. :)

-- 
Mike Gebis  gebis@ecn.purdue.edu  mgebis@eternal.net


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

Date: Fri, 18 Sep 1998 08:49:44 -0400
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: how safe is xor encryption ?
Message-Id: <360256E8.A6C@gecm.com>

Michael J Gebis wrote:
> genepool@netcom.com (Jim Michael) writes:
> }I think there are no commercial restrictions on Blowfish.
> 
> It also appears there is not a perl module for Blowfish.
> 
> This may need to be fixed. :)

Yes. For starters, here is a source for more info:
http://www.counterpane.com/blowfish.html

Cheers,

Jim


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

Date: Fri, 18 Sep 1998 13:58:26 +0100
From: Andrew MacInnes <a.g.macinnes@rl.ac.uk>
Subject: Re: I need a script writen, can someone help me please
Message-Id: <360258F2.6B5615D2@rl.ac.uk>

Gareth Hall wrote:

> Can somone write a script for me. Anyone who is fimiliar with MAME
> would have an advantage. I need a script that will generate a table
> for my web page from mame -listfull -noclones, it will have to be able
> to have the number of columns inputted at the command line, also the
> url where the .zip files can be downloaded from. i have one allready,
> but it only worls from the mamelist.txt file and this isn't really
> good for my purpose. I can send anyone more info if they want it.
>
> Thank for the help in advance.
> Answers by email please.


I take it this is another joke, not as good as Patrick Timmins' earlier
post, but funny.

What? Its not a joke??

Could the author read the "QUESTIONS (was: Perl Programmer Needed)"
thread started by Patrick Timmins on 09/09/98 and see how this question
_should_ be worded.

Most programmers here will _help_ you write scripts, but don't expect
them to do all the work for you.


Cheers

Andrew MacInnes

- RAL, DCI,                  E-mail:A.G.MacInnes@rl.ac.uk -
- R27 - F31             Telephone (direct): (01235)446104 -
- Chilton, Didcot       Telephone (Mobile):  07775 943273 -
- Oxon, OX11 0QX                  http://www.dci.rl.ac.uk -




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

Date: Fri, 18 Sep 1998 14:29:54 +0100
From: Andrew MacInnes <a.g.macinnes@rl.ac.uk>
Subject: Re: Is there any FAQ?
Message-Id: <36026052.57F98D83@rl.ac.uk>

Hansi Hinterseer wrote:

> Hi!
>
> I wondered if there is a FAQ about Perl or the NGs. Is there? Or any
> recommended tutorials?
>
> Thanks, Hansi

Read the FAQ!! :)

But seriously....

Go to www.perl.com, its ace!!

Beginers tutorial is available at http://www.scs.leeds.ac.uk/Perl/


Hope this helps



Cheers

Andrew MacInnes

- RAL, DCI,                  E-mail:A.G.MacInnes@rl.ac.uk -
- R27 - F31             Telephone (direct): (01235)446104 -
- Chilton, Didcot       Telephone (Mobile):  07775 943273 -
- Oxon, OX11 0QX                  http://www.dci.rl.ac.uk -





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

Date: Fri, 18 Sep 1998 12:23:27 GMT
From: fty@utk.edu (Jay Flaherty)
Subject: Re: Javascript or Perl or Java?
Message-Id: <36024e86.64303148@alder>

On Thu, 17 Sep 1998 09:46:35 GMT, laksh5614@my-dejanews.com wrote:

>Please can somebody clarify the difference between  using Javascript, Java,
>Perl? As a Beginner what should a person know to start off with Internet
>Programming?

Javascript bundled with CSS, DOM = Dynamic HTML - Very slick but lacks
server interactivity (i.e. database access). Some what of a steep
learning curve for beginners. Currently 2 "interpretations" of the DOM
and CSS with NS and MS.

Java - very nice if you want to go beyond the limitations of the
browser. Can access databases via JDBC. Very steep learning curve.
Currently slow compared to compiled code.

Perl - Excellent tools to handle CGI (CGI.pm), Database access
(DBI.pm), excellent text parsing. Some what easy to learn. Currently
lacks interaction with the DOM. When are we going to have a Perlscript
(i.e. client side programming)?   :-)

Good luck...jay


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

Date: Tue, 15 Sep 1998 14:51:07 -0700
From: Vince <vmp12@csufresno.edu>
Subject: Need help with a simple program (newbie).
Message-Id: <35FEE14B.305BA1E@csufresno.edu>

Disclaimer: I'm a newbie.

Ok, I'm working on a script that takes MM/DD/YYYY as the input and then
returns the date and time (to the nearest hour) of the next new, first
quarter, full, and last quarter moon on or after the date given.

Here's the algorithms I've devised:

M = month number
D = day of the month (with decimals if you want a particular time)
Y = year (four digits)

STEP 1:If M > 2 then leave Y and M unchanged, however, if M = 1 or M = 2

then replace Y by Y-1, and M by M + 12

STEP 2: A = INT(Y/100)
STEP 3: B = 2 - A + INT(A/4)

To calculate lunar phases do the following:

Given: Phase_time = 2451550.0975 + 29.530588853 * k + 0.0001337 * T^2 +
0.000000150 * T^3 + 0.000000000 * T^4 where ^ => exponentiation and
"where an integer value of k gives a New Moon, and  integer increased by

0.25 gives a First Quarter, by 0.50 gives a Full Moon, by 0.75 gives a
Last Quarter."

k is approximated by (year - 2000) * 12.3685 where "year" can have a
fraction part (for exammple, March 1998 is 1998.25).

T is defined as k/1236.85

After achieving the phase_time (which is a Julian Day) we then to
convert this to Day, Month, Year, Time.  We do the following:

Let JD be the Julian Day.

STEP 1: add 0.5 to JD, and let Z be the integer part and F the fraction
of the result.

STEP 2: if Z< 2299161, set A=Z

STEP 3: if Z >= 2299161, calculate the following: alpha = INT((Z -
1867216.25)/36524.25)
A= Z + 1 + alpha - INT(alpha/4)

STEP 4: B = A + 1524
C = INT((B - 122.1)/365.25)
D=INT(365.25*C)
E=INT((B-D)/30.6001)

STEP 5: the day of the month (with decimals) is:
B - D - INT(30.6001 * E) + F

STEP 6: the month number m is
E - 1 if E < 14
E - 13 if E = 14 or 15

STEP 7: the year is
C - 4716 if m > 2
C - 4715 if m = 1 or 2

That's it.  So example would be something like:

01/01/1977

year would equal 1977.13
k is approximated by (1977.13 - 2000) * 12.3685 = -282.87

Since k should be an integer for New Moon, round up to -283.

T is then -283/1236.85 = -0.22881, and by the formula for phase_time
returns the result of 2443192.94101 which is then passed to fine the
month/day/year of the New Moon, First Quarter, Full Moon and Last
Quarter.

Now I am not a programmer I'm just an austronomy zealot that's trying to

find a simple program to this for me so I don't have to do it by hand.

Attached is my current source code.  I appreciate anyone's help.

Thanks, Vince

#!/usr/bin/perl

sub calc {
  $a = int ($year / 100);
  $b = 2 - $a + int ($a / 4);
  $jd = int (365.25 * ($year + 4716)) + int (30.6001 * ($month + 1)) +
$day +$b - 1525;
  $jde = $jd + 65;
  print "JD: $jd\n";
  print "JDE: $jde\n";
  &calc_lunar_phases;
}

sub convert_JD {
  print "hehehe: $_";
  $jd += .5;
  $jd_test = $jd;
  ($z,$f)=split('.',$jd_test);
  if ($z < 2299161)
    {
      $a = $z;
    }
  if ($z >= 2299161)
    {
      $alpha = int (($z - 1867216.25) / 36524.25);
      $a = $z + 1 + $alpha - int (alpha / 4);
    }
  $b = $a + 1524;
  $c = int(($b - 122.2)/365.25);
  $day = int(365.25 * $c);
  $e = int(($b-$day)/30.6001);
  $day_of_month = $b - $d - int(30.6001 * $e) + $f;
  print "Day: $day_of_month\n";
  if ($e < 14)
    {
      $month_is = $e - 1;
      print "Month: $month_is\n";
    }
  if ($e == 14 | $e == 15)
    {
      $month_is = $e - 13;
      print "Month: $month_is\n";
    }
  if ($month > 2)
    {
      $year_is = $c - 4716;
      print "Year: $year_is\n";
    }
  if ($month == 1 | $month ==2)
    {
      $year_is = $c - $4715;
      print "Year: $year_is\n";
    }
}

sub calc_lunar_phases {
  $first_quarter = .25;
  $full_moon = .50;
  $last_quarter = .75;

  $k = ($year_in_decimal - 2000) * 12.3685;

  $T = $k / 1236.85;

  $phase_time = 2451550.09765 + 29.54058853 * $k + 0.0001337 * $T**2 +
0.000000150 * $T**3 + 0.00000000073 * $T**4;
  print "hehehe: $_";
  $frst_qt_plus_phase_time = $first_quarter + $phase_time;
  $fll_mn_plus_phase_time = $full_moon + $phase_time;
  $lst_qt_plus_phase_time = $last_quarter + $phase_time;
  print "Phase time-----------------\n"; &convert_JD;
  print "First quarter--------------\n"; &convert_JD;
  print "Full moon------------------\n"; $convert_JD;
  print "Last quarter---------------\n"; &convert_JD;
}

print "Please enter the date to find JD: ";
chomp($date_using=<STDIN>);
($month,$day,$year)=split /\//, $date_using;
if ($month == 1) {
  $temp_month = $day;
}
if ($month == 2) {
  $temp_month = 31 + $day;
}
if ($month == 3) {
  $temp_month = 59 + $day;
}
if ($month == 4) {
  $temp_month = 90 + $day;
}
if ($month == 5) {
  $temp_month = 120 + $day;
}
if ($month == 6) {
  $temp_month = 151 + $day;
}
if ($month == 7) {
  $temp_month = 181 + $day;
}
if ($month == 8) {
  $temp_month = 212 + $day;
}
if ($month == 9) {
  $temp_month = 243 + $day;
}
if ($month == 10) {
  $temp_month = 273 + $day;
}
if ($month == 11) {
  $temp_month = 304 + $day;
}
if ($month == 12) {
  $temp_month = 334 + $day;
}

$day_month = $temp_month / 365;
$year_in_decimal = $day_month + $year;

if ($month > 2)
  {
   &calc;
  }
if ($month == 1 || $month == 2)
  {
    $year = $year - 1;
    $month = $month + 12;
    &calc;
  }




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

Date: Fri, 18 Sep 1998 12:30:32 GMT
From: Garry Williams <garry@america.net>
Subject: Re: newbie - time difference
Message-Id: <360252B2.BBD3D108@america.net>

use Time::Local;

-Garry Williams

robert.sanford@platinum.com wrote:
> 
> i have times from two different sources. the first source is using
> localtime(time) and the second is a list of parameters that include
> year, month, day in month, hour, minute, second.
> 
> my question is - what is the best way to determine if a certain period
> has elapsed between localtime and time given as parameters? is there a
> way to convert time given as parameters and the time data structure
> into a numeric value (number of seconds since 1970 for example) that i
> can say:
>    $timeDiff = $localTime - $paramTime
> 
> thanks,
> 
> rjsjr


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

Date: Fri, 18 Sep 1998 07:47:37 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
To: robert.sanford@platinum.com
Subject: Re: newbie - time difference
Message-Id: <36025669.B71EA9F5@houston.Geco-Prakla.slb.com>

[courtesy cc to cited author]

robert.sanford@platinum.com wrote:
> 
> i have times from two different sources. the first source is using
> localtime(time) and the second is a list of parameters that include
> year, month, day in month, hour, minute, second.
> 
> my question is - what is the best way to determine if a certain period
> has elapsed between localtime and time given as parameters? is there a
> way to convert time given as parameters and the time data structure
> into a numeric value (number of seconds since 1970 for example) that i
> can say:
>    $timeDiff = $localTime - $paramTime
Short answer:
Yes.

Longer answer:
perldoc Time::Local
(look up timelocal)


> 
> thanks,
> 
> rjsjr
HTH.

Cheers,
Dave

-- 
Dave Barnett	Software Support Engineer	(281) 596-1434


My inferiority complex is not as good as yours.


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

Date: Fri, 18 Sep 1998 12:56:01 GMT
From: c960901@student.dtu.dk
Subject: Newbie needs CGI help
Message-Id: <6ttl91$jpd$1@nnrp1.dejanews.com>

Hi

I'm trying to make a CGI that when executes just writes a file and
returns a string to the applet that called it. The source looks like
this:
#!/usr/local/bin/perl -w

$write_file = "c:\\httpd\\HtDocs\\test.mpr";
open(OUT,">>$write_file") || die "Error: $write_file $1";
print OUT "Test 1 2 3...\n";
close(OUT);

Content-type: text/html

print("Abcdefghijkl");
exit 0;

But I get the following compile errors (because of the Content-type):

Argument "type" isn't numeric in subtract at C:\httpd\Cgi-Bin\test.pl line 8.
Argument "Content" isn't numeric in subtract at C:\httpd\Cgi-Bin\test.pl line
8. syntax error at C:\httpd\Cgi-Bin\test.pl line 8, near "type:" Unquoted
string "text" may clash with future reserved word at C:\httpd\Cgi-Bin\test.pl
line 8. Unquoted string "html" may clash with future reserved word at
C:\httpd\Cgi-Bin\test.pl line 10. Execution of C:\httpd\Cgi-Bin\test.pl
aborted due to compilation errors.

I'll be grateful of any help. Please send the reply to my E-mail adress,
thanks in advance.

Morten


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


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

Date: Fri, 18 Sep 1998 08:38:57 -0400
From: Maxim Weinstein <weinstem@bms.com>
Subject: Re: Newbie needs help
Message-Id: <36025461.84157FF9@bms.com>

Alastair wrote:

> Basically, you need to do more than merely 'look' over a few perl resources
> (whatever they are). If you want to learn and understand, the best way is to
> actually get stuck in and try things out. It really isn't hard. The program you
> want is pretty straightforward.
>
> I'd buy a book on perl (e.g. Learning Perl from O'Reilly) and start to read and,
> more importantly, try.

Yeah, you're right of course.  It's just the "so much to do, so little time"
phenomenon.  Studying for MCSE exams, trying to pick up some basic Linux, etc.  :)

-- Max



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

Date: Fri, 18 Sep 1998 12:35:45 GMT
From: Garry Williams <garry@america.net>
Subject: Re: passing argument !!!!
Message-Id: <360253EC.9175A8E2@america.net>

Does 

    system("browser_crno.ksh '$DATE' > $DOCS_DIR/$out_put");

help?

-Garry Williams

nguyen.van@imvi.bls.com wrote:
> 
> I try to pass an argument from perl script to korn script which is called by
> perl script. The following is my code:
> 
> system("browser_crno.ksh $DATE > $DOCS_DIR/$out_put");
> 
> where $DATE is the perl's and korn's argument.
> 
> This seems not working for me. Thanks in advance.
> 
> Van
> 
> -----== Posted via Deja News, The Leader in Internet Discussion ==-----
> http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 18 Sep 98 12:16:43 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl & Java - differences and uses
Message-Id: <906121251.956565@thrush.omix.com>

Terry Reedy <tjreedy@udel.edu> wrote:
	>snip<
: Actually, Python allows optional use of '#{' and '#}' as block delimiters
: (but only at the ends of lines, in addition to normal indentation).  One 
: could add these where desired for the purpose described above.

	Does this actually have any effect on Python's blocking, or is it
	just the editor kluge it looks like?

	Funny, #{ and #} look a lot like line noise to me. ;-P

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: 18 Sep 98 13:05:26 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Perl & Java - differences and uses
Message-Id: <906124168.801207@thrush.omix.com>

Andrew Dalke <dalke@bioreason.com> wrote:
    >snip<
: and more cumbersome in Perl (unless something has been added to
: perl since 5.003 days, which wouldn't surprise me given the other
: changes I didn't know about :).

        Quite a bit has been added, but not in this area.

: This uses named groups (the "?P<>" construct) and the fact the
: you have better access to subgroup information (the feature
        >snip<
: so you can get the start and end positions of the pattern match.
        >snip code sample<
: What does the perl version of this look like?

        A bit more complex algorithm is needed for Perl in this particular
        case, as the need for pos() and/or index() would be needed.  In
        defense of Perl, data manipulation does not start and end with
        regular expressions.  Don't make me turn around and challenge
        Python's data manipulation abilities with something like:
                
            $string     = "John Doe";
            $first_name = \substr ($string, 0, 4);

            $$first_name= "Jane";
            print $string;

            ## Prints Jane Doe

        <insert evil grin here>

        ?P<> is a slick feature, I'll admit, but I do wonder when it would
        be of use?  I do some pretty funky re myself, and have only found
        and extremely limited number of cases that I had to drop down to
        index() and pos().

        Could someone please show a real world example of this feature
        in use?

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: 18 Sep 1998 09:34:18 -0400
From: akuchlin@cnri.reston.va.us (Andrew M. Kuchling)
Subject: Re: Perl & Java - differences and uses
Message-Id: <3dvhml7det.fsf@amarok.cnri.reston.va.us>

Zenin <zenin@bawdycaste.org> writes:
> : About as valid as flaming about Perl using special characters to
> : determina a variables type. The only other language I know of that
> : uses that silly trick is BASIC.
>
> 	Which BASIC?  The ones I've used haven't done this.

Certainly the early Microsoft BASICs on the various 8-bit computers
did this.  In Commodore BASIC, A$ was definitely a string, and if I
disremember it correctly, A% was an integer while A was a floating
point number.  (It's been a long time...)

-- 
A.M. Kuchling			http://starship.skyport.net/crew/amk/
When I read passages like this, I want to look for the nearest wall to bang my
head against.
    -- S.T. Joshi, "Arthur Machen: The Mystery of the Universe" in _The Weird
       Tale_



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

Date: Fri, 18 Sep 1998 06:31:48 -0600
From: "Paul Pype" <ppype@connect.ab.ca>
Subject: Perl for Win32 dilemma
Message-Id: <3601fc94.0@skylite.connect.ab.ca>

I am a Perl newbie working with ActiveState's Perl for Win32 v5.00502. I
think I've found a bug in the interpreter, but I may just be missing
something obvious. I would like to find out if other's have experienced
similar behaviour:

The code for my very simple script is:

    print "Enter a list, one element on each line (Ctrl-Z to end):\n";
    @newlist = <STDIN>;
    @newlist = reverse( @newlist );
    print "The list in reverse order is: \n @newlist";

Running the script twice produces the following results:

    C:\My Documents\Learning Perl on Win32 Systems>perl ex3-1.plx
    Enter a list, one element on each line (Ctrl-Z to end):
    AAA
    BBB
    CCC
    The list in reverse order is:
     CCC
     BBB
     AAA

    C:\My Documents\Learning Perl on Win32 Systems>perl ex3-1.plx
    Enter a list, one element on each line (Ctrl-Z to end):
    AAA
    BBB
    CCC
     CCC
     BBB
     AAA

    C:\My Documents\Learning Perl on Win32 Systems>

As you can see, the script executes fine the first time, but fails to
execute line 4 properly the second time.

Any insight would be appreciated.





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

Date: Fri, 18 Sep 1998 08:32:42 -0500
From: Mary E Tyler <dejah@DejahsPrivateIce.com>
Subject: Re: Perl implementation question
Message-Id: <360260F7.3834@DejahsPrivateIce.com>

empower.eng wrote:
> 
> Hi,
> I have my code that's kind of implemented and worked, but I know there is a
> better way,
> can some Perl expert give me some idea.
> 
> What I have now is
> ($H1, $H2, $D1, $D2, $D3) = split(/:/);
> and it works fine.
> 
> But the list on the left side is in multiple places and I know they will be
> changed, more or less.
> What I like to be able to do is (not correct Perl syntax).
> $Header = ($H1, $H2);
> $Data = ($D1, $D2, $D3);
> Then
> ($Header, $Data) = split(/:/);
> And better yet able to use $Header and $Data to print.
> 
> I tried a number quoting methods and none seems to work for me. Any idea and
> help is greatly appriciated.
> 
> --Van

you had a minor syntax error.

@Header = ($H1, $H2);
@Data = ($D1, $D2, $D3);
(@Header, @Data) = split(/:/);

first, in assigning a list to a scalar, you have just assigned the count
of the items in the list, so no, what you wrote does not do what you
want. however, if you assign to a list (ie an array, not a scalar) and
recall that comma operator does in a list context then it will work.

dejah

-- 
i trust i make myself obscure, i have need of obscurity now- robert bolt

a heated exchange of unread mail would be welcomed by all- christensen

Skating Fiction. Featuring the  highly acclaimed serial On The Edge!
http://www.DejahsPrivateIce.com


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

Date: Fri, 18 Sep 1998 08:00:42 -0500
From: Dave Barnett <barnett@houston.Geco-Prakla.slb.com>
Subject: Re: Perl one-liners
Message-Id: <3602597A.E2FBA6D2@houston.Geco-Prakla.slb.com>

Aamir Sehbai wrote:
> 
> Is there a collection of Perl one-liners somewhere on the Web?
Search deja-news for posts by Abigail.  She has a one-liner at the
bottom of her posts.  They're often different from one post to the next,
so ....

That should give you a good start.

Cheers,
Dave

-- 
Dave Barnett	Software Support Engineer	(281) 596-1434


Indecision is the key to flexibility.


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

Date: 18 Sep 1998 09:18:20 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Perl one-liners
Message-Id: <6ttmis$ims$1@monet.op.net>


In article <Pine.OSF.3.96.980918023938.30301A-100000@osf1.gmu.edu>,
Aamir Sehbai  <asehbai@osf1.gmu.edu> wrote:
>Is there a collection of Perl one-liners somewhere on the Web?

I have a collection at <URL:http://www.plover.com/~mjd/perl/LOD/>.

But many of them are one-liners that you would not actually want to use.

  $line =~ s/${\ quotemeta '$a'}/b/;
  if (defined $eq ? $eq->($a->[-$i], $b->[-$j]) : $a->[-$i] eq $b->[-$j]) {
  @header_lines  = split /^(?!\s)/m, $HEADER;
  sub untaint {(keys%{{$_[0],0}})[0]}  # `The Dunwich Horror'
  $top *= $top > 0; 
  my @s = (&senders(), &forwarders(), @H{'Reply-to'}); 
  join $;,@_; 
  my (@q, $i) = @_; # This line is solemnly dedicated to \mjd. 
  @tokens = split(/([\(\[\{<>\}\]\)\s])/, $input); 
  sprintf(split(/$;/o, shift()); 
  $suffix++ while $userdb->get_data("$u$suffix"); 
  length($_[0] = $out); 
  @tokens = split(/(:=|\*\*|[-()+*\/;]|[A-Za-z_]\w*|(?:\d+(?:\.\d+)?))/,
  $str); 
  local $" = ')('; 
  @ftype = split /[. ]+/, '. p c ? d ? b ? - ? l ? s ? ? ?'; 
  unless (x = new(ELEMENT)) die("Out of memory"); 
  <<EOM; 
  $setuid = $setuid * 2 + ($perm =~ s/([st])$/($1 eq lc $1)?'x':'-'/ie); 
  @ADDRS = (@{+shift}, @EXTRA_ADDRS); 
  [map {[$first,@$_],['',@$_]} @$pow]; 
  my $pow2 = [map {[@$_]} @$pow]; 
  while ... die ... next .. chomp ... last 
  $revmemotable{$wrapper} = "$cref"; # Ha ha, Tom. 
  my @c = ("\0" x (3*$X)) x $Y; 



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

Date: Fri, 18 Sep 1998 08:35:18 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: print statement. Please help
Message-Id: <6ttk26$slo$1@earth.superlink.net>

Hello -

nguyen.van@imvi.bls.com writes:

>Hi guys,

>I have this problem. The following is my code:

>----------------------------------------------------

>($day, $month, $year) = (localtime)[3,4,5];
>$current_date = printf ("%04d%02d%02d", $year+1900, $month+1, $day);
>chop ($current_date);
>printf "$current_date\n";

>up to this point, it's alright but have problem with the folowing:

No it isn't - see below.

>I want to concatenate strings together

>$out_put =  $current_date . ".browser.html";
>print $out_put, "\n";

>however, this doesn't work for me any idea?


You're misusing printf.  Your second line ($current_date = ...) causes
the date to be *printed* in the format you want, and the return value
assigned to $current_date.  At that point, the date is on your screen,
and the value of $current_date is 1 (assuming the call to printf worked).

Then you chop $current_date.  $current_date is now empty.  The statement
"printf "$current_date\n";  outputs "\n".  You *think* it's printing the
date, but that's because you printf'ed the date already.  (Interesting
example of something working (or appearing to work) by coincidence.)

Then, you concatenate $current_date - an empty string - with ".browser.html".
The result, not surprisingly, is ".browser.html", and that's what gets
printed.  

Here's a modified version that works.  Note that it uses sprintf, not
printf.

my ($day, $month, $year) = (localtime)[3,4,5];
my $out_put = sprintf("%04d%02d%02d.browser.html", $year+1900, $month+1, $day);


and another, shorter one:

use Date::Manip;
my $out_put = UnixDate("today", "%Y%m%d.browser.html");


and DateCalc would also allow for doing something along these lines, perhaps
less concisely but faster.


David Black
dblack@saturn.superlink.net


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

Date: Fri, 18 Sep 1998 07:23:16 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: print statement. Please help
Message-Id: <kbjtt6.p9d.ln@metronet.com>

nguyen.van@imvi.bls.com wrote:

: I have this problem. 


   Yes.

   Your code is missing a single character (an 's')...


: The following is my code:

: ----------------------------------------------------

: ($day, $month, $year) = (localtime)[3,4,5];
: $current_date = printf ("%04d%02d%02d", $year+1900, $month+1, $day);
                  ^^^^^^

   This printf() call writes (without a newline) to STDOUT and returns 1.

   The 1 is the value that $current_date gets.


: chop ($current_date);


   This is the clue that should have given away the problem.

   Why do you need to remove the last character here?

   You are deleting the '1', leaving $current_date as the empty string.
   
: printf "$current_date\n";


   Then you print an empty string and a newline.


: up to this point, it's alright 


   As you can now see, we are already past where the problem is.
   


: however, this doesn't work for me 
                ^^^^^^^^^^^^

   Useless.

   Not helpful to those that are trying to help you.

   Say what you expected and what you are getting instead.


: any idea?


   Use sprintf() instead of printf().



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


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

Date: Fri, 18 Sep 1998 08:37:06 -0400
From: Ian Lowe <Ian_Lowe@fanniemae.com>
Subject: Process checking
Message-Id: <360253F2.EE680FB9@fanniemae.com>

I am fairly new to Perl, and am trying my hand at it by writing a
program which will report the health of a daemon.  My problem is with
the test for daemon health.  I am using the grep function, but its use
seems to preclude the use of ( $? eq 1 ) as a test, since according to
the Camel book, $? only returns status on backticks, system(), or closed
pipes (but not functions).  How then could I test for truth?

Please see the code below:

#!/export/Tivoli/efmperl/bin/perl

$LOG = "/tmp/server_status";


@st = qw(syslogd cron sendmail);
@ps = `ps -eo comm`;

open(LOG,">$LOG") || die "Can't create /tmp/server_status\n";
print LOG `date`;


foreach $proc (@st) {
    print LOG "Checking process $proc:\t";
    @greplist = grep { /$proc/ } @ps;
        if ( $? eq 1 ) {
            print LOG "OK\n"; }
        else {
            print LOG "Error\n"; }
}


Thanks,

Ian


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

Date: Fri, 18 Sep 1998 13:02:50 GMT
From: Garry Williams <garry@america.net>
Subject: Re: Q:Non-blocking system read - how to cancel block but not program?
Message-Id: <36025A38.7637679D@america.net>

I think you need to do the sysread in an eval block and discover the
time out in $@.  (See _Programming Perl_, Wall, etal., Second Edition,
O'Reilly, p. 341.): 

	eval {
	    local $SIG{ALRM} = sub { die "timeout occurred"; };
	    alarm($timeout);
	    die "$!" unless sysread(SOCK, $buffer, 400));
	    alarm(0);
	};
	alarm(0);		# in case sysread failed (race condition?)
	if ( $@ =~ /timeout occurred/ ) {
	    print "sysread: time out, $timeout seconds\n";
	} elsif ( $@ ) {
	    print "sysread: $@\n";
	}

Your problem seems to be automatically restarting system calls.  You
*could* deal with that directly by climbing into POSIX::sigaction, but
that's a lot of complication for such a simple need to just time out
long-running system calls.  

-Garry Williams

Cosmas Lang wrote:
> 
> I've got the following problem (perl5.004):
> My perl program tests several tcp servers in well defined time
> intervalls by sending a request and then reading some bytes from them.
> Now in some rare cases the select returns, but the sysread blocks, so I
> have to cancel the read.
> But
> 
>           READ: {
>               local $SIG{'ALRM'} = sub { $timed_out = 1; };
>               alarm $timeout;          # prevent blocking of sysread()
> 
>               if ($req_length > 0 && !$timed_out) {
>                   syswrite (SOCK, $request, $req_length);      # send request
>               }
>               sysread  (SOCK, $buffer, 400) unless $timed_out; # read answer
>           } # End READ
>             $time_left = alarm(0);
> 
> doesn't solve the problem, because the sub returns right back into the
> sysread.
> Either does a
>   sub { last READ; }
> because it's not possible to jump from one subroutine to a label in
> another one.
> I think in perl5.003 that was allowed, even with a 'goto', but I want to
> have it run in 5.004 now.
> 
> Any suggestions how I can tell perl to cancel the sysread WITHOUT having
> to put it in a fork and kill that?
> ---------
> Cosmas Lang  (Cosmas.Lang@Uni-Mainz.DE)


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

Date: Fri, 18 Sep 1998 13:13:56 +0100
From: Julian Gilbey <J.D.Gilbey@qmw.ac.uk>
Subject: Re: regular expression puzzle
Message-Id: <36024E84.43BDABB@qmw.ac.uk>

Ralph Brands wrote:
> 
> I have a text file in which some characters are coded by bounding them
> with "&" and ";" so that:
> 
> &ae;
> &d;
> &t;         are all characters
> 
> w&ae;nt
> &ae;llum    are both words
> 
> If I want to search for strings that contain both of two regular
> expressions as separate words I do the substitution below. But this
> matches string1 only if there is more than 1 space between "&ae;nt" and
> "dog"! Any suggestions as to how I can change the regular expression
> substitution to get around this would be gratefully appreciated,
> 
> Ralph Brands
> 
> #!/usr/bin/perl
> 
> $firstregexp = "&ae;nt";
> $secondregexp = "dog";
> 
> $string1 = "a string with &ae;nt dog and other words";
> $string2 = "a string with &ae;nt and dog";
> 
> #to match separate words only if new word boundary condition is met:
> 
> $firstregexp =~ s/$firstregexp/(^|[^a-z&;])$firstregexp([^a-z&;]|\$)/gi;
> $secondregexp =~ s/$secondregexp/(^|[^a-z&;])$secondregexp([^a-z&;]|\$)/gi;

Excuse me, but are you REALLY trying to substitute "&ae;nt" with
"(^|[^a-z&;])$firstregexp([^a-z&;]|\$)"??  I think what you want is more
like:

   if ($string1 =~ /(^|[^\w&;])$firstregexp([^\w&;]|\$)/ and
         $string1 =~ /(^|[^\w&;])$secondregexp([^\w&;]|\$)/) { ... };

that is, match, not substitution.

   Julian

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

            Julian Gilbey             Email: J.D.Gilbey@qmw.ac.uk
       Dept of Mathematical Sciences, Queen Mary & Westfield College,
                  Mile End Road, London E1 4NS, ENGLAND
      -*- Finger jdg@goedel.maths.qmw.ac.uk for my PGP public key. -*-


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

Date: Fri, 18 Sep 1998 09:11:42 EDT
From: dblack@saturn.superlink.net (David A. Black)
Subject: Re: Regular Expressions for Reading Data
Message-Id: <6ttm6e$4ao$1@earth.superlink.net>

jzobel@my-dejanews.com writes:

>Hi.

>I would like to use something like for example

>/(?:(?:(\d*);)*\n)/go

>to read data like

>33;44;55;23524538;
>2;
>33;64576;2353425234;

>Unfortunately $1 is a bit 'small'. It only reads 2353425234. It should better
>be a reference to an array of references to arrays:

>$1 = [[33,44,55,23524538],[2], [33,64576,2353425234]]

>With this, regular expressions would be a perfect tool for reading all kinds
>of especially weird data formats.

But they would cease to be an excellent tool for doing what they now do
very well.

>Is there a patch or extension for the regex machine which gives me that?

I hope not.  Why remove from Perl the extremely important functionality of those
variables, to achieve something you can achieve anyway?

What you want is something like:

my @parsed = map { [ grep /\w/, split ';' ] } <DATA>;


David Black
dblack@saturn.superlink.net


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

Date: Fri, 18 Sep 1998 13:20:51 GMT
From: jzobel@my-dejanews.com
Subject: Re: Regular Expressions for Reading Data
Message-Id: <6ttmni$l45$1@nnrp1.dejanews.com>

In article <874su57q0p.fsf@smart.ruhr.de>,
  Thomas Neumann <tom@smart.ruhr.de> wrote:
> jzobel@my-dejanews.com writes:
> > I would like to use something like for example
> >
> > /(?:(?:(\d*);)*\n)/go
> >
> > to read data like
> >
> > 33;44;55;23524538;
> > 2;
> > 33;64576;2353425234;
> >
> > Unfortunately $1 is a bit 'small'. It only reads 2353425234. It should
better
> > be a reference to an array of references to arrays:
> >
> > $1 = [[33,44,55,23524538],[2], [33,64576,2353425234]]
>
> Probably not, but what about
>
> my $rows = [ map { chomp; [ split /;/ ] } <> ];
>
> # To test it out...
> for (@$rows) {
>   for (@$_) { print "$_ " }
>   print "\n";
> }

This does of course work. But what I would like to have is a general tool that
can read about everything given a description of the data format as a regular
expression.

> Should be faster, too.

Don't care.


Joachim

Also this posting has a valid from header email replies to user@kud.com where
user = jzobel are prefered.


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


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

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


Administrivia:

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

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


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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

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

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

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

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

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


------------------------------
End of Perl-Users Digest V8 Issue 3749
**************************************

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