[32003] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3267 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jan 26 00:09:23 2011

Date: Tue, 25 Jan 2011 21:09:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 25 Jan 2011     Volume: 11 Number: 3267

Today's topics:
    Re: Help reading Perl - what is this doing? <kyla.r.davis@gmail.com>
    Re: Help reading Perl - what is this doing? <uri@StemSystems.com>
    Re: Help reading Perl - what is this doing? <sherm.pendley@gmail.com>
    Re: Help with Perl Q (Finding Largest & Smallest number <pradeep.bg@gmail.com>
    Re: Help with Perl Q (Finding Largest & Smallest number <jurgenex@hotmail.com>
    Re: Help with Perl Q <jurgenex@hotmail.com>
    Re: Help with Perl Q <tadmc@seesig.invalid>
    Re: Help with Perl Q <ralph@happydays.com>
    Re: Help with Perl Q <cartercc@gmail.com>
    Re: Help with Perl Q <pradeep.bg@gmail.com>
        Is there an ARRAY designator for REGEX vals? <spydox@gmail.com>
    Re: Is there an ARRAY designator for REGEX vals? <sherm.pendley@gmail.com>
    Re: Learning Object Oriented Programming (newbie) <tzz@lifelogs.com>
    Re: Learning Object Oriented Programming (newbie) <skye.shaw@gmail.com>
        NSIS and Strawberry Perl, delivering an application <cartercc@gmail.com>
    Re: Perl and Linux greymausg@mail.com
    Re: Perl and Linux <Luuk@invalid.lan>
        Quotemeta & Regex question re-posted as plain text <ela@yantai.org>
    Re: Quotemeta & Regex question re-posted as plain text <jurgenex@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 25 Jan 2011 12:39:29 -0800 (PST)
From: caelica <kyla.r.davis@gmail.com>
Subject: Re: Help reading Perl - what is this doing?
Message-Id: <f7cbf28c-af3e-4c54-af3d-254b8a39fc90@z26g2000prf.googlegroups.com>

On Jan 24, 4:59=A0pm, Jim Gibson <jimsgib...@gmail.com> wrote:
> In article
> <0941f151-5445-4549-bc73-e26873df4...@d1g2000pra.googlegroups.com>,
>
> caelica <kyla.r.da...@gmail.com> wrote:
> > New to Perl and trying to read my way through some Perl scripts. =A0I'v=
e
> > looked up the individual characters to find their meaning but I can't
> > put it together.
>
> > Can anyone tell me what these lines are doing to the variable?
>
> > $var_in_for_loop[i] =3D~ s/^\?+$//;
> > $var_in_for_loop[i] =3D~ s/^ +//;
>
> Both of those lines would seem to contain an error. I say "seem"
> because the lines will compile and execute, but they don't make sense.
>
> You likely mean this:
>
> $var_in_for_loop[$i] =3D~ s/^\?+$//;
> $var_in_for_loop[$i] =3D~ s/^ +//;
>
> Notice that I have added a '$' character before each 'i'. $i is a
> scalar variable that can contain, for example, an integer index into
> the @var_in_for_loop array. The original 'i' is a "bareword", that may
> be interpreted as a character string and converted into the value zero,
> which is probably not what you want.
>
> The variable $var_in_for_loop[$i] is a member of the array
> @var_in_for_loop (with index starting from zero).
>
> The first line looks for a string consisting only of one or more '?'
> characters and, if it finds such a string, deletes all of the '?'
> characters, replacing them with nothing, resulting in an empty string.
>
> The second lines looks for a string with one or more spaces at the
> beginning of the string and removes them, leaving any subsequent
> characters as they are.
>
> To read these lines you need to know that:
>
> =3D~ is the binding operator that applies the substitution operator to
> the right of the binding operator to the variable to its left.
>
> s/// is the substitution operator.
>
> The first pair of // encloses the pattern (regular expression, or RE).
>
> The second pair of // encloses the replacement string, empty in both of
> these cases.
>
> ^ is the RE "meta-character" that matches "start-of-string".
>
> \? is a literal question-mark character (escaped because an unescapoed
> '?' is a meta-character).
>
> + is a meta-character meaning "one or more of the preceding character".
>
> $ is a meta-character matching "the end of the string".
>
> --
> Jim Gibson

Yes Jim, you are correct.  I was typing those lines in from my code
and accidentally left out the $ in front of i in the variable.  They
are correct in the code, typo on my part.  Thank you for the
explanation!  I could see the end result but needed a breakdown of the
line to understand.  This is helpful.

Kyla


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

Date: Tue, 25 Jan 2011 16:25:25 -0500
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Help reading Perl - what is this doing?
Message-Id: <877hdsisl6.fsf@quad.sysarch.com>

>>>>> "c" == caelica  <kyla.r.davis@gmail.com> writes:

  c> Yes Jim, you are correct.  I was typing those lines in from my code
  c> and accidentally left out the $ in front of i in the variable.  They
  c> are correct in the code, typo on my part.  Thank you for the
  c> explanation!  I could see the end result but needed a breakdown of the
  c> line to understand.  This is helpful.

then learn this lesson: never retype code for posting. always cut/paste
it so we can read exactly what you are running.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


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

Date: Tue, 25 Jan 2011 16:34:31 -0500
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Help reading Perl - what is this doing?
Message-Id: <m2aaiobrbs.fsf@sherm.shermpendley.com>

"Uri Guttman" <uri@StemSystems.com> writes:

>>>>>> "c" == caelica  <kyla.r.davis@gmail.com> writes:
>
>   c> Yes Jim, you are correct.  I was typing those lines in from my code
>   c> and accidentally left out the $ in front of i in the variable.  They
>   c> are correct in the code, typo on my part.  Thank you for the
>   c> explanation!  I could see the end result but needed a breakdown of the
>   c> line to understand.  This is helpful.
>
> then learn this lesson: never retype code for posting. always cut/paste
> it so we can read exactly what you are running.

 ... as the posting guidelines suggest, I might add. :-)

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Tue, 25 Jan 2011 06:54:17 -0800 (PST)
From: Deepu <pradeep.bg@gmail.com>
Subject: Re: Help with Perl Q (Finding Largest & Smallest numbers & getting difference)
Message-Id: <871ae8d5-357b-4a3a-b8b1-7cd12f904c28@k14g2000pre.googlegroups.com>

> If you meant to ask something different then maybe you want to explain
> how e.g.
> =A0 =A0 =A0 =A0 1.60 -> temp8
> is related to temp8 or temp8->temp2 or 0.42 or anything at all in your
> desired output.

Sorry for my incomplete explanation..basically the file is an output
of some calculation and then i need to get the difference from each of
the largest value with each of the smallest value in the file.

For example:
* temp7, temp8 & temp9 are largest value in the file & temp1 & temp2
are smallest values in the file.
* Next i need to get the difference & print out as below.
* File has multiple largest & smallest numbers.

temp7 - temp1 -> 0.42
temp7 - temp2 -> 0.42

Thanks..






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

Date: Tue, 25 Jan 2011 18:34:39 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help with Perl Q (Finding Largest & Smallest numbers & getting difference)
Message-Id: <9g1vj655fuskjltlv9hsoh4kp8dgkoopbl@4ax.com>

Deepu <pradeep.bg@gmail.com> wrote:
>> If you meant to ask something different then maybe you want to explain
>> how e.g.
>>         1.60 -> temp8
>> is related to temp8 or temp8->temp2 or 0.42 or anything at all in your
>> desired output.
>
>Sorry for my incomplete explanation..basically the file is an output
>of some calculation and then i need to get the difference from each of
>the largest value with each of the smallest value in the file.

That difference would always be the same value because even if there are
multiple instances of largest and smallest, their values and thus their
differences will always be the same.

So, what you are really looking for is
a) the smallest value and the largest value(!) of your list
b) the difference between them
c) a list of all identifiers which have the largest value
d) a list of all identifiers which have the smallest value

