[6887] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 512 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 21 20:06:28 1997

Date: Wed, 21 May 97 17:00:21 -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           Wed, 21 May 1997     Volume: 8 Number: 512

Today's topics:
     Re: Change or Delete a line in a FILE <tcyang@netcom.com>
     Re: Getting Week Number (Bjvrn Nilsson)
     Re: Help in Removing lines with duplicate Field Ones (Martin Cohen)
     helpful new florida website htreetrunk@hotmail.com
     How to work with data files? cs277@columbia.edu
     Re: How would you optimize this ugly script? (Chipmunk)
     Newbie writing to a file question. <rking@thepoint.net>
     Pre-Compiling Perl classes. <shahjn@cig.mot.com>
     Re: Random number generator (Jonathan C. Willeke)
     RCS-style version mgmt implementation in Perl? (Vicki Brown)
     Reading the last line of a file <rmaillet@inigo.us.dg.com>
     Re: Stalling Perl Reports.... <rootbeer@teleport.com>
     storing the output of commands to perl variables  ..... lji@peakaccess.net
     Re: syntax for subroutine reference with sort (Charles DeRykus)
     Re: Time stamping with perl <jhi@alpha.hut.fi>
     Re: yyyymmdd from localtime? <aas@bergen.sn.no>
     Re: yyyymmdd from localtime? (Mike Stok)
     Re: yyyymmdd from localtime? <aas@bergen.sn.no>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Wed, 21 May 1997 22:26:49 GMT
From: Tung-chiang Yang <tcyang@netcom.com>
Subject: Re: Change or Delete a line in a FILE
Message-Id: <EAJyCp.KFv@iglou.com>

You need to tell us what kind of line you want to delete, say,

(1) an empty line,
(2) a line with the keyword "tcyang", or
(3) the 103rd line.

==============================
Cheetat Yap (tat@pc.jaring.my) wrote:
: Dear Sirs/Madams

: 	Can anyone suggest a direct way to change or delete a line in the
: middle of a TEXT FILE.....


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

Date: Wed, 21 May 1997 22:45:42 +0200
From: s93bni@csd.uu.se (Bjvrn Nilsson)
Subject: Re: Getting Week Number
Message-Id: <s93bni-ya02408000R2105972245420001@snews.zippo.com>

In article <5lc88l$i8v@drn.zippo.com>, Bjvrn Nilsson
(bjorn.w.nilsson@edt.ericsson.se) wrote:

> Hi all!
> 
> A little thing where I just want to know if there already is a solution.
> I want to create a subfunction (or similar) that computes the week number
> given a date. I looked at the description of Steffen Beyer's Datecalc, but
> it seems to be Unix-specific and it depends upon a C-program. For sure it
> has a lot of features, but I only need the week number to run on an NT.
> 
> Thanks in advance.
> 
> Bjvrn

Hi all!

Thanks for your responses in this matter. I posted a follow-up article on
the format of week numbers used in Sweden, i.e. in brief, if the first week
of the year starts earlier than Thursday, it's week no. 1, else it's the
last week of the preceeding year.

I'll get to the coding and testing first thing tomorrow and I'll post the
results.

Cheers

Bjvrn


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

Date: 21 May 97 12:27:18 GMT
From: mcohen@arl.mil (Martin Cohen)
Subject: Re: Help in Removing lines with duplicate Field Ones
Message-Id: <3382EA26.75DA@arl.mil>

