[18090] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 250 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Feb 8 21:10:39 2001

Date: Thu, 8 Feb 2001 18:10:23 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981684623-v10-i250@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 8 Feb 2001     Volume: 10 Number: 250

Today's topics:
        How can I modify the value of a variable directly from  <pobbard@hotresponse.com>
    Re: How can I modify the value of a variable directly f <godzilla@stomp.stomp.tokyo>
    Re: How can I modify the value of a variable directly f <sumus@aut.dk>
    Re: How can I modify the value of a variable directly f (Tom Hoffmann)
    Re: How can I modify the value of a variable directly f (Randal L. Schwartz)
    Re: How can I modify the value of a variable directly f <godzilla@stomp.stomp.tokyo>
        How to run Perl on Windows 2000? <ilogix@hotmail.com>
    Re: How to run Perl on Windows 2000? (Damian James)
    Re: Modules/Constants. (Garry Williams)
    Re: Modules/Constants. <dorsettest@uk.insight.com>
    Re: Modules/Constants. <dorsettest@uk.insight.com>
    Re: non repeating random numbers <kstep@pepsdesign.com>
    Re: Perl, Solaris and readdir64 (Garry Williams)
    Re: Problems with Perl on Apache? <mischief@velma.motion.net>
    Re: Regular Expression Question (Damian James)
    Re: Regular Expression Question <elijah@workspot.net>
    Re: removing empty line <mischief@velma.motion.net>
        sending attachments <troyr@vicnet.net.au>
    Re: sending attachments <tony_curtis32@yahoo.com>
        sort of about sort <ccx138@coventry.ac.uk>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 8 Feb 2001 18:35:25 -0500
From: "Philip Obbard" <pobbard@hotresponse.com>
Subject: How can I modify the value of a variable directly from within a sub?
Message-Id: <95va5s$qf1$1@taliesin.netcom.net.uk>

Hi all,

I have a feeling this is a pretty basic question, but the answer isn't what
I expected (yet).

I'm writing some reports that display numbers like:
9100
34566

I wanted to display them like
9,100
34,566

So, I found &commify at www.perldoc.com (in the FAQ). It looks like this:

sub commify
 {
        local $_  = shift;
        1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
        return $_;
    }

In my code, I can do:
my $number = 32566;
$number = commify($number);

$number now returns 32,566 - so this works fine. However, I also tried:
&commify(\$number);

 ...hoping that would change the value of $number directly (since I am
passing it by reference), but obviously I am misunderstanding something
about either (1) the &commify function (which I only barely understand) or
(2) references, which I *think* I understand... but not in this case.

If anyone can explain to me how I can change the value in place, I'd
appreciate it! I'm using perl 5.005, if that makes any difference.

Thanks,
Philip





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

Date: Thu, 08 Feb 2001 16:07:34 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How can I modify the value of a variable directly from within a sub?
Message-Id: <3A8334C6.9C89A06A@stomp.stomp.tokyo>

Philip Obbard wrote:

(snippage)

> I'm writing some reports that display numbers like:
> 9100
> 34566
 
> I wanted to display them like
> 9,100
> 34,566
 
> sub commify
> {
>  local $_  = shift;
>  1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
>  return $_;
> }
 
> In my code, I can do:
> my $number = 32566;
> $number = commify($number);
 
> $number now returns 32,566 - so this works fine. 
> However, I also tried: &commify(\$number);
 
> ...hoping that would change the value of $number directly
> (since I am passing it by reference)
 


Try this syntax:

$number = ${\&commify($number)};


Godzilla!


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

Date: 09 Feb 2001 01:15:29 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: How can I modify the value of a variable directly from within a sub?
Message-Id: <snlolnj2.fsf@macforce.sumus.dk>

"Philip Obbard" <pobbard@hotresponse.com> writes:
[...]
> sub commify
>  {
>         local $_  = shift;
>         1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
>         return $_;
>     }
> 
> In my code, I can do:
> my $number = 32566;
> $number = commify($number);
> 
> $number now returns 32,566 - so this works fine. However, I also tried:
> &commify(\$number);
> 
> ...hoping that would change the value of $number directly (since I am
> passing it by reference)