Each of these is easy enough to compute.

>For example:
>* temp7, temp8 & temp9 are largest value in the file & temp1 & temp2
>are smallest values in the file.
>* Next i need to get the difference & print out as below.
>* File has multiple largest & smallest numbers.
>
>temp7 - temp1 -> 0.42
>temp7 - temp2 -> 0.42

And then simply create an output of all combinations from list of
largest and list of smallest identifiers and print the pre-computed
difference at the end of each line.

jue


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

Date: Tue, 25 Jan 2011 03:24:51 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help with Perl Q
Message-Id: <a8ctj65dfkoh9fbj3tl98i17p4vngg88td@4ax.com>

Deepu <pradeep.bg@gmail.com> wrote:
>Hi All,
>
>I have a problem and would like to get some ideas on the
>implementation.
>
>I have a file with contents as:
>
>1.18 -> temp1
>1.18 -> temp2
>1.26 -> temp3
>1.34 -> temp4
>1.40 -> temp5
>1.50 -> temp6
>1.60 -> temp7
>1.60 -> temp8
>1.60 -> temp9
>
>I need to get the output as:
>
>temp9 -> temp1 => 0.42
>temp9 -> temp2 => 0.42
>
>temp8 -> temp1 => 0.42
>temp8 -> temp2 => 0.42
>
>temp7 -> temp1 => 0.42
>temp7 -> temp2 => 0.42

