Ask a Question related to PERL Miscellaneous, Design and Development.
-
Jeff 'japhy' Pinyan #1
Re: copy list until...
On 17 Sep 2003 [email]jimbo@jimbo.com[/email] wrote:
@oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents;>I would like to copy the list of presidents up to but not including
>current or future presidents (not for any particular reason):
>
>my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
>my @oldpresidents;
See 'perlop' for the .. operator (flip-flop, not range).
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
Jeff 'japhy' Pinyan Guest
-
copy a part of a list to another list
i store my search result in a list and want to divide that list into 3 or 4 smaller lists How can i do this please help.. -
ibm flash copy, hp business copy
dfreybur@yahoo.com (Doug Freyburger) wrote in message news:<7960d3ee.0406080727.42c9875a@posting.google.com>... but in either case, we still... -
previous favorites list copy comment
Regarding the comment earlier about copying one's favorites list, thank you for that info I've always wanted. Does someone know how to proceed... -
cdrecord copy destroyed another windows copy !!!
# cdrecord -msinfo dev=1,1,0 RAW/R16 0,221691 # cdrecord -msinfo dev=1,1,0 RAW/R16 44317,51858 what can be implied by those 2 messages ? How... -
cdrecord copy destroyed another windows NERO copy for re-writable media
# cdrecord -msinfo dev=1,1,0 RAW/R16 0,221691 # cdrecord -msinfo dev=1,1,0 RAW/R16 44317,51858 what can be implied by those 2 messages ? How... -
D Borland #2
Re: copy list until...
Using the $_ 'default' will help clean up your code a little, like so :-
my @presidents = qw(Roosevelt Kennedy Reagan Clinton Bush Jenna_Jameson );
my @oldpresidents;
foreach (@presidents)
{
last if( /^Bush$/ );
push @oldpresidents, $_;
}
Dagmar
<jimbo@jimbo.com> wrote in message
news:3f6860f0$0$58715$e4fe514c@news.xs4all.nl...current or> Hi,
>
> I would like to copy the list of presidents up to but not including, 'Jenna Jameson' );> future presidents (not for any particular reason):
>
> my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush'> my @oldpresidents;
>
> foreach my $president ( @presidents )
> {
> last if( $president eq 'Bush' );
> push( @oldpresidents , $president );
> }
>
> Is there a more perlquick way to do this?
>
---
This e-mail has been virus scanned and is certified virus Free.
Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
Version: 6.0.518 / Virus Database: 316 - Release Date: 9/11/03
D Borland Guest
-
Dave Saville #3
Re: copy list until...
On Wed, 17 Sep 2003 09:55:26 -0400, Jeff 'japhy' Pinyan wrote:
I was trying to understand how this worked but it seems it does not :-)>>>my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
>>my @oldpresidents;
> @oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents
Argument "true" isn't numeric in range (or flip) at try line 5.
Use of uninitialized value in range (or flip) at try line 5.
Use of uninitialized value in range (or flip) at try line 5.
Roosevelt
Kennedy
Reagan
Clinton
Bush
Jenna Jameson
(Perl 5.8.0 OS/2)
Regards
Dave Saville
NB switch saville for nospam in address
Dave Saville Guest
-
Abigail #4
Re: copy list until...
[email]jimbo@jimbo.com[/email] (jimbo@jimbo.com) wrote on MMMDCLXIX September MCMXCIII
in <URL:news:3f6860f0$0$58715$e4fe514c@news.xs4all.nl >:
"" Hi,
""
"" I would like to copy the list of presidents up to but not including current
"" future presidents (not for any particular reason):
""
"" my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
So, what happened with Truman, Eisenhower, Johson, Nixon, Ford and Carter?
And how are you going to distinguish between papa Bush and baby Bush,
if all you have are last names?
"" my @oldpresidents;
""
"" foreach my $president ( @presidents )
"" {
"" last if( $president eq 'Bush' );
"" push( @oldpresidents , $president );
"" }
""
"" Is there a more perlquick way to do this?
""
#!/usr/bin/perl
use strict;
use warnings;
my @pres = (qw /Roosevelt Truman Eisenhouwer Kenndey Johnson Nixon Ford
Carter Reagan/, "papa Bush", "Clinton", "baby Bush",
"Jenna Jameson");
my $f = 0;
my @old = grep {! (/baby Bush/ .. $f)} @pres;
print "@old\n";
__END__
Roosevelt Truman Eisenhouwer Kenndey Johnson Nixon Ford Carter Reagan
papa Bush Clinton
--
# Count the number of lines; code doesn't match \w. Linux specific.
()=<>;$!=$=;($:,$,,$;,$")=$!=~/.(.)..(.)(.)..(.)/;
$;++;$*++;$;++;$*++;$;++;`$:$,$;$" $. >&$*`;
Abigail Guest
-
Tad McClellan #5
Re: copy list until...
[email]jimbo@jimbo.com[/email] <jimbo@jimbo.com> wrote:
> up to but not including current or> my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush'> last if( $president eq 'Bush' );
In order to exclude the current Bush and include the previous Bush,
you would need some way of distinguishing between the two.
<grin>
--
Tad McClellan SGML consulting
[email]tadmc@augustmail.com[/email] Perl programming
Fort Worth, Texas
Tad McClellan Guest
-
Jeff 'japhy' Pinyan #6
Re: copy list until...
On Wed, 17 Sep 2003, Dave Saville wrote:
Wow, I did so many wrong things. I thought the operand had to be numeric>On Wed, 17 Sep 2003 09:55:26 -0400, Jeff 'japhy' Pinyan wrote:
>>>>>>>my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush' , 'Jenna Jameson' );
>>>my @oldpresidents;
>> @oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents
>I was trying to understand how this worked but it seems it does not :-)
for Perl to implicitly compare it to $., and I expected scalar context IN
the grep (shouldn't it be?), and I thought the flip-flop operator would
work in this case. It doesn't seem to work easily.
Sorry I didn't test that code...
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
Jeff 'japhy' Pinyan Guest
-
Uri Guttman #7
Re: copy list until...
>>>>> "J'P" == Jeff 'japhy' Pinyan <pinyaj@rpi.edu> writes:
J'P> Wow, I did so many wrong things. I thought the operand had to be numeric>>>>> @oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents
>> I was trying to understand how this worked but it seems it does not :-)
J'P> for Perl to implicitly compare it to $., and I expected scalar context IN
J'P> the grep (shouldn't it be?), and I thought the flip-flop operator would
J'P> work in this case. It doesn't seem to work easily.
grep EXPR is done in scalar context but the block provides list context
it seems. i don't think that is comparing anything to $. the problem is
... in list context is trying to make a range of vals from 'true' to
undef or whatever eq returns as false. so list .. barfs since one of the args
is a string and the other is a number.
and with a little fooling around i can't seem to get the .. to work
either. i think it seems to be freshly evaluated when entering the block
so it gets reset. not sure. but i have used scalar .. many times in
plain conditionals.
uri
--
Uri Guttman ------ [email]uri@stemsystems.com[/email] -------- [url]http://www.stemsystems.com[/url]
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- [url]http://jobs.perl.org[/url]
Damian Conway Class in Boston - Sept 2003 -- [url]http://www.stemsystems.com/class[/url]
Uri Guttman Guest
-
Brian Helterline #8
Re: copy list until...
<jimbo@jimbo.com> wrote in message
news:3f6860f0$0$58715$e4fe514c@news.xs4all.nl...current or> Hi,
>
> I would like to copy the list of presidents up to but not including, 'Jenna Jameson' );> future presidents (not for any particular reason):
>
> my @presidents = ( 'Roosevelt' , 'Kennedy' , 'Reagan' , 'Clinton' , 'Bush'
Last I checked, there is a 'Bush' on both sides on 'Clinton'
--
brian
Brian Helterline Guest
-
Chris Mattern #9
Re: copy list until...
Brian Helterline wrote:
Isn't there always?>
> Last I checked, there is a 'Bush' on both sides on 'Clinton'
>
Chris Mattern
Chris Mattern Guest
-
Helgi Briem #10
Re: copy list until...
On Wed, 17 Sep 2003 16:54:27 -0400, Chris Mattern <syscjm@gwu.edu>
wrote:
He he.>Brian Helterline wrote:>Isn't there always?>>
>> Last I checked, there is a 'Bush' on both sides on 'Clinton'
>>
--
Helgi Briem hbriem AT simnet DOT is
Excuse the munged address. My last
e-mail address was killed by spammers.
Helgi Briem Guest
-
Anno Siegel #11
Re: copy list until...
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
".." does an implicit compare with $. when it sees a constant. (It>> >>>>> "J'P" == Jeff 'japhy' Pinyan <pinyaj@rpi.edu> writes:>> >>> @oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents
> >>
> >> I was trying to understand how this worked but it seems it does not :-)
> J'P> Wow, I did so many wrong things. I thought the operand had to be numeric
> J'P> for Perl to implicitly compare it to $., and I expected scalar context IN
> J'P> the grep (shouldn't it be?), and I thought the flip-flop operator would
> J'P> work in this case. It doesn't seem to work easily.
>
> grep EXPR is done in scalar context but the block provides list context
> it seems. i don't think that is comparing anything to $. the problem is
> .. in list context is trying to make a range of vals from 'true' to
> undef or whatever eq returns as false. so list .. barfs since one of the args
> is a string and the other is a number.
>
> and with a little fooling around i can't seem to get the .. to work
> either. i think it seems to be freshly evaluated when entering the block
> so it gets reset. not sure. but i have used scalar .. many times in
> plain conditionals.
would be nicer if it only did that for numeric constants.) The solution
is to use a non-constant expression. "do { 1}" and "do { 0}" work
nicely for true and false. So:
my @oldpresidents = grep { do { 1} .. $_ eq 'Bush' } @presidents;
Anno
Anno Siegel Guest
-
Anno Siegel #12
Re: copy list until...
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
".." does an implicit compare with $. when it sees a literal. (It>> >>>>> "J'P" == Jeff 'japhy' Pinyan <pinyaj@rpi.edu> writes:>> >>> @oldpresidents = grep { "true" .. $_ eq "Bush" } @presidents
> >>
> >> I was trying to understand how this worked but it seems it does not :-)
> J'P> Wow, I did so many wrong things. I thought the operand had to be numeric
> J'P> for Perl to implicitly compare it to $., and I expected scalar context IN
> J'P> the grep (shouldn't it be?), and I thought the flip-flop operator would
> J'P> work in this case. It doesn't seem to work easily.
>
> grep EXPR is done in scalar context but the block provides list context
> it seems. i don't think that is comparing anything to $. the problem is
> .. in list context is trying to make a range of vals from 'true' to
> undef or whatever eq returns as false. so list .. barfs since one of the args
> is a string and the other is a number.
>
> and with a little fooling around i can't seem to get the .. to work
> either. i think it seems to be freshly evaluated when entering the block
> so it gets reset. not sure. but i have used scalar .. many times in
> plain conditionals.
would be nicer if it only did that for numeric literals.) The solution
is to use a non-literal expression. "do { 1}" and "do { 0}" work
nicely for true and false. So:
my @oldpresidents = grep { do { 1} .. $_ eq 'Bush' } @presidents;
Anno
Anno Siegel Guest
-
Bart Lateur #13
Re: copy list until...
Anno Siegel wrote:
Not good. Let me give an easier to test example:> my @oldpresidents = grep { do { 1} .. $_ eq 'Bush' } @presidents;
rint grep { do { 1 } .. $_ eq 'N' } 'A'..'Z';
This is supposed to print letter 'A' .. 'N', no? Yet it doesn't stop at
'N':
ABCDEFGHIJKLMNOPQRSTUVWXYZ
All of them. The problem is off course that when it finished at the end,
it'll start testing again upfront, and pass!
You need an extra flag, I'm afraid there's no way around it.
print grep { !$a++ .. $_ eq 'N' } 'A'..'Z';
-->
ABCDEFGHIJKLMN
Maybe somebody can find a way using double use of .. to eliminate the
variable, but I'm not sure.
--
Bart.
Bart Lateur Guest
-
Abigail #14
Re: copy list until...
Bart Lateur (bart.lateur@pandora.be) wrote on MMMDCLXX September MCMXCIII
in <URL:news:slbkmvo0lm5ab6nvcdcqtib30fgmtbhmmg@4ax.c om>:
() Anno Siegel wrote:
()
() > my @oldpresidents = grep { do { 1} .. $_ eq 'Bush' } @presidents;
()
() Not good. Let me give an easier to test example:
()
() rint grep { do { 1 } .. $_ eq 'N' } 'A'..'Z';
()
() This is supposed to print letter 'A' .. 'N', no? Yet it doesn't stop at
() 'N':
()
() ABCDEFGHIJKLMNOPQRSTUVWXYZ
()
() All of them. The problem is off course that when it finished at the end,
() it'll start testing again upfront, and pass!
()
() You need an extra flag, I'm afraid there's no way around it.
()
() print grep { !$a++ .. $_ eq 'N' } 'A'..'Z';
Sure there is:
print grep {!($_ eq "N" .. do {0})} "A" .. "Z"'
---> ABCDEFGHIJKLM
Or:
perl -wle 'print grep {!(/N/ ... /N/)} "A".. "Z"'
Abigail
--
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";
Abigail Guest
-
Anno Siegel #15
Re: copy list until...
Bart Lateur <bart.lateur@pandora.be> wrote in comp.lang.perl.misc:
Ugh... you're right. When I tested I must have seen what I expected,> Anno Siegel wrote:
>>> > my @oldpresidents = grep { do { 1} .. $_ eq 'Bush' } @presidents;
> Not good. Let me give an easier to test example:
>
> rint grep { do { 1 } .. $_ eq 'N' } 'A'..'Z';
>
> This is supposed to print letter 'A' .. 'N', no? Yet it doesn't stop at
> 'N':
>
> ABCDEFGHIJKLMNOPQRSTUVWXYZ
>
> All of them. The problem is off course that when it finished at the end,
> it'll start testing again upfront, and pass!
not what was actually there.
Abigail has suggested elegant solutions, but they're not very readable.> You need an extra flag, I'm afraid there's no way around it.
>
> print grep { !$a++ .. $_ eq 'N' } 'A'..'Z';
> -->
> ABCDEFGHIJKLMN
>
> Maybe somebody can find a way using double use of .. to eliminate the
> variable, but I'm not sure.
More straightforward:
my @chars = 'A' .. 'Z';
print grep { $_ eq $chars[ 0] .. $_ eq 'N' } @chars;
But that requires the original list to be a named array, not to mention
elegance. It also has problems when the original list elements are not
unique, but so do Abigail's solutions.
Anno
Anno
Anno Siegel Guest



Reply With Quote

