[24211] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6403 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 15 00:06:06 2004

Date: Wed, 14 Apr 2004 21:05:07 -0700 (PDT)
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, 14 Apr 2004     Volume: 10 Number: 6403

Today's topics:
    Re: Changing from C thought to Perl <lv@aol.com>
    Re: fixed the bbs... <matthew.garrish@sympatico.ca>
        how to resolve a variable but disallow interpolation in <prak@cox.net>
    Re: how to resolve a variable but disallow interpolatio <prak@cox.net>
    Re: how to resolve a variable but disallow interpolatio <bmb@ginger.libs.uga.edu>
    Re: how to resolve a variable but disallow interpolatio <mb@uq.net.au.invalid>
    Re: import() override - comments? <mb@uq.net.au.invalid>
    Re: perl's severe lack of in-line comment ability <bmb@ginger.libs.uga.edu>
    Re: perldoc incompetence: perlre /s <lv@aol.com>
    Re: perldoc incompetence: perlre /s <lv@aol.com>
        Two mini-golfish problems <jkrugman@yahbitoo.com>
    Re: Two mini-golfish problems <uri@stemsystems.com>
    Re: Two mini-golfish problems <wherrera@lynxview.com>
        use of uninitialised value <cenxnfu@rpr.nevmban.rqh>
        Variables in an array (Cosmic Cruizer)
    Re: Variables in an array <jurgenex@hotmail.com>
    Re: Where To Go For Classroom Training in CGI? <bmb@ginger.libs.uga.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 14 Apr 2004 21:31:03 -0500
From: l v <lv@aol.com>
Subject: Re: Changing from C thought to Perl
Message-Id: <xtmfc.234$Ho2.7296@dfw-read.news.verio.net>

Rob Perkins wrote:


> Well *my* point is that since Perl can be organized in such a way that
> a C, Pascal, Java, or BASIC programmer could easily see the algorithm,
> people who share code ought to program for readability. That's "why".
> 
> Rob

Agreed!!  I always try to code for when I get paged at 2:30 in the 
morning after a case of beer.  Damn that not logic.  And don't get me 
started on Perl golf.

Len




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

Date: Wed, 14 Apr 2004 21:59:37 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: fixed the bbs...
Message-Id: <90mfc.22388$vF3.1424631@news20.bellglobal.com>


"Robin" <robin @ infusedlight.net> wrote in message
news:c5k1uf$7nc$1@reader2.nmix.net...
>
> > Are you sure you're not the Alaskan electrician in a new life?
> >
> >
> hahahahahahah.....
>
>

Which begs the question, do you even know what you're laughing at?

And please stop stripping attribution lines from your replies...




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

Date: Wed, 14 Apr 2004 20:20:34 -0500
From: Praveen Kallakuri <prak@cox.net>
Subject: how to resolve a variable but disallow interpolation in regex match
Message-Id: <pan.2004.04.15.01.20.34.186836@cox.net>

hi-

one of the lines i am reading from a file contains the following text:

2004-04-13 14:03:06,502 [Thread-1 2] | ServiceCache: adding
'lms.createCertificate'.

i read this line along with others in the file into a list. problem is,
whenever a list element containing this line is used as part of a regex,
perl bombs with:

	Invalid [] range "d-1" in regex; marked by <-- HERE in m/2004-04-13
	14:03:06,502 [Thread-1 <-- HERE  2] | ServiceCache: adding
	'lms.createCertificate'./ at spec_re.pl line 11, <FD> line 1.

it seems that "Thread-1 is being considered as a range in []. i wrote a
smaller test program that can simulate this error and this is how it
looks:

	while (<FD>) {
		chomp;
		if ( $_ !~ $_ ) {
			print "this should never print\n";
		}
	}

perdiag, perlre, or perlop did not help me find a way around this error.
(or i missed it even if it was there.) can someone tell me how i can tell
perl to simply resolve the variable "$_" but not interpolate it during a
match?


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

Date: Wed, 14 Apr 2004 21:29:41 -0500
From: Praveen Kallakuri <prak@cox.net>
Subject: Re: how to resolve a variable but disallow interpolation in regex match
Message-Id: <pan.2004.04.15.02.29.34.903307@cox.net>

