[7110] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 735 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 15 09:17:11 1997

Date: Tue, 15 Jul 97 06:00:43 -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           Tue, 15 Jul 1997     Volume: 8 Number: 735

Today's topics:
     Re: $$$ LOAN BUSINESS, EASY MONTHLY INCOME, NO BRAINER  <keys@babylon5fan.corn.on.the.cob>
     Re: A few questions about invoking a perl script. (Matthew Burnham)
     Re: CPAN help (Danny Aldham)
     Re: Extracting fields from data question (Even Holen)
     Re: hash ref from list (Even Holen)
     Re: How to obtain expand of contain of variable? <rootbeer@teleport.com>
     Re: Implmenting flock <rootbeer@teleport.com>
     Re: Learning Perl book (David Faciane)
     Re: LoL dynamic generation in Perl 4 R36 <rootbeer@teleport.com>
     Re: mooshing files, 2 > 1 <me@anon.com>
     Once more... Q: Parallel port & Delphi... (Ammar Aganovic)
     Re: online tutorial <merlyn@stonehenge.com>
     Oraperl bind_param problem (Thomas Tien)
     Perl 5 debug <eshraghf@syntegra.bt.co.uk>
     Re: Perl Traceroute <rootbeer@teleport.com>
     Re: Q: object serialization standard in perl (M.J.T. Guy)
     Re: recursion <ajohnson@gpu.srv.ualberta.ca>
     Re: recursion <malunjkars@aol.com>
     Re: regexp- capturing matched pattern with an alternati (Chris Schleicher)
     Re: Sorting By Date (Andrew M. Langmead)
     sub prototypes in 5.003 and 5.004 (Gabor)
     Subroutines in different files <clark@s3i.com>
     Re: Text file cutoff (Eric Bohlman)
     use OR require (suite) <dantin@icp.grenet.fr>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Mon, 14 Jul 1997 20:15:14 -0600
From: Keys <keys@babylon5fan.corn.on.the.cob>
Subject: Re: $$$ LOAN BUSINESS, EASY MONTHLY INCOME, NO BRAINER $$
Message-Id: <33CADD32.74FD2584@babylon5fan.corn.on.the.cob>

a5@a.a wrote:
> 
> I have participated in the standard "Please put me on your mailing list" letter and found it to be worth
> my time (I get 1 or 2 handfulls or letters every day) but I also found that it's results were nowhere


What makes you think anyone in comp.lang.perl.misc actually cares?  Most
of us are here to discuss Perl programming...


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

Date: Mon, 14 Jul 1997 21:23:42 GMT
From: danew@enterprise.net (Matthew Burnham)
Subject: Re: A few questions about invoking a perl script.
Message-Id: <33c9f5b4.1045778@194.72.192.4>


sean hynes <sehynes@cise.ufl.edu> wrote:

>1.  Is there a way cause a PERL script to be invoked when an html link
>is selected / or when a page is opened, other than SSI's?
Only if you get the perl script to load the actual page and pass it back
to the browser.

>2.  I have a page with multiple frames.  Is there a way to have a CGI
>PERL link in one frame, that produces HTML output in another frame on
>the same page?
Not without making the CGI script make a new index.html page that calls
itself or another script again.

This should be in comp.infosystems.www.authoring.cgi really.

-- 
Matthew Burnham, Manager, MindWeb | danew@enterprise.net
Commercial web design and hosting, reasonable rates
UKP24/Mb/Year for DIY space | mindweb@pobox.co.uk
FTP, CGI, password protection, etc. too!
http://www.mindweb.co.uk/


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

Date: 11 Jul 1997 23:35:57 -0700
From: danny@lennon.postino.com (Danny Aldham)
Subject: Re: CPAN help
Message-Id: <5q78kd$5h3$1@lennon.postino.com>

Will Linden (wlinden@panix.com) wrote:
:     Is there something else I am doing wrong? Or are non-superusers unable
: to use the modules?