Trivial:

	use warnings; use strict;
	for my $i (9, 8, 7) {
	    for my $j (1, 2) {
		print "temp$ i-> temp$j => 0.42\n";
	    }
	    print "\n";
	}

And you don't even need the input from that file.

If you meant to ask something different then maybe you want to explain
how e.g. 
	1.60 -> temp8
is related to temp8 or temp8->temp2 or 0.42 or anything at all in your
desired output.

jue


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

Date: Tue, 25 Jan 2011 08:40:19 -0600
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: Help with Perl Q
Message-Id: <slrnijtnvs.dcg.tadmc@tadbox.sbcglobal.net>

Deepu <pradeep.bg@gmail.com> wrote:

> Subject: Help with Perl Q


Please put the subject of your article in the Subject of your article.


> Thanks for your time...


Yeah, right.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

Date: Tue, 25 Jan 2011 10:40:35 -0500
From: Ralph Malph <ralph@happydays.com>
Subject: Re: Help with Perl Q
Message-Id: <b4f08$4d3eeef3$ce534406$17959@news.eurofeeds.com>

On 1/25/2011 9:40 AM, Tad McClellan wrote:
> Deepu<pradeep.bg@gmail.com>  wrote:
>
>> Subject: Help with Perl Q
>
>
> Please put the subject of your article in the Subject of your article.
I guess auto-posting your horseshit "posting guidelines" does a lot of
good!
ha ha ha
0\/\/ned!


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

Date: Tue, 25 Jan 2011 08:49:42 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Help with Perl Q
Message-Id: <65f2b992-6a24-4925-b328-21f57e9e3a9e@k30g2000vbn.googlegroups.com>

On Jan 25, 2:33=A0am, Deepu <pradeep...@gmail.com> wrote:
> Hi All,
>
> I have a problem and would like to get some ideas on the
> implementation.

Script and output below. This is a crude, inelegant solution, but it
may be all you need. The key is using parallel arrays to calculate and
print your results. The only trick is to build the parallel arrays,
and that took me a minute or two.

SCRIPT:
#! perl
use strict;
use warnings;