On Wed, 14 Apr 2004 21:44:32 -0400, Brad Baxter wrote:

> On Wed, 14 Apr 2004, Praveen Kallakuri wrote:
> 
>> it seems that "Thread-1 is being considered as a range in []. i wrote a
>> smaller test program that can simulate this error and this is how it
>> looks:
>>
>> 	while (<FD>) {
>> 		chomp;
>> 		if ( $_ !~ $_ ) {
>> 			print "this should never print\n";
>> 		}
>> 	}
>>
>> perdiag, perlre, or perlop did not help me find a way around this error.
>> (or i missed it even if it was there.) can someone tell me how i can tell
>> perl to simply resolve the variable "$_" but not interpolate it during a
>> match?
>>
> 
> \Q (perlre), as in: if ( $_ !~ "\Q$_" ) {
> 
> Regards,
> 
> Brad


aah
 that was simple. thanks brad. 



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

Date: Wed, 14 Apr 2004 21:44:32 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: how to resolve a variable but disallow interpolation in regex match
Message-Id: <Pine.A41.4.58.0404142142110.5016@ginger.libs.uga.edu>

On Wed, 14 Apr 2004, Praveen Kallakuri wrote:

> it seems that "Thread-1 is being considered as a range in []. i wrote a
> smaller test program that can simulate this error and this is how it
> looks:
>
> 	while (<FD>) {
> 		chomp;
> 		if ( $_ !~ $_ ) {
> 			print "this should never print\n";
> 		}
> 	}
>
> perdiag, perlre, or perlop did not help me find a way around this error.
> (or i missed it even if it was there.) can someone tell me how i can tell
> perl to simply resolve the variable "$_" but not interpolate it during a
> match?
>

\Q (perlre), as in: if ( $_ !~ "\Q$_" ) {

Regards,

Brad


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

Date: Thu, 15 Apr 2004 11:59:04 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: how to resolve a variable but disallow interpolation in regex match
Message-Id: <c5kq98$hu9$1@bunyip.cc.uq.edu.au>

Praveen Kallakuri wrote:

> hi-
> 
> one of the lines i am reading from a file contains the following text:
> 
> 2004-04-13 14:03:06,502 [Thread-1 2] | ServiceCache: adding
> 'lms.createCertificate'.
> 
> i read this line along with others in the file into a list. problem is,
> whenever a list element containing this line is used as part of a regex,
> perl bombs with:
> 
> 	Invalid [] range "d-1" in regex; marked by <-- HERE in m/2004-04-13
> 	14:03:06,502 [Thread-1 <-- HERE  2] | ServiceCache: adding
> 	'lms.createCertificate'./ at spec_re.pl line 11, <FD> line 1.
> 
> it seems that "Thread-1 is being considered as a range in []. i wrote a
> smaller test program that can simulate this error and this is how it
> looks:
> 
> 	while (<FD>) {
> 		chomp;
> 		if ( $_ !~ $_ ) {
> 			print "this should never print\n";
> 		}
> 	}
> 
> perdiag, perlre, or perlop did not help me find a way around this error.
> (or i missed it even if it was there.) can someone tell me how i can tell
> perl to simply resolve the variable "$_" but not interpolate it during a
> match?

my $re_breaker = "[Thread-1]";
my $check = "THIS CONTAINS [Thread-1] !!!";
print "OK!\n" if $check =~ /\Q$re_breaker\E !!!\z/;
#                           ^^           ^^

\Q quotes everything up to the end of the RE or until a \E is found. The quote 
range is worked out at compile time so you don't have to worry about $re_breaker 
containing \E.

You can also use quotemeta:

my $re_breaker = quotemeta("[Thread-1]");
my $check = "THIS CONTAINS [Thread-1] !!!";
print "OK!\n" if $check =~ /$re_breaker !!!\z/;

MB



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

Date: Thu, 15 Apr 2004 11:43:52 +1000
From: Matthew Braid <mb@uq.net.au.invalid>
Subject: Re: import() override - comments?
Message-Id: <c5kpco$r3t$1@bunyip.cc.uq.edu.au>

Anno Siegel wrote:
<snip>
> I get it now... it's just a matter of timing.  Importing a function
> copies a coderef to *whatever the function is at the moment* to the
> importing package.  Later changing the definition in the exporting
> package won't change the behavior of the already exported function.
> 
> You can redefine import semantics to change that.  A simpler way would
> be to delay imports until all modifications have been done:
> 
>     use T1; # no imports here.  loading may actually not be necessary
>             # at this point.
> 
>     # load behavior-modifying modules
>     use T2;
>     use T3_a_III;
>     # etc...
> 
>     # now import modified functions
>     use T1 qw( t1 t2 s1 s2);
> 
> This would import the functions as modified by T1 and T3_a_III.  If
> that is a possibility, I'd go with that and leave Exporter alone.

Aha. Right, that makes a kind of sense. After having a look at Exporter::Heavy I 
_think_ (there's some complex code in there!) that this shows a difference between:

	eval "sub $caller\::$func { goto &$class\::$func }";

and
	no strict 'refs';
	*{"$caller\::$func"} = \&{"$class\::$func"};

It also turns out that for my program at least it is easier to override Exporter 
than juggle the order of imports due to the fact that some of the overrides also 
internally use the library functions and I want them to notice the updates too 
(an extra twist I forgot to add before).

ANd after a little testing I've improved the new import function to not use an 
eval at all. Instead, it does:

	no strict 'refs';
	*{"$caller\::$func"} = sub { goto &{"$class\::$func"} };

Same effect, no eval. Acts like a 'soft' version of Exporter.... Hmmm, maybe 
there's a package in that....

MB



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

Date: Wed, 14 Apr 2004 21:54:43 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: perl's severe lack of in-line comment ability
Message-Id: <Pine.A41.4.58.0404142149070.5016@ginger.libs.uga.edu>

On Thu, 15 Apr 2004, Dan Jacobson wrote:

> I don't know what you guys are talking about with /* */. It's not on
> perldoc perlsyn, and
> $ perl -we 'print 5 /* c style single line comment */ ,7'
> Bareword found...

No, it's not there.  Perl doesn't have in-line comments.  No one is going
to apologize for that.

Sorry,

Brad


PS: I'm ignoring (?#text) in regexen.  As I usually do.


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

Date: Wed, 14 Apr 2004 21:42:27 -0500
From: l v <lv@aol.com>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <dEmfc.235$Ho2.7307@dfw-read.news.verio.net>

Vetle Roeim wrote:

> * l. v.
> 
>>Vetle Roeim wrote:
>>
>>
>>>* Michele Dondi
>>>
> 
> [...]
> 
>>>>Am I the only one seeing the contradiction?!?
>>>
>>>  What he does in the privacy of his own home is none of our
>>>  business.  ;-)
>>>
>>
>>I thought he was talking about himself as well.
> 
> 
>   Um... Who are you talking about? Michele or Lee?
> 
> 

I was talking about the OP and what he/she wants to do to Perl coders 
 ... and it was a bad joke.  I no way was I referring to Michele or Lee, 
sorry if it appeared I was.

Len



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

Date: Wed, 14 Apr 2004 21:47:06 -0500
From: l v <lv@aol.com>
Subject: Re: perldoc incompetence: perlre /s
Message-Id: <AImfc.237$Ho2.7307@dfw-read.news.verio.net>

l v wrote:

> Vetle Roeim wrote:
> 
>> * l. v.
>>
>>> Vetle Roeim wrote:
>>>
>>>
>>>> * Michele Dondi
>>>>
>>
>> [...]
>>
>>>>> Am I the only one seeing the contradiction?!?
>>>>
>>>>
>>>>  What he does in the privacy of his own home is none of our
>>>>  business.  ;-)
>>>>
>>>
>>> I thought he was talking about himself as well.
>>
>>
>>
>>   Um... Who are you talking about? Michele or Lee?
>>
>>
> 
> I was talking about the OP and what he/she wants to do to Perl coders 
> ... and it was a bad joke.  I no way was I referring to Michele or Lee, 
> sorry if it appeared I was.
> 
> Len
> 

cut and pasted wrong
I no way was I referring to Michele !!  Lee was the OP

Len



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

Date: Thu, 15 Apr 2004 03:31:18 +0000 (UTC)
From: J Krugman <jkrugman@yahbitoo.com>
Subject: Two mini-golfish problems
Message-Id: <c5kvm6$oi3$1@reader2.panix.com>



OK, here's a little problem that I'd like to propose in the Perl
golf (mini-golf?) vein.

Given a string $x that we may assume contains no newline characters,
split it into chunks of $n characters long separated my newlines.
E.g. if $n == 2,

               'fu'
  'fubar' ---> 'ba'
               'r'

What's the most succinct Perl to achive this end-result?

Thanks,

jill

-- 
To  s&e^n]d  me  m~a}i]l  r%e*m?o\v[e  bit from my a|d)d:r{e:s]s.



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