Most of the modules are only perl code themselves. The few modules that
require linking into the perl binary probably require root. Unless you
build your own binary on a machine where you have root, and move it over.
But for most of the modules, you just need to let perl know where they are.
On a machine where I don't have root, I created a bin directory in my 
home directory, run perl out of it, and I put all the modules in directories
under it. The -I/m/usr0/usr0/a/aldham/bin tells perl to look in this
directory for the modules. So the first line in my scripts reads: 
 
#!/m/usr0/usr0/a/aldham/bin/perl -wI/m/usr0/usr0/a/aldham/bin

--
Danny         SCO Ace , MCSE , JAPH , DAD
I don't need to hide my e-mail address, I broke my sendmail.


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

Date: 14 Jul 1997 14:32:38 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: Extracting fields from data question
Message-Id: <slrn5ske1h.s0i.evenh@ra.pvv.ntnu.no>

In article <33c7a0e7.3144601@news.interport.net>, Hugh Appet wrote:
>I have a script which accesses a flat file, comma delimited database
>of addresses. The data is as follows:
>storename,address,city,state,zip,phone

I assume that you splits this before proceeding. Something like

 ($storename, $address, $city, $state, $zip, $phone) = split (',');

>I thought of putting other delimiters inside the field ,
>Los Angeles:West Hollywood. But I still can't figure out how to get
>the whole portion that matches. Any help would be appreciated.

I guess it would be easiest to do so if using delimiters. One solution
then is something along the lines of:

#!/usr/bin/perl

$city = "Los Angeles:West Hollywood";
$match = "Hollywood";

foreach (split(':',$city)) {
  if(/$match/) {
    print "New city is: $_\n";
  }
}

And then simply rebuild the whole line if wanted...


Hope this helps.

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: 14 Jul 1997 15:17:49 GMT
From: evenh@ra.pvv.ntnu.no (Even Holen)
Subject: Re: hash ref from list
Message-Id: <slrn5skgm7.s0i.evenh@ra.pvv.ntnu.no>

In article <33C6B758.3C9E@ti.com>, Chris Mason wrote:
>	I know I'm exceeding my question quota here, but this is ticking me
>off.  I'm writing a function which takes a colon seperated list and
>turns it into a hash reference.  I have a global hash of hashes
>(%HASHES) under which all of the data lives.  For example,

I don't think there exist a question quota... There only exists stupid
or worse questions which don't deserve answers... Your question doesn't
qualify this time... :)

Although I don't quite see the use of it... :) But that's your
problem...

>makehashref("ahash:somehash:anotherhash:akey");
>
>would return a reference to 
>$HASHES{'ahash'}{'data'}{'somehash'}{'anotherhash'}{'akey'}

If this is what you want returned then why don't you build this using
eval and a substring?

Try something like:

#!/usr/bin/perl

$HASHES{ahash}{somehash}{anotherhash}{akey} = 'Coool';

$ref = makehashref("ahash:somehash:anotherhash:akey");
print "Reference : $ref. And dereferenced: $$ref\n";

$ref2 = makehashrefUgly("ahash:somehash:anotherhash:akey");
print "Uglyreference : $ref2. And uglydereferenced: $$ref2\n";

#
# A sub building a hash reference from a :-separated field
#
sub makehashref {
  my($name) = @_;
  my ($refString);
 
  $refString = '\$HASHES';
  foreach(split(/:/, $name)) {
    $refString .= "{$_}";
  }
  #print "Reference: $refString\n";
  return eval $refString;
}

#
# And as a one-liner... Ugly, but functional... :)
#  Please don't ask for explanation of the following :-D
#
sub makehashrefUgly {
  return eval "\\\$HASHES{'".join("'}{'",split(/:/,shift))."'}";
}


>Any ideas?  Suggestions?  Style comments?

Now you got ideas and suggestions. And a bad style example... :)