my %temps;
my (@lowest, @highest);
my $lowest =3D 1000000;
my $highest =3D -1000000;
while (<DATA>)
{
    next unless /\d/;
    chomp;
    my ($temp, $name) =3D split(/ -> /, $_);
    $lowest =3D $temp if $temp < $lowest;
    $highest =3D $temp if $temp > $highest;
    $temps{$name} =3D $temp;
}

foreach my $k (sort keys %temps)
{
    push (@lowest, "$k:$temps{$k}") if $temps{$k} =3D=3D $lowest;
    unshift (@highest, "$k:$temps{$k}") if $temps{$k} =3D=3D $highest;
}

#print "lowest: $lowest [@lowest], highest: $highest [@highest]\n";

foreach my $high (@highest)
{
    my ($name1, $temp1) =3D split(/:/, $high);
    foreach my $low (@lowest)
    {
        my ($name2, $temp2) =3D split(/:/, $low);
        printf("%s minus %s is %f\n", $name1, $name2, $temp1 -
$temp2);
    }
    print "\n";
}

exit(0);

__DATA__
1.18 -> temp1
1.18 -> temp2
1.26 -> temp3
1.34 -> temp4
1.40 -> temp5
1.50 -> temp6
1.60 -> temp7
1.60 -> temp8
1.60 -> temp9

OUTPUT:

>perl perlQ.plx
temp9 minus temp1 is 0.420000
temp9 minus temp2 is 0.420000

temp8 minus temp1 is 0.420000
temp8 minus temp2 is 0.420000

temp7 minus temp1 is 0.420000
temp7 minus temp2 is 0.420000


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

Date: Tue, 25 Jan 2011 09:23:50 -0800 (PST)
From: Deepu <pradeep.bg@gmail.com>
Subject: Re: Help with Perl Q
Message-Id: <10e5dfe2-f65b-415b-a673-4ddf84a926bf@v17g2000prc.googlegroups.com>

On Jan 25, 8:49=A0am, ccc31807 <carte...@gmail.com> wrote:
> On Jan 25, 2:33=A0am, Deepu <pradeep...@gmail.com> wrote:
>
> > Hi All,
>
> > I have a problem and would like to get some ideas on the
> > implementation.
>
> Script and output below. This is a crude, inelegant solution, but it
> may be all you need. The key is using parallel arrays to calculate and
> print your results. The only trick is to build the parallel arrays,
> and that took me a minute or two.
>
> SCRIPT:
> #! perl
> use strict;
> use warnings;
>
> my %temps;
> my (@lowest, @highest);
> my $lowest =3D 1000000;
> my $highest =3D -1000000;
> while (<DATA>)
> {
> =A0 =A0 next unless /\d/;
> =A0 =A0 chomp;
> =A0 =A0 my ($temp, $name) =3D split(/ -> /, $_);
> =A0 =A0 $lowest =3D $temp if $temp < $lowest;
> =A0 =A0 $highest =3D $temp if $temp > $highest;
> =A0 =A0 $temps{$name} =3D $temp;
>
> }
>
> foreach my $k (sort keys %temps)
> {
> =A0 =A0 push (@lowest, "$k:$temps{$k}") if $temps{$k} =3D=3D $lowest;
> =A0 =A0 unshift (@highest, "$k:$temps{$k}") if $temps{$k} =3D=3D $highest=
;
>
> }
>
> #print "lowest: $lowest [@lowest], highest: $highest [@highest]\n";
>
> foreach my $high (@highest)
> {
> =A0 =A0 my ($name1, $temp1) =3D split(/:/, $high);
> =A0 =A0 foreach my $low (@lowest)
> =A0 =A0 {
> =A0 =A0 =A0 =A0 my ($name2, $temp2) =3D split(/:/, $low);
> =A0 =A0 =A0 =A0 printf("%s minus %s is %f\n", $name1, $name2, $temp1 -
> $temp2);
> =A0 =A0 }
> =A0 =A0 print "\n";
>
> }
>
> exit(0);
>
> __DATA__
> 1.18 -> temp1
> 1.18 -> temp2
> 1.26 -> temp3
> 1.34 -> temp4
> 1.40 -> temp5
> 1.50 -> temp6
> 1.60 -> temp7
> 1.60 -> temp8
> 1.60 -> temp9
>
> OUTPUT:
>
> >perl perlQ.plx
>
> temp9 minus temp1 is 0.420000
> temp9 minus temp2 is 0.420000
>
> temp8 minus temp1 is 0.420000
> temp8 minus temp2 is 0.420000
>
> temp7 minus temp1 is 0.420000
> temp7 minus temp2 is 0.420000


