[30555] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1798 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 16 21:09:46 2008

Date: Sat, 16 Aug 2008 18:09:11 -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           Sat, 16 Aug 2008     Volume: 11 Number: 1798

Today's topics:
    Re: array comparision <ben@morrow.me.uk>
    Re: CLPM - a help group? <worrall-unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall.unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall.unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall.unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <worrall.unet@cs.bris.ac.uk>
    Re: CLPM - a help group? <john@castleamber.com>
    Re: CLPM - a help group? <m@rtij.nl.invlalid>
    Re: CLPM - a help group? <john@castleamber.com>
    Re: FAQ 4.2 Why is int() broken? <m@rtij.nl.invlalid>
        Help with Array Usage <pradeep.bg@gmail.com>
    Re: Help with Array Usage <jurgenex@hotmail.com>
    Re: Help with Array Usage <tadmc@seesig.invalid>
    Re: How to make PerlScript work in firefox3 on xpsp3 <spamtrap@dot-app.org>
    Re: List Context in a Boolean Expression <amphetamachine@gmail.com>
    Re: List Context in a Boolean Expression <mjcarman@mchsi.com>
    Re: List Context in a Boolean Expression <jurgenex@hotmail.com>
    Re: Newbie: Simple conditional on regexp match <szrRE@szromanMO.comVE>
    Re: Show specific part <rvtol+news@isolution.nl>
    Re: The Importance of Terminology's Quality <m@rtij.nl.invlalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 16 Aug 2008 22:37:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: array comparision
Message-Id: <dttjn5-0as.ln1@osiris.mauzo.dyndns.org>


Quoth h3xx <amphetamachine@gmail.com>:
> 
> # check each member by the indexes
> map {
>     $fail = 1 unless $nums1[$_] == $nums2[$_]
> } 0 .. $#nums1;

Why are you using map in void context? I know it works, but it's rather
bad style.

    for (0..$#nums1) {
        $fail = 1 unless $nums1[$_] == $nums2[$_];
    }

Better would be to exit the loop early as soon as you know it will fail,
viz.

    for (0..$#nums1) {
        unless ($nums1[$_] == $nums2[$_]) {
            $fail = 1;
            last;
        }
    }

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
                                                               ben@morrow.me.uk


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

Date: Sat, 16 Aug 2008 10:04:45 -0700
From: Adam Worrall <worrall-unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <LLDpk.4431$zv7.975@flpi143.ffdc.sbc.com>

Justin C wrote:
> On 2008-08-13, Adam Worrall <worrall+unet@remove.cs.bris.ac.uk> wrote:
>> Stop assuming everyone agrees with the "popular" views.
> 
> Stop assuming that everyone accept you doesn't.

So, it's ok for you and others to make a particular assumption but it's 
not for someone of the opposing view? Why the double standard?

   - Adam


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

Date: Sat, 16 Aug 2008 10:21:14 -0700
From: Adam Worrall <worrall.unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <D0Epk.18015$cW3.2803@nlpi064.nbdc.sbc.com>

Justin C wrote:
> On 2008-08-13, Adam Worrall <worrall-unet@cs.bris.ac.uk> wrote:
>> John Bokma wrote:
>>> Something that /appears/ to function as, in this case, a voluntary help 
>>> desk, doesn't make it one.
>> It also doesn't not make it one. Why is it you can dictate what it is or 
>> isn't yet any other person who gets buried for it?
> 
> Al Qaeda, selling cookies door-to-door, dressed as boy scouts,
> apparently raising money for Georgian orphans doesn't make Al Qaeda a
> charitable organisation either. They're still terrorists. 

What the hell does this have to do with anything?

> Even if they raised billions for orphans around the world would you
> disregard 9/11 and not call them terrorists?

I would not disregard 9/11 and they would indeed still be terrorists, 
but I ask again, what does this have to do with anything?

> This group is for discussion of Perl. That many people request, and get,
> help here changes nothing.

Exactly, it functions like like the volunteer desk I once worked on. 
That was the point, and some of you went nuts over it as if it was an 
attack on your religion.

> Did you come for a five minute argument or the full half-hour?

I have not run away from anything, so please do not imply otherwise.

> Most normal people would have just given up by now and either gone away
> or shut up, chalking one up to experience. 

Why, because _you_ saw that's right? That alone doesn't mean it _the_ 
correct, or the only correct course of action. _Not_ giving up is 
sometimes the better approach, and giving up here only tells that the 
wrong side has been allowed to win.