Hope this helps. If you do want to test the reference before returning
then do so... :-)

Regards,
Even Holen
-- 
<><   Even Holen, evenh@pvv.ntnu.no, http://www.pvv.ntnu.no/~evenh/   :-)


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

Date: Mon, 14 Jul 1997 20:41:09 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: web_user <torche@linkvest.ch>
Subject: Re: How to obtain expand of contain of variable?
Message-Id: <Pine.GSO.3.96.970714203848.22574H-100000@kelly.teleport.com>

On 14 Jul 1997, web_user wrote:

> Newsgroups: comp.lang.perl, de.comp.lang.perl

If your news administrator still carries comp.lang.perl, please encourage
him or her to check out the frequent posting about bogus newsgroup names
in news.announce.newgroups. You'll be doing yourself and many others a
favor to use comp.lang.perl.misc (and other valid Perl newsgroups) 
instead. 

    news:news.announce.newgroups

> I want expand $command_with_param after than the contain has been set. 

Do you mean that you have a variable which contains a string, and within
that string you want to replace '$foo' with the current value of $foo?

    $string =~ s/\$foo/$foo/g;		# Maybe this?

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Mon, 14 Jul 1997 18:05:03 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Joseph Davidson <jhd@Radix.Net>
Subject: Re: Implmenting flock
Message-Id: <Pine.GSO.3.96.970714180316.7499E-100000@kelly.teleport.com>


On 14 Jul 1997, Joseph Davidson wrote:

> I have Perl 5.000 on SunOS 5.4 Generic_101945-13.  It does not support the 
> flock function.  Do I need a later version of Perl, a re-build or what to 
> support flock?

If you're using 5.000, you should install 5.004. That will solve your
flock problem, as well as many other shortcomings of 5.000. Literally
hundreds of bugs have been fixed since that version came out. Hope this
helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 15 Jul 1997 01:18:05 -0400
From: dave@nws.fsu.edu (David Faciane)
Subject: Re: Learning Perl book
Message-Id: <5qf16d$7vm@kate.nws.fsu.edu>

[Posted and mailed]

In article <5qdrg3$pq5@prometheus.acsu.buffalo.edu>,
Kevin D Ruggiero <kdr@cs.buffalo.edu> wrote:
>
>has anybody checked out the new Learning Perl, Second Edition by O'Reilly
>yet?  I think it just came out this month (July), and I was wondering if
>it was any good.  I'd like to learn the basics of Perl as quickly as
>possible, and I heard the first one edition of this book was pretty good.
>


I'm sure it is just a revision of the First Edition, which was excellent.
(my opinion, of course) :-) 

If you're just starting with Perl and don't have a lot of prior experience with
C, /bin/sh, awk, sed, et al.,  (which will shorten the Perl Onramp greatly)
then this is THE book to get. If you don't require a lot of hand-holding 
then jump right in with Programming Perl (aka, The Turquoise Camel). Either 
way you can't go wrong. :-)







-- 
David Faciane                 |web: http://www.nws.fsu.edu/~dave	 
NOAA National Weather Service |Real-Time Worldwide Marine Weather Reports 
Tallahassee, FL               |  http://www.nws.fsu.edu/buoy	 
Sender of unsolicited email agrees to pay $500 for my proofreading services. 


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

Date: Mon, 14 Jul 1997 09:10:13 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Greg Marton <gremio@Glue.umd.edu>
Subject: Re: LoL dynamic generation in Perl 4 R36
Message-Id: <Pine.GSO.3.96.970714085037.19902J-100000@kelly.teleport.com>

On Sun, 13 Jul 1997, Greg Marton wrote:

> | This is perl, version 4.0

> and am at the mercy of my sysadmins in this respect so I don't think an
> upgrade to 5 will come as quickly as I need it, 