Thanks a lot your response..


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

Date: Tue, 25 Jan 2011 11:17:23 -0800 (PST)
From: Spydo <spydox@gmail.com>
Subject: Is there an ARRAY designator for REGEX vals?
Message-Id: <efea2c65-24cf-4014-889d-519d2f679e4d@a10g2000vby.googlegroups.com>

I vaguely recall this was asked before so I apologize if its a repeat
but I can't find an answer. Which implies the answer is no. But I'm
hoping I'm wrong..

We have the convenience of @_ defined as( $_[0], $_[1], ... ,$_[-1] )

is there a similar array for @something  defined as ( $1, $2, $3, ... ,
$n )

?

if not, it would be useful, since on-occasion I find I need ( $1, $2,
$3, ... ,$n )  which would be more concisely written @something..



Respectfully,
Mr S


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

Date: Tue, 25 Jan 2011 15:15:56 -0500
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Is there an ARRAY designator for REGEX vals?
Message-Id: <m2ipxcbuyr.fsf@sherm.shermpendley.com>

Spydo <spydox@gmail.com> writes:

> if not, it would be useful, since on-occasion I find I need ( $1, $2,
> $3, ... ,$n )  which would be more concisely written @something..

In list context, the match operator returns a list of matched subexp-
ressions, as in:

  my @matches = $string =~ m/(foo)(bar)(baz)/;

  my ($foo, $bar, $baz) = m/(foo)(bar)(baz)/;

Also possibly of interest, after a successful match, @- and @+ contain
the start and end offsets of the match and any submatches.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Tue, 25 Jan 2011 08:33:55 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Learning Object Oriented Programming (newbie)
Message-Id: <874o8x59yk.fsf@lifelogs.com>

On Mon, 24 Jan 2011 12:29:54 -0500 "Uri Guttman" <uri@StemSystems.com> wrote: 

>>>>>> "SS" == Skye Shaw!@#$ <skye.shaw@gmail.com> writes:
SS> On Jan 24, 12:02 am, "Skye Shaw!@#$" <skye.s...@gmail.com> wrote:
>>> On Jan 23, 10:45 pm, "Uri Guttman" <u...@StemSystems.com> wrote:
>>> 
>>> > have you tested that? really tested it? it will not do what you think it
>>> > does. classic abuse of ?:.
>>> 
>>> What do I think it does?

SS> Well, aside from my typo:  @_ ? $self->{farm} = shift : $self->{farm};
SS> how is it abuse?

UG> well, it doesn't WORK. try it. really try it out. and it is abuse for
UG> that reason.

This line is near the top of my list for misguided
almost-getting-it-but-not-quite use of Perl.  It's a mess of techniques
that may have made sense separately[1] but joined they create an unholy
union that will burn in my retinas for a while.  Otherwise, it was OK.

Ted

[1] OP: you probably want "$self->{farm} = shift if @_;"


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

Date: Tue, 25 Jan 2011 09:57:50 -0800 (PST)
From: "Skye Shaw!@#$" <skye.shaw@gmail.com>
Subject: Re: Learning Object Oriented Programming (newbie)
Message-Id: <c30bdfea-5c43-4bee-a3f6-196c1feb12e3@8g2000prt.googlegroups.com>

