[9314] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2909 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 19 06:07:22 1998

Date: Fri, 19 Jun 98 03:00:23 -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, 19 Jun 1998     Volume: 8 Number: 2909

Today's topics:
    Re: [Q] On WAKING a sleeping process... <rootbeer@teleport.com>
        Code Efficiency <ismithr@info.curtin.edu.au>
    Re: if (something eq "somethingfgjhf") (Patrick Timmins)
    Re: if (something eq "somethingfgjhf") (Bob Trieger)
    Re: Making Life Easy - Templates, XSSI, Variables and s (Andy Wardley)
        Moving application from DOS to a GUI. <Clemens.Hintze@bln.sel.alcatel.de>
        Newbie Question <webmaster@dragonslist.com>
        PERL IDE?? Is that it? <dario@omny.com>
    Re: Problems with newlines in perl regexp <dalsboji@sjo.statkart.no>
        Q: Trouble with a perl script that downloads a file for GustavoCollazo@hotmail.com
        Reference to arrays <thomas@ikos.com>
    Re: REVIEW: Perl CGI Programming - No Experience Requir (Rahul Dhesi)
        Script for abbreviations expansion? <oak@crl.RemoveMe.com>
        Script for changing password radhikary@hotmail.com
    Re: the ?PATTERN? match syntax (Abigail)
        unzip using perl userjeff@my-dejanews.com
        what would be the best strategy for a port scanner? any <alyons@wolffe.net>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 19 Jun 1998 07:47:41 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: [Q] On WAKING a sleeping process...
Message-Id: <Pine.GSO.3.96.980619004558.17544V-100000@user2.teleport.com>

On 19 Jun 1998, k y n n wrote:

> I have a process that every hour analyzes the contents of a large
> datafile, and sleeps in between.  

Why isn't it just run by cron, or on demand? But okay... :-)

> Occasionally, however, I would like to have it analyze the data on
> command; i.e. I'd like to wake it up, as it were.  So, my question is,
> how can I wake a sleeping process,

Send it a signal; see the perlfunc and perlipc manpages. Hope this helps!

> To reply directly by e-mail, remove the upper-case letters from the
> return address in the header.

To get replies directly by e-mail, remove the upper-case letters from the
return address in your header. :-)

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 19 Jun 1998 15:07:11 +0800
From: Ray Smith <ismithr@info.curtin.edu.au>
Subject: Code Efficiency
Message-Id: <358A0E1F.41C6@info.curtin.edu.au>

Hi all,

I have written a perl program that builds an HTML table of currently
booked records.  The code first serach for all valid entires, based on a
room ID and a date code.  I'm using DB_File for this so its a little
slow (about 1.5 secs to go through 3500 entries), but I'll be installing
oracle shortly so should be able to over come this.  The problem I'm
having is that once the required entries have been retreived in need to
produce an HTML table of the data.  This table is taking 8 secs to be
printed out.  Can anyone give me some tips on speeding this up??  I'm
running perl 5.004 in IRIX 6.3.

Thanks for you time and any information, Ray.

Here's my code to produce the table, sorry its a quite messy:



#
#createTimeTable
#produces the actual booking time table
#
sub createTimeTable()
{
   local($firstDate)=@_;
   				           			   		  
local($timeBlock,$day,$currentDateTime,$key,$values,$st,    	                 
$startDateTime);
   local($varNumber,$sdate,$edate,$name,$contact,$hours,$lastDate);
   local($school,$user,$cellcolor);
   local(@entries)=();
     
   #set the initial time => 7 am 
   $startDateTime=&Date_SetTime($firstDate,"07:00");
   $currentDateTime=$startDateTime;
   $lastDate=&DateCalc($firstDate,"+7 d");
   
   #set @booked from the room dataBase
   #lock the database
   if (open (DB_FH, "<$booked_file")) {
   
	&lock(DB_FH,$LOCK_EX);
   
	#add the dummy look it seems to need this ?why?
	$booked_recno->get($booked_recno->length-1,$values);
	#make and array of all entries for current week
	for ($st=$booked_recno->seq($key,$values,R_FIRST);
	    $st==0;$st=$booked_recno->seq($key,$values,R_NEXT) ) {
     
	    #split the values
	    ($varNumber, $sdate, $edate, $name,$reason,
$contact,                    $school, $user) = split(/\\/,$values);
	    #get the next if not correct item
	    #print "EN=$roomNum -- CN=$varNumber<BR>";
	    next if $varNumber ne $varNum;
	    #print "KEY:$key->$values<BR>";
	    #check to see if the date is in the range
	    #print "$firstDate -- $sdate -- $lastDate<BR>";
	    next if ($sdate lt $firstDate && $sdate gt $lastDate);
	    #add the $values to @entries
	    push(@entries,$values);
      
	} #end of for loop for getting entries
	#print "End Status=$st:$!<P>";
	#release the database
	$booked_recno->sync;
	&unlock(DB_FH);
	close(DB_FH);   
   	#this takes about 1 sec to complete

	#print "Found Entries = [@entries]<P>";


	#create the date table
	print "<P><TABLE BORDER=\"1\"
CELLPADDING=\"5\"                                 CELLSPACING=\"0\">";
	print "<TR ALIGN=\"CENTER\">";
	print "<TD WIDTH=\"40\">Date:</TD>";
	for ($i=0;$i<7;$i++) {
	    #format date the string => Day<BR>d Month
	    $dateString = 
	       &UnixDate( &DateCalc($startDate,"+$i d"),"%a<BR>%e %b");
	    
	    #put into the table
	    print "<TD WIDTH=\"80\">$dateString</TD>";
	
	}
	#close the Date heading  - just close the row
	print "</TR>";
	print "<TR ALIGN=\"CENTER\">";
	print "<TD WIDTH=\"40\" ALIGN=\"CENTER\">Time:</TD>";
	print "<TD WIDTH=\"80\"
ALIGN=\"CENTER\"                                       
COLSPAN=\"7\">&nbsp;</TD>";
	print "</TR>";
   
	#add the rows for each of the times 7am - 10pm in 1/2 hour lots
	my($totCells)=32;
	#to hold the name of the person who booked the item
        $currentName=''; 
	local(@bookedDays);
	for ($t1=0;$t1<7;$t1++) {
	    for ($t2=0;$t2<$totCells;$t2++) {
		$bookedDays[$t1][$t2]=0;  
	    }
	}
	undef $t1;undef $t2;
	#[days][hours]to use instead of conlumn offset
       
	#
	#this seems to take forever
	#	

	for ($timeBlock=0;$timeBlock<$totCells;$timeBlock++){
	    #add the time label
	    $timeLabel=&UnixDate($currentDateTime,"%R");
	    print "<TR ALIGN=\"CENTER\"><TD WIDTH=\"40\"                
ALIGN=\"CENTER\"><FONT SIZE=\"2\">$timeLabel</FONT></TD>";
	    
	    
	    for ($day=0;$day<7;$day++) { #for each day in time => columns
	 
		$tempDate = &DateCalc($currentDateTime,"+$day d");
		#$temp=&UnixDate($tempDate,"%a %R"); 
	 
		#if bookedDays has a value then go to the next day
		next if $bookedDays[$day][$timeBlock]!=0;
	  
		#go through the found entries and check to see if any fit
		foreach $values (@entries) {
		    ($varNumber, $sdate, $edate, $name,
$reason,                              $contact, $school, $user) =
split(/\\/,$values);
		    #if the start date is not the same try the next
		    next if $sdate ne $tempDate;
		    #else work out how many 30 min units this booking runs for
		    $length = Delta_Format( DateCalc( $sdate,
$edate,                                  \$err), 1,"%hd") * 2;
		    #make sure that its rounded to the nearest cell
		    $length = sprintf("%.0f",$length) ;
		    #print "Length1 = $length<BR>";
		    $length=1 if ($length<1);
		    #print "Length = $length<BR>";
		    if ($reason eq "") {
			$currentName="$name<BR>$contact";
		    }
		    else {
			$currentName="$reason<BR>$name<BR>$contact";
		    }
		    #set the cell background color according to the $school
		    if ($school eq ' OT ') {$cellcolor="6a99e8";} #blue 
		    elsif ($school eq ' PT ') {$cellcolor="bfffbf";} #green
		    elsif ($school eq ' POD ') {$cellcolor="ffffb6";} #Yellow
		    elsif ($school eq ' Private ') {$cellcolor="ffbfbf";} #red
		    elsif ($school eq ' Exams ') {$cellcolor="6e959e";} #Acqua
		    else {$cellcolor="fafafa";} #gray
	    
		    #there will only ever be one booking on
this                             #date+time so this will
		    #be the last
		    last;
	    
		} #end of entries for loop
       
		#check to see if we have passed the last column
		#should never get there now as the $day is incremented if a booking
		#already exists
	
		#if not booked insert an empty cell
		if ($currentName eq '') {
		    print "<TD WIDTH=\"80\">&nbsp;</TD>";
	   
		}
		else { # add the currentname and rowspan with the bgcolor light grey
		    print "<TD bgcolor=\"$cellcolor\" VALIGN=\"TOP\"WIDTH=\"80\"
ROWSPAN=\"$length\" ALIGN=\"LEFT\"><FONT
SIZE=\"1\">$currentName</FONT></TD>";
		} 
	 
		#insert the columnOffsets - bookedDays
		for ($temp=$timeBlock;$length>0;$temp++,$length--) {
		    #add to the next bookedDays
		    $bookedDays[$day][$temp]++;
		    #remove one from the length
		}
	   
		#clear the currentName;
		$currentName='';
		$length=0;
		
	    }	#end of each day for loop
        
	 
	 
	 
	    #close the row
	    print "</TR>";   
         
	    #increment the current date time
	    $currentDateTime=&DateCalc($currentDateTime,"+30 minutes");
	    #print "CurrentDateTime=$currentDateTime<BR>"; 
	
	} #end of timeblock for loop
	   
	#close the booked table
	print "</TABLE><P>";
   
    
    } #end of open if
    else { #if unable to open the data base file
	print"Error in trying to open database access: $!<P>";
	print "Try reloading the page.<P>";
    }

} #end of function