I don't know about that. As I see it, you have several options. 

  * You could install the new version yourself, without being root.

  * You could get a job as a sysadmin and install Perl as root.

  * You could bribe your sysadmins to do what you need (a pizza
    party with free beer has been reported to be successful).

  * You could find an employer who doesn't subject you to such
    frustrations, since life is too short to be stuck in a
    Dilbert comic strip. :-)

> I'm trying to generate a List of Lists on the fly.  I'm used to this
> being rather simple, as in:
>          while (<>) {
>              @tmp = split;
>              push @LoL, [ @tmp ];
>          }
> My Perl, though, doesn't like this.  

Nope; no references in Perl4. :-(

> as the motto of the language is TMTOWTDI, I'm looking for one that'll
> work with my version of Perl. 

The usual way in those days was to use soft references, although you could
do something like this.

    while (<>) {
	@tmp = split;
	push @LoL, join("\0", @tmp);
    }

Not so convenient, is it? Oh, well. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Mon, 14 Jul 1997 23:03:12 -0700
From: Chris Hostetter <me@anon.com>
Subject: Re: mooshing files, 2 > 1
Message-Id: <33CB12A0.77F2AB21@anon.com>


John Bergmayer wrote:

> what would be my best bet for doing this?

without taking the time to write, debug, and sell you source code
directly  i would recomend something along the lines of...

"open" bar to a "FILEHANDLE"
"while" the FILEHANDLE (getting one line at a time)
	"split" each line by whitespace
	make a "hash" keyed by the partnum, and valued with the price
"close" the FILEHANDLE

open foo to another FILEHANDLE
while the FILEHANDLE
	"split" each line by whitespace
	look up the partnumber in the hash...
	"if" it "exists", 
		"*" it with the quantity
		print the line the way you want it
	"else"
		print the line with N/A
close the FILEHANDLE

(you should be able to find all of the "quoted" words in the Camel
book... or by greping the man pages.  If you run into any problems
getting acctual code to work, feel free to post more questions, or email
me directly: i don't mind)

	-good luck

---

------------------------ The Hoss Man ---  "c4"
-------------------- Chris M Hostetter --      --Deep Blue
---------- hossman@uclink3.berkeley.edu -  "Resign!"
http://www.rescomp.berkeley.edu/~hossman/      --Gary Kasparov


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

Date: Tue, 15 Jul 1997 12:04:30 GMT
From: aganovic@bigfoot.com (Ammar Aganovic)
Subject: Once more... Q: Parallel port & Delphi...
Message-Id: <33cb648f.1019035@news.tu-graz.ac.at>

Since I am not very comfortable with Delphi, the
links I found in this newsgroup were no good for
me.

What I am looking for is a simple DPR that will
demonstrate me HOW to control the parallel port
outs. So if you have some stupid & simple dpr (I
guess dpr is all I need - or might there be dlls?)
on your hard disk, please mail it to me.
Thanx in advance,
Ammar

(WIN95 & Delphi 2.0)

--
bass   @   sbox.tu-graz.ac.at


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

Date: 14 Jul 1997 04:58:37 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: danew@enterprise.net (Matthew Burnham)
Subject: Re: online tutorial
Message-Id: <8cwwmtn8uq.fsf@gadget.cscaper.com>

>>>>> "Matthew" == Matthew Burnham <danew@enterprise.net> writes:

Matthew> print '#' . join("\n#", @lines); is one of many ways.

Although I would find:

	print map "#$_", @lines;

much easier to comprehend, and nicer when you want to change "#" to
something else.

map is your friend.  Use map.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 414 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: 14 Jul 1997 22:50:58 GMT
From: tien@beast.Trenton.EDU (Thomas Tien)
Subject: Oraperl bind_param problem
Message-Id: <5qeagi$7gc@simba>


	I apologize if this is slightly off-topic (it was either here or 
comp.lang.perl.modules).  The problem I am having is with trying to insert 
LONG RAW data into an Oracle database using Oraperl and/or DBI.  
	Basically, my codes seem correct (to myself, anyway :) ), but
on the bind_param line... 

    $csr->bind_param(1, $res, \%attrib)|| die("Bind : $ora_errstr");
    
	it keeps on crashing with a segmentation fault.  I suspect the
script as is may not read in the whole file without truncation either, but I
have yet to even get that far.  

	The system is a Sparc5 (SVR4) with 5.002.  Any help or pointers
would be greatly appreciated (and sorry the code listing is going to be kind
of long)...


-----begin of code----- 
#!/usr/local/bin/perl

use Oraperl;
use DBI;

        $SIG{__WARN__} = sub { warn $_[0] unless $_[0] =~ /^Bad free/ };
        $lda = &ora_login('database', 'uid', 'password');

        $filename = "a.out";    #some dummy binary file foobar'ed for testing
        $fileid = 5;            #foobar value hard-coded for testing

# Read in contents of binary file and set filesize to $res
        open(BIN_DWG, $filename);
        read(BIN_DWG, $res, -s $filename);
        close(BIN_DWG);
        $filesize = length($res);
        print ("Successfully read: $filesize bytes\n");        

        $lda->debug(3);  

        $csr = $lda->prepare ("insert into binary_drawings (id, drawing) 
values ($fileid, :1)") || die("Insert : $ora_errstr");
        my(%attrib);
        $attrib{'ora_type'} = 24;       # LONG RAW
        $csr->bind_param(1, $res, \%attrib)|| die("Bind : $ora_errstr");
	#^^^that is line 29 ^^^
        $csr->execute() ||  die "Execute: $ora_errstr";
        print("Filesize: $filesize      $truncated: $ora_trunc");

        &ora_logoff($lda);               

----- end of code -----

	And the resulting output:

----- begin error messages -----
>Successfully read: 74764 bytes
    DBI::db=HASH(0x196e00) debug level set to 3
    -> prepare for DBD::Oracle::db (DBI::db=HASH(0x154d1c)~0x196e00 'insert 
into binary_drawings (id, drawing) values (5, :1)')
    <- prepare= DBI::st=HASH(0x196ddc)
    -> bind_param for DBD::Oracle::st (DBI::st=HASH(0x196ddc)~0x196ecc 1 '.ELF..
 .....................8...4.........4. ...(...........4...4......................
 ................................................................................
 .\.................................. HASH(0x154ee4))
Caught a SIGSEGV at readbin.pl line 29
Abort (core dumped)                    
----- end error messages -----

	Table definition:

----- begin table def -----
 Name                            Null?    Type
 ------------------------------- -------- ----
 ID                              NOT NULL NUMBER
 DRAWING                                  LONG RAW      
----- end table defs -----


Thomas Tien				Jr. System Administrator/Programmer
tien@beast.tcnj.edu			Applied Information Services
http://www.tcnj.edu/~tien/		http://www.appliedinfo.com/


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

Date: Tue, 15 Jul 1997 13:12:25 -0700
From: Farshad Eshraghi <eshraghf@syntegra.bt.co.uk>
Subject: Perl 5 debug
Message-Id: <33CBD9A9.245@syntegra.bt.co.uk>

Hi everyone,

I have installed Perl 5.003 on HP/UX env.

I want to debug by doing perl -d but it complains about not finding
perldb.pl

I have the perl5db.pl but no perldb.pl on the distribution.

I can't debug at the moment!

I have used -I in command line to include the lib directory since the
use lib command gives a syntax error

Cheers,

Farshad


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

Date: Mon, 14 Jul 1997 09:24:00 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Kirk Spessard <spessard@dfw.paranet.com>
Subject: Re: Perl Traceroute
Message-Id: <Pine.GSO.3.96.970714092049.19902L-100000@kelly.teleport.com>

On Fri, 11 Jul 1997, Kirk Spessard wrote:

> Does anyone know how you would implement a traceoute utility in Perl?

One way would be to get the source for somebody else's traceroute utility,
and do what it does. Another way is to use code something like this.

    system("/usr/local/bin/traceroute", $some_site);	# :-)

Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 14 Jul 1997 17:17:26 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Q: object serialization standard in perl
Message-Id: <5qdmv6$kk4@lyra.csx.cam.ac.uk>

Jason Moore  <jmoore@sober.com> wrote:
>hi,
>
>I'm wondering if there is a standard way to write perl objects to a
>file.  (aka pickling, serialization, freezing)  I've seen various
>modules that do this, but I always prefer to go with a standard --
>particularly one that works on NT and unix.  The closest thing I've
>found is CGI.pm's client-state methods, but I don't think this is the
>most efficient or elegant solution.

Data::Dumper from CPAN may be what you want.


Mike Guy


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

Date: Sat, 12 Jul 1997 01:35:38 -0500
From: Andrew Johnson <ajohnson@gpu.srv.ualberta.ca>
Subject: Re: recursion
Message-Id: <33C725BA.323D736F@gpu.srv.ualberta.ca>

Bob Lockie wrote:
> 
> I can't seem to do recursion in Perl.
> 
> I need to call a subroutine recursively but it doesn't seem
> to work.
> 
> Can someone help?

in what way doesn't it seem to work? no output? 
unexpected output? error messages?...
post some code which illustrates your problem
and someone here may be able to assist you...

in the meantime, here's a version of the age old
recursive factorial function: (though a simple loop
version would be better):

sub fact {
   my $n=shift;
   return $n if $n==1;
   return $n*&fact(--$n);
}

regards
andrew


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

Date: Fri, 11 Jul 1997 23:50:09 -0700
From: Sanjay Malunjkar <malunjkars@aol.com>
To: Bob Lockie <bjlockie@nortel.ca>
Subject: Re: recursion
Message-Id: <33C72921.14569214@aol.com>

Bob Lockie wrote:

> I can't seem to do recursion in Perl.
>
> I need to call a subroutine recursively but it doesn't seem
> to work.
>
> Can someone help?
>
> Thanks.

 If I get your question right, then here goes one example of recursion
in perl:

#Calcu;ate the factorial.
sub fact($)
{
  my $n=shift;

  return $n*fact($n-1) if ($n-1);
  return 1;
}

$ans=fact(10);
print "fact(5)=$ans\n";



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

Date: 14 Jul 1997 12:07:46 -0700
From: chrissch@cs.uoregon.edu (Chris Schleicher)
Subject: Re: regexp- capturing matched pattern with an alternation character
Message-Id: <5qdte2$e4e@psychotix.cs.uoregon.edu>
Keywords: regexp pattern_match, $1 $2 variables, alternation pattern

In article <5qas33$sj$1@news.dgsys.com>,
Dave Naden <dnaden@dgs.dgsys.com> wrote:
>   /[a-zA-Z0-9]{1,8}\.[a-zA-Z0-9]{1,3}/   # (regular 8.3 format)
>
>   /[a-zA-Z0-9]{1,8}(\.[a-zA-Z0-9]{1,3})?/  # (choice of 8 or 8.3 formats)
>
>
>The problem comes when I want to capture the filename with the $& or the $1, 
>$2 variables; the second pattern above only gives the easiest match (the 8 
>chars) and then stops before matching the 8.3 even if it's there.  But the 
>first pattern only matches 8.3 filenames, and misses those without a suffix.

Well, you want another set of parentheses in there, but aside from that
it looks good from me:

    [~] 6 % perl
    while (<DATA>) {
    	if (/([a-zA-Z0-9]{1,8})(\.[a-zA-Z0-9]{1,3})?/) {
             ^                ^

    	    print "Matched: '$1', '$2'\n";
    	}
    }
    __DATA__
    autoexec.bat
    autoexec
    Matched: 'autoexec', '.bat'
    Matched: 'autoexec', ''

This is Perl5.004_01 on Solaris 2.5.


Hope this helps,

--chris
-- 
     Chris Schleicher                      Office:  541/346-3998
     Univ of Oregon CIS GTF                email: chrissch@cs.uoregon.edu
                URL: http://www.cs.uoregon.edu/~chrissch/


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

Date: Tue, 15 Jul 1997 01:16:08 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Sorting By Date
Message-Id: <EDC66w.F1J@world.std.com>


Robert Luscombe <ralst37+@pitt.edu> writes:

>I am very new to Perl.  I have a file with colon delimited fields that I
>need
>to sort by date and time.  The first 6 fields contain time and date
>info.

>hour:minute:second:month:day-of-month:year: ... etc ...

[stuff deleted]
>I thought something like this would work with sort:

[stuff deleted]
>    $bdate = $year.$mon.$mday.$hour.$min.$sec;

>    return $adate <=> $bdate;
>}

>but I can't do this because of single-digit values.  

>I have just started learning Perl, as is obvious from the code above...
>can 
>anyone help?  I am also doing this on a Novell 4.11 machine, which
>doesn't
>seem to come with or support the standard Perl libraries and modules
>(does it?).

Maybe you could grab the libraries from the standard distribuition. Do
I remember correctly that the Novell Netware port was based on 4.036?
In that version is a library called timelocal.pl which takes a list
similar to that is returned from localtime and converts it back into
the number of seconds since Jan 1, 1970. If you convert your dates
into that format, then it will be a simple numeric comparison.


If you can't do that, then maybe you could use printf instead of print
and pad everything with zeros so that things fall in the same column.

You will wind up with much more efficient sorting if you extract your
data before the sort routine:

while(<>) {
    ($hour, $min, $sec, $mon, $mday, $year, $status, $first_name,
     $last_name, $email, $add_1, $add_2, $city, $state, $country, 
     $zip, $tel, $comments) = split(/:/,$_);
 
     push(@date, &timelocal($sec,$min,$hour,$mday,$mon,$year));
     push(@line, $_);
}

@sorted = @line[ sort by_date  0 .. $#line ];

sub by_date {
  $date[$a] <=> $date[$b];
}

For more details about this method of sorting, see either the FAQ, or
<URL:http://www.perl.com/CPAN/docs/FMTEYEWTK/sorting>
 
 
-- 
Andrew Langmead


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

Date: 14 Jul 1997 20:59:11 GMT
From: gabor@vinyl.quickweb.com (Gabor)
Subject: sub prototypes in 5.003 and 5.004
Message-Id: <5qe3v0$a21$1@flint.sentex.net>

I wrote a whole bunch of perl scripts using the protos from 5.003.

ie.

sub foo($$@);

blah;
 ...;

sub foo {
    blah;
    ...;
}

Now this worked in 5.003 but won't work in 5.004.

I now have to change my scripts to

sub foo($$@);

blah;
 ...;

sub foo($$@) {
    blah;
    ...;
}

Notice the subtle difference of having to have the proto in both the
declaration and the definition of sub foo.  Is this a bug in 5.004 or
was the behaviour a bug in 5.003?
BTW, I use 'use strict' in all my scripts, if that makes a difference.

--
Gabor Egressy : gabor@quickweb.com
    No, I am not going to explain it.  If you can't figure it out, you
    didn't want to know anyway...  -- Larry Wall, 1991


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

Date: 14 Jul 1997 16:46:24 -0400
From: Clark Dorman <clark@s3i.com>
Subject: Subroutines in different files
Message-Id: <du3hxnyzi.fsf@s3i.com>


Greetings,
	My program has gotten large enough that I want to split up the
source into different files (just about 1000 lines right now).  BTW,
the program is a "spawner" that starts long execution time jobs all
over our network, depending on the load that they have (and stops
them, and keeps track of how the runs are going, etc.).  I'm going to
present it for comment when I feel comfortable with it, and if people
are interested in it.  

	I was wondering what approaches that people have taken to do
dividing up their perl source into more manageable chunks of code.  I
am not at the "create packages, bless objects, etc." stage.  I just
want to have more screen-sized chunks of code to work with.  It would
seem to simple enough to do:

####Begin of foo.pl###########
#!/home/dorman/bin/perl -w

use myfactorial;

for (1..10) {
   $returnedval = &myfactorial( $_ );
   print " $_! = ($returnedval) \n";
}
###### End of foo.pl

and the subroutine is:

##### Begin of myfactorial.pm #######
#
# A subroutines that does factorial
#

sub myfactorial {
   my ( $base ) = shift;

   if ( $base == 1) {
      return 1;
   }
   else {
      return( $base * &myfactorial( $base - 1 ) ) ;
   }

}
1;
#### End of myfactorial.pm #######

But I was wondering if this is the standard way of doing this.  Any
suggestions?  Is there any need for things like Exporter?  And what
sorts of naming conventions for subroutines have people adopted? 

--
Clark


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

Date: Tue, 15 Jul 1997 01:11:41 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Text file cutoff
Message-Id: <ebohlmanEDC5zH.2rq@netcom.com>


Mike Felix (MIKEF@msmlab.byu.edu) wrote:

: The problem: when I try to add a person, I have the script read in lines
: from the old file and write them in the new file until the person's last
: name is less than (lt) the name read.  Then it writes the new person,
: then reads and writes all remaining people.  Then I copy the new file
: over the old file.  For some reason, it inserts the new person fine and
: continues reading the lines from the old file up until some place near
: the bottom of the file, which varies depending on the length of the
: person I inserted, and suddenly stops.  The new file isn't complete.
: Could there be some kind of memory leak?

: sub writenew {

:    $insert = 0;

:    while ($insert == 0) {
:       $line = <FILE1>;  
:       @data = split(/\s*\|\s*/, $line, $fields);
:       $names = @data[2] . @data[0];   #lastnamefirstname

Those @'s should be $'s.

:       if ($names gt $lastname) {
:           $insert = 1;
:           print FILE2 ($firstname. "|" . $middlename . "|" 
: 		. $lastname . "|" . $email . "\n");

:           print FILE2 ($line);

You're going to do this regardless of the outcome of the if statement, so 
move it outside the block.

:       }
:       if ($insert == 0) {
:            print FILE2 ($line);
:       }

Get rid of this if statement; see above.

:    }

:    while ($line = <FILE1>) {  #write remaining lines
:       print FILE2 ($line);

This is better written as 

     while (<FILE1>) {
       print FILE2;

since as you wrote it, it will prematurely terminate if it encounters a 
blank line.  If you really want to make an assignment, write it as

     while (defined($line=<FILE1>))

:    }

You haven't closed FILE2 at this point, which means that there's likely to
be data buffered up but not yet written to disk, so the last several lines
you wrote aren't going to get copied (instead, they're going to get
written to alumtemp.txt when your script terminates). This is probably
what's causing your problem. 

:    `copy alumni.log alumni.bak`;
:    `copy alumtemp.txt alumni.log`;

It would make more sense to use system() here, as you're not trying to 
get the standard output of the copy command.  Using system() will also 
let you check for error conditions.

: }

Right away, I see one serious problem with your algorithm; it can't cope
with the case where the new record has to go at the end of the existing
records.  In that case, it's going to endlessly loop trying to read empty
lines past the end of FILE1. 



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

Date: Tue, 15 Jul 1997 10:28:22 +0200
From: Joelle D'Antin & Nicolas Gregoire <dantin@icp.grenet.fr>
Subject: use OR require (suite)
Message-Id: <33CB34A6.7B0A@icp.grenet.fr>

I call my libarry with :
require '/users/dantin/perl/biblios/recherche_par_prenom.pl';

help me.


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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