> On Mon, 24 Jan 2011 12:29:54 -0500 "Uri Guttman" <u...@StemSystems.com> wrote:
>
> >>>>>> "SS" == Skye Shaw!@#$ <skye.s...@gmail.com> writes:
>
> SS> On Jan 24, 12:02 am, "Skye Shaw!@#$" <skye.s...@gmail.com> wrote:
>
> >>> On Jan 23, 10:45 pm, "Uri Guttman" <u...@StemSystems.com> wrote:
>
> >>> > have you tested that? really tested it? it will not do what you think it
> >>> > does. classic abuse of ?:.
>
> >>> What do I think it does?
>
> SS> Well, aside from my typo:  @_ ? $self->{farm} = shift : $self->{farm};
> SS> how is it abuse?
>
> UG> well, it doesn't WORK. try it. really try it out. and it is abuse for
> UG> that reason.
>
> This line is near the top of my list for misguided
> almost-getting-it-but-not-quite use of Perl.  It's a mess of techniques
> that may have made sense separately[1] but joined they create an unholy
> union that will burn in my retinas for a while.

Please elaborate.




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

Date: Tue, 25 Jan 2011 08:59:55 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: NSIS and Strawberry Perl, delivering an application
Message-Id: <1b612b75-ef42-4280-8535-b9c1fa91f61a@u13g2000prd.googlegroups.com>

Ben Morrow mentioned fairly recently using NSIS to deliver a Perl app
(on Windows) and someone else mentioned using Strawberry Perl with it.

Has anyone here actually done this? If so, and if you don't mind being
available for a little hand holding, please contact me off line at
'ccc31807' at yahoo dot com.

This will be my first attempt, and I don't mind documenting the steps,
but I'm a little daunted at the prospect of dipping my toe in the
water.

Thanks, CC.


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

Date: 25 Jan 2011 20:54:03 GMT
From: greymausg@mail.com
Subject: Re: Perl and Linux
Message-Id: <slrnijudnr.5fu.greymausg@gmaus.org>

On 2011-01-23, sln@netherlands.com <sln@netherlands.com> wrote:
> On Sun, 23 Jan 2011 10:50:58 -0600, Ignoramus4862 <ignoramus4862@NOSPAM.4862.invalid> wrote:
>
>>On 2011-01-22, E.D.G. <edgrsprj@ix.netcom.com> wrote:
>>> The ActiveState version of Perl runs quite well with Windows.  Can anyone 
>>> comment on how well it runs with Linux?
>>>
>>> Is Linux actually the preferred operating system for Perl?  Or might that be 
>>> Unix?
>>>
>>
>>perl is usually a standard part of Linux distributions. I would say
>>that it runs better on Linux than on Windows.
>>
> Even if it was compiled for Windows?
>
> -sln

Ehhhh, _NO_

Course, you could try using it under Wine...


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

Date: Tue, 25 Jan 2011 22:10:50 +0100
From: Luuk <Luuk@invalid.lan>
Subject: Re: Perl and Linux
Message-Id: <prq318-lfh.ln1@luuk.invalid.lan>

On 23-01-11 17:50, Ignoramus4862 wrote:
> On 2011-01-22, E.D.G. <edgrsprj@ix.netcom.com> wrote:
>> The ActiveState version of Perl runs quite well with Windows.  Can anyone 
>> comment on how well it runs with Linux?
>>
>> Is Linux actually the preferred operating system for Perl?  Or might that be 
>> Unix?
>>
> 
> perl is usually a standard part of Linux distributions. I would say
> that it runs better on Linux than on Windows.
> 
> i

But WHAT does it doe better on Linux than on Windows?

If its only 'running' than ik could also buy meself a pair of nike's...

-- 
Luuk


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

Date: Wed, 26 Jan 2011 10:46:33 -0800
From: "ela" <ela@yantai.org>
Subject: Quotemeta & Regex question re-posted as plain text
Message-Id: <iho1sf$fmd$1@ijustice.itsc.cuhk.edu.hk>