--
Ray Smith
Department of Physiotherapy
Curtin University of Technology
Selby St Shenton Park 6008 Aust.
Ph: 	+61 8 9266 3667
Fax: 	+61 8 9266 3636
Email: 	ray@guardian.curtin.edu.au
--


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

Date: Fri, 19 Jun 1998 07:06:26 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: if (something eq "somethingfgjhf")
Message-Id: <6md2li$2tj$1@nnrp1.dejanews.com>

In article <6mcagi$9dn$1@ligarius.ultra.net>,
  sowmaster@juicepigs.com (Bob Trieger) wrote:
>
> [ posted and mailed ]
>
> ptimmins@netserv.unmc.edu (Patrick Timmins) wrote:
>
> -> Why eq ? Why not regex? eg:
>
> Because regex takes atleast 3 times longer.
>
> Both will do the job but getting it done faster is usually better.
>
[snip]

Wrong! observe:

use Benchmark;
$foo = "something wicked this way comes.";
$bar = "something";

timethese 1000000, {
    regex   =>  sub {
            die if ($foo !~ /$bar/);
    },
    equal   => sub {
            die if (substr($foo,0,9) ne substr($bar,0,9));
            }
};

On my system, this outputs:

Benchmark: timing 1000000 iterations of equal, regex...
     equal: 12 secs (11.43 usr  0.00 sys = 11.43 cpu)
     regex: 12 secs (11.90 usr  0.00 sys = 11.90 cpu)

So over the course of a million iterations, you've saved me less than half a
second. Plus your option isn't very adabtable. Whenever $bar changes you've
got to putz around with your substr length parameters for substr $foo and
substr $bar. You can have your half a second! :)

Patrick Timmins
U. Nebraska Medical Center

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 19 Jun 1998 09:35:03 GMT
From: sowmaster@juicepigs.com (Bob Trieger)
Subject: Re: if (something eq "somethingfgjhf")
Message-Id: <6mdbfk$6je$1@ligarius.ultra.net>

[ posted and mailed ]

ptimmins@netserv.unmc.edu (Patrick Timmins) wrote:

-> use Benchmark;
-> $foo = "something wicked this way comes.";
-> $bar = "something";
-> 
-> timethese 1000000, {
->     regex   =>  sub {
->             die if ($foo !~ /$bar/);
->     },
->     equal   => sub {
->             die if (substr($foo,0,9) ne substr($bar,0,9));
->             }
-> };
-> 
-> On my system, this outputs:
-> 
-> Benchmark: timing 1000000 iterations of equal, regex...
->      equal: 12 secs (11.43 usr  0.00 sys = 11.43 cpu)
->      regex: 12 secs (11.90 usr  0.00 sys = 11.90 cpu)
-> 
-> So over the course of a million iterations, you've saved me less than half a
-> second. Plus your option isn't very adabtable. Whenever $bar changes you've
-> got to putz around with your substr length parameters for substr $foo and
-> substr $bar. You can have your half a second! :)