Date: Thu, 15 Apr 2004 03:38:59 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Two mini-golfish problems
Message-Id: <x7ad1dc3l9.fsf@mail.sysarch.com>

>>>>> "JK" == J Krugman <jkrugman@yahbitoo.com> writes:

  JK> OK, here's a little problem that I'd like to propose in the Perl
  JK> golf (mini-golf?) vein.

  JK> Given a string $x that we may assume contains no newline characters,
  JK> split it into chunks of $n characters long separated my newlines.
  JK> E.g. if $n == 2,

<untested> and prolly long but at least it is clear

my @lines = map "$_\n", $x =~ /(.{1,2})/g ;

or use s/// if you don't mind destroying $x

	$x =~ s/(.{1,2})/$1\n/g ;
	$x =~ s/(.{1,$n})/$1\n/g ;

that uses greediness to handle any remainder chunk

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 14 Apr 2004 21:51:06 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: Two mini-golfish problems
Message-Id: <29mdnb80IOQ4m-Pd4p2dnA@adelphia.com>

J Krugman wrote:

> OK, here's a little problem that I'd like to propose in the Perl
> golf (mini-golf?) vein.
> 

> Given a string $x that we may assume contains no newline characters,
> split it into chunks of $n characters long separated my newlines.
> E.g. if $n == 2,
> 
>                'fu'
>   'fubar' ---> 'ba'
>                'r'
> 
> What's the most succinct Perl to achive this end-result?