I'm not a coward, I will stand up for what I know is right and what is 
obviously wrong (which those who are wrong conveniently rely on time 
honored defensive mechanisms to make their non-points - such as just 
branding anyone they don't like as a "troll.")

> You seem intent on making as many enemies as possible,  and ending up
 > in a record number of kill-files.

You seem intent on implying my intent :) My goal here is/was not to make 
as many enemies as possible, but it's clear one cannot voice against 
what may be the status-quo in some people's eyes, without getting buried 
by the very people who think they own the news group, which is quite 
laughable in and of itself.

> Whatever your intention, if you request help here in the
> future you may well find yourself short of respondents through
> persevering with this stupid argument.

Thanks, but I know how to find help when I need it.

> Right or wrong, who cares when it's this tedious? Please, give it up.

So what? Then why are you reading it. Weather or not the thread is 
boring to you, who are you dictate to others how to proceed in a thread? 
  A thread is for everyone, not just you. If you don't like a way a 
thread is going, than _don't_ _read_ _it_. It's very simple.

In fact, this sort of thing exactly proves me point about the certain 
type of people on Usenet who which to push their will on others, which 
really has no place in a peer to peer environment. There is no central 
government, and people who act like they are the president is what's the 
problem here.

   - Adam


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

Date: Sat, 16 Aug 2008 10:36:21 -0700
From: Adam Worrall <worrall.unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <NeEpk.18022$cW3.16280@nlpi064.nbdc.sbc.com>

Sherm Pendley wrote:
> Adam Worrall <worrall-unet@cs.bris.ac.uk> writes:
> 
>> Sherm Pendley wrote:
>>> Adam Worrall <worrall+unet@remove.cs.bris.ac.uk> writes:
>>>
>>>> When did I say that? All I said was that it functions like a
>>>> _volunteer_ help desk
>>> What you said is wrong. Help desk workers are obligated to answer
>>> questions as given. 
>> No, not all help desk work that way. Please stop using that one
>> blanket statement to cover all various kinds of help services that
>> exist out there.
> 
> I *didn't* use it to cover various kinds of help services. 

Then why did you say I was wrong? I even used a personal experience and 
you still said I was wrong. You used an example that was different than 
what I said and what I said does apply to this group.

> Quite to the contrary, *you* are the one trying to stretch the 
 > definition.

Not true at all. I merely used a personal experience and compared the 
similarities to how this and many other groups function and the lot of 
you just jumped into defense mode as if someone was trying to tear down 
your religion.

> A help desk is a place where people can go with the expectation of
> receiving assistance, without commentary that isn't relevant to their
> questions.

There you go again. This does not really apply to a _volunteer_ help 
desk where you are _not_ obligated to answer _anything_, which _how_ 
_this_ _group_ _functions_.

> A place where such diversionary discussion is welcome and expected,
> such as this one, is not a help desk. People who come here might find
> help, or they might not.

I never actually this group or any other group is a help desk. I said it 
_functions_ just like a volunteer help desk, like the one I served on once.

>> so please spare me the superiority complex.
> 
> *You* are accusing *me* of having a superiority complex? 

If the shoe fits.

> I hate to break it to you, but I'm not the one walking into an 
 > established community, and telling everyone in it that they're doing
 > things wrong and ought to change their ways.

There you go again. I NEVER told anyone what they were doing was wrong. 
I was merely stating a fact about how this and many other group 
function. Please learn to read, learn to no twist the truth into 
something far from it, and frankly, it's easier to breathe when your 
head  has been dislodged from your lower carrier.

   - Adam


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

Date: Sat, 16 Aug 2008 10:39:50 -0700
From: Adam Worrall <worrall.unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <2iEpk.18023$cW3.11214@nlpi064.nbdc.sbc.com>

John Bokma wrote:
> Adam Worrall <worrall-unet@cs.bris.ac.uk> wrote:
> 
>> No, not all help desk work that way. Please stop using that one blanket 
>> statement to cover all various kinds of help services that exist out 
>> there. I have worked one on so I know first hand, so please spare me the 
>> superiority complex.
> 
> So you worked at a voluntary help desk that had no obligation to function?

That's not what I said. We were not obligated to give help, but we did 
so because we wanted to. We weren't even paid for the time spent there 
(though we were paid for other things outside of the desk.)

   - Adam


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

Date: Sat, 16 Aug 2008 10:41:22 -0700
From: Adam Worrall <worrall.unet@cs.bris.ac.uk>
Subject: Re: CLPM - a help group?
Message-Id: <ujEpk.18025$cW3.13072@nlpi064.nbdc.sbc.com>