Your regex isn't correct for what the original poster was looking for. He 
specificall said the first 8 characters. Anchor your match to the beginning 
and retry the timing.


Bob Trieger
sowmaster@juicepigs.com
" Cost a spammer some cash: Call 1-800-239-0341
    and hang up when the recording starts. "


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

Date: Fri, 19 Jun 1998 08:49:50 GMT
From: abw@cre.canon.co.uk (Andy Wardley)
Subject: Re: Making Life Easy - Templates, XSSI, Variables and such
Message-Id: <EusJ72.2G4@cre.canon.co.uk>

Ron Savage <rpsavage@ozemail.com.au> wrote:
>This problem has been solved by the author of Text::MetaText. 

Hey, I resemble that remark!

As Ron says, Text::MetaText can do this for you.

Your html template files might look like this:

    %% INCLUDE header %%

    <body bgcolor="%% bgcol %%">
    ...
    blah...blah...<a href="mailto:%%email%%">Email Me!</a>...blah...
    ...
    </body>   

    %% INCLUDE footer %%

You can define the variable values ('bgcol' and 'email' in the above example)
in the perl script that uses Text::MetaText, in a separate config file, 
in the document itself:

    %% DEFINE 
       bgcol = "#ffffff"
       email = "abw@kfs.org"
    %%

or as attributes to an INCLUDE directive:

   %% INCLUDE header bgcol="#ffffff" %%
   
Text::MetaText is avialable from CPAN. It includes a 'make-like' utility
called 'metapage' which can traverse your web site document tree and run
the template processor for you.  



A


--
Andy Wardley <abw@kfs.org>   Signature regenerating.  Please remain seated.
     <abw@cre.canon.co.uk>   For a good time: http://www.kfs.org/~abw/


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

Date: Fri, 19 Jun 1998 08:37:33 GMT
From: Clemens Hintze <Clemens.Hintze@bln.sel.alcatel.de>
Subject: Moving application from DOS to a GUI.
Message-Id: <13706.7290.446764.582286@slbh37.unix01>


I have not really done the same, but I have written an editor which enable
us to edit data stored in a project-internal format. This editor was first
written in Tcl/Tk at whole. But to improve the performance, I have rewritten
some functions in C and linked them together with the rest.

Today I would use Python instead of Tcl/Tk. In the good old Tcl 7.x there was
only a string interface to C functions, which sucks on speed, but was very
easy to understand and to use. Now Tcl 8.x has gotten an object interface like
Python has from the beginning on. In my opinion the object interface is
slightly more complicate than the old Tcl string interface. But it is much
faster!

For me, Python is the ideal language to glue existent components together. 
It is as easy as Tcl with its new object interface, but much more powerful as
language itself.

I have not done such thing in Perl, but I have read the documentation, what to
do to glue C functions together with Perl. Sorry Perl'ees, but IMHO it is very
complicate compared to Python or Tcl/Tk. Perl was really not invented to be a
glue language on C level, IMHO!

The bad news is, that you cannot simply link your C functions together with
Python or Tcl, both Python and Tcl have a calling scheme, which C functions
to be called by the interpreters have to follow.

You functions have to be announced to Python, to enable the interpreter to
call them. All functions will have a certain kind of parameters filled by the
corr. interpreter. All functions have to return it's results thru a certain
mechanism to the calling interpreter. So I think you would at least have to
wrap your existing functions, to enable them to be used from Python (the same
for Tcl).

The good news is, that there is a tool called SWIG which can generate such
wrapping functions for you.

Hope that help you.

Bye,
Cle.

-- 
| Clemens Hintze * ACB/EO  ____  OMC-R Software Developement
| Phone: +49 30 7002-3241  \  /  ALCATEL Mobile Communication Division ITD
| Fax  : +49 30 7002-3851   \/   Colditzstr. 34-36, D-12099 Berlin, Germany
|             mailto:Clemens.Hintze@bln.sel.alcatel.de


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