Remember: succint, maintainable, fast. Choose 2 of 3 :)

anyhow...

$x = 'fubar';
$x=~s/(..)/$1\n/g;print $x;



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

Date: Wed, 14 Apr 2004 20:39:10 -0700
From: Cognition Peon <cenxnfu@rpr.nevmban.rqh>
Subject: use of uninitialised value
Message-Id: <Pine.GSO.4.50.0404142033270.19603-100000@ece2.ece.arizona.edu>


I am getting desried output for the following piece, but -w switch to perl
is reporting that 'if />.*/' in the code uses uninitialized value. The
input file follows. I also tried another combination of if statement, but
the error still persists. 'if /^(>.*)/' accessing the match from $1.


while(<FILE>) {
        my ($header, ) = ();
        next if /^$/;
        chomp;

        if (/>.*/) { # Use of uninitialized value here
                $header = $&;
                $bin = (split('[_-]', $header))[1];
                push @{$bins{$bin}}, $header;
        } else {
                $fasta{$header} = $_;
        }
}
close(FILE);

>uTSLPxov-bin3-005614
TAATTTAGAAAAAATCATGGCCCCACATTTTGTCAAGGATTCTTACAAGTGATATTCAAATATCTAATCTAAAATGATTATCTAGAAATTGGCACATTCTAAGTGTGCAGATGCTGATGAGGAGCAGGTATTGATAGACAGCGCGTTATG[C/T]GTCAAAGGATGTCTATCCTTTGCTAAAGTGTTACTCTGACTATGCTGTAAAAAGCAGGAGGTAAGAGCTTAAGAAAGAGGAGTAAAAGAGATAATTCTCATGAGATAAACTCTAAGGATTGATGCTGTGCTCCAGGTCTCTCCAGTGTTT