Yeah, but the commify() expects a number - not a ref to a scalar.

You can change commyfy to operate on a reference:

-------------------------
sub commify_by_ref {
    my ( $scalarref ) = @_;
    1 while $$scalarref =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
    return $$scalarref; # if you still want it to return the commified number
}

my $number = 32566;
commify_by_ref( \$number ); # pass reference
print "$number\n";
---------------------------

or you can exploit the fact that function parameters are
in fact syntactically sugared references:

---------------------------
sub commify_param {
    1 while $_[ 0 ] =~ s/^([-+]?\d+)(\d{3})/$1,$2/;
    return $_[ 0 ]; # if you still want it to return the commified number
}

my $number = 32566;
commify_param( $number ); # note called with the number itself as parameter
print "$number\n";
---------------------------

I find the latter solution superior in beauty.

-- 
Jakob Schmidt
http://aut.dk/orqwood
etc.


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

Date: Fri, 09 Feb 2001 00:16:55 GMT
From: tom.hoffmann@worldnet.att.net (Tom Hoffmann)
Subject: Re: How can I modify the value of a variable directly from within a sub?
Message-Id: <slrn986dhq.lj.tom.hoffmann@localhost.localdomain>

On Thu, 8 Feb 2001 18:35:25 -0500, Philip Obbard wrote:

>sub commify
> {
>        local $_  = shift;
         ^^^^^
>        1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
>        return $_;
>    }


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

Date: 08 Feb 2001 16:49:35 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: How can I modify the value of a variable directly from within a sub?
Message-Id: <m166ikistc.fsf@halfdome.holdit.com>

>>>>> "Godzilla!" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:


Godzilla!> Try this syntax:

Godzilla!> $number = ${\&commify($number)};

Operative word being "try" because the dereferencing of the reference
really isn't getting you anything.

This code can be trivially transformed, accomplishing the same thing
with less CPU, to:

        $number = commify($number);

And we're back to where we started.

Kira, I'm happy you're learning about references, but please
understand what you type before you post it!

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 08 Feb 2001 17:11:29 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: How can I modify the value of a variable directly from within a sub?
Message-Id: <3A8343C1.F4AA1CC3@stomp.stomp.tokyo>

Randal wrote:
 
> >>>>> Godzilla! wrote:
 
> Godzilla!> Try this syntax:
 
> Godzilla!> $number = ${\&commify($number)};
 
> Operative word being "try" because the dereferencing of the reference
> really isn't getting you anything.
 
> This code can be trivially transformed, accomplishing the same thing
> with less CPU, to:
 
>         $number = commify($number);
 
> And we're back to where we started.

Works too! I tested both formats.

 
> Kira, I'm happy you're learning about references, but please
> understand what you type before you post it!


Well, you know I like keeping you boys running
around in circles, similar to how my distant
ancestors kept boys running wagon trains around
in circles.

Clearly I misunderstood what was asked.
Thank you for pointing out my error. I will
read this question again for comprehension,
then shoot flaming arrows at covered wagons.

Godzilla! * Dances With Lizards *


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

Date: Fri, 09 Feb 2001 00:14:49 GMT
From: "Sean" <ilogix@hotmail.com>
Subject: How to run Perl on Windows 2000?
Message-Id: <ZDGg6.5392$TR6.165409@sodalite.nbnet.nb.ca>

Having never worked with Perl before, I would really appreciate some advice
on how to run Perl CGI scripts on Windows 2000 server...any recommendations
on interpreters etc? thanks in advance.


-Sean-




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

Date: 9 Feb 2001 00:57:45 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: How to run Perl on Windows 2000?
Message-Id: <slrn986g45.giv.damian@puma.qimr.edu.au>