I wish pasting the content won't make any character loss but my program and 
data is like the following:

You can see data1 is simply the substring of data2 and therefore I pass the 
file containing data2 as $file1 and then the longer one as $file1 to my perl 
program. $file1 content will be split by the delimiter tab and to check 
against whether it contains any pattern that exist in data1.

I appreciate your advice about what's going wrong as I cannot simply replace 
all the special characters in the file in advance.


<DATA1>
NZ_AAJX02000024.1|_revcom_54779..55912|beta-lactamase

<DATA2>
NZ_AAJX02000024.1|_revcom_54779..55912|beta-lactamase precursor|identified 
by match to protein family HMM PF00144 A


#PROGRAM

#!/usr/bin/perl
use warnings; use strict;

my ( $file1, $file2, $outname) = @ARGV;

my $name = "wholeline";
my $cmpsout = "";

if ($outname ne "") {
 $cmpsout = $outname . ".xls";
} else {
 $cmpsout = $file1 . "_AND_$name" . "_$file2.xls";
}
open( my $FP1, '<', $file1) or die "could not open '$file1' $!";
open( my $FP2, '<', $file2) or die "could not open '$file2' $!";

open my $CMPS, '>', $cmpsout or die "could not open ' $cmpsout' $!";

my $i=0;
my @row1s;
my $line;
#read file1 into row
while ( $line = <$FP1> ) {
 chomp $line;
 $row1s[$i]=  [ split(/\t/, $line) ];
 $i++;
}

my @row2s;
#read file2 into row
my $j=0;
while ( $line = <$FP2> ) {
 chomp $line;
 $row2s[$j]= $line;
 $j++;
}

for my $aref1 (@row1s) {

 FILE2: for my $aref2 (@row2s) {

    my $match = 1;

    my $pattern = $aref1->[0];
    $pattern = quotemeta $pattern ;
    $aref2 = quotemeta $aref2;

  print "pattern: $pattern";<STDIN>;
print "aref2: $aref2"; <STDIN>;
    if ( $pattern !~ /$aref2/ ) {
     $match = 0;
     next;
    }

  print "MATCH-$match\n";<STDIN>;
    if ($match == 1) {
     print $CMPS "$aref1->[0]\n$aref1->[1]\n";
     last FILE2;
    }
     }
}




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

Date: Tue, 25 Jan 2011 20:01:20 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Quotemeta & Regex question re-posted as plain text
Message-Id: <mh6vj611tm10fgteh4o67a6enrbtf9188j@4ax.com>

"ela" <ela@yantai.org> wrote:
>I wish pasting the content won't make any character loss but my program and 
>data is like the following:
>
>You can see data1 is simply the substring of data2 and therefore I pass the 
>file containing data2 as $file1 and then the longer one as $file1 to my perl 
>program. $file1 content will be split by the delimiter tab and to check 
>against whether it contains any pattern that exist in data1.

Is your data1 a regular expression? If not then there is no need to
wield the big RE stick: as simple call of index() will tell you if it is
a substring of some other string.

If you insist on using m//, then you need to escape all RE
meta-characters in your pattern ...

[...]
>    my $pattern = $aref1->[0];
>    $pattern = quotemeta $pattern ;
>    $aref2 = quotemeta $aref2;

 ... which apparently you are doing here.

>    if ( $pattern !~ /$aref2/ ) {

But why are you calling the string "pattern" and the regular expression
pattern "aref". Are you trying to confuse your readers?

And why on earth are you doing a quotemeta on your string? Now your
string of maybe 
	(Hello-all)
has become 
	\(Hello\-all\)
and obviously that will not be matched by e.g. the quotemeta'ed 
	o\-a
which would be searching for a literal o, followed by a dash, followed
by an a.

jue


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3267
***************************************


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