Date: Fri, 19 Jun 1998 08:53:48 GMT
From: Sifu Hall <webmaster@dragonslist.com>
Subject: Newbie Question
Message-Id: <358A25DD.9A4C87F8@dragonslist.com>

How can I sort a mulit-dimensional array an a specific element?  For
example if I have an array @Schools, how can I sort this array to be
alphabetic by the third element?


webmaster@dragonslist.com



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

Date: Fri, 19 Jun 1998 06:25:25 -0300
From: "Dario Andrade" <dario@omny.com>
Subject: PERL IDE?? Is that it?
Message-Id: <358a2f63.0@news1.ibm.net>

I read at Developers that there was a PERL IDE for developing perl scripts.

is that true? where can I get it?

thanks,

Dario <dario@omny.com>





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

Date: Fri, 19 Jun 1998 09:08:51 +0200
From: "Jan Inge Dalsbx" <dalsboji@sjo.statkart.no>
To: Eli the Bearded <*@qz.to>
Subject: Re: Problems with newlines in perl regexp
Message-Id: <358A0E83.DA7E1380@sjo.statkart.no>

Eli the Bearded wrote:

> In comp.lang.perl.misc, Jan Inge Dalsbx <dalsboji@sjo.statkart.no> wrote:
> > # seach for zero to 1 line at the end of $pre
> > $pre =~ /(.*?\n){0,$lines}$/;
>
> I think you want
>
>  $pre =~ /(             # grabbing parens
>            (?:          # grouping parens
>             [^\n]*\n    # pattern
>            ){0,$lines}  # count of group
>           )             # all captured
>           $             # anchor
>           /x;           # /x ignore whitespace and comments

No, your regexp did the same as mine. It don't find the double newline at the
end of a string.

Look at this example (also using friendly quoting operators):

use English;

$file=0;
# use 2 strings to simulate simple ASCII-files with newlines
foreach ("abc\n123\n", "abc\n123\n\n")
{
    printf qq/This is "file" %d:\n/, ++$file;
    print;
    print qq/-EOF-\n/;

    foreach $line (1..3)
    {
        print qq/Search for $line line(s) from EOF...\n/;
        /((?:[^\n]*\n){0,$line})$/;
        print qq/M:($MATCH)P:($POSTMATCH)\n/;
    }
}

Result:

This is "file" 1:
abc
123
-EOF-
Search for 1 line(s) from EOF...
M:(123
)P:()
Search for 2 line(s) from EOF...
M:(abc
123
)P:()
Search for 3 line(s) from EOF...
M:(abc
123
)P:()
This is "file" 2:
abc
123

-EOF-
Search for 1 line(s) from EOF...
M:(123
)P:(
)
Search for 2 line(s) from EOF...
M:(abc
123
)P:(
)
Search for 3 line(s) from EOF...
M:(abc
123

)P:()
---------------------
Searching in "file" 1 is looking good.

Searching in "file" 2, with the extra newline at the end, don't work as i
want. The result for "file" 2 should be:
------------
Search for 1 line(s) from EOF...
M:(
)P:()
Search for 2 line(s) from EOF...
M:(123

)P:()
Search for 3 line(s) from EOF...
M:(abc
123

)P:()
---------------------

I want $POSTMATCH to be empty each time!

Is it something with the anchor ($) in the regexp? Is the last newline
"invissible" when using $?




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

Date: Fri, 19 Jun 1998 07:47:28 GMT
From: GustavoCollazo@hotmail.com
Subject: Q: Trouble with a perl script that downloads a file for web user...
Message-Id: <6md52g$77o$1@nnrp1.dejanews.com>

Hello. I have a link on my web page that calls on this PERL script...

************************
#!/usr/bin/perl
$logfile = 'downloads.txt';

$date = `date`; # gets the current date
chop($date);    # chops the newline off the date

open(LOG,">>$logfile");
print LOG $date;
print LOG "\n";
close(LOG);

print "Content-Type: application/octet-stream\n\n";
open(OPENFILE, "mchess.zip") || die "Cannot open mchess.zip: $!";
open(STDOUT);
binmode(OPENFILE);
binmode(STDOUT);
while(<OPENFILE>){
  print;
}
close(OPENFILE);
close(STDOUT);
************************
The CGI script basically adds an entry to a file ("downloads.txt") and then
downloads the file for the user. I'm trying to keep track of how many people
download the file and both the logfile and the downloading of the file work.