Michael Carman wrote:
> Adam Worrall wrote:
>> No, not all help desk work that way.
> 
> Why the ^%*!& are you still arguing this?

Because it's the truth. I wouldn't have thought that anyone would have a 
problem with that...

   - Adam


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

Date: 16 Aug 2008 18:18:03 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: CLPM - a help group?
Message-Id: <Xns9AFC874DE2890castleamber@130.133.1.4>

Adam Worrall <worrall.unet@cs.bris.ac.uk> wrote:

> John Bokma wrote:
>> Adam Worrall <worrall-unet@cs.bris.ac.uk> wrote:
>> 
>>> No, not all help desk work that way. Please stop using that one
>>> blanket statement to cover all various kinds of help services that
>>> exist out there. I have worked one on so I know first hand, so
>>> please spare me the superiority complex.
>> 
>> So you worked at a voluntary help desk that had no obligation to
>> function? 
> 
> That's not what I said. We were not obligated to give help,

How did it function is you all were not obligated to give help? Of course 
we're not talking here about help out of the scope of the help desk.

> but we did
> so because we wanted to.

And you could come and go when ever you wanted, stay away without calling 
in sick. Do nothing the whole day, being rude at everybody without a 
single problem?

-- 
John    http://johnbokma.com/ - Hacking & Hiking in Mexico

Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html


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

Date: Sat, 16 Aug 2008 20:24:10 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: CLPM - a help group?
Message-Id: <pan.2008.08.16.18.24.10@rtij.nl.invlalid>

On Sat, 16 Aug 2008 10:36:21 -0700, Adam Worrall wrote:

>> A help desk is a place where people can go with the expectation of
>> receiving assistance, without commentary that isn't relevant to their
>> questions.
> 
> There you go again. This does not really apply to a _volunteer_ help
> desk where you are _not_ obligated to answer _anything_, which _how_
> _this_ _group_ _functions_.

That's not how a volunteer help desk functions, so stop pretending it is.

(And you have been explained this several times already so I'm not going 
to explain it again).

M4


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

Date: 16 Aug 2008 22:53:03 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: CLPM - a help group?
Message-Id: <Xns9AFCB5ED8B683castleamber@130.133.1.4>

Adam Worrall <worrall.unet@cs.bris.ac.uk> wrote:

> wrong. I was merely stating a fact about how this and many other group
> function.

This group *functioning* like a help desk, doesn't make it one. So there 
is no problem at all if someone here states that this group is *not* a 
helpdesk, simply because it isn't.

A nail can function like a screw, but that doesn't make a nail a screw, 
even though you have used one time a nail to replace a missing screw.

-- 
John    http://johnbokma.com/ - Hacking & Hiking in Mexico

Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html


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

Date: Sun, 17 Aug 2008 00:15:32 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: FAQ 4.2 Why is int() broken?
Message-Id: <pan.2008.08.16.22.15.32@rtij.nl.invlalid>

On Mon, 04 Aug 2008 15:32:41 +0200, Peter J. Holzer wrote:

> On 2008-07-30 19:50, John W Kennedy <jwkenne@attglobal.net> wrote:
>> Peter J. Holzer wrote:
>>> On 2008-07-30 14:03, John W Kennedy <jwkenne@attglobal.net> wrote:
>>>> However, Intel is dragging its feet on adding decimal floating point,
>>>> per IEEE-754r.
>>
>>> If there truly is demand for this, then that's good for IBM. They can
>>> sell lots of Power6 boxes.
>>
>> And z/Architecture.
> 
> z/Architecture isn't exactly mass-market.

Well, not mass market, but gaining in popularity pretty fast. You won't 
have one at home presumably, but all gigs I worked at the past ten years 
had several of those. Yes several, running multiple virtual machines.

OTOH, those virtual machines typically ran AIX (or linux) and did not 
take advantage (AFAIK) of the decimal floating point at all.

M4


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

Date: Sat, 16 Aug 2008 14:23:50 -0700 (PDT)
From: Deepu <pradeep.bg@gmail.com>
Subject: Help with Array Usage
Message-Id: <5265a42a-41dc-47d6-b3bc-5d70586c67ce@i24g2000prf.googlegroups.com>

Hi All,

I need some help on how i can proceed for the question below.

I have a file <test.txt> with the contents as below:

test 1 1 0
testa 1 1 0
test 2 2 0
test 1 2 0
test 2 3 0
testb 2 2 0
testc 3 3 0
test 2 4 0
test 3 3 0

Next i need to get the 'unique' numbers in the first column for the
row which starts with 'test'.

Next i need to overwrite the same file <test.txt> with the same
contents as above and in addition i need to add a line like 'testfinal
1 0 0' for the unique numbers.

Example Output file <test.txt>:

test 1 1 0
testa 1 1 0
test 2 2 0
test 1 2 0
test 2 3 0
testb 2 2 0
testc 3 3 0
test 2 4 0
test 3 3 0
<-- New lines below-->
testfinal 1 0 0
testfinal 2 0 0
testfinal 3 0 0

Thanks for the help.


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

Date: Sat, 16 Aug 2008 23:19:09 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Help with Array Usage
Message-Id: <ntnea49iu49qrttsla8gbk0s790u66b0j2@4ax.com>

Deepu <pradeep.bg@gmail.com> wrote:
>I have a file <test.txt> with the contents as below:
>
>test 1 1 0
>testa 1 1 0
>test 2 2 0
>test 1 2 0
>test 2 3 0
>testb 2 2 0
>testc 3 3 0
>test 2 4 0
>test 3 3 0
>
>Next i need to get the 'unique' numbers 

Whenever you hear the word 'unique' you should automatically think
'hash'. Just store those numbers as keys of a hash.
 
>in the first column for the
>row which starts with 'test'.

Just split() the line. BTW: I think you meant the second column

>Next i need to overwrite the same file <test.txt> with the same
>contents as above and in addition i need to add a line like 'testfinal
>1 0 0' for the unique numbers.

Better to just append the new information to the existing file, see the
append mode of open().
I guess you know how to print() to a file?

jue


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

Date: Sat, 16 Aug 2008 18:51:11 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Help with Array Usage
Message-Id: <slrngaepvf.qkf.tadmc@tadmc30.sbcglobal.net>

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


> I need some help on how i can proceed for the question below.


How to proceed depends a great deal on where you are.

How far toward solving your problem have you gotten?


> I have a file <test.txt> 


Part of the solution to your problem will then be opening a file for reading.

Do you know how to open a file for reading?

    my $fname = 'test.txt';
    open my $IN, '<', $fname or die "could not open '$fname' $!";


> with the contents as below:
>
> test 1 1 0
> testa 1 1 0
> test 2 2 0
> test 1 2 0
> test 2 3 0
> testb 2 2 0
> testc 3 3 0
> test 2 4 0
> test 3 3 0


Part of the solution to your problem will then be reading from an
opened filehandle.