>uTSLPxov-bin4-005119
AAAGAGCCCGTAGGCGTTTAGGTGTTATATAGTGCAGCCAGAAAGCTCTGGAGCATCAGGGAGACTCCAACTTAAGGCAACAGCATGGGTGAATAAGGGCTTCCTGTGGACTGGCAATGAGAGGCAAAACCTGGTGCTTGAGCACTGGCC[C/T]CTAAGGCAGGCCTTACAGATCTCTTACACTCGTGGTGGGAAGAGTTTAGTGTGAAACTGGGGTGGAATTGGGTGTCCACGTATGTTCCCTTTTGCCTTACTATATGTTCTGTCAGTTTCTTTCAGGAAAATCTTCATCTTACAACTTGTA
>uTSLPxov-bin4-006317
ACCCTCTTTGTCCTATTTTTCTTTCTTCCAGACCAAAAGTACCGAGTTCAACAACACCGTCTCTTGTAGCAATCGGGTGAGTAGAGAGTTCAGTGCTGCTGGCTTTCTCCAGGGAGACGCCAGGCATTTTGGAGAGGGAGTATCCTGCTA[C/T]GTGCAGAACTCCGAGAGGTGCCTGGGCTCCGGGACGCCGCCGCCGGGGGAAAGGGGACATCTGGGCTGTCAGAGCGGGGCTGCGCCTAGCTTGGGACAACACTTCTGTTCCAATTTAGGGAGAGGAAGTCTCTATCCGGAGGAAAGGCAA




-- 
echo cenxnfu@rpr.nevmban.rqh | perl -pe 'y/a-z/n-za-m/'

Q: How many CPU's does it take to execute a job?
A: Four. Three to hold it down, and one to rip its head off.
-------------------------------------
Printed using 100% recycled electrons


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

Date: Thu, 15 Apr 2004 03:47:05 GMT
From: XXjbhuntxx@white-star.com (Cosmic Cruizer)
Subject: Variables in an array
Message-Id: <Xns94CBD363DB310ccruizermydejacom@64.164.98.49>

I would like to create something similar to the following:

my $sm1 = "apple";
my $sm2 = "orange";
my $sm3 = "lemon";

my @sm_list = qw($sm1 $sm2 $sm3); 

foreach (@sm_list) {
  print $_;
}

I would like the output to be: apple orange lemon

I understand why this does not work, but is there some way I can change the 
print statement to print get my desired output?


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

Date: Thu, 15 Apr 2004 04:02:34 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Variables in an array
Message-Id: <uPnfc.34506$F9.1129@nwrddc01.gnilink.net>

Cosmic Cruizer wrote:
> I would like to create something similar to the following:
>
> my $sm1 = "apple";
> my $sm2 = "orange";
> my $sm3 = "lemon";
>
> my @sm_list = qw($sm1 $sm2 $sm3);
>
> foreach (@sm_list) {
>   print $_;
> }
>
> I would like the output to be: apple orange lemon
>
> I understand why this does not work, but is there some way I can
> change the print statement to print get my desired output?

Unfortunately there is, please check the FAQ for "How can I use a variable
as a variable name?"
A much better solution is to use a more appropriate data structure:

use strict;
use warnings;
my %fruit = (sm1 => 'apple',
        sm2 => 'orange',
        sm3 => 'lemon');
my @sm_list = qw(sm1 sm2 sm3);
foreach (@sm_list) {
   print $fruit{$_};
}

jue




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

Date: Wed, 14 Apr 2004 21:27:32 -0400
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Where To Go For Classroom Training in CGI?
Message-Id: <Pine.A41.4.58.0404142119260.12546@ginger.libs.uga.edu>

On Wed, 14 Apr 2004, Sherm Pendley wrote:

> JC wrote:
>
> > I'm not sure that the use of PERL signals incompetence, though
>
> You're right - that was a bad choice of terms on my part.
>
> > ; rather, it might more identify an outsider (or newbie).
>
> Consider what you're saying here in the context of the original question
> about finding training. Would you consider someone who's a newbie, an
> outsider to the community who hasn't read the FAQ, to be a well qualified
> Perl trainer? I wouldn't.

I've just looked at a pile of resumes, some of which indicate that the
individual is proficient in PERL.  I'm thinking probably not.  I'm not so
close-minded as to base a decision on that, but it certainly gives me
pause.

Regards,

Brad


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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