Guest Account wrote:
[deleted unnecessary restriction]
- Purpose:   Keep only those records in the file which have a UNIQUE
-            field #1.
- 
-            Duplicates may occur on more than two lines (i.e., field
-            one of record 6 may match field one of record 21, 98, 2110,
-            and 65535.  Regardless of the number of duplications, ALL
-            duplicate lines must be cleaned from the file.
-
[I don't know what following means:] 
- Field 1:   Alternates between numeric only, alpha only, or
alpha-numeric
-            values.
- 
- I have ended up doing this in C because I couldn't figure out if perl
could

What method did you use in C; why wouldn't it work in Perl?

- handle it.  Can someone tell me a Perl solution?  I sincerly
appreciate it.
- 
- Jason.

I tested the following script on one small file.  It turned out to be
surprisingly complicated.

# Perl script to delete records of a file with non-unique keys - 5/21/97
mc
# If OK to change order of file could use unix utility: sort -u -o file
file
# If not:                   cat -n file | sort -u +0.6n -0.17 | sort -o
file

open(FILE,$file=shift) || die "Can't open $file - $!\n";
$start=tell(FILE); # seek position for first record
while(<FILE>) {
	$key=substr($_,0,10); # or however you extract the key
	if ($keys{$key}) { # Key is not unique.
		$position=$keys{$key};
		($rec,$start,$end)=split(/,/,$position);
		$rec="-000000001"; # Forget it.
		$keys{$key}="$rec,$start,$end";
	}
	else { # Key has not yet been seen.
		$end=tell(FILE)-2; # end of previous record (why 2?)
		$rec=sprintf("%010d",$.); # for sorting
		$keys{$key}="$rec,$start,$end"; # Record its place.
	}
	$start=tell(FILE); # Update seek position
}

$out="$file.new";
open(OUT,">$out") || die "Can't create $out - $!\n";
for $position (sort values(%keys)) { # Get unique keys in original
order.
	($rec,$start,$end)=split(/,/,$position);
	if ($rec > 0) {
		$size=$end-($start-1);
		seek(FILE,$start,0);
		$record="";
		$nbyts=read(FILE,$record,$size);
		if ($nbyts != $size) {
			die "Something wrong with $file at byte $end\n";
		}
		print OUT $record; # Build new file.
	}
}
close(OUT);
close(FILE);
-- 
Martin Cohen - AMSAA-North - Custom House Rm 800 Phila PA 19106-2976


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

Date: Wed, 21 May 1997 19:11:37
From: htreetrunk@hotmail.com
Subject: helpful new florida website
Message-Id: <5lvv8g$mpa@tesla.netline.net>

organizations or business trips, meetings plans, family vacations, etc. in Florida
are well handled by the people at    www.floridatime.com    check out and bookmark
this site for future reference.



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

Date: Thu, 22 May 1997 02:19:55 GMT
From: cs277@columbia.edu
Subject: How to work with data files?
Message-Id: <3383acee.2249373@news.inx.net>

I have a file where on each line there is a string and a number such
as

Furniture  23
Bedroom & kitchen 45
Bathroom and bacement 30

and so on.

I want to read this into an array and change the numbers based on
comparisons on the strings. (the strings will be the keywords for
comparisons and when I get a match I work with the number - an
associative
array).  How can I do this (read the file into the associative array)?

Thanks

--
Daniel


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

Date: 21 May 1997 20:56:37 GMT
From: Ronald.J.Kimball@dartmouth.edu (Chipmunk)
Subject: Re: How would you optimize this ugly script?
Message-Id: <5lvni5$cgg$1@dartvax.dartmouth.edu>

In article <5lt44g$lpi@winter.erols.com>
murple@ares.bsg.erols.net (Craig Schenk) writes:

> 
> This is a particularly ugly script. In theory, this is what it is supposed to do:
>    - Reads in a comma-delimited file from the Novell-based sales system (MAGIC)
>    - Splits each line into fields, and assigns variables
>    - Grabs the domain choices (up to 3) and parses whois queries to find the
>      first choice which is not taken
>    - Reads in a blank InterNIC registration template that has placeholders
>      and substitutes in the variable values
>    - If there are no acceptible domain name choices, it should generate a
>      error ticket based on the sales ticket number.
> I would GREATLY appreciate any advice anyone could give for improvements.
> 
> Here is a sample of the sales system's flat file output. The file (domproc.txt)
> consists of many of these lines. I have broken it up here to fit on the screen.
> Note that there is an extra space following the comma between the state and
> zip code.
> 
> "ZZ182266609A","SUGARLOAF MOUNTAIN WORKS ","WLADKOWSKI, BEVERLY      ",
> "200 ORCHARD RIDGE DRIVE     ","#215 ","GAITHERSBURG    ","MD", "20878",
> "301","990","1400","  0","  0","0000","05/19/97","ERO-DOMAIN  ","$   0.00",
> "00/00/00","smworks  ","PO#97-310             sugarloafcrafts.com
>                          "," "
> 
> And here is the script itself:
> 
> #!/usr/bin/perl -U
> 
> $ENV{PATH} = "/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin";
> 
> require "/www/dns/config.pl";
> 
> # Open up the output of a B.B. report from MAGIC
> open (DOMPROC,"/f-drive/data/domain/domproc.txt");

You should always check the return value of open.
For example:
open (DOMPROC,"/f-drive/data/domain/domproc.txt")
  || die "Unable to open domproc.txt: $!";

> 
> while (<DOMPROC>)
> {
>         if ($_ !~ /^[\012\015]/)
>         {
>                 # These variables will be local
>                 my($street_in, $suite, $hph1, $hph2, $hph3, $wph1, $wph2, $wph3, 
>                    $bullshit1, $domraw);
> 
>                 # Split Magic's fields into various variables
>                 my($in1, $in2) = split(/\", \"/, $_);
>                 ($ticket,$orgname,$contact,$street_in,$suite,$city,$state) =
>                   split(/\",\"/, $in1);
>                 ($zipcode,$hph1,$hph2,$hph3,$wph1,$wph2,$wph3,$selldate,
>                  $bullshit1,$price,$expiration,$username,$domraw) =
>                   split(/\",\"/, $in2);

Your split statements make strong assumptions about the format of the
input.  If you're comfortable with that, that's fine.
You don't need to backslash quotes in regular expressions.

>                 $ticket =~ s/\"//;
> 
>                 # Strip tailing whitespace
>                 $orgname =~ s/\s+$//;
>                 $contact =~ s/\s+$//;
>                 $street_in =~ s/\s+$//;
>                 $username =~ s/\s+$//;

You might be able to do this before you split, with:
$in1 =~ s/\s+"/"/g;
$in2 =~ s/\s+"/"/g;
Given the pattern you are using in the first split (/", "/), you have
to do it after you split into $in1 and $in2.

> 
>                 # If theres only one name given use it as both
>                 if ($contact eq "") { $contact = $orgname; }
>                 if ($orgname eq "") { $orgname = $contact; }

Do you need to be concerned with the case where both $contact and
$orgname are ""?

>                 # Assemble broken strings
>                 $street = "$street_in" . " $suite";
>                 $homephone = "($hph1)" . " $hph2" . "-$hph3";
>                 $workphone = "($wph1)" . " $wph2" . "-$wph3";

There's no need to use interpolation and concatenation.
$street = "$street_in $suite";
$homephone = "($hph1) $hph2-$hph3";
$workphone = "($wph1) $wph2-$wph3";

>                 chomp($domraw);

Why don't you chomp($_) at the beginning of the loop?

>                 # Strip notes off domain field
>                 $domainnotes = substr($domraw,0,22);
> 
>                 # Convert the rest of domain field to lowercase
>                 my($domains_lowered) = lc($domraw);

>                 # Split domain field into choices
>                 $domainchoice1 = substr($domains_lowered,22,26);
>                 $domainchoice2 = substr($domains_lowered,48,26);
>                 $domainchoice3 = substr($domains_lowered,74);

You could probably use unpack for this.  You'll have to look up the
syntax for that.

>                 # Strip tailing whitespaces
>                 $domainchoice1 =~ s/\s+$//;
>                 $domainchoice2 =~ s/\s+$//;
>                 $domainchoice3 =~ s/\s+$//;
> 
>                 &open_log;
> 
>                 # Go through (what appear to be) domain choices and parse them
>                 # against whois to see if it is taken
>                 if ($domainchoice1 =~ /[a-z]+\.\w\w\w/)

This pattern won't necessarily match the whole string.  It will match
as few as one lowercase letter, followed by a period, followed by 3
alphanumerics, anywhere in the string.  You may want to anchor it with
$.
You match exactly 3 characters after the '.'.  Some domains have only
2, some have 4.
Is there a reason you match alphanumerics (including 0-9 and _) after
the '.', but not before?  Lots of ip address have numbers and
underscores in the first parts, but I think only letters appear after
the final period.
Finally, you could try to match the whole string, rather than just the
end, anchoring with ^ and using ()*.
How about:
/^(\w+\.)*[a-z]{2,4}$/

>                 {
>                         if (&whois_check("$domainchoice1") eq "OK")

There's no need to use "" here.  Just do &whois_check($domainchoice1)

>                         {
>                                 &submit("$domainchoice1");
>                                 goto NEXT;

I'd suggest using loop labels and the next statement instead of goto.

>                         }
>                 }
>                 if ($domainchoice2 =~ /[a-z]+\.\w\w\w/)
>                 {
>                         if (&whois_check("$domainchoice2") eq "OK")
>                         {
>                                 &submit("$domainchoice2");
>                                 goto NEXT;
>                         }
>                 }
>                 if ($domainchoice3 =~ /[a-z]+\.\w\w\w/)
>                 {
>                         if (&whois_check("$domainchoice3") eq "OK")
>                         {
>                                 &submit("$domainchoice3");
>                                 goto NEXT;
>                         }
>                 }

Instead of creating 3 separate variables and repeating the same code
three times, you could do this:

@domainchoices = (substr($domains_lowered,22,26),
                  substr($domains_lowered,48,26),
                  substr($domains_lowered,74)
                 );
# Once again, unpack would be better for this.  I don't know the syntax

foreach (@domainchoices)
{
  if (/[a-z]+\.\w\w\w/)
    # (Alternative regexp suggested above)
  {
    if (&whois_check($_) eq "OK")
    {
      &submit($_);
      goto NEXT;
      # goto is icky, use loop labels, and the last, next, and continue
statements
    }
  }
}
# and then the case where you generate the error ticket here

>                 else
>                 {
>                         print "No domains found!!! Creating error ticket!\n";
>                         &submit_error;
>                         goto NEXT;
>                 }
>         }
>         NEXT:
> }
> 
> # Check domain with whois
> sub whois_check
> {
>         my(@whois_result);
>         my($testdomain) = @_;
> 
>         if ($testdomain =~ /^www\./)
>         {
>                 $testdomain = substr($testdomain,4);
>         }

You could replace those 4 lines with
$testdomain =~ s/^www\.//;

>         print "\nCHECKING: $testdomain\n";
> 
>         open(WHOIS, "/usr/bin/whois $testdomain |");
>         while(<WHOIS>)
>         {
>                 push(@whois_result, $_);
>         }
> 
>         if ($whois_result[1] =~ /^No match/) 
>         {
>                 $domainname = $testdomain;
>                 return "OK";
>         }
>         else
>         {
>                 print "Taken, bummer...\n";
>                 return "Taken";
>         }
> }
> 
> # Open a ticket in the domain factory system
> sub submit
> {
>         my($FILENAME) = "$NEWDIR/$domainname";
> 
>         print "Opening ticket $FILENAME\n";
> 
>         # Make sure there's not a request already pending
>         # by checking for the existence of a domain ticket
>         unless (( -e $FILENAME ) || (-e "$PENDINGDIR/$domainname") ||
>                 (-e "$REGGEDDIR/$domainname") ||
>                 (-e "$FAILEDDIR/$domainname") ||
>                 (-e "$SUBMITTEDDIR/$domainname") ||
>                 (-e "$DONEDIR/$domainname") ||
>                 (-e "$NOTDONEDIR/$domainname"))
>         {
>                 # What is the top level domain?
>                 my($top) = substr($domainname, -3);

What if the domainname has a 2 or 4 letter extension?
my($top) = $domainname =~ /\.([a-z]+)$/;

>                 print "OK! Submitting $domainname under $top\n";
> 
>                 open(NEWTICKET,"> $FILENAME");

As above, you need to check the return value of open!

>                 open (TEMPLATE, $DNSTEMPLATE);

Check the return value of open!

>                 print NEWTICKET "\n\n";
>                 while (<TEMPLATE>)
>                 {
>                         if (/\{ACTION\}/) { s/\{ACTION\}/N/; }

You don't need to match and substitute.  Just substitute:
s/\{ACTION\}/N/;

>                         if (/\{PURPOSE\}/)
>                         {
>                                 if ($top eq "com")
>                                 {
>                                         s/\{PURPOSE\}/Request domain name $domainname to provide information about the services provided by $orgname/;
>                                 }
>                                 elsif ($top eq "net")
>                                 {
>                                         s/\{PURPOSE\}/Request domain name $domainname to provide network services for $orgname/;
>                                 }
>                                 elsif ($top eq "org")
>                                 {
>                                         s/\{PURPOSE\}/Request domain name $domainname to provide information about the non-profit services of $orgname/;
>                                 }
>                                 elsif ($top eq "edu")
>                                 {
>                                         s/\{PURPOSE\}/Request domain name $domainname to provide information about the educational services of $orgname/;
>                                 }
>                                 elsif ($top eq "gov")
>                                 {
>                                         s/\{PURPOSE\}/Request domain name $domainname to provide information about the government services of $orgname/;
>                                 }
>                 }

What if it's not com, net, org, edu, or gov?

>                         if (/\{COMPLETE\}/) { s/\{COMPLETE\}/$domainname/; }
>                 if (/\{ORG\}/) { s/\{ORG\}/$orgname/; }
>                         if (/\{ADDRESS\}/) { s/\{ADDRESS\}/$street/; }
>                         if (/\{CITY\}/) { s/\{CITY\}/$city/; }
>                         if (/\{STATE\}/) { s/\{STATE\}/$state/; }
>                         if (/\{ZIP\}/) { s/\{ZIP\}/$zipcode/; }
>                         if (/\{COUNTRY\}/) { s/\{COUNTRY\}/US/; }
>                 if (/\{ADMIN_HANDLE\}/) { s/\{ADMIN_HANDLE\}//; }
>                 if (/\{ADMIN_NAME\}/) { s/\{ADMIN_NAME\}/$contact/; }
>                         if (/\{ADMIN_ORG\}/) { s/\{ADMIN_ORG\}/$orgname/; }
>                         if (/\{ADMIN_ADDRESS\}/) { s/\{ADMIN_ADDRESS\}/$street/; }
>                         if (/\{ADMIN_CITY\}/) { s/\{ADMIN_CITY\}/$city/; }
>                         if (/\{ADMIN_STATE\}/) { s/\{ADMIN_STATE\}/$state/; }
>                 if (/\{ADMIN_ZIP\}/) { s/\{ADMIN_ZIP\}/$zipcode/; }
>                         if (/\{ADMIN_COUNTRY\}/) { s/\{ADMIN_COUNTRY\}/US/; }
>                         if (/\{ADMIN_PHONE\}/) { s/\{ADMIN_PHONE\}/$homephone/; }
>                         if (/\{ADMIN_EMAIL\}/) { s/\{ADMIN_EMAIL\}/$username\@erols\.com/; }
>                         if (/\{BILLING_HANDLE\}/) { s/\{BILLING_HANDLE\}//; }
>                         if (/\{BILLING_NAME\}/) { s/\{BILLING_NAME\}/$contact/; }
>                         if (/\{BILLING_ORG\}/) { s/\{BILLING_ORG\}/$orgname/; }
>                         if (/\{BILLING_ADDRESS\}/) { s/\{BILLING_ADDRESS\}/$street/; }
>                 if (/\{BILLING_CITY\}/) { s/\{BILLING_CITY\}/$city/; }
>                 if (/\{BILLING_STATE\}/) { s/\{BILLING_STATE\}/$state/; }
>                 if (/\{BILLING_ZIP\}/) { s/\{BILLING_ZIP\}/$zipcode/; }
>                 if (/\{BILLING_COUNTRY\}/) { s/\{BILLING_COUNTRY\}/US/; }
>                         if (/\{BILLING_PHONE\}/) { s/\{BILLING_PHONE\}/$homephone/; }
>                         if (/\{BILLING_EMAIL\}/) { s/\{BILLING_EMAIL\}/$username\@erols\.com/; }
>                         if (/\{INVOICE_TYPE\}/) { s/\{INVOICE_TYPE\}/P/; }

For all the above, checking for a match before doing a substitution is
unecessary, just do the substitution.
If it's possible those strings could appear more than once, don't
forget the /g modifier.

>                         print NEWTICKET;
>                 }
>                 close (NEWTICKET);
>                 system("chown $WEB_UID $FILENAME");
>                 system("chmod 664 $FILENAME");
> 
>                 # Set up the logdir
>                 system("mv $LOGDIR/$ticket $LOGDIR/$domainname");

You might want to check the return value of system.
(Don't forget, for system commands, 0 is success, non-zero is an
error.)

>                 open(LOG, ">> $LOGDIR/$domainname");

Check
the
return
value
of
open
!

>                 print LOG `date`;
>                 print LOG "Using Domain Name: $domainname\n";
>                 print LOG "--------------------------------------------------------------------------------\n";
>                 close(LOG);
>         }
>         else
>         {
>                 print "Already in process!\n";
>         }
> }
> 
> sub open_log
> {
>         # my(@domerr);
>         # @domerr =~ s/\"//;
>         open(LOG, "> $LOGDIR/$ticket");

!nepo fo eulav nruter eht kcehC

>         print LOG "\n--------------------------------------------------------------------------------\n";
>         $open_date = `date`;
>         print LOG "Ticket Opened: $open_date";
>         print LOG "Sell Date: $selldate\n";
>         print LOG "Organization Name: $orgname\n";
>         print LOG "Contact Name: $contact\n";
>         print LOG "Address: $street\n";
>         print LOG "City: $city\n";
>         print LOG "State: $state\n";
>         print LOG "Zip: $zip\n";
>         print LOG "Phone: $homephone\n";
>         print LOG "Secondary Phone from MAGIC: $workphone\n";
>         print LOG "Username: $username\n";
>         print LOG "Notes: $domainnotes\n";
>         print LOG "Domain Choices from MAGIC: $domainchoice1\n";
>         print LOG "                           $domainchoice2\n";
>         print LOG "                           $domainchoice3\n";
>         print LOG "--------------------------------------------------------------------------------\n";

Could do all that with one print statement if you wanted.  But, you
don't have to.

>         close(LOG);
> }
> 
> sub submit_error
> {
>         system("mv $LOGDIR/$ticket $ERRDIR");

Might want to check the return value of system.  (0 is good, non-zero
is bad.)

>         open(LOG, ">> $ERRDIR/$ticket");

Cektertr au foe!hc h eunvleo pn

>         print LOG `date`;
>         print LOG "No acceptible domain choices - Creating error ticket!\n";
>         print LOG "--------------------------------------------------------------------------------\n";
>         close(LOG);
> }
> 
> 

You have numerous lines which are longer than a screen width.  I'd
suggest you put them on multiple lines, as I have done for many of them
above.

I hope all that helps!

Chipmunk


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

Date: Wed, 21 May 1997 04:54:11 -0000
From: "Kings" <rking@thepoint.net>
Subject: Newbie writing to a file question.
Message-Id: <01bc655f$a5c23d00$ada2f6ce@rking.thepoint.net>

 Hello,
          Bought the Llama book and am slowly plowing through it. 
          The trouble I'm having is writing to a file the right way, on a
specific line. I'm trying to do it like this below. I took it from several
scripts I read.  Perl question follows.

###############
open (FILE,"posts.html") || die "Can't Open\n";
@lines = <FILE>;
close(FILE);
#####

#In posts.html there is a <!--begin--> line

open (POST,">posts.html") || die "Can't Open postpath: $!\n";
foreach $line (@lines) {
        if ($line =~ /<!--begin-->/) {
                print POST "<!--begin-->\n";
                print POST "$input{'name'} <br>\n";
                print POST "He/She is $input{'age'} years old<br>\n";
                print POST "And
thinks:<br>$input{'thoughts'}<hr><br><br>\n";
                close (POST);
 }
 else {
               print POST ("cannot do it");
}                  

This doesn't work, and I can't really figure out why. It prints the
variables, html tags, and it prints 'cannot do it" three times. 
	I don't understand how it reads in posts.html into the @lines variable,
and then is supposed to print to posts.html later. It seems like it opens
posts.html, finds <!--begin--> in @lines and prints to @lines. I don't
understand the link. 


I can't figure it out from the book(Llama book), and try as I might, I
can't get it to work like the other script that I took it from. 

I am working with unix and perl 4 (Trying to convince ISP to install 5)
Any advice on whats wrong or a better way to write to a specific place in
an html file?


Thanks, RKing 



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

Date: Wed, 21 May 1997 17:22:38 -0500
From: "Junaid Shah [C]" <shahjn@cig.mot.com>
Subject: Pre-Compiling Perl classes.
Message-Id: <338375AE.41C67EA6@cig.mot.com>

Hi,

I was wondering if there is a way to pre-compile (or pre-intrepret) Perl
classes/packages. We have some huge classes and at run-time, are
experiencing a performance hit.

Thanks...
-- 
----------------------------------------------------------
  Junaid Shah     Ph:(847)632-7040    Fax:(847)632-6733
  Enabling Technologies, Motorola Inc.
----------------------------------------------------------


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

Date: Wed, 21 May 1997 23:33:30 GMT
From: jwilleke@ix.netcom.com (Jonathan C. Willeke)
Subject: Re: Random number generator
Message-Id: <338383f9.1141218@nntp.ix.netcom.com>

simon@scoutnet.org.uk (Simon Pearce) wrote:

>Hi all,
>
>I'm after a snippet of code that will produce a random number between
>1 and 49 (yes for a lottery number generator).
>
>Any ideas?
>
>Simon Pearce
>simonp@dircon.co.uk
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>       A message from SIMON PEARCE, General Manager, ScoutNet UK
>        Country Co-ordinator (UK), Global ScoutNet Organization
>                   Disguised as simon@scoutnet.org.uk
>       Find me in uk.rec.scouting   IRC -> #scouting - @Simon_UK
>                         Telephone 0370 840412
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
>    ScoutNet UK - The BEST in Scouting Online - www.scoutnet.org.uk
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

The Camel book recommends

    int(rand 49) + 1

Don't forget to seed rand with srand.  If you want something a little
better, you could initialize an array with values from rand and
randomly select an element.  If you want anything more complicated
than that, consult a reference; perhaps:

  Knuth, _The Art of Computer Programming_, Vol. 2.
  Press, et. al, _Numerical Recipes in (Pascal|Fortran|C)_.
    [see http://cfata2.harvard.edu/nr/nrhome.html]
  Schneier, _Applied Cryptography_.

If you're doing this for a lottery simulation, don't forget that
lotteries usually work on the model of sampling without replacement,
so make sure you don't pick the same number twice in a given batch.

--Jon

Jon Willeke <jwilleke@ix.netcom.com>


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

Date: Wed, 21 May 1997 15:13:03 -0700
From: vlb@apple.com (Vicki Brown)
Subject: RCS-style version mgmt implementation in Perl?
Message-Id: <vlb-ya023580002105971513030001@news2.apple.com>

I would love to find a simple Revision Control System, ala RCS, to use on a
Macintosh. It doesn't have to have a fancy GUI and I really don't want a
high overhead
"design your project, multiple variants, multiple users" interface. I want
(essentially) RCS: checkin and checkout. diff and merge if/when I need
them. A log, deltas, checkin comments. Adherence to the KISS principle.

A version of RCS re-implemented in Perl would probably be just fine;
I'll port it to MacPerl and off I'll go.
I haven't (yet) been able to find what I'm looking for.

Does anyone know of a Perl implementation of RCS? (Or something akin to RCS?)
I really don't have time to write this myself :-(

Please respond by Email (vlb@apple.com); I don't read NetNews often. If I
get anything that seems worth sharing I'll post back a summary. 

Thanks -

Vicki

-- 
-------------
Vicki Brown - vlb@apple.com, www.mklinux.apple.com - Apple Computer
MkLinux advocate, Rhapsodist, Stagehand, Utility repair tech, Web Gardener


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

Date: Wed, 21 May 1997 19:22:49 -0400
From: Bob Maillet <rmaillet@inigo.us.dg.com>
Subject: Reading the last line of a file
Message-Id: <338383C8.856D7023@inigo.us.dg.com>

I am trying to get my program to read the last line of a file..
I have tried a loop but had no luck..does anyone have any suggestions?
here is a chunk of what I have so far which displays all the data in the
file..

open (FILE, $database);
@file = (<FILE>);
close(FILE);

foreach $line (@file)
{
  $_ = $line;
@ok = split(/","/, $line);
print "$ok[0]  $ok[1]  $ok[2]\n";
}
exit (0);



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

Date: Wed, 21 May 1997 16:30:23 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Daniel J Pearce <djp@sai-baba.demon.co.uk>
Subject: Re: Stalling Perl Reports....
Message-Id: <Pine.GSO.3.96.970521162610.735g-100000@kelly.teleport.com>

On Wed, 21 May 1997, Daniel J Pearce wrote:

> What I am having trouble with is holding the screen after stdout is full. 
> What I need is to include a statement that basically does a 'more' on the
> standard output.

Well, if you're about to re-write 'more', why not simply let the user pipe
the output to their pager in the first place? In that way, it's the
user's choice how (and whether) it gets paged. That will be much more
convenient if, for example, your script will someday have a web interface. 

If you must do so, though, it's not hard to open a pipe to a pager
yourself (respecting the user's choice of $PAGER, of course). Just print
to that, and it'll take care of everything. Hope this helps! 

-- Tom Phoenix        http://www.teleport.com/~rootbeer/
rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
Randal Schwartz Case:     http://www.lightlink.com/fors/



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

Date: Wed, 21 May 1997 19:04:03 -0400
From: lji@peakaccess.net
Subject: storing the output of commands to perl variables  .....  NT specific
Message-Id: <33837F63.78B9@peakaccess.net>

Hello - is there a straight-forward way of storing the 
output of a sub-command into perl variable (a way that works 
accross platforms - even NT).   I'm looking for the 
equivalent of the following in korn shell
	VAR="$(cmd line)"

I would like to avoid using system("   ") to dump to 
a file, and then reading in the file ....

Thanks for any pointers.

Louie I.


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

Date: Wed, 21 May 1997 20:02:52 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: syntax for subroutine reference with sort
Message-Id: <EAJros.Hr5@bcstec.ca.boeing.com>

In article <338204C1.789D2F77@caldera.com>,
Tim Bird  <tbird@caldera.com> wrote:
 > The sort routine can take the a subroutine as its first
 > argument.  According to one perl book I have, you can give
 > this subroutine parameter by one of a couple of ways:
 > 1) as a block
 > 2) as a subroutine name
 > 3) as a scalar whose value is a subroutine name
 > 4) as a scalar whose value is a subroutine reference
 > 
 > I can't figure out how to get the 4th option working.  I have
 > tried numerous syntaxes, to no avail.  I have successfully
 > gotten option 3 to work, but I would have preferred 4.
 > Does someone know how to do this?
 > 
 > Here's some code:
 > 
 > sub enum_compare {
 > 	$enumOrder{$a} <=> $enumOrder{$b};
 > }
 > 
 > # 2) works ok
 > foreach $item (sort enum_compare keys(%records)) {...}
 > 
 > # 3) works ok
 > $sortFunc = "enum_compare";
 > foreach $item (sort $sortFunc keys(%records)); {...}
 > 
 > # 4) this doesn't work - what am I doing wrong?
 > $sortFunc = \&enum_compare;
 > foreach $item (sort $sortFunc keys(%records)); {...}
 > 
 > # 4) nor does this work
 > $sortFunc = \&enum_compare;
 > foreach $item (sort &$sortFunc keys(%records)); {...}
 > 
 > Any advice is appreciated.
 > 

I was suprised too to see #4 produce a 
 "Not a GLOB reference at..." error.

So this slight modification works:

$sortFunc = *enum_compare;
foreach $item ( sort $sortFunc keys %records ) {
 ... 

The documentation (even Camel 2, pg 218) seems misleading. 



HTH,

--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: 21 May 1997 21:09:06 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: Time stamping with perl
Message-Id: <oeelo581yv1.fsf@alpha.hut.fi>


: $timestamp = `date`;

: $_=`date`;
: ($day,$month,$date,$time,$time_zone,$year)=split ' ', s/:/ /;

: ($day,$month,$date,$hours,$mintues,$seconds,$time_zone,$year)
:	=split /:| /, `date`;

or

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();

or

use POSIX qw(strftime);
$timestamp = strftime("%Y-%m-%d.%H:%M:%S", localtime());

You can see the format letters (%x) from your usual C programming
documentation for strftime.

-- 
$jhi++; # http://www.iki.fi/~jhi/


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

Date: 22 May 1997 00:01:10 +0200
From: Gisle Aas <aas@bergen.sn.no>
Subject: Re: yyyymmdd from localtime?
Message-Id: <hyb98trh5.fsf@bergen.sn.no>

Vincent Kargatis <kargatis@jackaldog.gsfc.nasa.gov> writes:

> I want to get a YYYYMMDD from localtime.  Is there a simpler way than
> this (I'm just curious from an educational standpoint):
> 
> ($day,$month,$year)=(localtime)[3,4,5];
> $month++;
> $month="0"."$month" if length($month)==1;
> $date=($year+1900).$month.$day;
> 
> Is there a one-line version?

If you insist:

 sprintf("%4d%02d%02d", sub{$_[0]+1900,$_[1]+1,$_[2]}->((localtime)[5,4,3]));

-- 
Gisle Aas <aas@sn.no>


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

Date: 21 May 1997 22:11:15 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: yyyymmdd from localtime?
Message-Id: <5lvru3$qek@news-central.tiac.net>

In article <33835BE6.33@jackaldog.gsfc.nasa.gov>,
Vincent Kargatis  <kargatis@jackaldog.gsfc.nasa.gov> wrote:
>I want to get a YYYYMMDD from localtime.  Is there a simpler way than
>this (I'm just curious from an educational standpoint):

>Is there a one-line version?

If you have the posix module then:

  use POSIX qw/strftime/;

  $date = strftime '%Y%m%d', localtime;

might work for you.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: 22 May 1997 00:17:25 +0200
From: Gisle Aas <aas@bergen.sn.no>
Subject: Re: yyyymmdd from localtime?
Message-Id: <hoha4mpvu.fsf@bergen.sn.no>

Gisle Aas <aas@bergen.sn.no> writes:

>  sprintf("%4d%02d%02d", sub{$_[0]+1900,$_[1]+1,$_[2]}->((localtime)[5,4,3]));

This is better:

  sprintf "%4d%02d%02d", sub{$_[5]+1900,$_[4]+1,$_[3]}->(localtime)

(You will need perl5.004 for it to work)

-- 
Gisle Aas <aas@sn.no>


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

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

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