Thus spake Sean on Fri, 09 Feb 2001 00:14:49 GMT:
>Having never worked with Perl before, I would really appreciate some advice
>on how to run Perl CGI scripts on Windows 2000 server...any recommendations
>on interpreters etc? thanks in advance.
>

You should investigate Indigo Perl (http://www.indigostar.com), which comes
with a fully integrated version of Apache (you knew that you need a web
server to run CGI scripts, yes?). There simply is no comparison between
Apache and IIS/PWS. This also takes the first-timer trauma out of getting
an Apache/mod_perl/Perl installation going properly.

I also recommend you get a copy of _Learning Perl on Win32 Systems_ by
Schwartz, Olson and Christiansen. Also, _Programming Perl_ (the Camel) and
_The Perl Cookbook_. Make sure to get a 3rd edition Camel (which covers
version 5.6). 

HTH, and good luck

Cheers,
Damian
-- 
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,;ord($&)-$:-$;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval;               #requires 5.6.0 ## my first attempt at one of these...


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

Date: Thu, 08 Feb 2001 23:38:13 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Modules/Constants.
Message-Id: <F5Gg6.707$Ld2.4018@eagle.america.net>

On Wed, 07 Feb 2001 17:30:35 +0000, Kelly Dorset
<dorsettest@uk.insight.com> wrote:
>> 
>> >When that script is used by the coms modules, here is the error:
>> >
>> >Bareword "C_LOGIN" not allowed while "strict subs" in use at
>> >        /scripts/include/coms.pm line 95 (#1)
>
>use chunk;  check.
>chunk.pm defines C_LOGIN; 	check.
>C_LOGIN in @chunk::EXPORT;	check.
>
>any more ideas?!

Show the code that fails.  Of course it needs to be suitably trimmed.
The code should exhibit the problem.  

-- 
Garry Williams


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

Date: Fri, 09 Feb 2001 00:48:54 +0000
From: Kelly Dorset <dorsettest@uk.insight.com>
Subject: Re: Modules/Constants.
Message-Id: <3A833E76.BACE6777@uk.insight.com>


<big snip>
> >any more ideas?!
> 
> Show the code that fails.  Of course it needs to be suitably trimmed.
> The code should exhibit the problem.

ok.  starting with the constants file (pebbleconst.pm): 

------------------------------------
sub BEGIN {  
    
    print "Const module imported\n";
    
    require Exporter;
    use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

    @ISA = qw(Exporter);
    @EXPORT = qw(
            C_SYSTEM 
            C_HELLO
            C_PING_REQ 
            C_PING_REPLY 
		<snip>
		);
    @EXPORT_OK = ();
    %EXPORT_TAGS = ( );

}

use constant P_OK => 1;		
use constant C_HELLO => 1;
use constant C_PING_REQ => 2;
use constant C_PING_REPLY => 3;

<snip>

	
return 1;
------------------------------------
The head of the file which imports it correctly:

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

#########################################################################
<snip commented info>
#########################################################################

BEGIN {   
	unshift (@INC, "./include");
}

# Module Declarations
use pebbleconst;
use pebblecurses;
use pebblecoms;	  			# Communications Module (in the include/ dir)
use diagnostics;
use strict;				# Lets pretend we are real programmers


# Variable Declarations
<snip rest of file>

------------------------------------
and then pebblecoms.pm which can't imported it...

------------------------------------
package pebblecoms;

use Socket;						# Standard Perl Sockets module
use diagnostics;
use strict;

use pebbleconst;

#########################
#  Begin sub executed before compile.
sub BEGIN {  
    
    unshift (@INC, "$wd/include");
    print "Coms module imported\n";
    
    require Exporter;
    use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

    @ISA = qw(Exporter);
    @EXPORT = qw( <snip lot of functions> );
    @EXPORT_OK = ();
    %EXPORT_TAGS = ( );

}

<snip functions follow>

<this is the line which fails>

sub requestuserlist() {
	
	my $command = C_USERLIST; 	<-------- Here with the following error
------------------------------------
Bareword "C_USERLIST" not allowed while "strict subs" in use at
        include/pebblecoms.pm line 30 (#1)
    
    (F) With "strict subs" in use, a bareword is only allowed as a
    subroutine identifier, in curly brackets or to the left of the "=>"
symbol.
    Perhaps you need to predeclare a subroutine?	

Make sense?  For the whole set of scripts, take a look at 

http://www.boreworms.com/kelly/pebble/

Thanks for your perseverance!
--
k
kelly@boreworms.com


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

Date: Fri, 09 Feb 2001 00:55:16 +0000
From: Kelly Dorset <dorsettest@uk.insight.com>
Subject: Re: Modules/Constants.
Message-Id: <3A833FF4.80732776@uk.insight.com>



Kelly Dorset wrote:
> 
> <big snip>
> > >any more ideas?!
> >
> > Show the code that fails.  Of course it needs to be suitably trimmed.
> > The code should exhibit the problem.
> 

> ------------------------------------
> package pebblecoms;
> 
> use Socket;                                             # Standard Perl Sockets module
> use diagnostics;
> use strict;
> 
> use pebbleconst;
> 
> #########################
> #  Begin sub executed before compile.
> sub BEGIN {
> 
>     unshift (@INC, "$wd/include");
>     print "Coms module imported\n";
> 

oops.  This bit actually reads:

	unshift (@INC, "./include");
	print "Coms module imported\n";

sorry! 

k


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

Date: Thu, 8 Feb 2001 19:08:43 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: non repeating random numbers
Message-Id: <95vce3$8pm$1@slb0.atl.mindspring.net>

----- Original Message -----
From: "Jason from The Workshop" <jason@cyborgworkshop.com>
Newsgroups: comp.lang.perl.misc
Sent: Thursday, February 08, 2001 10:32 AM
Subject: non repeating random numbers

>> I have need to generate a random number between 1 and 50 without using a
>> number that has already been generated.   Its for an online test for our
>> employees consisting of 50 questions that all need to be asked, but I
want
>> to make sure that they are random and of course no question is asked
twice.

3h 27m of brewhaha later...

> I have a great starting point now, and its obvious that I need to rethink
how Im
> approaching this. Thank you all again.

Following this thread, I understand that you are using a database somewhere
in this process.  In the course of rethinking your solution, consider this.
DON'T USE HARDWIRED LOGIC WHEN THE DATABASE ENGINE CAN DO THE WORK FOR YOU!
Sorry about the shouting - you will thank me for it 6 months from now when
management decides that they want 75 questions instead of 50.

Consider the scenario: Many employees will be asked many questions, and the
database will store the responses.  The SQL to set this up would look
something like this:

<< BEGIN SQL CODE >>

CREATE TABLE employees {
    employee_id INTEGER PRIMARY KEY,
    first_name TEXT,
    last_name TEXT
);

CREATE TABLE questions (
    question_id INTEGER PRIMARY KEY,
    question TEXT
);

CREATE TABLE responses (
    employee_id INTEGER ,
    question_id INTEGER ,
    response TEXT
);

<< END SQL CODE >>

Now assume that we have populated the employees and questions table with
some data.  The number of questions does not matter; let's say 50 for now.
When an employee responds to a question, we add a record to the responses
table.

<< BEGIN PERL CODE >>

my $sql = <<'__SQL__';
INSERT INTO responses (
    employee_id,
    question_id,
    response
)
VALUES (?, ?, ?)
__SQL__

my $sth = $dbh->prepare($sql);
$sth->execute($employee_id, $question_id, $response);

<< END PERL CODE >>

How do we select a list of unanswered questions?  Let the database engine do
the work using a nested select:

<< BEGIN PERL CODE >>

### THIS WON'T WORK WITH MySQL ###

my $sql = <<'__SQL__';
SELECT *
FROM questions
WHERE question_id NOT IN (
    SELECT question_id
    FROM responses
    WHERE employee_id = ?
)
__SQL__

my $sth = $dbh->prepare($sql);
$sth->execute($employee_id);
my $unanswered = $sth->fetchall_arrayref;

<< END PERL CODE >>

If you are using MySQL or another database that does not support nested
selects, things get more complicated....

<< BEGIN PERL CODE >>

### THIS WORKS WITH MySQL ###

# Select the answered questions for employee_id

my $sql = <<'__SQL__';
SELECT question_id
FROM responses
WHERE employee_id = ?
__SQL__

my $sth = $dbh->prepare($sql);
$sth->execute($employee_id);
my $answered = $sth->fetchall_arrayref;
$sth->finish;

# Select the unanswered questions

$sql = 'SELECT * FROM questions';

if (@$answered) {
    $sql .= ' WHERE question_id NOT IN ('
          . join(',', map {$_->[0]} @$answered) . ')';
}

$sth = $dbh->prepare($sql);
$sth->execute;
my $unanswered = $sth->fetchall_arrayref;
$sth->finish;

<< END PERL CODE >>

Now $unanswered contains a reference to an array of unanswered question
records.  The beauty is that you can randomly pick any record, confident
that the question was not already answered because the database told you so.

<< BEGIN PERL CODE >>

if (@$unanswered ) {
    my $rec = $unanswered->[rand(@$unanswered )];
    my ($question_id, $question) = @$rec;
    # Go ahead, ask the question
}
else {
    # The employee has answered them all
}

<< END PERL CODE >>

HTH,

Kurt Stephens





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

Date: Fri, 09 Feb 2001 00:00:18 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Perl, Solaris and readdir64
Message-Id: <mqGg6.722$Ld2.4018@eagle.america.net>

On Thu, 08 Feb 2001 13:25:17 GMT, James Pearson
<j.pearson@ge.ucl.ac.uk> wrote:

[snip]

>I can reproduce the same problem with some C code:
>
>dirp = opendir(dir);
>while ((dp = readdir(dirp)) != NULL)
>  printf("%s ", dp->d_name);
>closedir(dirp);
>
>If I replace readdir() in the C code with readdir64(), then it works OK
>- the contents of the directory in question are printed out ...
>
>So my question is, can I do something similar in perl? Can I force perl
>on Solaris to use readdir64() somehow? Or, is there some sort of
>readdir64 for perl available via a module etc.?

    Rebuild perl with -DUSE_LARGE_FILES

-- 
Garry Williams


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

Date: Thu, 08 Feb 2001 23:45:53 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Problems with Perl on Apache?
Message-Id: <t86bth9p25g802@corp.supernews.com>

Thomas Schulz <dk_sz@hotmail.com> wrote:
> I use ActiveState Perl,  Apache 1.3.14 and Windows 2000 Pro.
> ActiveStatePerl is loacted: D:\webserve\perl\bin.
> Apache is loacted: D:\webserve\Apache.
> Apache is standard setup (with includes enabled though in options - e.g. my
> "echo" and "include" works fine). As a side note I also have PHP working
> (but i think I would like to try Perl instead as it seems to be more
> "programmer" orientated). I use "/" instead of "\" in my Apache httpd.conft
> as that is explicitly written in the help/comments in the config file.

> My problem is. Where "hello world" is supposed to show up.. I get an empty
> line in my output. here is my "test scenario".

> [D:\webserve\apache\htdocs; testperl.shtml;]
> <html>
> <!--#exec cgi="/cgi-bin/helloworld.pl"-->
> </html>

> [D:\webserve\apache\cgi-bin; helloworld.pl;]
> #!c:/webserve/perl/bin
> print "Content-type: text/html\n\n";
> print "Hello, world";

I'm not an expert on embedding Perl into web pages with SSI, but I'd
say you may not need to print headers if you're in the middle of the
page.

Try bringing up a regular CGI in Perl, like this:

$ cat helloweb.pl
print <<EOF;
Content-type: text/html

<html>
<body>
Hello, world!
</body>
</html>
EOF


Then go from there.

> Anyone here has an Apache/Perl config that works? What Perl distribution?
> Could anyone maybe send their httpd.conf (that is, if noone has a suggestion
> that works) where Perl works on?

When you start asking about web server configs, it's time to start
asking in a web server group. 

Chris

-- 
Christopher E. Stith

Where there's a will, there's a lawyer.



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

Date: 8 Feb 2001 23:16:34 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Regular Expression Question
Message-Id: <slrn986a6e.giv.damian@puma.qimr.edu.au>

Thus spake Rudolf Polzer on Thu, 8 Feb 2001 22:00:33 +0100:
>bonjaa@my-deja.com <bonjaa@my-deja.com> schrieb Folgendes:
>> How can I write a regular expression for the following:
>> 
>> One or more A followed by zero or more B followed by one or more C,
>> with the total length (all A's + B's + C's) greater than 10?
>> Simply saying A+B*C+ is apparently not enough, because the final
>> condition (length greater than 10) is not met.
>
>Why a regex?
>length $_ > 10 and /A+B*C+/ will do, too.
                     ^^^^^^
What do YOU call that pattern match, then?

Note that the OP wanted to test the length of the _match_, not the line.
DHA's solution in this thread did this.

Cheers,
Damian
-- 
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,;ord($&)-$:-$;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval;               #requires 5.6.0 ## my first attempt at one of these...


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

Date: 9 Feb 2001 00:13:16 GMT
From: Eli the Bearded <elijah@workspot.net>
Subject: Re: Regular Expression Question
Message-Id: <eli$0102081913@qz.little-neck.ny.us>

In comp.lang.perl.misc, David H. Adler <dha@panix2.panix.com> wrote:
> <bonjaa@my-deja.com> wrote:
> >One or more A followed by zero or more B followed by one or more C,
> >with the total length (all A's + B's + C's) greater than 10?
> >Simply saying A+B*C+ is apparently not enough, because the final
> >condition (length greater than 10) is not met.
> /(A+B*C+)/ and length($1) > 10;

That's what everybody says.

#!/usr/bin/perl -w
$re   = '';
$len  = 10; # minimum length of match
$minA = 1;  # minimum number of As
$minB = 0;  # minimum number of Bs
$minC = 1;  # minimum number of Cs
for($a = $minA; $a <= ($len -1); $a ++) {
  for ($b = $minB; $b < (10 - $a); $b++) {
    $c = $minC + (($len - 1) - $a - $b);
    $re .= "A{$a,}B{$b,}C{$c,}|";
  }
}
chop $re;
$re =~ s/\{1,\}/+/g;
$re =~ s/\{0,\}/*/g;
$re =~ s/\|/\n\t|/g;
$re =~ s/([ABC])/\t$1/g;
print "\t/$re\n\t/x;\n";
__END__ 
:r! perl -x %
	/	A+	B*	C{9,}
	|	A+	B+	C{8,}
	|	A+	B{2,}	C{7,}
	|	A+	B{3,}	C{6,}
	|	A+	B{4,}	C{5,}
	|	A+	B{5,}	C{4,}
	|	A+	B{6,}	C{3,}
	|	A+	B{7,}	C{2,}
	|	A+	B{8,}	C+
	|	A{2,}	B*	C{8,}
	|	A{2,}	B+	C{7,}
	|	A{2,}	B{2,}	C{6,}
	|	A{2,}	B{3,}	C{5,}
	|	A{2,}	B{4,}	C{4,}
	|	A{2,}	B{5,}	C{3,}
	|	A{2,}	B{6,}	C{2,}
	|	A{2,}	B{7,}	C+
	|	A{3,}	B*	C{7,}
	|	A{3,}	B+	C{6,}
	|	A{3,}	B{2,}	C{5,}
	|	A{3,}	B{3,}	C{4,}
	|	A{3,}	B{4,}	C{3,}
	|	A{3,}	B{5,}	C{2,}
	|	A{3,}	B{6,}	C+
	|	A{4,}	B*	C{6,}
	|	A{4,}	B+	C{5,}
	|	A{4,}	B{2,}	C{4,}
	|	A{4,}	B{3,}	C{3,}
	|	A{4,}	B{4,}	C{2,}
	|	A{4,}	B{5,}	C+
	|	A{5,}	B*	C{5,}
	|	A{5,}	B+	C{4,}
	|	A{5,}	B{2,}	C{3,}
	|	A{5,}	B{3,}	C{2,}
	|	A{5,}	B{4,}	C+
	|	A{6,}	B*	C{4,}
	|	A{6,}	B+	C{3,}
	|	A{6,}	B{2,}	C{2,}
	|	A{6,}	B{3,}	C+
	|	A{7,}	B*	C{3,}
	|	A{7,}	B+	C{2,}
	|	A{7,}	B{2,}	C+
	|	A{8,}	B*	C{2,}
	|	A{8,}	B+	C+
	|	A{9,}	B*	C+
	/x;

Elijah
------
generalizing to different numbers of letters left as an exercise


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

Date: Fri, 09 Feb 2001 00:59:41 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: removing empty line
Message-Id: <t86g7ts0t8f62f@corp.supernews.com>

Ted Fiedler <tfiedler@zen.moldsandwich.com> wrote:
> how would I remove an empty line from only the end of a file?

Assuming you really know you have an empty line, that "empty line"
means two newlines with nothing in between and you want to get rid
of both newlins, and that stat() and truncate() work on your system:

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

my $file = 'filename';

my $size = ( stat( $file ) )[7];
truncate( $file, ( $size - 2) ) || die "Can't truncate(): $!\n";
-------------------------

If "empty line" means one newline after the last line with data
or if you want to rid of the one newline and leave the other
from the previous scenario:

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

my $file = 'filename';
my $size = ( stat( $file ) )[7];
truncate( $file, ( $size - 1) ) || die "Can't truncate(): $!\n";
###  notice this change... ^
-------------------------

Testing to see if you have trailing blank lines is left as an
exercise. ;)


Chris

-- 
Christopher E. Stith

It's not the U in UBE that pisses people off. It's the B.
-- Martien Verbruggen in clp.misc



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

Date: Fri, 9 Feb 2001 12:32:52 -0800
From: "Troy Boy" <troyr@vicnet.net.au>
Subject: sending attachments
Message-Id: <jOHg6.146$FU5.4421@ozemail.com.au>

Hi there,
            What module can be used for sending mail attachments?

Does anyone have a pointer to a perldoc i can look at (which explains adding
attachments not just sending plain text messages) or an example?

Cheers

--
----------------------------------------------------------------
Troy Rasiah
Melbourne, Aus




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

Date: 08 Feb 2001 19:40:14 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: sending attachments
Message-Id: <87pugsmy69.fsf@limey.hpcc.uh.edu>

>> On Fri, 9 Feb 2001 12:32:52 -0800,
>> "Troy Boy" <troyr@vicnet.net.au> said:

> Hi there, What module can be used for sending mail
> attachments?

> Does anyone have a pointer to a perldoc i can look at
> (which explains adding attachments not just sending
> plain text messages) or an example?

MIME::Lite is a good place to start

hth
t
-- 
The avalanche has already started.
It is too late for the pebbles to vote.


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

Date: Fri, 09 Feb 2001 01:11:13 +0000
From: JMT <ccx138@coventry.ac.uk>
Subject: sort of about sort
Message-Id: <3A8343B1.A800D6D6@coventry.ac.uk>

Just for interest why wasn't sort implemented so you could use it like
the UNIX sort.
e.g. sort -n @array; to sort numerically. even sort -nr to reverse a
numeric sort.

It would seem to make sense because most of the time you either want to
sort in alpha order or numeric.
Without wanting to change the language is this something that could be
perl 6 ?

John.



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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.

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 V10 Issue 250
**************************************


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