Do you know how to read from an opened filehandle?

    while (<$IN>) {


> Next i need to get the 'unique' numbers in the first column 


There are no unique numbers in the "first" column.

There are no numbers at all in the first column.

There are no unique numbers in the second column, only duplicated numbers.

This is important, as using the proper term helps you find the solution.

    perldoc -q duplicate 

        How can I remove duplicate elements from a list or array?


> for the
> row which starts with 'test'.


Errr, *every* row shown starts with 'test'.

        if ( /^test\D+(\d+)/ ) {
            $final{$1}++;
        }


> Next i need to overwrite the same file <test.txt> with the same
> contents as above 


No you don't.

There is not much point in rewriting what is already there.


> and in addition i need to add a line 


Part of the solution to your problem will then be appending
to a file.

Do you know how to append to a file?


> like 'testfinal
> 1 0 0' for the unique numbers.

    open my $OUT, '>>', $fname or die "could not open '$fname' $!";
    foreach my $num ( sort {$a <=> $b} keys %final ) {
        print $OUT "testfinal $num 0 0 \n";
    }
    close $OUT;


> Thanks for the help.


If you are truly thankful, then please follow the Posting Guidelines
that are posted here frequently.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Sat, 16 Aug 2008 10:04:36 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to make PerlScript work in firefox3 on xpsp3
Message-Id: <m1myjdgiob.fsf@dot-app.org>

V S Rawat <vsrawat@gmail.com> writes:

> How to make PerlScript work in firefox3 on xpsp3?

Make FireFox support Active Scripting.

    <http://en.wikipedia.org/wiki/Active_Scripting>

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Sat, 16 Aug 2008 14:21:12 -0700 (PDT)
From: h3xx <amphetamachine@gmail.com>
Subject: Re: List Context in a Boolean Expression
Message-Id: <00bfb9b6-fc1b-4e4a-8473-9b7d6fc2b4f0@r66g2000hsg.googlegroups.com>

On Aug 16, 7:21=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> h3xx <amphetamach...@gmail.com> wrote:
> >I have a question about when things are and aren't taken to be a list
> >when doing boolean comparisons. I tested the following code:
>
> >my @foo =3D qw/ one two three /;
> >my @bar =3D ();
>
> >my @baz =3D @bar || @foo;
> >print "@baz\n";
>
> >This produces "one two three." Hence, we know that a list CAN be
> >returned from a boolean expression. I tried it the other way:
>
> >my @baz =3D @foo || @bar;
> >print "@baz\n";
>
> >This produced "3," the scalar evaluation of @foo. This is the same for
> >any amount of parentheses and using the "or" operand instead of "||."
> >Now, what happened?
>
> See The Fine Manual: perldoc perlop, section =A0"C-style Logical Or":
> =A0 =A0The "||" and "&&" [...] return the last value evaluated.
> and
> =A0 =A0 In particular, this means that you shouldn't use this for selecti=
ng
> =A0 =A0 between two aggregates for assignment:
> =A0 =A0 =A0 =A0 @a =3D @b || @c; =A0 =A0 =A0 =A0 =A0 =A0 =A0# this is wro=
ng
>
> jue

Ah. Thank you. I guess I'll just have to solve the problem using the
tried-and-true trinary method:

my @foo =3D qw/ one two three /;
my @bar =3D ();

my @baz =3D @bar ? @bar : @foo;


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

Date: Sat, 16 Aug 2008 23:51:38 GMT
From: Michael Carman <mjcarman@mchsi.com>
Subject: Re: List Context in a Boolean Expression
Message-Id: <eKJpk.246277$TT4.36999@attbi_s22>

Jürgen Exner wrote:
> 
> See The Fine Manual: perldoc perlop, section  "C-style Logical Or":
>    The "||" and "&&" [...] return the last value evaluated. 
> and
>     In particular, this means that you shouldn't use this for selecting
>     between two aggregates for assignment:
>         @a = @b || @c;              # this is wrong

That's the warning, but I don't think you quoted quite enough to explain
the behavior. I had to look it up myself because it seemed odd to me
that the left and right operands wouldn't be evaluated in the same
(scalar vs. list) context.

    Scalar or list context propagates down to the right operand if
    it is evaluated.

So the expression

    @baz = @bar || @foo;

really means

    @baz = scalar @bar || @foo;

The left operand is always evaluated in scalar context (it's a boolean
test) but the right operand takes it's context from the expression it's
used in.

The right way to write this is:

    @baz = @bar ? @bar : @foo;

-mjc


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

Date: Sun, 17 Aug 2008 00:40:28 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: List Context in a Boolean Expression
Message-Id: <5ssea4ll7mkgmo3eiih7stk00ahr2nse5p@4ax.com>

Michael Carman <mjcarman@mchsi.com> wrote:
>Jürgen Exner wrote:
>> 
>> See The Fine Manual: perldoc perlop, section  "C-style Logical Or":
>>    The "||" and "&&" [...] return the last value evaluated. 
>> and
>>     In particular, this means that you shouldn't use this for selecting
>>     between two aggregates for assignment:
>>         @a = @b || @c;              # this is wrong
>
>That's the warning, but I don't think you quoted quite enough to explain
>the behavior.

Well, no, of course I didn't. It was a teaser ...

> I had to look it up myself because it seemed odd to me

 ... to have you do exactly that. After all, I assume you are old enough
not to need someone to read the man pages to you.

jue


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

Date: Sat, 16 Aug 2008 11:53:16 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: Newbie: Simple conditional on regexp match
Message-Id: <g877mu0tv6@news4.newsguy.com>

xhoster@gmail.com wrote:
> Kenneth Brun Nielsen <kenneth.brun.nielsen@googlemail.com> wrote:
>> I need to perform a conditional on a regexp match. How can I do that
>> (easily) in PERL.
>>
>> The following prints out all lines - also the ones, that doesnt match
>> the regular expression.
>
> I don't believe you.  Show us an example of soatest.soa that
> demonstrates this behavior.

He said in his other reply that he forgot to escape the pipe in the 
regex (so it wasn't meant to be an alternation.)

>> #!/usr/bin/perl -w
>> open FILEHANDLE, "soatest.soa";
>> while (<FILEHANDLE>){
>>     if (/^\*| XI/) {
>>         print "match in line: $.\n";
>>     }
>> }

So it should be:

   while (<FILEHANDLE>){
       if (/^\*\| XI/) {

-- 
szr 




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

Date: Sat, 16 Aug 2008 20:37:40 +0200
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: Show specific part
Message-Id: <g87e41.gc.1@news.isolution.nl>

Amy Lee schreef:

> I'm a newbie in Perl and do some work in Bioinformatics. I write a
> tiny script to show the sequences. However, I have a problem while
> I'm going to further process. [...]
> And I hope I can save the whole protein sequences with their
> tags(>blahblah) into a file, like "protein" and save DNA sequences
> into "dna" file.


The following code expects "good input". It will be fooled by mixed-up
input like

>xxx
IGRRQWASLVTPMAKFDPEIVLEFYANAWPTEEGVRDMRSWVRGQWIPFDADA
tatactgatttccaggaggaaatagggcgccggcagtgggcatcactggttactcccatg
IGQLLGYPLVLEEGQECEYGQRRNRSDGFDEEA
>yyy
gaggccatcaagggatggtcgtttctccgggagcaacgcgtccagctcagggacgacgag
IGRRQWASLVTPMAKFDPEIVLEFYANAWPTEEGVRDMRSWVRGQWIPFDADA
tatactgatttccaggaggaaatagggcgccggcagtgggcatcactggttactcccatg
gccaagttcgatccggaaatagtccttgagttttatgccaatgcttggccaacagaggag


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

  my ($fh_dna, $fh_pro) = (\*STDOUT, \*STDERR);

  my $tag;

  while ( <DATA> ) {
      if ( /^>.+/ ) {
          $tag = $_;
          next; ###
      } elsif ( /^[acgt]+$/ ) {
          select $fh_dna;
      } elsif ( /^[A-Z]+$/ ) {
          select $fh_pro;
      } else {
          die;
      }
      $tag and print $tag and undef $tag;
      print;
  }

__DATA__
>xxx
IGRRQWASLVTPMAKFDPEIVLEFYANAWPTEEGVRDMRSWVRGQWIPFDADA
IGQLLGYPLVLEEGQECEYGQRRNRSDGFDEEA
>yyy
gaggccatcaagggatggtcgtttctccgggagcaacgcgtccagctcagggacgacgag
tatactgatttccaggaggaaatagggcgccggcagtgggcatcactggttactcccatg
gccaagttcgatccggaaatagtccttgagttttatgccaatgcttggccaacagaggag
>zzz
EGDAHAVSSTPAWVKPQQTPHGTHQYAQHHPSFSAHAGNASSST
PVQPKAPTQREAPQVPTPNTTRPAGNSNTTRNFPPRPLPEFTPLPMTYEDLLPSLIANHL
AVVTPGRVLEPPFPKWYDPNATCKYHGGVPGHSVEKCLALKYKVQHLMDAGWLTFQEDRP
NVRTNPLANHGGGAVNAVESD
>qqq
tggaagccgcagaagaatcgttagaaactgctttccag
tcttttgaggtggtcagcatttcctccgtggactccctctttgggcaaccttgtctgtcc
gatgcagcggtaatgatggcccgagttatgttggggaacggttttgaacccgggatgggt
ttagaaaaaaacaacggcggcataactagc


"shrunken code" variant of the while-loop:

  while ( <DATA> ) {
    /^>.+/      and $tag = $_ and next;
    /^[acgt]+$/ and select($fh_dna) or
    /^[A-Z]+$/  and select($fh_pro) or die;
    print $tag and undef $tag if $tag;
    print;
  }

-- 
Affijn, Ruud

"Gewoon is een tijger."



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

Date: Sun, 17 Aug 2008 00:10:59 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: The Importance of Terminology's Quality
Message-Id: <pan.2008.08.16.22.10.56@rtij.nl.invlalid>

On Thu, 14 Aug 2008 18:33:30 -0400, John W Kennedy wrote:

> Actually, I was thinking of the 1401. But both the 1620 and the 1401
> (without the optional Advanced Programming Feature) share the basic
> omission of any instruction that could do call-and-return without
> hard-coding an adcon with the address of the point to be returned to.
> (The Advanced Programming Feature added a 1401 instruction, Store
> B-address Register, that, executed as the first instruction of a
> subroutine, could store the return-to address.)

Raaaagh!!!!

Don't. Bring. Back. Those. Nightmares. Please.

The 1401 was a decent enough processor for many industrial tasks -- at 
that time -- but for general programming it was sheer horror.

M4


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

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 V11 Issue 1798
***************************************


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