The problem comes in when the user clicks the link that calls the script.
The browser brings up the "Save As" dialog for the user with the name of the
PERL script file, instead of the file I'm trying to download.


How do I get the browser to display the name of the download file and not the
script file. Thanx in advance!


Gustavo Collazo
Midnight Programmers

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 19 Jun 1998 10:21:03 +0200
From: "Thomas St. Pierre" <thomas@ikos.com>
Subject: Reference to arrays
Message-Id: <358A1F6F.85BA9E50@ikos.com>

Hi,

two questions about references to arrays:

1) Why isn't it possible (or is it?) to create a symbolic reference to a single element of an array eg:

$test="egon[0]";
$egon[0]="Guten Morgen";
$egon[1]="Guten Abend";
print "test: $test \n";
print $$test ,"\n";


printing the $$test resolves in an empty string. Is there a way around it?


2) I'm looking for a way to split an array (each array is extracted from one line in the input file) into two different files, based on rules read from a definition file. The input file is about 70MB with 100 elements per line so I need a fast way of doing the job.


eg.

@line=split //,$_;

line:  [0|1|1|1|0|0|0|1]

let's say bit 0,1,4 and 5,7  go into file "input"  1,2,3,6,7  into file "output" (note that 1 and 7 are in both files)


My take was to generate a list of references for the input and the output file where every element of the list points to one element of the input array. Upon reloading the array with the next line I thought the pointers would still point to the position in the array so i could dump the values by doing a foreach on the input and output list.

eg:

$output[0]=\$line[1]
$output[1]=\$line[2]
$output[2]=\$line[3]

 .....
$output[4]=\$line[7]

same thing for the input array


Unfortunately the references point to the v a l u e s  of the last line, not to the position in the array. So although the @line array was reloaded with a new line the pointers wouldn't be updated.

Is there a way of generating a reference to the position in the line array rather than to the value (symbolic ref didn't work, see above)


Thanks for you time


Regards

Thomas


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

Date: 18 Jun 1998 23:36:14 GMT
From: c.c.eiftj@54.usenet.us.com (Rahul Dhesi)
Subject: Re: REVIEW: Perl CGI Programming - No Experience Required
Message-Id: <6mc89e$sk5$1@samba.rahul.net>

In <35898507.709F@min.net> John Porter <jdporter@min.net> writes:

>Rahul Dhesi wrote:
>> 
>> My next question is:  If the only difference between the two is that one
>> is in a single variable, and the other is explicitly enumerated, why are
>> we making such a a big deal of this difference?

>Only because some people are having a hard time grasping it.
>Just how different is a school bus from a bunch of kids?

Name-calling, obscure references to perl internals, and silly analogies.
Are these what the original author of the 'Perl CGI Programming' should
have used to explain perl arrays and lists?
-- 
Rahul Dhesi <dhesi@spams.r.us.com>


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

Date: 19 Jun 1998 07:11:21 GMT
From: oak <oak@crl.RemoveMe.com>
Subject: Script for abbreviations expansion?
Message-Id: <6md2up$dou$1@nnrp1.crl.com>

I'm looking for a script to expand abbreviated words in text files.
I'd also like the script to be able to abbreviate non-abbreviated
words, i.e., to take regular English words and abbreviate them.

The script should take a list of abbreviations from a file such as:

bc because
hwe however
fe for example,
iow in other words,

You get the idea, mind you, the list is LONG - over 2000+ words at
last count.

Markus Laker wrote the script at the end of this post which does this
just fine - thanks Markus! However, there are some additional
capabilities and options now needed.

I have a web page describing the general ideas regarding
abbreviations.  The visions of this endeavor are big, it entails, in
essence, over-hauling the entire English language - really! :)
 ....somewhat anyway.  You'll also find this post there, aswell as a
guest book for ideas or comments. It's all at:
http://www.crl.com/~oak/abr.html

First I'll out-line what Markus' script already does, then I'll
outline the additional functionality needed, and I'll just have to
leave it to you perl gurus to decide whether the script needs to be
overhauled or if some additions to it are sufficient.

Markus' script will take a text file with a list of abbreviations of
the form:

bc because
abr abbreviate
etc...

and expand abbreviations in any text file according to the specified
abbreviations in the list. Actually, the script was meant to
abbreviate non-abbreviated words, but by reversing the abbreviations
list word order it will expand abbreviations.  Ultimately I'd like it
to be able to do either using the same abbreviations list.

The additional functionality needed is the following:

1. Expand or abbreviate using the same list: Using the same
abbreviations list as a base, have the option to either expand
abbreviated words in a text file, or to abbreviate regular words in a
text.  If not feasible, a script to reverse the abbreviation order in
the abbreviations list might be an adequate work around. All this
might be tricky given number 2 below.

2. Multi-worded expansions/abbreviations: In the abbreviation list the
first word might be the abbreviation and the second SINGLE word the
expansion. What's needed is that all subsecuent words, i.e., one OR
MORE words be considered as the expansion. With the current script I
can't have an abbreviation such as:

iow in other words

because "iow" is expanded only to "in". "iow" should expand to "in
other words". Or the reverse, "in other words" should contract to
"iow". The user will have to specify what he wants i.e., abbreviate or
expand.

3. Ignore provision: Ignore anything between x and x. For example,
"The two ltrd code t gt in s xbcx." Here I don't want "bc" to expand
to "because" so I've enclosed it with x's (of course the x's shoudn't
show up in the output).  There mustn't be any spaces between the two
x's. Perhaps there can also be something like; ignore anything
spanning multiple lines and spaces between "<!--xx" and "xx-->".

4. Provision for comment lines: The abbreviations list might have a
comment provision where lines beginning in # are to be ignored. (this
is not really essential but it would be nice)

5. Documentation within the perl script: This is so that non-perl
people can get an idea what's going on at particular stages of the
script. If possible some sense of modularity might be helpful so if
certain functions are not wanted one could just comment the section
out.

Any help with this script is greatly appreciated.


-Tony



== Begin Markus' Abbreviation Script ==

# Take unabbreviated text and an abbreviation dictionary
# and abbreviate the text.

# (c) Markus Laker, 1997.

# This is free software: you can use it on the same terms as Perl.





# The following sub takes a full word and an abbreviation
# and returns the abbreviation with the same capitalisation style
# as the full word: all lower, ALL UPPER or Proper.
# If the full word has random capitalisation, no abbreviation is done.
# Note: As an optimisation, abbreviations are stored in lower case,
# so we need change case only if we find some caps.

# We understand [.,'] but not diacriticals.  Sorry.

sub abbr($$)
{       local $_ = $_[0];
        my $ab = $_[1];
        /^[a-z'\.,]+$/?                                 $ab:
                /^[A-Z'\.,]+$/?                         uc $ab:
                        /^[A-Z][a-z'\.,]*$/?    ucfirst $ab:
                                                                        $_;
}


# Read the dictionary and compile a giant Perl statement
# to swap every full word in a line for its abbreviation.

sub read_dictionary($)
{       open DICT, $_[0] or die "Can't open $_[0]:\n$!";
        my (%dict, $code);
        while (<DICT>)
        {       $dict{lc $1} = $2 if /^\s*(\S+)\s+(\S+)\s*$/    }
        close DICT;
        die "No abbreviations found in the dictionary\n" unless %dict;
        $code = join '',
                'sub {',
                join('+', map qq[s/\\b(\\Q$dict{$_}\\E)\\b/abbr \$1,"$_"/ieg], keys %dict),
                '}';
        $code = eval $code;
        die "Couldn't write swapper function:\n$@" if $@;
        $code;
}

die "$0 dictionary [files...]\n" unless @ARGV;

# Tie it all together:
# Read the dictionary, build the swapper function and apply it to every input line.

my $swapper = read_dictionary shift;
while (<>)
{       &$swapper;
        print;
}




== End Markus' Abbreviation Script ==

As you can see Mark's script will also honor first letter
capitalizations, for example, Bc it will expand to "Because" but bc
will expand to "because", and something like bC will not expand at
all. This is useful in getting upper case in the first word of a
sentence.  I don't know how capitalizations are going to be
implimented in the grand scheme of things so I'd like this capability
to be an option.  Another option I'd like to integrate is this one
(written as a separate script) which aims to properly capitalize
uncapitalized text:
-------- begin Markus' capitalization script
# Capitalise the first alpha char in a paragraph as long as
# it's preceded only by spaces and quotes, and the first
# alpha after every dot, query and pling.
# Leave other capitals (e.g. in proper names) intact.

# This is a disproof of principle, as it were.

$/ = '';
while (<>)
{       s/^([\s"']*)(\w)/$1 . uc $2/e;          # do the first one;
        s/([\.\?\!]\W*)(\w)/$1 . uc $2/eg;      # do the rest.
        print;
}
-------- end Markus' capitalization script



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

Date: 19 Jun 1998 10:19:16 GMT
From: radhikary@hotmail.com
Subject: Script for changing password
Message-Id: <6mddv4$aen$1@orthanc.reference.com>

Is there a script available for changing Unix system password from a HTML page.
Thanks



  -------------------------------------------------------------------- 
  Posted using Reference.COM                  http://WWW.Reference.COM 
  FREE Usenet and Mailing list archive, directory and clipping service 
  -------------------------------------------------------------------- 


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

Date: 19 Jun 1998 07:13:22 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: the ?PATTERN? match syntax
Message-Id: <6md32i$a5f$1@client3.news.psi.net>

Mark-Jason Dominus (mjd@op.net) wrote on MDCCLIII September MCMXCIII in
<URL: news:6mcrp1$g9d$1@monet.op.net>:
++ 
++ In article <6mce3p$96f$1@nnrp1.dejanews.com>,
++  <topher67@my-dejanews.com> wrote:
++ >The match syntax "?PATTERN?" is very useful and should *not* be removed from
++ >perl.
++ 
++ OK.  Why?
++ 
++ I'm not trying to start an argument; I'm really curious.  A few months
++ ago I tried to make a list of the least-known and littlest-used Perl
++ features.  I polled some experienced Perl programmers for advice.
++ When I mentioned ?PATTERN? to them, most of them didn't know what I
++ was referring to.
++ 
++ When is ?...? useful?  What do you do with it?
++ 


Well, it allows you to put some question marks at some code
without putting it in a comment.

    $foo = $bar + 3;  ??;

Or you use it for silly JAPHs:

perl -we '$_ = q ?4a75737420616e6f74686572205065726c204861636b65720as?;??;
          for (??;(??)x??;??)
              {??;s;(..)s?;qq ?print chr 0x$1 and \161 ss?;excess;??}'



Abigail
-- 
perl -e '$a = q 94a75737420616e6f74686572205065726c204861636b65720a9 and
         ${qq$\x5F$} = q 97265646f9 and s g..g;
         qq e\x63\x68\x72\x20\x30\x78$&eggee;
         {eval if $a =~ s e..eqq qprint chr 0x$& and \x71\x20\x71\x71qeexcess}'


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

Date: Fri, 19 Jun 1998 09:08:17 GMT
From: userjeff@my-dejanews.com
Subject: unzip using perl
Message-Id: <6md9q1$csg$1@nnrp1.dejanews.com>

I am looking for a way( by using perl) that can
unzip a zipped file. Can anybody help me?
In more detail, if I want to find all lines containing 'hello'
in the file xyz. But the file was zipped and it exists in the
form xyz.zip in my directory. A usual way to do it is
pkunzip xyz.zip
then the file xyz generated. Then write a perl program:
open (FILE, "xyz");
 .......
The way I am looking for is
open (FILE, "xyz.zip");
find some way to transfer <FILE> into an unzipped form.
Then proceed as usual to find the lines containing 'hello'


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Fri, 19 Jun 1998 00:58:35 -0700
From: Adam Lyons <alyons@wolffe.net>
Subject: what would be the best strategy for a port scanner? any ideas, i thought this would be fun :)
Message-Id: <358A1A2B.907BD002@wolffe.net>

what would be the best strategy for a port scanner? any ideas, i thought
this would be fun :)

i was thinking that in my exploration of perl and sockets programming, a
good learning project would be a port scanner, if any one is interested
and would like to help me make this please let me know, especially if it
has been done.

--
____________________________________________________________
Adam Lyons
Engineering/Marketing
WolffeSoft Technologies
Today's Enterprise Level Software Solutions
Tempe, Az 85281
(602) 791-8659
alyons@wolffe.net
ICQ :: 12013959
____________________________________________________________




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

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

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